port from perforce
This commit is contained in:
43
aiwaz/Aiwaz/Resources/Camera/BaseCamera.cpp
Normal file
43
aiwaz/Aiwaz/Resources/Camera/BaseCamera.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "stdafx.h"
|
||||
#include "BaseCamera.h"
|
||||
|
||||
|
||||
BaseCamera::BaseCamera(IEngine& argEngine)
|
||||
: Transformation(argEngine)
|
||||
, m_NearClip(1.0f)
|
||||
, m_FarClip(100.0f)
|
||||
, m_AspectRatio(1.0f)
|
||||
{
|
||||
this->set_IsPreconditionForFollowingShaders(true);
|
||||
this->RecreateAllShaderParameters();
|
||||
}
|
||||
|
||||
|
||||
void BaseCamera::set_AspectRatio(float argValue)
|
||||
{
|
||||
m_AspectRatio = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void BaseCamera::set_FarClip(float argValue)
|
||||
{
|
||||
m_FarClip = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void BaseCamera::set_NearClip(float argValue)
|
||||
{
|
||||
m_NearClip = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void BaseCamera::RecreateAllShaderParameters()
|
||||
{
|
||||
this->SetParameter("ViewMatrix", &m_ViewMatrix, ParameterBindType::BindBySemantic);
|
||||
this->SetParameter("ProjectionMatrix", &m_ProjectionMatrix, ParameterBindType::BindBySemantic);
|
||||
|
||||
Transformation::RecreateAllShaderParameters();
|
||||
}
|
||||
40
aiwaz/Aiwaz/Resources/Camera/BaseCamera.h
Normal file
40
aiwaz/Aiwaz/Resources/Camera/BaseCamera.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "ICamera.h"
|
||||
#include "IEngine.h"
|
||||
#include "../Transformation/Transformation.h"
|
||||
|
||||
|
||||
class BaseCamera
|
||||
: public Transformation
|
||||
, public ICamera
|
||||
{
|
||||
public:
|
||||
BaseCamera(IEngine& argEngine);
|
||||
|
||||
virtual const D3DXMATRIX& get_ProjectionMatrix() const { return m_ProjectionMatrix; }
|
||||
virtual const D3DXMATRIX& get_ViewMatrix() const { return m_ViewMatrix; }
|
||||
|
||||
virtual void set_AspectRatio(float argValue);
|
||||
virtual float get_AspectRatio() const { return m_AspectRatio; }
|
||||
|
||||
virtual void set_FarClip(float argValue);
|
||||
virtual float get_FarClip() const { return m_FarClip; }
|
||||
|
||||
virtual void set_NearClip(float argValue);
|
||||
virtual float get_NearClip() const { return m_NearClip; }
|
||||
|
||||
virtual const ViewFrustum& get_ViewFrustum() const { return m_Frustum; }
|
||||
|
||||
protected:
|
||||
virtual void RecreateAllShaderParameters();
|
||||
|
||||
protected:
|
||||
float m_NearClip;
|
||||
float m_FarClip;
|
||||
float m_AspectRatio;
|
||||
|
||||
D3DXMATRIX m_ProjectionMatrix;
|
||||
D3DXMATRIX m_ViewMatrix;
|
||||
ViewFrustum m_Frustum;
|
||||
};
|
||||
89
aiwaz/Aiwaz/Resources/Camera/OrthographicCamera.cpp
Normal file
89
aiwaz/Aiwaz/Resources/Camera/OrthographicCamera.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "stdafx.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "OrthographicCamera.h"
|
||||
|
||||
|
||||
OrthographicCamera::OrthographicCamera(IEngine& argEngine)
|
||||
: BaseCamera(argEngine)
|
||||
, m_Width(1.0f)
|
||||
, m_Height(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
OrthographicCamera::~OrthographicCamera()
|
||||
{
|
||||
m_Engine.get_ResourceFactory().DeleteOrthographicCamera(*const_cast<OrthographicCamera*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void OrthographicCamera::set_Width(float argValue)
|
||||
{
|
||||
m_Width = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void OrthographicCamera::set_Height(float argValue)
|
||||
{
|
||||
m_Height = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void OrthographicCamera::Update(bool argForceUpdate)
|
||||
{
|
||||
BaseCamera::Update(argForceUpdate);
|
||||
|
||||
D3DXMATRIXA16 projectionMatrix;
|
||||
D3DXMATRIXA16 viewMatrix;
|
||||
|
||||
D3DXVECTOR3 worldPos = this->get_WorldPosition();
|
||||
D3DXVECTOR3 worldDirection = this->get_WorldDirection();
|
||||
D3DXVECTOR3 worldUpDirection = this->get_WorldUpDirection();
|
||||
|
||||
::D3DXMatrixOrthoLH(&projectionMatrix, m_Width, m_Height, m_NearClip, m_FarClip);
|
||||
::D3DXMatrixLookAtLH(&viewMatrix, &worldPos, &(worldPos + worldDirection), &worldUpDirection);
|
||||
|
||||
m_ProjectionMatrix = projectionMatrix;
|
||||
m_ViewMatrix = viewMatrix;
|
||||
|
||||
// generate view frustum
|
||||
D3DXMATRIXA16 viewProjection = viewMatrix * projectionMatrix;
|
||||
|
||||
// Left plane
|
||||
m_Frustum.Plane[0].a = viewProjection._14 + viewProjection._11;
|
||||
m_Frustum.Plane[0].b = viewProjection._24 + viewProjection._21;
|
||||
m_Frustum.Plane[0].c = viewProjection._34 + viewProjection._31;
|
||||
m_Frustum.Plane[0].d = viewProjection._44 + viewProjection._41;
|
||||
|
||||
// Right plane
|
||||
m_Frustum.Plane[1].a = viewProjection._14 - viewProjection._11;
|
||||
m_Frustum.Plane[1].b = viewProjection._24 - viewProjection._21;
|
||||
m_Frustum.Plane[1].c = viewProjection._34 - viewProjection._31;
|
||||
m_Frustum.Plane[1].d = viewProjection._44 - viewProjection._41;
|
||||
|
||||
// Top plane
|
||||
m_Frustum.Plane[2].a = viewProjection._14 - viewProjection._12;
|
||||
m_Frustum.Plane[2].b = viewProjection._24 - viewProjection._22;
|
||||
m_Frustum.Plane[2].c = viewProjection._34 - viewProjection._32;
|
||||
m_Frustum.Plane[2].d = viewProjection._44 - viewProjection._42;
|
||||
|
||||
// Bottom plane
|
||||
m_Frustum.Plane[3].a = viewProjection._14 + viewProjection._12;
|
||||
m_Frustum.Plane[3].b = viewProjection._24 + viewProjection._22;
|
||||
m_Frustum.Plane[3].c = viewProjection._34 + viewProjection._32;
|
||||
m_Frustum.Plane[3].d = viewProjection._44 + viewProjection._42;
|
||||
|
||||
// Near plane
|
||||
m_Frustum.Plane[4].a = viewProjection._13;
|
||||
m_Frustum.Plane[4].b = viewProjection._23;
|
||||
m_Frustum.Plane[4].c = viewProjection._33;
|
||||
m_Frustum.Plane[4].d = viewProjection._43;
|
||||
|
||||
// Far plane
|
||||
m_Frustum.Plane[5].a = viewProjection._14 - viewProjection._13;
|
||||
m_Frustum.Plane[5].b = viewProjection._24 - viewProjection._23;
|
||||
m_Frustum.Plane[5].c = viewProjection._34 - viewProjection._33;
|
||||
m_Frustum.Plane[5].d = viewProjection._44 - viewProjection._43;
|
||||
}
|
||||
31
aiwaz/Aiwaz/Resources/Camera/OrthographicCamera.h
Normal file
31
aiwaz/Aiwaz/Resources/Camera/OrthographicCamera.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseCamera.h"
|
||||
|
||||
|
||||
class OrthographicCamera
|
||||
: public BaseCamera
|
||||
, public IOrthographicCamera
|
||||
{
|
||||
public:
|
||||
OrthographicCamera(IEngine& argEngine);
|
||||
virtual ~OrthographicCamera();
|
||||
|
||||
virtual void set_Width(float argValue);
|
||||
virtual float get_Width() const { return m_Width; }
|
||||
|
||||
virtual void set_Height(float argValue);
|
||||
virtual float get_Height() const { return m_Height; }
|
||||
|
||||
virtual void Update(bool argForceUpdate);
|
||||
|
||||
virtual ICamera& get_Base() { return *dynamic_cast<ICamera*>(this); }
|
||||
|
||||
protected:
|
||||
// ICommandUser
|
||||
virtual string8 get_UserName() const { return "OrthographicCamera"; }
|
||||
|
||||
private:
|
||||
float m_Width;
|
||||
float m_Height;
|
||||
};
|
||||
80
aiwaz/Aiwaz/Resources/Camera/PerspectiveCamera.cpp
Normal file
80
aiwaz/Aiwaz/Resources/Camera/PerspectiveCamera.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "stdafx.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "PerspectiveCamera.h"
|
||||
|
||||
|
||||
PerspectiveCamera::PerspectiveCamera(IEngine& argEngine)
|
||||
: BaseCamera(argEngine)
|
||||
, m_Fov(90.0f)
|
||||
{
|
||||
}
|
||||
|
||||
PerspectiveCamera::~PerspectiveCamera()
|
||||
{
|
||||
m_Engine.get_ResourceFactory().DeletePerspectiveCamera(*const_cast<PerspectiveCamera*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void PerspectiveCamera::set_Fov(float argFov)
|
||||
{
|
||||
m_Fov = argFov;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void PerspectiveCamera::Update(bool argForceUpdate)
|
||||
{
|
||||
BaseCamera::Update(argForceUpdate);
|
||||
|
||||
D3DXMATRIXA16 projectionMatrix;
|
||||
D3DXMATRIXA16 viewMatrix;
|
||||
|
||||
D3DXVECTOR3 worldPos = this->get_WorldPosition();
|
||||
D3DXVECTOR3 worldDirection = this->get_WorldDirection();
|
||||
D3DXVECTOR3 worldUpDirection = this->get_WorldUpDirection();
|
||||
|
||||
::D3DXMatrixPerspectiveFovLH(&projectionMatrix, static_cast<float>(D3DXToRadian(m_Fov)), m_AspectRatio, m_NearClip, m_FarClip);
|
||||
::D3DXMatrixLookAtLH(&viewMatrix, &worldPos, &(worldPos + worldDirection), &worldUpDirection);
|
||||
|
||||
m_ProjectionMatrix = projectionMatrix;
|
||||
m_ViewMatrix = viewMatrix;
|
||||
|
||||
// generate view frustum
|
||||
D3DXMATRIXA16 viewProjection = viewMatrix * projectionMatrix;
|
||||
|
||||
// Left plane
|
||||
m_Frustum.Plane[0].a = viewProjection._14 + viewProjection._11;
|
||||
m_Frustum.Plane[0].b = viewProjection._24 + viewProjection._21;
|
||||
m_Frustum.Plane[0].c = viewProjection._34 + viewProjection._31;
|
||||
m_Frustum.Plane[0].d = viewProjection._44 + viewProjection._41;
|
||||
|
||||
// Right plane
|
||||
m_Frustum.Plane[1].a = viewProjection._14 - viewProjection._11;
|
||||
m_Frustum.Plane[1].b = viewProjection._24 - viewProjection._21;
|
||||
m_Frustum.Plane[1].c = viewProjection._34 - viewProjection._31;
|
||||
m_Frustum.Plane[1].d = viewProjection._44 - viewProjection._41;
|
||||
|
||||
// Top plane
|
||||
m_Frustum.Plane[2].a = viewProjection._14 - viewProjection._12;
|
||||
m_Frustum.Plane[2].b = viewProjection._24 - viewProjection._22;
|
||||
m_Frustum.Plane[2].c = viewProjection._34 - viewProjection._32;
|
||||
m_Frustum.Plane[2].d = viewProjection._44 - viewProjection._42;
|
||||
|
||||
// Bottom plane
|
||||
m_Frustum.Plane[3].a = viewProjection._14 + viewProjection._12;
|
||||
m_Frustum.Plane[3].b = viewProjection._24 + viewProjection._22;
|
||||
m_Frustum.Plane[3].c = viewProjection._34 + viewProjection._32;
|
||||
m_Frustum.Plane[3].d = viewProjection._44 + viewProjection._42;
|
||||
|
||||
// Near plane
|
||||
m_Frustum.Plane[4].a = viewProjection._13;
|
||||
m_Frustum.Plane[4].b = viewProjection._23;
|
||||
m_Frustum.Plane[4].c = viewProjection._33;
|
||||
m_Frustum.Plane[4].d = viewProjection._43;
|
||||
|
||||
// Far plane
|
||||
m_Frustum.Plane[5].a = viewProjection._14 - viewProjection._13;
|
||||
m_Frustum.Plane[5].b = viewProjection._24 - viewProjection._23;
|
||||
m_Frustum.Plane[5].c = viewProjection._34 - viewProjection._33;
|
||||
m_Frustum.Plane[5].d = viewProjection._44 - viewProjection._43;
|
||||
}
|
||||
27
aiwaz/Aiwaz/Resources/Camera/PerspectiveCamera.h
Normal file
27
aiwaz/Aiwaz/Resources/Camera/PerspectiveCamera.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseCamera.h"
|
||||
|
||||
|
||||
class PerspectiveCamera
|
||||
: public BaseCamera
|
||||
, public IPerspectiveCamera
|
||||
{
|
||||
public:
|
||||
PerspectiveCamera(IEngine& argEngine);
|
||||
virtual ~PerspectiveCamera();
|
||||
|
||||
virtual void set_Fov(float argValue);
|
||||
virtual float get_Fov() const { return m_Fov; }
|
||||
|
||||
virtual void Update(bool argForceUpdate);
|
||||
|
||||
virtual ICamera& get_Base() { return *dynamic_cast<ICamera*>(this); }
|
||||
|
||||
protected:
|
||||
// ICommandUser
|
||||
virtual string8 get_UserName() const { return "PerspectiveCamera"; }
|
||||
|
||||
private:
|
||||
float m_Fov;
|
||||
};
|
||||
Reference in New Issue
Block a user