Jump to content
  • Advertisement
Sign in to follow this  

How can I move 2 objects

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

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
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!