Jump to content
  • Advertisement
Sign in to follow this  
cutovoi

Big question about Rotation, Translation and to position objects

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

Hi fellows. I have a problem. In my app I put 3 cubes one in front of another. The first cube is in the -6.5 position of the z-axis. The second cube is in the 0.0 position od the z-axis. And the first, is in the 6.5 position of the z-axis. Well, at this moment, all systems go. These 3 cubes have functions that rotates and translates them. I use the D3DXMatrixRotationYawPitchRoll to make the transformations. I inform the cubes the following: when the rotation or translations reaches 90.0 the cubes stop to rotate or translate. Now the problem: when the cubes reaches the 90.0 ONLY THE CUBE that is in the 0.0 position in the beginning REMAINS in the screen, but the other cubes NO. All of then suffers the transformations. If I rotate 90 they rotate and only in the middle remains. Since the cubes is in the 90 degree in the x-axis, I inform them to rotate to y-axis. Then the cubes returns to the screen in the exactly position that they was in the x-axis, and when the cubes reaches 90, again the middle cube remais in the screen. I think that my problem is in the function that I call to set the position(called SetPositions). Fellows, sorry for the long explanation but this problem drives me crazy. I put the code below. Thanks a lot for the support.
D3DXMATRIX Cube::RotateX()
{
   D3DXMATRIX TempMatrix;
   static float sfAngle = 0;
   bLeftRight ? sfAngle+=0.05f : sfAngle-=0.05f;
   sfXAngle = sfAngle;
   D3DXMatrixRotationYawPitchRoll(&TempMatrix, D3DXToRadian(sfXAngle), D3DXToRadian(sfYAngle), 0.0f);
   return TempMatrix;
}

D3DXMATRIX Cube::RotateY()
{
   D3DXMATRIX TempMatrix;
   static float sfAngle = 0;
   bUpDown ? sfAngle+=0.05f : sfAngle-=0.05f;
   sfYAngle = sfAngle;
   D3DXMatrixRotationYawPitchRoll(&TempMatrix, D3DXToRadian(sfXAngle), D3DXToRadian(sfYAngle), 0.0f);
   return TempMatrix;
}

D3DXMATRIX Cube::RotateZ()
{
   D3DXMATRIX TempMatrix;
   D3DXMatrixRotationZ(&TempMatrix, timeGetTime()/1000.0f);
   return TempMatrix;
}

void Cube::ApplyRotation()
{  
   if(m_bSide)D3DXMatrixMultiply(&CubeMatrix, &(this->TranslateMatrix()), &(this->RotateX()));
   else D3DXMatrixMultiply(&CubeMatrix, &(this->RotateX()), &CubeMatrix);
   m_DirectDevice->SetTransform(D3DTS_WORLD, &CubeMatrix);
}

void Cube::ApplyTranslation()
{ 
   if(m_bSide)D3DXMatrixMultiply(&CubeMatrix, &(this->TranslateMatrix()), &(this->RotateY()));
   else D3DXMatrixMultiply(&CubeMatrix, &(this->RotateY()), &CubeMatrix);
   m_DirectDevice->SetTransform(D3DTS_WORLD, &CubeMatrix);
}

D3DXMATRIX Cube::TranslateMatrix()
{
   D3DXMATRIX TempMatrix;
   D3DXMatrixTranslation(&TempMatrix, m_fXPos, m_fYPos, m_fZPos);
   return TempMatrix;
}

void Cube::RenderCube()
{
   m_DirectDevice->SetStreamSource(0, m_DirectVertex, sizeof(VertexNonFVF));
   m_DirectDevice->SetVertexShader(FVFCUSTOM);
   if(m_bFirst)this->SetPositions(m_fXPos, m_fYPos, m_fZPos);
   if(this->m_DirectVertex != NULL) this->ApplyTexture();
   if(this->m_bRotate && sfXAngle <= 90.0)this->ApplyRotation(); else {this->m_bRotate = false; m_bFirst = false;}
   if(this->m_bTranslate && sfYAngle <= 90.0)this->ApplyTranslation(); else {this->m_bTranslate = false; m_bFirst = false;}
   m_DirectDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
   m_DirectDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 14);
   m_DirectDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 20, 2);
}

void Cube::SetPositions(float fX, float fY, float fZ)
{
   D3DXMatrixIdentity(&CubeMatrix);
   D3DXMatrixTranslation(&CubeMatrix, fX, fY, fZ);
   m_DirectDevice->SetTransform(D3DTS_WORLD, &CubeMatrix);
}


Share this post


Link to post
Share on other sites
Advertisement
Are you possibly translating them all to the same spot making it look like one cube is left.

Share this post


Link to post
Share on other sites
TWild, I didn't understand very well. Can you explain better?
FYI, this code is for to a cube class and not for to treat all cubes. I think that you've understood is that this code gets the world matrix of the whole app and make the transformations.
Am I right?? If not, sorry for my mistake..

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!