Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Wojtek

Pages: 1 2 [3] 4 5
31
Feedback / Survey
« on: February 28, 2010, 11:53:58 am »
Hello,

My friend writes a PhD Dissertation at Faculty of Management and Social Communication at the Jagiellonian University in Krakow, Poland. He is looking for programmers working in different countries and different cultures and he would be very thankful if You could help him with research by filling in the online questionnaire: http://www.survey.k-informatix.com/survey.php?code=ad0234 and/or share this post among Your colleagues.

The research is on organizational culture and its connection to a burnout syndrome and should not take more than 15-20 minutes.

Thanks,
Wojtek

32
Support / Re: Helper class for camera operations
« on: February 21, 2010, 11:50:51 pm »
Hello,

I have spent some additional time on the camera managers and came with new version of FollowingCameraManager. It behaves a little bit different than DummyObjectCameraManager. It is visible during object rotations, especially when camera perspective is changed (left mouse button) and object is rotated in 2 dimensions (arrow keys).

There is a link with sources: sources and app

And there are changed files:
Code: [Select]
public class FollowingCameraManager extends AbstractCameraManager
{
    private static final double MAX_POS_VERTICAL_ANGLE = Math.PI / 4;
    private static final double MIN_NEG_VERTICAL_ANGLE = 2 * Math.PI
    - MAX_POS_VERTICAL_ANGLE;
    private static final double RAD_BY_PIXEL = 1 / 200.0;

    private double camHAngle, camVAngle;

    @Override
    public void rotate(final double deltaX, final double deltaY)
    {
camVAngle = limitVerticalAngle(MathUtil.normalizeAngle(camVAngle
+ deltaY * RAD_BY_PIXEL));
camHAngle = MathUtil.normalizeAngle(camHAngle - deltaX * RAD_BY_PIXEL);
    }

    private double limitVerticalAngle(double angle)
    {
if (angle > MAX_POS_VERTICAL_ANGLE && angle < Math.PI)
    return MAX_POS_VERTICAL_ANGLE;
else if (angle < MIN_NEG_VERTICAL_ANGLE && angle > Math.PI)
    return MIN_NEG_VERTICAL_ANGLE;
return angle;
    }

    @Override
    public void update(Object3D target)
    {
resetCamera();
updateTargetRotation(target);
updateCameraPosition(target);
    }

    private void resetCamera()
    {
getCamera().setPosition(SimpleVector.ORIGIN);
getCamera().setOrientation(new SimpleVector(0, 1, 0),
    new SimpleVector(0, 0, -1));
    }

    private void updateTargetRotation(Object3D target)
    {
SimpleVector rotationVector = MathUtil.deriveAngles(target.getRotationMatrix());
getCamera().rotateAxis(getCamera().getYAxis(), -rotationVector.y);
getCamera().rotateAxis(getCamera().getZAxis(), -rotationVector.z);
getCamera().rotateAxis(getCamera().getXAxis(), -rotationVector.x);
getCamera().rotateCameraX((float) camVAngle);
getCamera().rotateCameraY((float) camHAngle);
    }

    private void updateCameraPosition(Object3D target)
    {
getCamera().setPosition(target.getTransformedCenter());
getCamera().moveCamera(Camera.CAMERA_MOVEOUT, getDistance());
    }

    @Override
    public void setCamera(Camera cam)
    {
super.setCamera(cam);
camHAngle = 0;
camVAngle = 0;
    }
}

Code: [Select]
public final class MathUtil
{

    private static final double FULL_ANGLE = 2 * Math.PI;

    public static double normalizeAngle(double angle)
    {
while (angle > FULL_ANGLE)
    angle -= FULL_ANGLE;
while (angle < 0)
    angle += FULL_ANGLE;
return angle;
    }
    public static SimpleVector deriveAngles(Matrix mat)
    {
float[] m = mat.getDump();
double heading;
double attitude;
double bank;
if (m[4] > 0.998) { // singularity at north pole
heading = Math.atan2(m[2],m[10]);
attitude = Math.PI/2;
bank = 0;

}
else if (m[4] < -0.998) { // singularity at south pole
heading = Math.atan2(m[2],m[10]);
attitude = -Math.PI/2;
bank = 0;
}
else{
heading = Math.atan2(-m[8],m[0]);
bank = Math.atan2(-m[6],m[5]);
attitude = Math.asin(m[4]);}
return new SimpleVector(bank,heading,attitude);
    }
}

Thanks,
Wojtek

33
Support / Re: Helper class for camera operations
« on: February 15, 2010, 08:56:50 pm »
Ok, I understand it now.

Thanks for all the help,
Wojtek

34
Support / Re: Helper class for camera operations
« on: February 12, 2010, 01:11:30 am »
Wow, it works :) Thanks a lot for help - I would struggle with it for a long time....
The other thing is that for sure I will have to read more about 3d gemetry to be able to understand it well.

In one of previous posts you have written:
Quote from: paulscode
I think the reason for this behavior is probably that you are using ship.rotateZ and ship.rotateX, which rotates the ship around its relative axis'.  When using one one of them, that axis is constant, so rotating only vertically or only "horizontally" behaves the way you would expect.  However, when you do rotations around both axis', they are no longer constant.

I really can't explain the problem any better than that, because honestly every time I try to figure it out logically, it seems like what you are doing should work, but it doesn't.
I am not sure if my observation would be usefull, especially that you have already solved the problem, but I have noticed that if you apply X and Z rotation to object and try to get angles by deriveAngles method, you will get 3 non-zero angles instead of 2.
I have found an article about rotation matrixes (link) which shows 2 interesting things:
* depending on order you apply rotations, the rotation matrix will look different
* you can apply rotations in only 2 dimensions, but 3rd dimension is also affected (see example where object is rotated by 90* about X, 90* about Y and -90* about X and it gives rotation of 90* about Z)
I also remember that EgonOlsen was writing about rotation order some time ago, so that could be a cause of strange behavior.
Perhaps if I reset ship rotations every time and apply full angles instead of doing incrementary rotations in different directions it will work good (I have not checked that yet, but just for pure curiosity I will)...

Thanks a lot one more time,
Wojtek

35
Support / Re: Helper class for camera operations
« on: February 11, 2010, 04:49:48 pm »
Hi,

Thanks for help and example code :) Regarding to way I am using JPCT I just wanted to wrap it quickly to show example - normally I use GLCanvasRenderer and swing so you can change freely if you like ;-)
 
I have run the example application and see that it is working much better :)
I have a one question about it.
When you run the app and press F3, and rotate ship horizontally only (using right/left arrows), you see that world is moving horizontally,
when you do the same but move vertically (up/down arrows), world is also moving vertically. Now, when you rotate ship vertically and horizontally and try for example to move up, you no longer sees that world is moving vertically but it is rather rotating.
What needs to be done to eliminate that effect, ie. no matter in which directions ship is rotated, when you rotate ship, the world will always move in the same way?

I started thinking that perhaps it is because you are looking on a world sphere from a different perspective, but in fact you are always looking at it from the same distance (sphere radius) because world sphere center is equal to camera position, so this should not be related to the perspective...

Thanks,
Wojtek

36
Support / Re: Helper class for camera operations
« on: February 10, 2010, 09:46:00 pm »
Hi, there is an example app that is using my camera managers: sources and app
Use left mouse button to rotate camera, arrows to rotate ship, mouse wheel to zoom, F1 or F2 to change camera manager.

Well, if you press F1, you will use OrbitingCameraManager which supports points 1-3:
It orbits around the ship so you can see it from different angles (there is a limitation for vertical rotations, so you cannot flip the ship).
It also looks at the ship from the same distance, so if ship moves, camera moves too.
And it allows to zoom in/zoom out (with some hardcoded limitations)

If you press F2 (it is default when you run the app), you will use FollowingCameraManager which supports 1-4 points.
It works similar as previous camera, but when ship is rotating, camera is rotating with it (so there is an effect of rotating world) while the first camera is not rotating (so there is an effect of rotating ship).

Personally I think that the second camera could be better for my purpose because it is not need to change camera perspective when ship is turning back.

Currently, it is only possible to turn left/right in my game (turning up and down is reserved for special effects like hyperjumps) so both cameras works well in that case, but I have noticed problem with FollowingCameraManager when you rotate ship in both directions.
Probably it is something wrong with the method SimpleVector MathUtil.deriveAngles(Matrix mat) or somewhere in the code of camera manager.

PS. I someone find them usefull, I can parametrize all the hardcoded constants, and make it more user friendly...

Thanks,
Wojtek

37
Support / Re: Helper class for camera operations
« on: February 09, 2010, 11:33:22 pm »
I see a lot of comments, thanks a lot. Let me create and post there a simple example app, so I will be able to explain better what I mean (especially with 4th point) and show how it works.
Regarding to paulscode suggestion about using parent/child relationship I have tried that (attach a child dummy object to target object, rotate/move it and set the camera position to it) but I spent one evening on that without success :(

For now I tried to use a code that .jayderyu posted and apply it to my class, however the range of returned angles for x and z (I am not using y so I have not checked it well) is from -PI/2 to PI/2 range, so they does reflect a full angle.
I have done a little modification in that code and it works for me now at least in most cases (I will show that also on example app):
Code: [Select]
    public SimpleVector deriveAngles(Matrix mat)
    {
SimpleVector s = new SimpleVector();
float[] m = mat.getDump();
s.x = (float) Math.atan(m[9] / m[10]);
s.y = (float) Math.asin(-m[2]);
s.z = (float) Math.atan(m[4] / m[0]);

if (m[0] < 0 && m[5] < 0)
    s.z += Math.PI;
if (m[5] < 0 && m[10] < 0)
    s.x += Math.PI;
return s;
    }

When I only wrap up code to an example app, I will post it here.

Thanks,
Wojtek

38
Support / Helper class for camera operations
« on: February 09, 2010, 01:15:14 am »
Hello,

I am trying to create a helper class that will attach camera to an object and allow to do following things:
1. show object from different angles (orbit camera around object)
2. follow the object (ie. when object moves, camera is also moving after it)
3. zoom in / zoom out
4. ignore object rotations (ie. when object is rotating, the camera is rotating with it, so it is looking always at the same point).

With your help (especialy paulscode - thanks a lot btw), I have created a simple class that does the most of that functionality (except 4th point).
Recently I started correcting it to make the 1st point working better and to implement missing one.

Well I have made a first thing working ok, but because of my lacks of 3d math knowledge I stucked in the last task.

I do not know how to get horizontal rotation angle (Y) and vertical rotation angle (Z) by which object3D is rotated. I need those angles to be able to rotate camera.
Can anybody help me with it?
I am asking about angles because matrix operations are still a little bit too difficult for me to understand so I have made my class working in following way:

1. During the initialization, I am positioning the camera after object
Code: [Select]
SimpleVector vec = new SimpleVector(0, -getDistance(), 0);
vec.add(object.getTransformedCenter());
cam.setPosition(vec);
and setting the camera orientation by:
Code: [Select]
cam.setOrientation(new SimpleVector(0, 1, 0), new SimpleVector(0, 0, -1));2. During the update of camera position (just before rendering) I am setting camera to the same point as object is and move it out by getDistance():
Code: [Select]
cam.setPosition(target.getTransformedCenter());    
cam.moveCamera(Camera.CAMERA_MOVEOUT, getDistance());
3. During camera rotation (orbiting effect) I am:
* moving camera in by getDistance(), saving its position, and setting pos to [0,0,0]
* rotating back X and Y by angles the camera was rotated in previous step
* increasing angles by delta values
* rotating Y and X by new angles
* restoring camera last position by moving camera out and adding saved position
Code: [Select]
private void restoreCameraPosition(Camera cam, SimpleVector shift)
{
cam.moveCamera(Camera.CAMERA_MOVEOUT, getDistance());
shift.add(cam.getPosition());
cam.setPosition(shift);
}

private SimpleVector moveCameraToZeroPosition(Camera cam)
{
cam.moveCamera(Camera.CAMERA_MOVEIN, getDistance());
SimpleVector shift = cam.getPosition();
cam.setPosition(new SimpleVector(0, 0, 0));
return shift;
}

@Override
public void rotate(double deltaX, double deltaY)
{
Camera cam = getCamera();
SimpleVector shift = moveCameraToZeroPosition(cam);
cam.rotateX((float) -vAngle);
cam.rotateY((float) -hAngle);
vAngle = limitVerticalAngle(MathUtil.normalizeAngle(vAngle + deltaY
/ 200));
hAngle = MathUtil.normalizeAngle(hAngle - deltaX / 200);
cam.rotateY((float) hAngle);
cam.rotateX((float) vAngle);
restoreCameraPosition(cam, shift);
}


Now, what I am planning to do is to modify the method that is updating camera position and, get (somehow) the rotation angles from target object and apply them to camera in the same way as I am doing it during camera rotation (ie. I will add them to the stored hAngle and vAngle). Probably I will have to store both angles separately to distinguish what angle is related to change the camera orbit position and what is related to object rotation.

When I finish that work I will post the full code for that class hoping that it may be usefull for others too...

Thanks,
Wojtek

39
Support / Re: Some questions.
« on: February 07, 2010, 02:13:46 pm »
Hello,

For my game I am sending a rotation angles of object and its coorinates (x,y,z) - 3 angles sent as float or double are smaller than matrixes.
However I am not saying it is best way to synchronize objects. I have heard that for games such as Quake, instead of sending coords and rotation parameters the action messages are sent (like: object started moving in that way, or object started rotating) and all clients (including server) symulates those moves/rotations by them own. In that case you do not have to send such a much amount of messages, but there is a still problem to synchronize clients timings etc. which may be more difficult ;-)

For the second question I cannot help you yet - in my game, server does not know JPCT models and currently I do not have collision implemented. However, I was thinking of solving it in one of two ways:
* the game client checks collision and when it occurs, it sends info to server - server will have to validate that message somehow and process collision
* server have a very simple models of objects (low polys, no textures etc) and it uses them for collision testing, however I am little afraid if this will work, because server processes much more objects than client and this may kill the server performance or use too much memory (I have many worlds/play arenas where client 'sees' only one at time while server processes all of them....)

I am only using 3ds files so I cannot help you with objs :(
For loading 3ds files I am using following method (that I have found in some post on forum):
Code: [Select]
static public Object3D loadObject(String path, String name, int scale)
{
Object3D[] model = Loader.load3DS(path + name + ".3ds", scale);
if (model.length == 0)
return null;
Object3D o3d = new Object3D(0);
Object3D temp = null;
for (int i = 0; i < model.length; i++)
{
temp = model[i];
temp.setCenter(SimpleVector.ORIGIN);
temp.rotateZ((float) (-.5 * Math.PI));
temp.rotateMesh();
temp.setRotationMatrix(new Matrix());
o3d = Object3D.mergeObjects(o3d, temp);
o3d.build();
}
return o3d;
}

I hope my post is helpful,
Thanks,
Wojtek

40
Support / Re: Question about transparency
« on: February 07, 2010, 01:49:56 pm »
Hello,

Thank you for your posts (well I am glad that you like the screenshot ;)).
Your posts helped me with solving the problem. There was two things that caused it.
The first one was that my objects had Object3D.TRANSPARENCY_MODE_ADD flag applied that made the stars showing through the billboard no matter of transparency value.

To solve it, I have removed that flag (so default mode is on now) and set the billboard transparency to 255 (at least Object3D.setTransparency() accepts values bigger than 1. When it was 1, the object was still transparent).

The other thing is that I did not have to remove alpha information from image and make invisible pixels black - it also works well with "new Texture(textureId, true)" :)

There is a screenshot:


Thanks,
Wojtek

41
Support / How LensFlare hiding works?
« on: February 07, 2010, 01:50:48 am »
Hi,

I was playing a little bit with the LensFlare class. It i a very nice feature :)
I see in the documentation that it is possible to enable hiding of that effect when there is something on a way between camera and light source (in fact it is enabled by default). During my play with that effect I was not able to achieve that and I was even able to see the same behavior on a terrain demo...
The first image shows the sun and lens flare effect:

When I hide behind mountain, the effect is still applied:

Is is a correct behavior? And if yes, how the hiding feature works?

Thanks,
Wojtek

42
Support / Question about transparency
« on: February 07, 2010, 01:40:56 am »
Hello,

I have a problem with setting correct transparency value for billboard image.
I have a spherical object that displays the galaxy background (stars etc) and a flat object with billboard flag (moon) that is closer to the camera than galaxy background.
The moon has transparency set to 255 and the texture image has fully transparent corners (to make moon round) and non transparent center (moon globe). The problem is that the stars from background image are rendered over moon surface (which should not happen, because moon should fully cover the background). Please see the screenshot.

Do you have any idea what could be wrong? I cannot set the transparency to -1 for moon object because the texture corners will be displayed :(
I can add that I am rendering it with hardware renderer.

Thanks,
Wojtek

43
Support / Re: How to add texture to textured object
« on: January 12, 2010, 11:19:34 pm »
Hello,

Excuse me that I have not replied earlier :(
I have tested that new method and it seems to work correctly.

Thanks,
Wojtek

44
Support / Re: obj world
« on: December 14, 2009, 07:02:13 pm »
Hi,

The Object3D class has "PolygonManager getPolygonManager()" method, which you can use to get the texture id assigned to given polygon of your object (see "int getPolygonTexture(int polyID)" method of PolygonManager).

Next, you can use TextureManager.getInstance(). getTextureByID(textureId) to get the texture object that is associated to id returned by PolygonManager.

Hope that helps.

BTW. It is not possible to get the list of textures if polygon has more textures assigned.

Wojtek

45
Support / Re: How to add texture to textured object
« on: December 14, 2009, 12:05:23 am »
Ok, so i will hold that information in my classes for now.

Thanks,
Wojtek

Pages: 1 2 [3] 4 5