www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Familyfriend on September 27, 2011, 11:25:04 am

Title: Box
Post by: Familyfriend on September 27, 2011, 11:25:04 am
Hi,
I'm a new 3d graphic programmer trying to implement a simple application that shows a rolling dice from the acellerometer vector. I'm tring to do in 3D graphic with jCPT-AE and Jinnjine (http://code.google.com/p/jinngine/ (http://code.google.com/p/jinngine/)) as physic engine.

I have already implemented the walls and the die both in the physic and in the graphic world.
Now my problem is that i can't deal with the rotation connection, i have a Matrix4 from the physic world and i can't figure out how to
use it to rotate the graphic object.

tries:
can someone help me, at least driving me to the right direction.


here is my code for the texture box: http://pastebin.com/W3xQhRtw
and the code for the frame:
Title: Re: Box
Post by: EgonOlsen on September 27, 2011, 04:18:08 pm
In JPCT, matrices are row-major. Might be that in your physics lib, they are column-major. You can easily convert between the two. Either transpose the matrix or use another way to make sure that x,y of one matrix is y,x in the other.
Title: Re: Box
Post by: Familyfriend on September 27, 2011, 04:33:58 pm
i tried to transpose it but it doesn't change anything.
here below there is an image of what i get after i use the setRotation(Matrix m) method on the die.

render result: http://ge.tt/94IrXC8/v/0

does it make you think at some issue in particular? I'm thinking at some GL configuration i'm missing or even at some wrong verticies, that's why i posted you the TextureBox class code.

anyway thx for you help.
Title: Re: Box
Post by: EgonOlsen on September 27, 2011, 05:37:56 pm
No. If the box goes crazy after applying the rotation matrix, it's an issue with that matrix. Can you post a matrix from the physics lib...preferably one with a known rotation. Just to make sure that it's actually a rotation matrix.
Title: Re: Box
Post by: Familyfriend on September 27, 2011, 06:23:13 pm
Code: [Select]
| 4.999999983927641     | 1.3521203987884335E-5  | -4.0067538875552356E-4 | -0.04895554408488278   |   
| -1.353701522130874E-5 | 4.999999996088675      | -1.9730685900529323E-4 | -0.0012040176435942087 |   
| 4.0067485487683144E-4 | 1.9730794316082318E-4  | 4.999999980052924      | 46.82875954697466      |
|     0.0               |     0.0                |     0.0                |     1.0                |

09-27 18:04:20.241: INFO/Matrix(3304): [0][0]4.999999983927641
09-27 18:04:20.256: INFO/Matrix(3304): [0][1]1.3521203987884335E-5
09-27 18:04:20.256: INFO/Matrix(3304): [0][2]-4.0067538875552356E-4
09-27 18:04:20.256: INFO/Matrix(3304): [0][3]-0.04895554408488278
09-27 18:04:20.256: INFO/Matrix(3304): [1][0]-1.353701522130874E-5
09-27 18:04:20.256: INFO/Matrix(3304): [1][1]4.999999996088675
09-27 18:04:20.256: INFO/Matrix(3304): [1][2]-1.9730685900529323E-4
09-27 18:04:20.256: INFO/Matrix(3304): [1][3]-0.0012040176435942087
09-27 18:04:20.256: INFO/Matrix(3304): [2][0]4.0067485487683144E-4
09-27 18:04:20.256: INFO/Matrix(3304): [2][1]1.9730794316082318E-4
09-27 18:04:20.256: INFO/Matrix(3304): [2][2]4.999999980052924
09-27 18:04:20.256: INFO/Matrix(3304): [2][3]46.82875954697466
09-27 18:04:20.256: INFO/Matrix(3304): [3][0]0.0
09-27 18:04:20.256: INFO/Matrix(3304): [3][1]0.0
09-27 18:04:20.256: INFO/Matrix(3304): [3][2]0.0
09-27 18:04:20.256: INFO/Matrix(3304): [3][3]1.0


here is the rotation matrix i get from the physicWorld, i'm sorry but i can't find the way to set a fixed angle to the physic object, anyway this is the rotation Matrix of the object just after the first bounce on a plane at  (0,0,50) without any rotation.

i hope this is enought.
Title: Re: Box
Post by: Familyfriend on September 27, 2011, 06:39:51 pm
mmm actually after you made me looking at the values of the matrix i noticed that it actually was not raw-major.

probably i made some mistake ( noob  :o ) in the code before because now i tried back to transpose it, and it works fine.

thanks for the help.
Title: Re: Box
Post by: EgonOlsen on September 27, 2011, 07:56:25 pm
Glad you solved it...however, it's not a rotation matrix. It's more of a transformation matrix into world space, because it seems to contain scale and translation. This works to a degree, but some parts of jPCT rely on the rotation matrix to be a proper 3x3 rotation matrix only. The better solution would be to split it into rotation (the upper 3x3 matrix), translation (the last row) and scale (the lenght of one row) and apply those value individually. Anyway...as long as it works this way...
Title: Re: Box
Post by: Familyfriend on September 27, 2011, 08:51:55 pm
yes, it is a world transformation matrix. My problem was that the setRotation matrix take a 4x4 matrix and i didn't know how to build it by the 3x3 matrix i could take from the physic object.
however thx a lot for your help and actually you answeard a lot of my question with this last answear.

I read something about the world transformation but i  couldn't understand how all the information could be stored just in one matrix. :D