1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include "Camera.h" // For Camera declarations.
Camera::Camera(bool setDynamic)
:dynamic(setDynamic),personality(0),position(0.0f, 0.0f, 0.0f),radius(0),theta(0),height(0){}
Camera::Camera(bool setDynamic, bool setPersonality)
:dynamic(setDynamic),personality(setPersonality),position(0.0f, 0.0f, 0.0f),radius(0),theta(0),height(0){}
Camera::Camera(bool setDynamic, bool setPersonality,D3DXVECTOR3 setPosition,float setRadius, float setRadiusMin, float setTheta, float setHeight)
:dynamic(setDynamic),personality(setPersonality)
{
radiusMin = setRadiusMin;
setPositioning(setPosition,setRadius,setTheta,setHeight);
}
Camera::~Camera()
{
}
void Camera::addPositioning(D3DXVECTOR3 addPosition, float addRadius, float addTheta, float addHeight)
{
position += addPosition;
if(radius+addRadius<radiusMin)
radius = radiusMin;
else
radius += addRadius;
theta += addTheta;
/*
if(theta >= 2.0f * D3DX_PI)
theta -= 2.0f * D3DX_PI;
if(theta <= -2.0f * D3DX_PI)
theta += 2.0f * D3DX_PI;
*/
// Originally, (Heap error)
if(fabsf(theta) >= 2.0f * D3DX_PI)
theta = 0.0f;
height += addHeight;
if (!dynamic)
constructViewMatrix();
}
void Camera::setPositioning(D3DXVECTOR3 setPosition, float setRadius, float setTheta, float setHeight)
{
position = setPosition;
if(setRadius<radiusMin)
radius = radiusMin;
else
radius = setRadius;
theta = setTheta;
if(fabsf(theta) >= 2.0f * D3DX_PI)
theta -= 2.0f * D3DX_PI;
if(theta <= -2.0f * D3DX_PI)
theta += 2.0f * D3DX_PI;
/*
if(theta >= 2.0f * D3DX_PI)
theta -= 2.0f * D3DX_PI;
if(theta <= -2.0f * D3DX_PI)
theta += 2.0f * D3DX_PI;
*/
// Originally, (Still worked though)
if(fabsf(theta) >= 2.0f * D3DX_PI)
theta = 0.0f;
height = setHeight;
if (!dynamic)
constructViewMatrix();
}
void Camera::constructProjectionMatrix(unsigned int width, unsigned int height)
{
D3DXMatrixPerspectiveFovLH(&projection, D3DX_PI * 0.25f, (float) width / (float) height, 1.0f, 5000.0f);
}
void Camera::constructViewMatrix()
{
float x = radius * cosf(theta);
float z = radius * sinf(theta);
D3DXVECTOR3 pos(x, height, z);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(&view,&pos, &position, &up);
}
D3DXMATRIX* Camera::getView()
{
if (dynamic)
constructViewMatrix();
return &view;
}
D3DXMATRIX* Camera::getProjection()
{
return &projection;
}
|