|
|
@@ -1,39 +1,39 @@
|
|
|
-#include "camera.h"
|
|
|
+#include "Camera.h"
|
|
|
#include "renderer.h"
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// SetAll =
|
|
|
+// setAll =
|
|
|
//=====================================================================================================================================
|
|
|
-void camera_t::SetAll( float fovx_, float fovy_, float znear_, float zfar_ )
|
|
|
+void Camera::setAll( float fovx_, float fovy_, float znear_, float zfar_ )
|
|
|
{
|
|
|
- fovx = fovx_;
|
|
|
- fovy = fovy_;
|
|
|
- znear = znear_;
|
|
|
- zfar = zfar_;
|
|
|
- CalcProjectionMatrix();
|
|
|
- CalcLSpaceFrustumPlanes();
|
|
|
+ fovX = fovx_;
|
|
|
+ fovY = fovy_;
|
|
|
+ zNear = znear_;
|
|
|
+ zFar = zfar_;
|
|
|
+ calcProjectionMatrix();
|
|
|
+ calcLSpaceFrustumPlanes();
|
|
|
}
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// Render =
|
|
|
+// render =
|
|
|
//=====================================================================================================================================
|
|
|
-void camera_t::Render()
|
|
|
+void Camera::render()
|
|
|
{
|
|
|
glPushMatrix();
|
|
|
- r::MultMatrix( transformation_wspace );
|
|
|
+ r::MultMatrix( transformationWspace );
|
|
|
|
|
|
- const float cam_len = 1.0;
|
|
|
- float tmp0 = cam_len / tan( (PI - fovx)*0.5 ) + 0.001;
|
|
|
- float tmp1 = cam_len * tan(fovy*0.5) + 0.001;
|
|
|
+ const float camLen = 1.0;
|
|
|
+ float tmp0 = camLen / tan( (PI - fovX)*0.5 ) + 0.001;
|
|
|
+ float tmp1 = camLen * tan(fovY*0.5) + 0.001;
|
|
|
|
|
|
float points [][3] = {
|
|
|
{0.0, 0.0, 0.0}, // 0: eye point
|
|
|
- {-tmp0, tmp1, -cam_len}, // 1: top left
|
|
|
- {-tmp0, -tmp1, -cam_len}, // 2: bottom left
|
|
|
- {tmp0, -tmp1, -cam_len}, // 3: bottom right
|
|
|
- {tmp0, tmp1, -cam_len}, // 4: top right
|
|
|
+ {-tmp0, tmp1, -camLen}, // 1: top left
|
|
|
+ {-tmp0, -tmp1, -camLen}, // 2: bottom left
|
|
|
+ {tmp0, -tmp1, -camLen}, // 3: bottom right
|
|
|
+ {tmp0, tmp1, -camLen}, // 4: top right
|
|
|
};
|
|
|
|
|
|
//glLineWidth( 2.0 );
|
|
|
@@ -63,67 +63,67 @@ void camera_t::Render()
|
|
|
|
|
|
// if( !strcmp( camera_data_user_class_t::GetName(), "main_cam") ) return;
|
|
|
// //for( uint i=0; i<2; i++ )
|
|
|
-// wspace_frustum_planes[TOP].Render();
|
|
|
+// wspaceFrustumPlanes[TOP].render();
|
|
|
}
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// LookAtPoint =
|
|
|
+// lookAtPoint =
|
|
|
//=====================================================================================================================================
|
|
|
-void camera_t::LookAtPoint( const vec3_t& point )
|
|
|
+void Camera::lookAtPoint( const vec3_t& point )
|
|
|
{
|
|
|
const vec3_t& j = vec3_t( 0.0, 1.0, 0.0 );
|
|
|
- vec3_t vdir = (point - translation_lspace).GetNormalized();
|
|
|
+ vec3_t vdir = (point - translationLspace).GetNormalized();
|
|
|
vec3_t vup = j - vdir * j.Dot(vdir);
|
|
|
vec3_t vside = vdir.Cross( vup );
|
|
|
- rotation_lspace.SetColumns( vside, vup, -vdir );
|
|
|
+ rotationLspace.SetColumns( vside, vup, -vdir );
|
|
|
}
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// CalcLSpaceFrustumPlanes =
|
|
|
+// calcLSpaceFrustumPlanes =
|
|
|
//=====================================================================================================================================
|
|
|
-void camera_t::CalcLSpaceFrustumPlanes()
|
|
|
+void Camera::calcLSpaceFrustumPlanes()
|
|
|
{
|
|
|
float c, s; // cos & sine
|
|
|
|
|
|
- SinCos( PI+fovx/2, s, c );
|
|
|
+ sinCos( PI+fovX/2, s, c );
|
|
|
// right
|
|
|
- lspace_frustum_planes[FP_RIGHT] = plane_t( vec3_t(c, 0.0, s), 0.0 );
|
|
|
+ lspaceFrustumPlanes[FP_RIGHT] = plane_t( vec3_t(c, 0.0, s), 0.0 );
|
|
|
// left
|
|
|
- lspace_frustum_planes[FP_LEFT] = plane_t( vec3_t(-c, 0.0, s), 0.0 );
|
|
|
+ lspaceFrustumPlanes[FP_LEFT] = plane_t( vec3_t(-c, 0.0, s), 0.0 );
|
|
|
|
|
|
- SinCos( (3*PI-fovy)*0.5, s, c );
|
|
|
+ sinCos( (3*PI-fovY)*0.5, s, c );
|
|
|
// top
|
|
|
- lspace_frustum_planes[FP_TOP] = plane_t( vec3_t(0.0, s, c), 0.0 );
|
|
|
+ lspaceFrustumPlanes[FP_TOP] = plane_t( vec3_t(0.0, s, c), 0.0 );
|
|
|
// bottom
|
|
|
- lspace_frustum_planes[FP_BOTTOM] = plane_t( vec3_t(0.0, -s, c), 0.0 );
|
|
|
+ lspaceFrustumPlanes[FP_BOTTOM] = plane_t( vec3_t(0.0, -s, c), 0.0 );
|
|
|
|
|
|
// near
|
|
|
- lspace_frustum_planes[FP_NEAR] = plane_t( vec3_t( 0.0, 0.0, -1.0 ), znear );
|
|
|
+ lspaceFrustumPlanes[FP_NEAR] = plane_t( vec3_t( 0.0, 0.0, -1.0 ), zNear );
|
|
|
// far
|
|
|
- lspace_frustum_planes[FP_FAR] = plane_t( vec3_t( 0.0, 0.0, 1.0 ), -zfar );
|
|
|
+ lspaceFrustumPlanes[FP_FAR] = plane_t( vec3_t( 0.0, 0.0, 1.0 ), -zFar );
|
|
|
}
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// UpdateWSpaceFrustumPlanes =
|
|
|
+// updateWSpaceFrustumPlanes =
|
|
|
//=====================================================================================================================================
|
|
|
-void camera_t::UpdateWSpaceFrustumPlanes()
|
|
|
+void Camera::updateWSpaceFrustumPlanes()
|
|
|
{
|
|
|
for( uint i=0; i<6; i++ )
|
|
|
- wspace_frustum_planes[i] = lspace_frustum_planes[i].Transformed( translation_wspace, rotation_wspace, scale_wspace );
|
|
|
+ wspaceFrustumPlanes[i] = lspaceFrustumPlanes[i].Transformed( translationWspace, rotationWspace, scaleWspace );
|
|
|
}
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// InsideFrustum =
|
|
|
+// insideFrustum =
|
|
|
//=====================================================================================================================================
|
|
|
/// Check if the volume is inside the frustum cliping planes
|
|
|
-bool camera_t::InsideFrustum( const bvolume_t& bvol ) const
|
|
|
+bool Camera::insideFrustum( const bvolume_t& bvol ) const
|
|
|
{
|
|
|
for( uint i=0; i<6; i++ )
|
|
|
- if( bvol.PlaneTest( wspace_frustum_planes[i] ) < 0.0 )
|
|
|
+ if( bvol.PlaneTest( wspaceFrustumPlanes[i] ) < 0.0 )
|
|
|
return false;
|
|
|
|
|
|
return true;
|
|
|
@@ -131,29 +131,29 @@ bool camera_t::InsideFrustum( const bvolume_t& bvol ) const
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// InsideFrustum =
|
|
|
+// insideFrustum =
|
|
|
//=====================================================================================================================================
|
|
|
/// Check if the given camera is inside the frustum cliping planes. This is used mainly to test if the projected lights are visible
|
|
|
-bool camera_t::InsideFrustum( const camera_t& cam ) const
|
|
|
+bool Camera::insideFrustum( const Camera& cam ) const
|
|
|
{
|
|
|
//** get five points. These points are the tips of the given camera **
|
|
|
vec3_t points[5];
|
|
|
|
|
|
// get 3 sample floats
|
|
|
- float x = cam.GetZFar() / tan( (PI-cam.GetFovX())/2 );
|
|
|
- float y = tan( cam.GetFovY()/2 ) * cam.GetZFar();
|
|
|
- float z = -cam.GetZFar();
|
|
|
+ float x = cam.getZFar() / tan( (PI-cam.getFovX())/2 );
|
|
|
+ float y = tan( cam.getFovY()/2 ) * cam.getZFar();
|
|
|
+ float z = -cam.getZFar();
|
|
|
|
|
|
// the actual points in local space
|
|
|
points[0] = vec3_t( x, y, z ); // top right
|
|
|
points[1] = vec3_t( -x, y, z ); // top left
|
|
|
points[2] = vec3_t( -x, -y, z ); // bottom left
|
|
|
points[3] = vec3_t( x, -y, z ); // bottom right
|
|
|
- points[4] = vec3_t( cam.translation_wspace ); // eye (allready in world space)
|
|
|
+ points[4] = vec3_t( cam.translationWspace ); // eye (allready in world space)
|
|
|
|
|
|
// transform them to the given camera's world space (exept the eye)
|
|
|
for( uint i=0; i<4; i++ )
|
|
|
- points[i].Transform( cam.translation_wspace, cam.rotation_wspace, cam.scale_wspace );
|
|
|
+ points[i].Transform( cam.translationWspace, cam.rotationWspace, cam.scaleWspace );
|
|
|
|
|
|
|
|
|
//** the collision code **
|
|
|
@@ -163,7 +163,7 @@ bool camera_t::InsideFrustum( const camera_t& cam ) const
|
|
|
|
|
|
for( uint j=0; j<5; j++ ) // for the 5 points
|
|
|
{
|
|
|
- if( wspace_frustum_planes[i].Test( points[j] ) < 0.0 )
|
|
|
+ if( wspaceFrustumPlanes[i].Test( points[j] ) < 0.0 )
|
|
|
++failed;
|
|
|
}
|
|
|
if( failed == 5 ) return false; // if all points are behind the plane then the cam is not in frustum
|
|
|
@@ -174,60 +174,60 @@ bool camera_t::InsideFrustum( const camera_t& cam ) const
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// CalcProjectionMatrix =
|
|
|
+// calcProjectionMatrix =
|
|
|
//=====================================================================================================================================
|
|
|
-void camera_t::CalcProjectionMatrix()
|
|
|
+void Camera::calcProjectionMatrix()
|
|
|
{
|
|
|
- float f = 1.0/tan( fovy*0.5f ); // f = cot(fovy/2)
|
|
|
-
|
|
|
- projection_mat(0,0) = f*fovy/fovx; // = f/aspect_ratio;
|
|
|
- projection_mat(0,1) = 0.0;
|
|
|
- projection_mat(0,2) = 0.0;
|
|
|
- projection_mat(0,3) = 0.0;
|
|
|
- projection_mat(1,0) = 0.0;
|
|
|
- projection_mat(1,1) = f;
|
|
|
- projection_mat(1,2) = 0.0;
|
|
|
- projection_mat(1,3) = 0.0;
|
|
|
- projection_mat(2,0) = 0.0;
|
|
|
- projection_mat(2,1) = 0.0;
|
|
|
- projection_mat(2,2) = (zfar+znear) / (znear-zfar);
|
|
|
- projection_mat(2,3) = (2.0f*zfar*znear) / (znear-zfar);
|
|
|
- projection_mat(3,0) = 0.0;
|
|
|
- projection_mat(3,1) = 0.0;
|
|
|
- projection_mat(3,2) = -1.0;
|
|
|
- projection_mat(3,3) = 0.0;
|
|
|
-
|
|
|
- inv_projection_mat = projection_mat.GetInverse();
|
|
|
+ float f = 1.0/tan( fovY*0.5f ); // f = cot(fovY/2)
|
|
|
+
|
|
|
+ projectionMat(0,0) = f*fovY/fovX; // = f/aspect_ratio;
|
|
|
+ projectionMat(0,1) = 0.0;
|
|
|
+ projectionMat(0,2) = 0.0;
|
|
|
+ projectionMat(0,3) = 0.0;
|
|
|
+ projectionMat(1,0) = 0.0;
|
|
|
+ projectionMat(1,1) = f;
|
|
|
+ projectionMat(1,2) = 0.0;
|
|
|
+ projectionMat(1,3) = 0.0;
|
|
|
+ projectionMat(2,0) = 0.0;
|
|
|
+ projectionMat(2,1) = 0.0;
|
|
|
+ projectionMat(2,2) = (zFar+zNear) / (zNear-zFar);
|
|
|
+ projectionMat(2,3) = (2.0f*zFar*zNear) / (zNear-zFar);
|
|
|
+ projectionMat(3,0) = 0.0;
|
|
|
+ projectionMat(3,1) = 0.0;
|
|
|
+ projectionMat(3,2) = -1.0;
|
|
|
+ projectionMat(3,3) = 0.0;
|
|
|
+
|
|
|
+ invProjectionMat = projectionMat.GetInverse();
|
|
|
}
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// UpdateViewMatrix =
|
|
|
+// updateViewMatrix =
|
|
|
//=====================================================================================================================================
|
|
|
-void camera_t::UpdateViewMatrix()
|
|
|
+void Camera::updateViewMatrix()
|
|
|
{
|
|
|
/* The point at which the camera looks:
|
|
|
- vec3_t viewpoint = translation_lspace + z_axis;
|
|
|
+ vec3_t viewpoint = translationLspace + z_axis;
|
|
|
as we know the up vector, we can easily use gluLookAt:
|
|
|
- gluLookAt( translation_lspace.x, translation_lspace.x, translation_lspace.z, z_axis.x, z_axis.y, z_axis.z, y_axis.x, y_axis.y, y_axis.z );
|
|
|
+ gluLookAt( translationLspace.x, translationLspace.x, translationLspace.z, z_axis.x, z_axis.y, z_axis.z, y_axis.x, y_axis.y, y_axis.z );
|
|
|
*/
|
|
|
|
|
|
|
|
|
// The view matrix is: Mview = camera.world_transform.Inverted(). Bus instead of inverting we do the following:
|
|
|
- mat3_t cam_inverted_rot = rotation_wspace.GetTransposed();
|
|
|
- vec3_t cam_inverted_tsl = -( cam_inverted_rot * translation_wspace );
|
|
|
- view_mat = mat4_t( cam_inverted_tsl, cam_inverted_rot );
|
|
|
+ mat3_t cam_inverted_rot = rotationWspace.GetTransposed();
|
|
|
+ vec3_t cam_inverted_tsl = -( cam_inverted_rot * translationWspace );
|
|
|
+ viewMat = mat4_t( cam_inverted_tsl, cam_inverted_rot );
|
|
|
}
|
|
|
|
|
|
|
|
|
//=====================================================================================================================================
|
|
|
-// UpdateWorldStuff =
|
|
|
+// updateWorldStuff =
|
|
|
//=====================================================================================================================================
|
|
|
-void camera_t::UpdateWorldStuff()
|
|
|
+void Camera::updateWorldStuff()
|
|
|
{
|
|
|
- UpdateWorldTransform();
|
|
|
- UpdateViewMatrix();
|
|
|
- UpdateWSpaceFrustumPlanes();
|
|
|
+ updateWorldTransform();
|
|
|
+ updateViewMatrix();
|
|
|
+ updateWSpaceFrustumPlanes();
|
|
|
}
|
|
|
|
|
|
|