So, I was working with 3D cameras and worlds, and I realized...I don't really understand what the matrices represent.
There is a ViewMatrix, a perspective matrix, an upmatrix, and a world matrix.
I thought that the ViewMatrix created the clipped world matrix, the perspective matrix scewed and transformed the world matrix to create an illusion of depth and perspective, and then a world matrix that contained the coordinates for everything...but that still leaves the up matrix, and I have NO idea what that would be.
I understand the math for creating perspective from matrices, but I don't know what the up matrix would be the equivalent to. What is this? How can I use this properly?
So far, I have created a camera like so...:
Camera.h:
Camera.cppCode:#include "camera.h" static float aspect = 800.0f / 600.0f; Camera::Camera(CameraType type) { _Type = type; _Position = _Rotation = PointF(0.0f, 0.0f, 0.0f); //D3DXVECTOR3 cameraPosition( 0.0f, 10.0f, 0.0f ); //D3DXVECTOR3 cameraTarget( 0.0f, 1.0f, 10.0f ); //D3DXVECTOR3 cameraUp( 0.0f, 1.0f, 0.0f ); //D3DXMatrixLookAtLH( &ViewMatrix, &cameraPosition, &cameraTarget, &cameraUp ); //GraphicDevice::GetService()->Device()->SetTransform( D3DTS_VIEW, &ViewMatrix ); ////D3DXMatrixPerspectiveFovLH(&ProjectionMatrix, PI/4, 1.0f, 1.0f, 5000.0f); ////GraphicDevice::GetService()->Device()->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix); // // Set the projection matrix //D3DXMatrixPerspectiveFovLH( &ProjectionMatrix, D3DX_PI / 2, aspect, 1.0f, 1000.0f ); //GraphicDevice::GetService()->Device()->SetTransform( D3DTS_PROJECTION, &ProjectionMatrix ); } Camera::~Camera(void) { } void Camera::Update(void) { //D3DXVECTOR3 cameraPosition(_Position.X(), _Position.Y(), _Position.Z()); //D3DXVECTOR3 cameraTarget(_Position.X()+cos(_Rotation.Z()), _Position.Y(), _Position.Z()+sin(_Rotation.X())); //D3DXVECTOR3 cameraUp(0.0f, 1.0f, 0.0f); // D3DXMatrixLookAtLH( &ViewMatrix, &cameraPosition, &cameraTarget, &cameraUp ); // // D3DXMatrixPerspectiveFovLH( &ProjectionMatrix, D3DX_PI / 2, aspect, 1.0f, 5000.0f ); // HRESULT a = GraphicDevice::GetService()->Device()->SetTransform( D3DTS_PROJECTION, &ProjectionMatrix ); //int i = 0; D3DXVECTOR3 Position(_Position.X(), _Position.Y(), _Position.Z()), Target(_Position.X(), _Position.Y(), _Position.Z()), UpVector(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&ViewMatrix, &Position, &Target, &UpVector); D3DXMatrixPerspectiveFovLH(&ProjectionMatrix, D3DX_PI / 2, aspect, 1.0f, 5000.0f); GraphicDevice::GetService()->Device()->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix); } void Camera::Rotate(TransformType type, PointF rotation) { switch(type) { case TransformTypes::Absolute: _Rotation = rotation; break; case TransformTypes::Relative: _Rotation += rotation; break; } } void Camera::Move(TransformType type, PointF A) { switch(type) { case TransformTypes::Absolute: _Position = A; break; case TransformTypes::Relative: _Position.Z(_Position.Z() + cos(A.Z()) + sin(A.Z())); _Position.X(_Position.Z() + cos(A.Z()) - sin(A.Z())); break; } }
Code:#include "camera.h" static float aspect = 800.0f / 600.0f; Camera::Camera(CameraType type) { _Type = type; _Position = _Rotation = PointF(0.0f, 0.0f, 0.0f); //D3DXVECTOR3 cameraPosition( 0.0f, 10.0f, 0.0f ); //D3DXVECTOR3 cameraTarget( 0.0f, 1.0f, 10.0f ); //D3DXVECTOR3 cameraUp( 0.0f, 1.0f, 0.0f ); //D3DXMatrixLookAtLH( &ViewMatrix, &cameraPosition, &cameraTarget, &cameraUp ); //GraphicDevice::GetService()->Device()->SetTransform( D3DTS_VIEW, &ViewMatrix ); ////D3DXMatrixPerspectiveFovLH(&ProjectionMatrix, PI/4, 1.0f, 1.0f, 5000.0f); ////GraphicDevice::GetService()->Device()->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix); // // Set the projection matrix //D3DXMatrixPerspectiveFovLH( &ProjectionMatrix, D3DX_PI / 2, aspect, 1.0f, 1000.0f ); //GraphicDevice::GetService()->Device()->SetTransform( D3DTS_PROJECTION, &ProjectionMatrix ); } Camera::~Camera(void) { } void Camera::Update(void) { D3DXVECTOR3 cameraPosition(_Position.X(), _Position.Y(), _Position.Z()); D3DXVECTOR3 cameraTarget(_Position.X()+cos(_Rotation.Z()), _Position.Y(), _Position.Z()+sin(_Rotation.X())); D3DXVECTOR3 cameraUp(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH( &ViewMatrix, &cameraPosition, &cameraTarget, &cameraUp ); D3DXMatrixPerspectiveFovLH( &ProjectionMatrix, D3DX_PI / 2, aspect, 1.0f, 5000.0f ); HRESULT a = GraphicDevice::GetService()->Device()->SetTransform( D3DTS_PROJECTION, &ProjectionMatrix ); //int i = 0; //D3DXVECTOR3 Position(_Position.X(), _Position.Y(), _Position.Z()), // Target(_Position.X(), _Position.Y(), _Position.Z()), // UpVector(0.0f, 1.0f, 0.0f); //D3DXMatrixLookAtLH(&ViewMatrix, &Position, &Target, &UpVector); //D3DXMatrixPerspectiveFovLH(&ProjectionMatrix, D3DX_PI / 2, aspect, 1.0f, 5000.0f); //GraphicDevice::GetService()->Device()->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix); } void Camera::Rotate(TransformType type, PointF rotation) { switch(type) { case TransformTypes::Absolute: _Rotation = rotation; break; case TransformTypes::Relative: _Rotation += rotation; break; } } void Camera::Move(TransformType type, PointF A) { switch(type) { case TransformTypes::Absolute: _Position = A; break; case TransformTypes::Relative: _Position.Z(_Position.Z() + cos(A.Z()) + sin(A.Z())); _Position.X(_Position.Z() + cos(A.Z()) - sin(A.Z())); break; } }
Then I try to move it like so:
Code:if(KeyboardDevice::GetService()->Pressed(Keys::ArrowUp)) { camera.Move(TransformTypes::Relative, PointF(0.0f, 0.0f, 0.1f)); } else if(KeyboardDevice::GetService()->Pressed(Keys::ArrowDown)) { camera.Move(TransformTypes::Relative, PointF(0.0f, 0.0f, -0.1f)); }
So....Why doesn't this alter the perspective matrix, so that it appears that I am moving?
Does anyone know?



LinkBack URL
About LinkBacks


