# 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.

## 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)
{
D3DXMatrixIdentity(&CubeMatrix);
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;
return TempMatrix;
}



##### 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);

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632591
• Total Posts
3007250

×