www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Melssj5 on March 20, 2006, 10:39:34 pm

Title: alignment of an object3D
Post by: Melssj5 on March 20, 2006, 10:39:34 pm
how to get and set the alignment of an object3D?. Well for my game I decided to transmit the position and direction of some objects3D istead of the entire World, but I have noticed that the object3D class has no methods to do it, I mean, I can get the position easyly and the axis x, y and z, but how can align an object3D to that values if an object3D can be only aligned to a camera.
Title: alignment of an object3D
Post by: EgonOlsen on March 20, 2006, 11:26:48 pm
Just transfer the rotation matrix of the Object3D on the server (or even simpler: the dump obtained by Matrix.getDump()) and set the client's object rotation matrix to that (Matrix.setDump()). That should do the trick.
Title: alignment of an object3D
Post by: Melssj5 on March 21, 2006, 06:00:12 pm
ok, but what about the camera? the camera has not a get or set RotationMatrix method.
Title: alignment of an object3D
Post by: EgonOlsen on March 21, 2006, 06:04:58 pm
It has, the naming is just different, because it's inherited from BufferedMatrix. What is set- and getRotationMatrix() for an Object3D is set- and getBack() for the Camera.
Title: alignment of an object3D
Post by: Melssj5 on May 15, 2006, 05:04:59 am
Hi, I still have problems with that.!!!

OK, i got the rotarion Matrix from the Object3D, tranfer it, and use it on the setBack () metho of the camera, but it dont work.

1) When it should to to the right the camera go to left and viceversa. also up-down.

2) it seems that the axis of the matrix are not changing. The methos rotateX () always rotates respect to the same absolute axis not to the object3d relative.

I have been stuck on this for many weeks, but was shy to ask again. what can I do.???
Title: alignment of an object3D
Post by: EgonOlsen on May 15, 2006, 08:00:32 pm
Invert the matrix before applying it to the camera.
About the axis-thing: Yes, that's the way it's supposed to be. If you need the actual axis of the object, you may get this axis from the object and use the rotateAxis(...)-method instead.
Title: alignment of an object3D
Post by: Melssj5 on June 07, 2006, 08:01:20 am
Hi, how can I do it, sorry for asking here a way to do it, but nowadays I have nothing of time for researching this thing. Well, in fact I can obtain the current axis of the object by the getters methods, but how can I align a camera to them. I tried to rotate the camera on x, y and z axis, but the x, y and z axis obtained from the object 3d are relatives and no the proyections over the abosulte axis. How can I do it. Please help.
Title: alignment of an object3D
Post by: EgonOlsen on June 07, 2006, 08:12:07 am
Align the camera with an object:
Code: [Select]
camera.setBack(obj.getWorldTransformation().invert3x3());

Align the camera with an  arbitrary axis:
Code: [Select]
camera.setBack(axis.getRotationMatrix().invert3x3());

