#### Archived

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

# Rotating Objects

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

## Recommended Posts

I just finished writing a basic frame system for holding all objects in my game. I just came into a problem, as you see in my code I am using SetTransform(D3DTS_WORLD, &matrix); to rotate, well dumb old me didn''t know that that ment rotate the ENTIRE world, how would I go about only rotating an object?? Thanks in advance.

void ExoFrame::Update(LPDIRECT3DDEVICE8 device)
{
//Call that movement callback

if (callBack)
callBack(this, param);

//Create the temp matrices

D3DXMATRIX rotX,		//X axis rotation

rotY,		//Y axis rotation

rotZ,		//Z axis rotation

trans,		//Translation

temp;		//X/Y/Z axis togther

//Update the position by the velocitys

position.x += velocity.x;
position.y += velocity.y;
position.z += velocity.z;

velocity.x = 0.0f;
velocity.y = 0.0f;
velocity.z = 0.0f;

//Translate the matrix

D3DXMatrixTranslation(&trans, position.x, position.y, position.z);

//Rotate around pitch/yaw/roll

D3DXMatrixRotationX(&rotX, pitch);
D3DXMatrixRotationY(&rotY, yaw);
D3DXMatrixRotationZ(&rotZ, roll);

//Put the X+Y+Z axis together in temp

D3DXMatrixMultiply(&temp, &rotX, &rotY);
D3DXMatrixMultiply(&temp, &rotZ, &temp);

//Put all the matrices toghter into a matrix

D3DXMatrixMultiply(&temp, &trans, &temp);

//Set the class matrix to the one created

matrix = temp;

//If this frame is a child then we need to make its pos relative to the parent

if (GetParent())
{
//Temp for the parents matrix

D3DXMATRIX	mParent;
//Get the parents matrix

GetParent()->GetMatrix(mParent, device);
//Multiply the parent and child matrix

D3DXMatrixMultiply(&matrix, &matrix, &mParent);
}

//Set the world matrix

device->SetTransform(D3DTS_WORLD, &matrix);
}
[/souce]  

##### Share on other sites
Check out my tutorial on matrix transformations at:

http://www.andypike.com/tutorials/directx8

-----------------------------
Andy Pike
DirectX 8 Tutorials: www.andypike.com

[edited by - bigandy on July 1, 2002 9:34:01 AM]

##### Share on other sites
Thank you very much, I will be bookmarking this one!

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633269
• Total Posts
3011148
• ### Who's Online (See full list)

There are no registered users currently online

×