Click to See Complete Forum and Search --> : Question about move 2 objects


C#er
May 23rd, 2006, 10:25 AM
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);
}