Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MetalWorX

World Coords,Model Coords( ooh drivin me nuts!! )

This topic is 6917 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

All i want is my 3d object to move relative to the world and to rotate around its own axis. Can somebody please help me??? I''m using D3D IM. Please refer to my other post (BIG problem in D3D IM....) for the code i have employed. thnx sandeep_kl@mailcity.com

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I read your other post,
I can''t give you any code, I don''t use Direct 3D IM yet, but you say your object rotate around the origin instead of around it''s own axis so I guess you
place the object in the world at lets say (400, 100) and then you want to rotate it 45 degrees and it rotates 45 degrees around the origin instead of it''s own axis
but now if you would rotate it first while it''s still at the origin , and then move it to the location (400, 100) it looks like it has been rotated around it''s own axis atleast that''s how I did it in OpenGl and I think everyone does it that way....

chris

Share this post


Link to post
Share on other sites
The transform matrix that Direct3D calls World Matrix transforms the objects coordinates from model space to world space.

So what you want is to first rotate your object in its own space, then translate it to its position in the world. You do this just as I wrote in your other post.

- WitchLord

Share this post


Link to post
Share on other sites
hi witchlord,

how do u do that??
I''m 17,stayin in INDIA,and i really need help from u pros!

i tried ur code and it yet rotates around the origin.
is there anything about the """SetTransform and GetTransform" routines??
would be great if u could give me some code with the "SetTransform" routine called.

thanx a MILLION for ur help!!

sandeep_kl@mailcity.com


Share this post


Link to post
Share on other sites
I have answered your question in your other post, but I'll do it again here to save you and me from trying to follow two threads at once.

Here's how you compute the world matrix for your object:

D3DMATRIX T,Ry,Rx;
D3DUtil_SetRotateXMatrix(Rx, RotX);
D3DUtil_SetRotateYMatrix(Ry, RotY);
D3DUtil_SetTranslateMatrix(T, Pos.x,Pos.y,Pos.z);

D3DMATRIX WorldMtx;
D3DMath_MatrixMultiply(WorldMtx, Rx, Ry);
D3DMath_MatrixMultiply(WorldMtx, WorldMtx, T);

m_pD3DDev->SetTransform(D3DTRANSFORMSTATE_WORLD, &WorldMtx);

This code will compute the following for every vertex in the object:

NewVertex = Vertex*Rx*Ry*T;

Which is to say that the object is first rotated around its own x-axis, then around its y-axis and finally translated to its position in the world.

- WitchLord

Edited by - WitchLord on May 15, 2000 10:30:33 AM

Share this post


Link to post
Share on other sites
Thanks witchlord but when i put the object to 0,0,0 and rotate it , the axis also turns thereby making it difficult to turn. this is the whole problem. the axis remains at origin but rotates along with the object, any translation will be relative to the axis from the objects location. is there any code available on the net. i would realyy like to get it

is something is holding the object in the 3d-worlds pipeline? wont i be able to read thru it. please let me know what holds the object confined to its location even if we dont calculate its travel in world coordinates.

are there any tutorials on this subject on the net
thnx a lot 4 ur help. please let me know

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If i got your problem correct you need to use some math. Unfortanatly i don''t have the formula right off the top of my head. give me an email and i''ll look it up for you eckiller@home.com

ECKILLER

Share this post


Link to post
Share on other sites
Hmm, I''m having trouble seeing your problem. I guess I have become too accustomed to matrix transformations.

You need to read about the Direct3D geometry pipeline. You have it in the SDK, it is also available here: MSDN Library

I will describe a short version here. This is the different transformations that the vertices in your models go through before being rendered:

Model(initial state)->World->View->Normalized Screen Space->Screen

You create your model in model space where the origin is the rotation center. Then the model is transformed into world coordinates by the world matrix, that you set with SetTransform(D3DTRANSFORMSTATE_WORLD,&World). Then it is transform into coordinates relative the camera with the View matrix. Then it is projected and into a normalized screen space (let''s not go in to what that means). Then finally it is scaled and translated so that it fits into the viewport that you set with SetViewport().

As I understand it you are having trouble setting up the model''s world matrix correctly. If you look at the code-snippet that I posted before the Rx matrix rotates the model around the models x-axis so that it can look up or down (commonly referred to as pitch). The model has now rotated within its coordinate system, but the coordinate system has not. Then you transform the model with the Ry matrix, that rotates it around the coordinatesystems y-axis (this will set the model''s heading or yaw). The model still looks down or up as set by the Rx matrix. Finally we translate the model to its correct position in the world with the T matrix, remember that the coordinatsystem has _not_ been transformed, by add the position vector to all vertices in the model.

Now, to shorten the computations for all of these transform all the matrices are multiplied together into one. The wonders of math will make sure that they keep the information. You must remember to do this in the correct order otherwise you will get unexpected results.

End of lesson. I hope that was able to shed some light upon your troubles.

PS. I hope you don''t expect me to be here in the forums 24 hours a day, or anyone else for that matter. I nobody answer, you must have the patience to wait at least until the next day.



- WitchLord

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!