Hope this helps.
Title: alignment of an object3D
Post by: Melssj5 on June 08, 2006, 08:11:02 am
No, it didnt worked, is the same problem that when beginning, it still is rotating respect to the absolute world axis. and not to the relative object3d axis.
Title: alignment of an object3D
Post by: Melssj5 on June 08, 2006, 08:13:20 am
I guess I should add a camera for each client for the server calcs and tranfer it to each client. But this will increase the bandwidth usage. Any other solution. I want to emulate "descent" gameplay.
Title: alignment of an object3D
Post by: EgonOlsen on June 08, 2006, 05:12:40 pm
Quote from: "Melssj5"
it still is rotating respect to the absolute world axis. and not to the relative object3d axis.
Of course it is, because that's what it's supposed to do, regardless of alignment/orientation. If you want a different behaviour, you have to use the rotateAxis()-methods, but i'm not sure how this is related to your problem, because i obviously don't understand it correctly.
Title: alignment of an object3D
Post by: Melssj5 on June 08, 2006, 09:02:12 pm
Well, the problem is that I need to move an object3d. The movement is suposed to be similar to the game descent. in which you can go ahead and back. you can rotate on any axis, to go up, down, left, right, or even to the z axis. So.... The craft can be on any direction and rotated on any axis. so I need to align a camera to that craft. I need a behavior similar to he one obtained with the setBack (Matrix) but the problems is that the rotation is done respect with the absolute world axis and not to the realtive craft axis.
Title: alignment of an object3D
Post by: EgonOlsen on June 09, 2006, 12:06:34 am
Ok, but you can obtain the craft's axis with one of the get?Axis()-methods in Object3D and rotate either the camera or the craft around that axis.
Title: alignment of an object3D
Post by: Melssj5 on June 09, 2006, 12:45:40 am
Yeah, I also tried that but the problem is the angle to rotate on that axis, because I would need to have the actual angle proyection from the camera to that relative axis in order to calc the difference angle. I was thinking on getting the x, y and z axis of the object3D, proyect them into the X, Y, and Z absoulte axis and then do a rotate over the 3 absoulte axis. What do you think?
Title: alignment of an object3D
Post by: EgonOlsen on June 09, 2006, 05:57:27 pm
After reading this multiple times, i have to admit...i don't get it... :?: The camera is located inside of the object? The object should perform the same rotations as the camera does? Then why doesn't it work to set the object's rotation matrix to the inverted camera one? And why should the angles with which the camera's rotates be different from the ones used on the object? I don't seem to get the actual problem here.
Title: alignment of an object3D
Post by: Melssj5 on June 11, 2006, 04:42:43 am
The problem with that is the rotation is not the expected one. The movements are done on the object, and then the camera is aligned to the object. For example if I rotateY 90 degres and after try to rotateZ it wont because it will rotate on another axis (X on this situation). I mean it seems that the set of Axis of the rotation matrix are facing absolute directions. I mean, the X axis always will be the same X axis even if the object3D have rotated and should have another relative set of axis. I would like to provide you a test case but I am afraid that it have still many bugs to fix before being runnable 100% times, oftenly got some exceptions when adding more than one craft at a time.
Title: alignment of an object3D
Post by: EgonOlsen on June 12, 2006, 05:56:52 pm
Quote from: "Melssj5"
I mean it seems that the set of Axis of the rotation matrix are facing absolute directions. I mean, the X axis always will be the same X axis even if the object3D have rotated...
Yes, that's exactly the way it's supposed to be. If you don't want that, you can always use the rotateAxis()-method with the axis' returned by get?Axis() from Object3D. That will give you the rotation around the relative ?-axis and there is no difference between that angles you have to apply to those axis' compared to the ones applied to the absolute axis'.
Title: alignment of an object3D
Post by: Melssj5 on June 13, 2006, 07:27:14 am
Yeah, I guess it may work, the problem was that I must modify the client - server. I didnt wanted to translate the angles that the object moved and didnt wanted to keep them on a client manipulable place for avoiding cheats. in anyway I guess I must translate a 3 float spaces array with the x, y, and z rotated angle and the 3 relative axis to make the server to rotate the camera over the 3 axis, but. I am afarid that it will increase the bandwidth usage. and the server processing charge that I noticed is high when doing tests.
Title: alignment of an object3D
Post by: EgonOlsen on June 13, 2006, 08:13:49 am
Transfering the rotation matrix should be sufficient, as already contains the rotations and the implicit axis'. I'm not really sure, what your client is sending to the server and vice versa, but keep in mind that transfering the angles only (yaw, pitch, roll) to specify an object's orientation in space isn't sufficient, because is has no "history" of the order of the rotations, which a rotation matrix has.
Title: alignment of an object3D
Post by: Melssj5 on June 15, 2006, 05:41:26 am
Hi, I tested the code you gave me, but it didnt run. I have a not serializable exception.

Here is the stack trace:

Code: [Select]




java.io.NotSerializableException: com.threed.jpct.GLRenderer
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
        at java.util.Hashtable.writeObject(Hashtable.java:812)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
        at Flier_Match.FMCliente.TCPManejo.enviar(TCPManejo.java:50)
        at Flier_Match.FMCliente.RenderThread.eventosMenu(RenderThread.java:365)
        at Flier_Match.FMCliente.RenderThread.hacerMovimientos(RenderThread.java:203)
        at Flier_Match.FMCliente.RenderThread.ejecutarComandos(RenderThread.java:197)
        at Flier_Match.FMCliente.RenderThread.run(RenderThread.java:167)

