Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


How to put a model in the "world of the camera" ?

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

[excuse my English] I have the ambitious objective to manage a day to make a space simulation. But for the moment I'm a newbie, and there are problems with my camera... I try to display a starfield. I know the idea of the "skybox" or "sphere", but I think have a better idea : render a "rectangle" in the bottom of the view, and move the texture (the universe, with stars, planets...) on this rectangle. But I don't know how to put the rectangle in the world of the camera, and not in the world of the scene. My test program resembles that :
D3DXMATRIX matView, matTranslate, matResult;
// Put a camera which moves on the right

D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( 0.0f + right, 0.0f, -500.0f),
&D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ));
// Translate the rectangle in the bottom

D3DXMatrixTranslation(&matTranslate, 0.0f, 0.0f, 900.0f);
// Say to make the translation of the model compared to the origin (0, 0, 0) of the camera

// and not compared to the origin of the scene, to keep the rectangle in the view

I tried several things, but without success
// Create the view

m_pd3dDevice->SetTransform(D3DTS_VIEW, &matResult);
// Render of the rectangle

Can you explain me how to fix a model to a camera ? Thanks... Edited by - Coudrak on November 3, 2001 5:40:28 AM

Share this post

Link to post
Share on other sites
You want to keep your rectangle always facing your camera , right? This technique is called billboarding, and is used for particle effects and other things. The direct x sdk comes with a billboarding sample that renders a bunch of trees as textured quads. Take a look at that sample, or search this and other sites for billboarding tutorials.

Share this post

Link to post
Share on other sites
Nooo, it's not exactly that

The rectangle must remain aligned with the view, yes, but it must also move itself like the camera. Because I would like have a backgound in fact.

And with this example (that I found in this forum)...

// Get the current view matrix

m_pd3dDevice->GetTransform(D3DTS_VIEW, &matView);

// Get the transposed matrix

D3DXMATRIX matTransposed;
D3DXMatrixTranspose(&matTransposed, &matView);

// Position the billboard
matTransposed._41 = X;
matTransposed._42 = Y;
matTransposed._43 = Z;

// Set as world transformation matrix
m_pd3dDevice->SetTransform(D3DTS_WORLD, &matTransposed);

// Draw whatever - will be aligned with view

... the problem is the coordinates (X, Y, Z) to place the rectangle are scene coordinates, and not camera coordinates. I would like when I move the camera, that the rectangle remains "hung" with the camera, to make a backgound 2D...

Edited by - Coudrak on November 4, 2001 6:47:25 AM

Share this post

Link to post
Share on other sites

I understand what you''re trying to do, and the solution is to take a simple object matrix and multiply it with the inverse view matrix, to get the final transformation matrix in world space..

In this example I just set the object as being 200 units away from the camera

// how to lock an object into a position in front of the camera

D3DMATRIX object;
D3DUtil_SetIdentityMatrix( object );
object(3,2) = 200.0f; // move the object away from the cam down the z axis 200 units

D3DMath_MatrixMultiply( finaltrans, InverseViewMatrix , object );

I think you already know how to get the inverse view matrix, and set the finaltrans matrix as the currect transform.



Share this post

Link to post
Share on other sites

  • 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!