• Advertisement


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

Rotating Objects

This topic is 5711 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

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);

Share this post

Link to post
Share on other sites

  • Advertisement