# Trying to get mesh plane to stay in front of camera

This topic is 4139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What I'm trying to do is create a mesh plane, put it 10 unit in front of the camera and having it follow the camera (match its rotation/transformation). To do this I basically decided to get the cameras view matrix and modify the z coordinate and add 10 to it so it can be placed ten units in front of the camera. What happened was the object was moving in exact opposite to the camera, when I moved the camera forward the object was moving backwards, rotating left, objects rotating right. So I made some of the transform coordinates negative so it aligns with the camera. Now the rotations work and so do the transformations, but if I transform the position of the camera the rotation stops working. Heres how I'm *trying* to get the matrix of the camera to make it work right:
D3DXVECTOR3 _right;
D3DXVECTOR3 _up;
D3DXVECTOR3 _look;
D3DXVECTOR3 _pos;

...
void Camera::getViewMatrix(D3DXMATRIX* V)
{
// Keep camera's axes orthogonal to eachother
D3DXVec3Normalize(&_look, &_look);

D3DXVec3Cross(&_up, &_look, &_right);
D3DXVec3Normalize(&_up, &_up);

D3DXVec3Cross(&_right, &_up, &_look);
D3DXVec3Normalize(&_right, &_right);

// Build the view matrix:
float x = -D3DXVec3Dot(&_right, &_pos);
float y = -D3DXVec3Dot(&_up, &_pos);
float z = -D3DXVec3Dot(&_look, &_pos);

(*V)(0,0) = _right.x; (*V)(0, 1) = _up.x; (*V)(0, 2) = -_look.x; (*V)(0, 3) = 0.0f;
(*V)(1,0) = _right.y; (*V)(1, 1) = -_up.y; (*V)(1, 2) = _look.y;  (*V)(1, 3) = 0.0f;
(*V)(2,0) = -_right.z; (*V)(2, 1) = _up.z; (*V)(2, 2) = _look.z; (*V)(2, 3) = 0.0f;
(*V)(3,0) = -x;        (*V)(3, 1) = -y;     (*V)(3, 2) = -z;     (*V)(3, 3) = 1.0f;
}


1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 11
• 16
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633003
• Total Posts
3009846
• ### Who's Online (See full list)

There are no registered users currently online

×