Jump to content
  • Advertisement
Sign in to follow this  
cutovoi

Object matrices

This topic is 4482 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'm developing a magiccube game. I'm having some difficulties to continue the project. I have 3 simple cubes, one for the left(rotating in the y axis and translating in the x axis), one for the right(rotating in the y axis and translating in the x negative axis) and one in the center ro tating in their y-axis. The two cubes rotating and translating fine, BUT these 2 guys doesn't translate around the middle cube, they cross the middle cube. I don't want to do this. I want to rotate the 2 cubes around the middle cube. Please help me in this fellows. Once again thanks a lot for the support. Below some part of my code:
the cube's constructor:

Cube::Cube(float fXVertex, float fYVertex, float fZVertex, float fXPos, float fYPos, float fZPos, LPDIRECT3DDEVICE8 DirectDevice, bool bSide)
{
   m_fXVertex = fXVertex;
   m_fYVertex = fYVertex;
   m_fZVertex = fZVertex;
   m_fXPos = fXPos;
   m_fYPos = fYPos;
   m_fZPos = fZPos;
   m_DirectDevice = DirectDevice;
   m_bSide = bSide;
   CreateVerticesBuffer();
}

the values:
theCube0  = new Cube(3.0f, 3.0f, 3.0f, -6.5f, 0.0f, 0.0f, this->g_pDirect3DDevice, true);
theCube1  = new Cube(3.0f, 3.0f, 3.0f,  0.0f, 0.0f, 3.0f, this->g_pDirect3DDevice, false);
   theCube2  = new Cube(3.0f, 3.0f, 3.0f,  6.5f, 0.0f, 0.0f, this->g_pDirect3DDevice, true);

Cube Functions:
D3DXMATRIX Cube::RotateX()
{
   D3DXMATRIX TempMatrix;
   D3DXMatrixRotationX(&TempMatrix, timeGetTime()/1000.0f);
   return TempMatrix;
}
D3DXMATRIX Cube::RotateY()
{
   D3DXMATRIX TempMatrix;
   D3DXMatrixRotationY(&TempMatrix, timeGetTime()/1000.0f);
   return TempMatrix;
}
D3DXMATRIX Cube::RotateZ()
{
   D3DXMATRIX TempMatrix;
   D3DXMatrixRotationZ(&TempMatrix, timeGetTime()/1000.0f);
   return TempMatrix;
}

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

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

void Cube::RenderCube()
{
   m_DirectDevice->SetStreamSource(0, m_DirectVertex, sizeof(VertexNonFVF));
   m_DirectDevice->SetVertexShader(FVFCUSTOM);
   this->SetPositions(m_fXPos, m_fYPos, m_fZPos);
   this->ApplyIt();
   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)
{
   D3DXMATRIX PositionMatrix;
   D3DXMatrixTranslation(&CubeMatrix, fX, fY, fZ);
}


Share this post


Link to post
Share on other sites
Advertisement
Take a look at this

It should give you a clear indication of what you need to do. It seems like you want some kind of planetary system.

Example (Rotating around an axis - Planet/moon system)
1) Translate your object
2) Rotate your object

Example (Rotating around an axis in place - The earth rotating)
1) Rotate your object
2) Translate your object

I hope this helps.
Take care.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!