Jump to content
  • Advertisement
Sign in to follow this  
sambsp

newbie's question

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

Following code, I am going to move a ball in a house with 3 wall and 1 ceiling, 1 floor,the camera is static (won't move any way, so in my mind, the scene is a moving ball inside a house). As I did, I first rendered walls, ceiling and floor, then I set a translation matrix for the ball, then render the ball. But result shows that seems my camera moves after the translation, not static now. Help me with this problem. // we'll render the scene now g_pd3dDevice->BeginScene(); // vertex buffer g_pd3dDevice->SetStreamSource (0, g_pVertextBuf, 0, sizeof (D3DVERTEX)); g_pd3dDevice->SetFVF (D3DVERTEX::FVF); // wall g_pd3dDevice->SetTexture( 0, g_pWallTextures ); g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 0, 2); g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 4, 2); g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 8, 2); // ceiling g_pd3dDevice->SetTexture( 0, g_pCeilingTextures ); g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 12, 2); // floor g_pd3dDevice->SetTexture( 0, g_pFloorTextures ); g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 16, 2); // ball (only the ball from .x file) D3DXMatrixTranslation (&matNow, 0, 0, Z); g_pd3dDevice->SetTransform (D3DTS_WORLDMATRIX(0), &matNow); g_pBallMesh->DrawSubset (0); g_pd3dDevice->EndScene(); // end of the scene rendering

Share this post


Link to post
Share on other sites
Advertisement
You need to set the world matrix before rendering your room as well as setting the world matrix before rendering you ball.
Assuming your room is static and positioned at the origin, use something like:

D3DXMatrixIdentity(&matNow);
g_pd3dDevice->SetTransform (D3DTS_WORLDMATRIX(0), &matNow);

insert the code just before you render your room primitives.

Then reset your world matrix again after rendering your room primitives and before rendering your ball like this

// we'll render the scene now
g_pd3dDevice->BeginScene();

// vertex buffer
g_pd3dDevice->SetStreamSource (0, g_pVertextBuf, 0, sizeof (D3DVERTEX));
g_pd3dDevice->SetFVF (D3DVERTEX::FVF);

// ******* inserted code here*********

D3DXMatrixIdentity(&matNow);
g_pd3dDevice->SetTransform (D3DTS_WORLDMATRIX(0), &matNow);

// ******* end of inserted code *********

// wall
g_pd3dDevice->SetTexture( 0, g_pWallTextures );

g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 0, 2);
g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 4, 2);
g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 8, 2);

// ceiling
g_pd3dDevice->SetTexture( 0, g_pCeilingTextures );
g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 12, 2);

// floor
g_pd3dDevice->SetTexture( 0, g_pFloorTextures );
g_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 16, 2);

// ball (only the ball from .x file)
D3DXMatrixTranslation (&matNow, 0, 0, Z);
g_pd3dDevice->SetTransform (D3DTS_WORLDMATRIX(0), &matNow);
g_pBallMesh->DrawSubset (0);

g_pd3dDevice->EndScene();
// end of the scene rendering




When you set the world transform this will always be in effect (even in subsequent frames)until you set it to something else.

HTH,
Cambo_frog

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!