Rotations
Hi!
Lets say i created 2 cubes and render them to the screen , now how can i rotate around any axis just ONE cube , not the whole world (world tranformation)
???
tnx Xeno.
In OpenGL you could use:
glRotatef(Amount to Rotate , X-Axis , Y-Axis , Z-Axis);
Call this function before the creation of the object you wish to rotate.
Edited by - reaptide on 4/19/00 3:15:44 PM
glRotatef(Amount to Rotate , X-Axis , Y-Axis , Z-Axis);
Call this function before the creation of the object you wish to rotate.
Edited by - reaptide on 4/19/00 3:15:44 PM
If you''re using OpenGL, I''ve got the solution:
glMatrixMode(GL_MODELVIEW);
glLoadIdendity();
...
DrawCube();
glRotated(..);
DrawCube();
If you want to draw anything which shouldn''t rotate with the second cube, use glPushMatrix() before calling glRotate() and glPopMatrix() after drawing the rotated objects.
Visit our homepage: www.rarebyte.de.st
GA
glMatrixMode(GL_MODELVIEW);
glLoadIdendity();
...
DrawCube();
glRotated(..);
DrawCube();
If you want to draw anything which shouldn''t rotate with the second cube, use glPushMatrix() before calling glRotate() and glPopMatrix() after drawing the rotated objects.
Visit our homepage: www.rarebyte.de.st
GA
In Direct3D you have three matrices that control the final coordinates of the vertices.
The world matrix is used to place objects in the world coordinate system
The view matrix is used to transform world coordinates into camera coordinates
The projection matrix is used to project the view coordinates onto the screen
To rotate the cube you would do something like this:
D3DXMATRIX R, T, W;
D3DXMatrixRotationX(&R, Angle); // Rotate the cube around it''s own origin
D3DXMatrixTranslation(&T, Pos.x, Pos.y, Pos.p); // Translate it to its position in the world
D3DXMatrixMultiply(&W, &R, &T); // Concatenate the transformation matrices
pD3DDev->SetTransform(D3DTRANSFORMSTATE_WORLD, (D3DMATRIX*)&W);
Of course you can add more rotations, just keep in mind that the rotations should happen before the translation otherwise the cube won''t be where it''s supposed to be.
WitchLord
The world matrix is used to place objects in the world coordinate system
The view matrix is used to transform world coordinates into camera coordinates
The projection matrix is used to project the view coordinates onto the screen
To rotate the cube you would do something like this:
D3DXMATRIX R, T, W;
D3DXMatrixRotationX(&R, Angle); // Rotate the cube around it''s own origin
D3DXMatrixTranslation(&T, Pos.x, Pos.y, Pos.p); // Translate it to its position in the world
D3DXMatrixMultiply(&W, &R, &T); // Concatenate the transformation matrices
pD3DDev->SetTransform(D3DTRANSFORMSTATE_WORLD, (D3DMATRIX*)&W);
Of course you can add more rotations, just keep in mind that the rotations should happen before the translation otherwise the cube won''t be where it''s supposed to be.
WitchLord
You rotate the cube you want to rotate BEFORE you translate them.
Then you rot/trans them again for the world transformation.
Then you rot/trans them again for the world transformation.
Hi,
Try using the D3D Util functions;
Set your objects position in the world..
D3DUtil_SetTranslateMatrix(position, xpos, ypos, zpos);
Here I''m rotating about x & y, so set up two rotation matrices..
D3DUtil_SetRotateYMatrix(yrotate, yangle);
D3DUtil_SetRotateXMatrix(xrotate, xangle);
Multiply them together to form one rotation matrix..
D3DMath_MatrixMultiply(rotate, yrotate, xrotate);
Now multiply the positional and rotational matrices into the player matrix..
D3DMath_MatrixMultiply(MatrixPlayer, position, rotate);
These Util functions can be a little long winded at times, but they are very robust and error-free (I hope!) so they are great when your starting out (like me :-) )
Remember to #include
Cheers
Matt
Check out my project at: www.btinternet.com/~Matthew.Bennett
Try using the D3D Util functions;
Set your objects position in the world..
D3DUtil_SetTranslateMatrix(position, xpos, ypos, zpos);
Here I''m rotating about x & y, so set up two rotation matrices..
D3DUtil_SetRotateYMatrix(yrotate, yangle);
D3DUtil_SetRotateXMatrix(xrotate, xangle);
Multiply them together to form one rotation matrix..
D3DMath_MatrixMultiply(rotate, yrotate, xrotate);
Now multiply the positional and rotational matrices into the player matrix..
D3DMath_MatrixMultiply(MatrixPlayer, position, rotate);
These Util functions can be a little long winded at times, but they are very robust and error-free (I hope!) so they are great when your starting out (like me :-) )
Remember to #include
Cheers
Matt
Check out my project at: www.btinternet.com/~Matthew.Bennett
That include is d3dutil.h
There you go, you wait for a D3D answer and three come at once!
Cheers
Matt
Check out my project at: www.btinternet.com/~Matthew.Bennett
There you go, you wait for a D3D answer and three come at once!
Cheers
Matt
Check out my project at: www.btinternet.com/~Matthew.Bennett
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement