Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Using the 3DMATH commands, How to get World Limb Position?

Author
Message
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 28th May 2010 09:00
I never did this through 3d math and remember reading somewhere that you multiply the inverse matrix of the specific 3d position in it's local space with the world space matrix to get the true world 3d position. Uhm, I hope I made some sense there.

Basically I want to use the 3dmath commands to do what the LIMB POSITION X/Y/Z commands can do.

If I can get the maths right, the Sphere should cover the Cube that is attached as a limb to the main cube.

Side note: I tried "GLUE OBJECT TO LIMB" to glue the second cube as a limb to the first cube, but apparently there must be an existing limb all ready there as I get an error complaining that the limb doesn't exist. So I had to go the long route to make a mesh of the first cube and using ADD LIMB to get all that done.

Anyways, is this possible? What I got goes haywire! I'm still trying though...


Any help would be greatly appreciated




ExoDev.Com |XBOX360 CONTROLLER LIBRARY|USE DARK GDK WITH LATEST DIRECTX| C2Q2.66, 8G RAM, GeFORCE 9800 X2, VISTA 64Bit
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 28th May 2010 09:20
quick non-100%-comprehensive response:
one thing is amiss for sure: The matrix4 commands use radians, not degrees, multiply all your angles by .017453293 (pi/180) before feeding 'em into a matrix4 function. this should get rid of the "haywire" movement.

A thing that might still cause a problem is the multiply matrix 4 command. You would think that, given matrix A and B, saying:
multiply matrix4 result, A, B
would set result=A*B... but it doesn't. In actuality, result=B*A (which is a BIG problem, because matrix multiplication doesn't associate like that... errm... in case you didn't know.)


Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 28th May 2010 09:26
Thanks for the tips Neuro! The degrees to radians made it move smooth. But still, It's not exactly right as it rotates in the opposite direction around 0,0,0. Will look into the multiply matrix4... that could be my problem right there as you suggested...

ExoDev.Com |XBOX360 CONTROLLER LIBRARY|USE DARK GDK WITH LATEST DIRECTX| C2Q2.66, 8G RAM, GeFORCE 9800 X2, VISTA 64Bit
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 28th May 2010 11:10
I believe this was what you wanted to achieve:



The commands I added are written in lowercase.

There were 3 problems in your code:
- You were translating your matrix with the limb offset. But, the limb offset is actually a vector that rotates along with the object, and so it should be used in the vector that you want to transform.
- There was no need to use the inverse of the matrix4. I don't know where you got this, but using these matrices usually means rotation of vectors (eg you say 'rotate 30°', then it will rotate 30° and not -30° which is the case when changing coordinate system). Besides, the inverse of a rotation matrix is a rotation matrix, but using its negative angle, and the inverse of a translation matrix is a translation matrix over its negative translation vector.
- You weren't using any vectors that eventually would hold the object position

You basically set a vector to the offset you want to have (in this example you picked the offset (5.0, 0.0, 0.0, 1.0) which you can see as the local position vector of the limb. Then you transform that vector using the matrix you built. In your example that matrix4 will rotate the vector YPR and then translate it over the object's position.

Cheers!
Sven

Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 28th May 2010 11:31
Cheers!

I will go over what you said and learn from it.

At one time I was playing around with opengl where I had to do all the matrix/vector math myself. I was trying to do exactly this but obviously never succeeded. At that time when internet searching for a subject like this, I had read something about inverse matrices to trasform object space into world space. Guess I was searching down the wrong path.

Thankyou soooo much for taking time out and showing me how to do it right! T'is exciting!

ExoDev.Com |XBOX360 CONTROLLER LIBRARY|USE DARK GDK WITH LATEST DIRECTX| C2Q2.66, 8G RAM, GeFORCE 9800 X2, VISTA 64Bit

Login to post a reply

Server time is: 2024-05-19 20:27:44
Your offset time is: 2024-05-19 20:27:44