Title: alignment of an object3D
Post by: Melssj5 on June 15, 2006, 05:51:33 am
In fact the jpct v11 wprks fine, but Its an older, for example the changes you made for my model 3d program, didnt worked with Flier Match, and neither did the one you send me by mail
Title: alignment of an object3D
Post by: EgonOlsen on June 15, 2006, 08:55:19 am
Damn...i'm pretty sure that i had found the problem...i'll have a look later. What about the alignment problem? Does it work the way you wanted it now?
Title: alignment of an object3D
Post by: Melssj5 on June 16, 2006, 03:53:55 am
Well, about the alignment I must say: YES and NO. Actually the camera is aligned mostly like I expected, but the camera is watching to the rear part of the craft, I mean is looking to the oposite direction, I tried to fix it rotating it 90 degrees at the beginning of the program, but it didnt work, also tried to move the object3D but nothing, is like is being alignes to the original position in anyway. I guess that is not a huge problem and will be able to fix it by myself. Thanks a lot.
Title: alignment of an object3D
Post by: EgonOlsen on June 16, 2006, 08:03:03 am
Quote from: "Melssj5"
but the camera is watching to the rear part of the craft, I mean is looking to the oposite direction,
Sure? Maybe it looks like that to you, because i switched the meaning of A and Z!? If not, then why not just rotate the craft's mesh at initialization by 180 degrees around Y?

Code: [Select]
obj.rotateY((float) Math.PI);
obj.rotateMesh();
obj.setRotationMatrix(new Matrix());
Title: alignment of an object3D
Post by: Melssj5 on June 16, 2006, 02:30:38 pm
I actually did obj.rotateY (Math.PI) but nothing seems to happen, I have a clue on why this is happenig but will fix it tomorrow at night.
Title: alignment of an object3D
Post by: EgonOlsen on June 16, 2006, 03:13:41 pm
Quote from: "Melssj5"
I actually did obj.rotateY (Math.PI) but nothing seems to happen, I have a clue on why this is happenig but will fix it tomorrow at night.
That's because it doesn't change the relative relation between the craft and the camera, i.e. the viewer. The camera aligns itself on the positive z-axis of the craft. If this is pointing to the rear, rotating the craft doesn't help, because it also rotates the z-axis with it. You have to rotate the craft relative to the axis, which is what the code should do. But i'm having problems to understand how you came to this conclusion!? I mean, there is no craft visible at all, is it? So how do you determine that you are looking to the rear?
Title: alignment of an object3D
Post by: Melssj5 on June 17, 2006, 04:19:58 am
Of course there is a problem, because I am making a multiplayer game, and what happens with the aligned camera also happens with other players crafts (every client have a list of them) and cameras (own of each player) So, it seems to be ok but when is a craft in front you dont see it, only when is behind.
Title: alignment of an object3D
Post by: Melssj5 on June 17, 2006, 08:48:42 am
Quote from: EgonOlsen
Quote from: "Melssj5"


Code: [Select]
obj.rotateY((float) Math.PI);
obj.rotateMesh();
obj.setRotationMatrix(new Matrix());


Well, nothing happens? I guess its a magical Issue or something. I out the code when the game is begging but nothing!!!!, what can I do?
Title: alignment of an object3D
Post by: EgonOlsen on June 17, 2006, 11:25:22 am
The code should rotate the mesh of the craft...if there is one, but there isn't, hence my question. That's what i currently don't understand about this problem. There is no visible sign of looking to the rear or to the front. I really don't understand how "rear" is defined in your game. I mean it's all a question of definition. I may load a level upside down and define down as up and vice versa. Fact is: In jPCT, front means "along the positive z-Axis" and that's what you get ATM. If you have a model that's different, rotate it's mesh (that's what this code is supposed to do). Everything else is just a question of the coordinate system you are acutally thinking in.
Title: alignment of an object3D
Post by: Melssj5 on June 18, 2006, 01:18:12 am
Well, if you run just one client. it has no sense of rotating the mesh because is removed in anyway, but when they are 2 clients,(2 crafts on the World) and they are front to front, then you cant see none of them. but if they are back to back you see both. The camera is directed to the oposite Z craft axis.

About the definitions, well, front is the front of the craft (where the camera should be watching) and the rear is the rear of the craft (where the turbines are). So, the camera is watching from the center of the craft to the the rear part, thats the oposite Z axis.

Every client chose a craft from a list and when beggining the game the selected craft is sent to the sever to add it to a list of all the current players, this list os passed to all the clients on each iteration, so each client can see others crafts (this crafts are not being rotated but the code you game me is like not having written the code for rotating it)
Title: alignment of an object3D
Post by: Melssj5 on June 18, 2006, 02:12:58 am
PROBLEM SOLVED! THANKS A LOT, I DONT KNOW WHY THE FIRST TIME IT DIDNT HAPPENED, IN ANYWAY IS FULL WORKING NOW.!
Title: alignment of an object3D
Post by: EgonOlsen on June 18, 2006, 11:14:12 am
Cool! :mrgreen: