Sign in to follow this  

How can I move 2 objects

Recommended Posts

Fellows I have 2 cubes that I want to move with the YawPitchRoll method. I set the position of the 2 cubes in the beginning with SetPositions function that is part of a cube class:
void Cube::SetPositions(float fX, float fY, float fZ)
   D3DXMatrixTranslation(&CubeMatrix, fX, fY, fZ);
   m_DirectDevice->SetTransform(D3DTS_WORLD, &CubeMatrix);

I use the YawPitchRoll function to rotate and translate in my other functions. When the cube reaches the 90 degree in the y-axis or in the x-axis, the cubes returns to the position that I've define in the beginning. The problem is in the SetPositions function that I use in the RenderCube function. It maintains the values that I set in the beginning. My question is: how can I maintain the position that the YawPitchRoll sets when I call my function that perform the transformations? I put the code of the RenderCube function and one of the functions that use the YawPitchRoll. Fellows thanks a lot.
void Cube::RenderCube()
   m_DirectDevice->SetStreamSource(0, m_DirectVertex, sizeof(VertexNonFVF));
   this->SetPositions(m_fXPos, m_fYPos, m_fZPos);
   if(this->m_DirectVertex != NULL) this->ApplyTexture();
   if(sfXAngle <= 90.0)this->ApplyRotation();
   if(sfYAngle <= 90.0)this->ApplyTranslation();
   m_DirectDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
   m_DirectDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 14);
   m_DirectDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 20, 2);

Function that uses the YawPitchRoll function:
D3DXMATRIX Cube::RotateY()
   D3DXMATRIX TempMatrix;
   static float sfAngle = 0;
   bUpDown ? sfAngle+=0.05f : sfAngle-=0.05f;
   sfYAngle = sfAngle;
   D3DXMatrixRotationYawPitchRoll(&TempMatrix, D3DXToRadian(sfYAngle), D3DXToRadian(sfXAngle), 0.0f);
   return TempMatrix;

Share this post

Link to post
Share on other sites
I don't know what apply Rotation does but I'm guessing that you use SetTransform(D3DTS_WORLD, &matrix) where matrix is the product of the position and rotation matrices.

You could use MultiplyTransform() with the same parameters. The multiply transform
takes the current world matrix and multiplies it with the given matrix, so in this way the cube rotation will be "added" to its current rotation state.

You could also maintain your current rotation angle and then keep using the set transform function. when rotating the cube use D3DXMatrixRotationYawPitchRoll(&TempMatrix, D3DXToRadian(currentYAngle + sfYAngle), D3DXToRadian(currentXAngle + sfXAngle), 0.0f);

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this