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

Started by
4 comments, last by Coudrak 22 years, 5 months ago
[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
Advertisement
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.
Thanks a lot.
I didn''t know that the "Billboarding" is what I search
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
D3DXMATRIX matView;

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
Hi,

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 cameraD3DMATRIX object;D3DUtil_SetIdentityMatrix( object );object(3,2) = 200.0f; // move the object away from the cam down the z axis 200 unitsD3DMath_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.

Cheers

Matt



Yeepee !!!
It works, thanks very much


(I used the D3DXMatrixInverse function to inverse the matrix view.)

This topic is closed to new replies.

Advertisement