Jump to content
  • Advertisement
Sign in to follow this  
chillypacman

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.

If you intended to correct an error in the post then please contact us.

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;
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

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