When I grab the position of the camera and the target position of the camera, I can create a view matrix.
These figures are exported out along with the axe or kwxporter in an .x file.
But as I cannot export the aspect ratio and far clip distance. I have to make them up by myself.
Currently, I use an aspect ratio of 0.33 and far clip distance of 10000.0f
And I set the visible object at 0,0,0 (identity) and unity scale (didn't move it or scale it, just same to the original scene recorded in max)
and I see nothing in the viewport.
#include <string>
#include "..\tinyxml\tinyxml.h"
#include "CCamera.h"
#include "..\Utilities\Utilities.h"
CCamera::CCamera()
{
m_vPos = D3DXVECTOR3(0.0f,0.0f,0.0f);
m_vLookAt = D3DXVECTOR3(0.0f,0.0f,0.0f);
D3DXMatrixIdentity(&m_matOrientation);
m_bChangingView = false;
}
void CCamera::Create(float fAspect, float fFar)
{
D3DXMatrixPerspectiveFovLH(&m_matProj,
D3DX_PI/4, fAspect, 1.0f, fFar );
}
void CCamera::Update(float dt, bool bUpdateFrustum)
{
if(m_bChangingView)
{
m_vPos = m_vEndPos;
m_vLookAt = m_vEndLookAt;
m_bChangingView = false;
}
// Set the view matrix
D3DXQUATERNION qR;
D3DXQuaternionRotationYawPitchRoll(&qR, m_vLookAt.x, m_vLookAt.y, m_vLookAt.z);
D3DXMatrixAffineTransformation(&m_matOrientation, 1.25f, NULL, &qR, &m_vPos );
D3DXMatrixInverse( &m_matView, NULL, &m_matOrientation );
// Deceleating the yaw/pitch/roll velocities works great for keyboard control,
// but it gives me motion sickness when used with mouselook, so I commented it out
// and replaced it with multiplication by zero, which disables the velocities.
// Your mileage may vary.
if(bUpdateFrustum)
UpdateFrustum();
}
void CCamera::UpdateFrustum()
{
D3DXMATRIX Matrix;
D3DXMatrixMultiply(&Matrix, &m_matView, &m_matProj);
// Calculate the planes
m_FrustumPlanes[0].a = Matrix._14 + Matrix._13; // Near plane
m_FrustumPlanes[0].b = Matrix._24 + Matrix._23;
m_FrustumPlanes[0].c = Matrix._34 + Matrix._33;
m_FrustumPlanes[0].d = Matrix._44 + Matrix._43;
D3DXPlaneNormalize(&m_FrustumPlanes[0], &m_FrustumPlanes[0]);
m_FrustumPlanes[1].a = Matrix._14 - Matrix._13; // Far plane
m_FrustumPlanes[1].b = Matrix._24 - Matrix._23;
m_FrustumPlanes[1].c = Matrix._34 - Matrix._33;
m_FrustumPlanes[1].d = Matrix._44 - Matrix._43;
D3DXPlaneNormalize(&m_FrustumPlanes[1], &m_FrustumPlanes[1]);
m_FrustumPlanes[2].a = Matrix._14 + Matrix._11; // Left plane
m_FrustumPlanes[2].b = Matrix._24 + Matrix._21;
m_FrustumPlanes[2].c = Matrix._34 + Matrix._31;
m_FrustumPlanes[2].d = Matrix._44 + Matrix._41;
D3DXPlaneNormalize(&m_FrustumPlanes[2], &m_FrustumPlanes[2]);
m_FrustumPlanes[3].a = Matrix._14 - Matrix._11; // Right plane
m_FrustumPlanes[3].b = Matrix._24 - Matrix._21;
m_FrustumPlanes[3].c = Matrix._34 - Matrix._31;
m_FrustumPlanes[3].d = Matrix._44 - Matrix._41;
D3DXPlaneNormalize(&m_FrustumPlanes[3], &m_FrustumPlanes[3]);
m_FrustumPlanes[4].a = Matrix._14 - Matrix._12; // Top plane
m_FrustumPlanes[4].b = Matrix._24 - Matrix._22;
m_FrustumPlanes[4].c = Matrix._34 - Matrix._32;
m_FrustumPlanes[4].d = Matrix._44 - Matrix._42;
D3DXPlaneNormalize(&m_FrustumPlanes[4], &m_FrustumPlanes[4]);
m_FrustumPlanes[5].a = Matrix._14 + Matrix._12; // Bottom plane
m_FrustumPlanes[5].b = Matrix._24 + Matrix._22;
m_FrustumPlanes[5].c = Matrix._34 + Matrix._32;
m_FrustumPlanes[5].d = Matrix._44 + Matrix._42;
D3DXPlaneNormalize(&m_FrustumPlanes[5], &m_FrustumPlanes[5]);
}
void CCamera::ChangeView(D3DXVECTOR3 *vPos, D3DXVECTOR3 *vAt)
{
m_vEndPos = *vPos;
m_vEndLookAt = *vAt;
m_bChangingView = true;
}
bool CCamera::CheckSphere(D3DXVECTOR3 *vCenter, float *fRadius)
{
int i;
for(i = 0; i < 6; i++)
if(D3DXPlaneDotCoord(&m_FrustumPlanes[i], &D3DXVECTOR3(vCenter->x, vCenter->y, vCenter->z)) < -*fRadius)
return false;
return true;
}
m_Cam[0].ChangeView(&m_Warehouse.GetPosition("Camera001"), &m_Warehouse.GetPosition("Camera001_Target"));
m_Cam[0].Create(0.33f, 10000.0f);
m_Cam[0].Update(0);
Any ideas I can fix that one up.
Thanks
Jack