converted camera class

This commit is contained in:
Erik Persson 2013-11-29 09:20:37 +01:00
parent 8138afb6b5
commit 32c529feb6
1 changed files with 52 additions and 33 deletions

View File

@ -81,14 +81,15 @@ void Camera::LookAt(Oyster::Math::Float3 pos, Oyster::Math::Float3 target, Oyste
{ {
Oyster::Math::Float3 L; Oyster::Math::Float3 L;
D3DXVec3Subtract(&L, &target, &pos);
L = target - pos; L = target - pos;
D3DXVec3Normalize(&L, &L); L.Normalize();
Oyster::Math::Float3 R;
D3DXVec3Cross(&R, &worldUp, &L); Oyster::Math::Float3 R;
D3DXVec3Normalize(&R, &R); R = worldUp.Cross(L);
R.Normalize();
Oyster::Math::Float3 U; Oyster::Math::Float3 U;
D3DXVec3Cross(&U, &L, &R); U = L.Cross(R);
this->m_position = pos; this->m_position = pos;
this->mLook = L; this->mLook = L;
@ -109,7 +110,7 @@ Oyster::Math::Float4x4 Camera::Proj()const
Oyster::Math::Float4x4 Camera::ViewsProj()const Oyster::Math::Float4x4 Camera::ViewsProj()const
{ {
Oyster::Math::Float4x4 M; Oyster::Math::Float4x4 M;
D3DXMatrixMultiply(&M, &this->mView, &this->mProj); M = mView * mProj;
return M; return M;
} }
@ -129,7 +130,8 @@ void Camera::Pitch(float angle)
Oyster::Math::Float4x4 R; Oyster::Math::Float4x4 R;
D3DXMatrixRotationAxis(&R, &-mRight, radians); //D3DXMatrixRotationAxis(&R, &-mRight, radians);
Oyster::Math3D::RotationMatrix(radians,-mRight,R);
this->mUp = CrossMatrix(this->mUp, R); this->mUp = CrossMatrix(this->mUp, R);
this->mLook = CrossMatrix(this->mLook, R); this->mLook = CrossMatrix(this->mLook, R);
} }
@ -141,7 +143,8 @@ void Camera::Yaw(float angle)
Oyster::Math::Float4x4 R; Oyster::Math::Float4x4 R;
Oyster::Math::Float3 up(0,1,0); Oyster::Math::Float3 up(0,1,0);
D3DXMatrixRotationAxis(&R, &-up, radians); //D3DXMatrixRotationAxis(&R, &-up, radians);
Oyster::Math3D::RotationMatrix(radians,-up,R);
this->mRight = CrossMatrix(this->mRight, R); this->mRight = CrossMatrix(this->mRight, R);
this->mUp = CrossMatrix(mUp, R); this->mUp = CrossMatrix(mUp, R);
@ -150,33 +153,49 @@ void Camera::Yaw(float angle)
void Camera::UpdateViewMatrix() void Camera::UpdateViewMatrix()
{ {
D3DXVec3Normalize(&this->mLook, &this->mLook); mLook.Normalize();
D3DXVec3Cross(&this->mUp, &this->mLook, &this->mRight); mUp = mLook.Cross(mRight);
D3DXVec3Normalize(&this->mUp, &this->mUp); mUp.Normalize();
D3DXVec3Cross(&this->mRight, &this->mUp, &this->mLook); mRight = mUp.Cross(mLook);
float x = -m_position.Dot(mRight);
float y = -m_position.Dot(mUp);
float z = -m_position.Dot(mLook);
float x = -D3DXVec3Dot(&this->m_position, &mRight); //this->mView(0, 0) = this->mRight.x;
float y = -D3DXVec3Dot(&this->m_position, &mUp); mView.m11 = mRight.x;
float z = -D3DXVec3Dot(&this->m_position, &mLook); //this->mView(1, 0) = this->mRight.y;
mView.m21 = mRight.y;
//this->mView(2, 0) = this->mRight.z;
mView.m31 = mRight.z;
//this->mView(3, 0) = x;
mView.m41 = x;
this->mView(0, 0) = this->mRight.x; //this->mView(0, 1) = this->mUp.x;
this->mView(1, 0) = this->mRight.y; mView.m12 = mUp.x;
this->mView(2, 0) = this->mRight.z; //this->mView(1, 1) = this->mUp.y;
this->mView(3, 0) = x; mView.m22 = mUp.y;
//this->mView(2, 1) = this->mUp.z;
mView.m32 = mUp.z;
//this->mView(3, 1) = y;
mView.m42 = y;
this->mView(0, 1) = this->mUp.x; //this->mView(0, 2) = this->mLook.x;
this->mView(1, 1) = this->mUp.y; mView.m13 = mLook.x;
this->mView(2, 1) = this->mUp.z; //this->mView(1, 2) = this->mLook.y;
this->mView(3, 1) = y; mView.m23 = mLook.y;
//this->mView(2, 2) = this->mLook.z;
mView.m33 = mLook.z;
//this->mView(3, 2) = z;
mView.m43 = z;
this->mView(0, 2) = this->mLook.x; //this->mView(0, 3) = 0.0f;
this->mView(1, 2) = this->mLook.y; mView.m14 = 0.0f;
this->mView(2, 2) = this->mLook.z; //this->mView(1, 3) = 0.0f;
this->mView(3, 2) = z; mView.m24 = 0.0f;
this->mView(0, 3) = 0.0f; //this->mView(2, 3) = 0.0f;
this->mView(1, 3) = 0.0f; mView.m34 = 0.0f;
this->mView(2, 3) = 0.0f; //this->mView(3, 3) = 1.0f;
this->mView(3, 3) = 1.0f; mView.m44 = 1.0f;
} }