Removing outdated CVS files from the main trunk
This was SVN commit r1399.
This commit is contained in:
parent
314689a0bf
commit
a975b4988b
@ -1,108 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Camera.Cpp
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CCamera holds a view and a projection matrix.
|
||||
// It also has a frustum which can be used to
|
||||
// cull objects for rendering.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Camera.H"
|
||||
|
||||
extern int xres, yres;
|
||||
|
||||
CCamera::CCamera ()
|
||||
{
|
||||
m_ViewPort.m_Width = 1280;
|
||||
m_ViewPort.m_Height = 1024;
|
||||
m_ViewPort.m_X = 0;
|
||||
m_ViewPort.m_Y = 0;
|
||||
}
|
||||
|
||||
CCamera::~CCamera ()
|
||||
{
|
||||
}
|
||||
|
||||
void CCamera::SetProjection (float nearp, float farp, float fov)
|
||||
{
|
||||
float h, w, Q;
|
||||
|
||||
m_NearPlane = nearp;
|
||||
m_FarPlane = farp;
|
||||
m_FOV = fov;
|
||||
|
||||
float Aspect = (float)m_ViewPort.m_Width/(float)m_ViewPort.m_Height;
|
||||
|
||||
w = 1/tanf (fov*0.5f*Aspect);
|
||||
h = 1/tanf (fov*0.5f);
|
||||
Q = m_FarPlane / (m_FarPlane - m_NearPlane);
|
||||
|
||||
m_ProjMat.SetZero ();
|
||||
m_ProjMat._11 = w;
|
||||
m_ProjMat._22 = h;
|
||||
m_ProjMat._33 = Q;
|
||||
m_ProjMat._34 = -Q*m_NearPlane;
|
||||
m_ProjMat._43 = 1.0f;
|
||||
}
|
||||
|
||||
//Updates the frustum planes. Should be called
|
||||
//everytime the view or projection matrices are
|
||||
//altered.
|
||||
void CCamera::UpdateFrustum ()
|
||||
{
|
||||
CMatrix3D MatFinal;
|
||||
CMatrix3D MatView;
|
||||
|
||||
MatView = m_Orientation.GetTranspose ();
|
||||
|
||||
MatFinal = m_ProjMat * MatView;
|
||||
|
||||
//get the RIGHT plane
|
||||
m_ViewFrustum.SetNumPlanes (6);
|
||||
|
||||
m_ViewFrustum.m_aPlanes[0].m_Norm.X = MatFinal._41-MatFinal._11;
|
||||
m_ViewFrustum.m_aPlanes[0].m_Norm.Y = MatFinal._42-MatFinal._12;
|
||||
m_ViewFrustum.m_aPlanes[0].m_Norm.Z = MatFinal._43-MatFinal._13;
|
||||
m_ViewFrustum.m_aPlanes[0].m_Dist = MatFinal._44-MatFinal._14;
|
||||
|
||||
//get the LEFT plane
|
||||
m_ViewFrustum.m_aPlanes[1].m_Norm.X = MatFinal._41+MatFinal._11;
|
||||
m_ViewFrustum.m_aPlanes[1].m_Norm.Y = MatFinal._42+MatFinal._12;
|
||||
m_ViewFrustum.m_aPlanes[1].m_Norm.Z = MatFinal._43+MatFinal._13;
|
||||
m_ViewFrustum.m_aPlanes[1].m_Dist = MatFinal._44+MatFinal._14;
|
||||
|
||||
//get the BOTTOM plane
|
||||
m_ViewFrustum.m_aPlanes[2].m_Norm.X = MatFinal._41+MatFinal._21;
|
||||
m_ViewFrustum.m_aPlanes[2].m_Norm.Y = MatFinal._42+MatFinal._22;
|
||||
m_ViewFrustum.m_aPlanes[2].m_Norm.Z = MatFinal._43+MatFinal._23;
|
||||
m_ViewFrustum.m_aPlanes[2].m_Dist = MatFinal._44+MatFinal._24;
|
||||
|
||||
//get the TOP plane
|
||||
m_ViewFrustum.m_aPlanes[3].m_Norm.X = MatFinal._41-MatFinal._21;
|
||||
m_ViewFrustum.m_aPlanes[3].m_Norm.Y = MatFinal._42-MatFinal._22;
|
||||
m_ViewFrustum.m_aPlanes[3].m_Norm.Z = MatFinal._43-MatFinal._23;
|
||||
m_ViewFrustum.m_aPlanes[3].m_Dist = MatFinal._44-MatFinal._24;
|
||||
|
||||
//get the FAR plane
|
||||
m_ViewFrustum.m_aPlanes[4].m_Norm.X = MatFinal._41-MatFinal._31;
|
||||
m_ViewFrustum.m_aPlanes[4].m_Norm.Y = MatFinal._42-MatFinal._32;
|
||||
m_ViewFrustum.m_aPlanes[4].m_Norm.Z = MatFinal._43-MatFinal._33;
|
||||
m_ViewFrustum.m_aPlanes[4].m_Dist = MatFinal._44-MatFinal._34;
|
||||
|
||||
//get the NEAR plane
|
||||
m_ViewFrustum.m_aPlanes[5].m_Norm.X = MatFinal._41+MatFinal._31;
|
||||
m_ViewFrustum.m_aPlanes[5].m_Norm.Y = MatFinal._42+MatFinal._32;
|
||||
m_ViewFrustum.m_aPlanes[5].m_Norm.Z = MatFinal._43+MatFinal._33;
|
||||
m_ViewFrustum.m_aPlanes[5].m_Dist = MatFinal._44+MatFinal._34;
|
||||
}
|
||||
|
||||
void CCamera::SetViewPort (SViewPort *viewport)
|
||||
{
|
||||
m_ViewPort.m_X = viewport->m_X;
|
||||
m_ViewPort.m_Y = viewport->m_Y;
|
||||
m_ViewPort.m_Width = viewport->m_Width;
|
||||
m_ViewPort.m_Height = viewport->m_Height;
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Camera.H
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CCamera holds a view and a projection matrix.
|
||||
// It also has a frustum which can be used to
|
||||
// cull objects for rendering.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include "Frustum.H"
|
||||
#include "Matrix3D.H"
|
||||
|
||||
//view port
|
||||
struct SViewPort
|
||||
{
|
||||
unsigned int m_X;
|
||||
unsigned int m_Y;
|
||||
unsigned int m_Width;
|
||||
unsigned int m_Height;
|
||||
};
|
||||
|
||||
|
||||
class CCamera
|
||||
{
|
||||
public:
|
||||
CCamera ();
|
||||
~CCamera ();
|
||||
|
||||
//Methods for projection
|
||||
void SetProjection (CMatrix3D *proj) { m_ProjMat = *proj; }
|
||||
void SetProjection (float nearp, float farp, float fov);
|
||||
CMatrix3D GetProjection () { return m_ProjMat; }
|
||||
|
||||
//Updates the frustum planes. Should be called
|
||||
//everytime the view or projection matrices are
|
||||
//altered.
|
||||
void UpdateFrustum ();
|
||||
CFrustum GetFustum () { return m_ViewFrustum; }
|
||||
|
||||
void SetViewPort (SViewPort *viewport);
|
||||
SViewPort GetViewPort () { return m_ViewPort; }
|
||||
|
||||
//getters
|
||||
float GetNearPlane () { return m_NearPlane; }
|
||||
float GetFarPlane () { return m_FarPlane; }
|
||||
float GetFOV () { return m_FOV; }
|
||||
|
||||
public:
|
||||
//This is the orientation matrix. The inverse of this
|
||||
//is the view matrix
|
||||
CMatrix3D m_Orientation;
|
||||
|
||||
private:
|
||||
//keep the projection matrix private
|
||||
//so we can't fiddle with it.
|
||||
CMatrix3D m_ProjMat;
|
||||
|
||||
float m_NearPlane;
|
||||
float m_FarPlane;
|
||||
float m_FOV;
|
||||
SViewPort m_ViewPort;
|
||||
|
||||
CFrustum m_ViewFrustum;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,144 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Frustum.Cpp
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CFrustum is a collection of planes which define
|
||||
// a viewing space. Usually associated with the
|
||||
// camera, there are 6 planes which define the
|
||||
// view pyramid. But we allow more planes per
|
||||
// frustum which maybe used for portal rendering,
|
||||
// where a portal may have 3 or more edges.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Frustum.H"
|
||||
|
||||
CFrustum::CFrustum ()
|
||||
{
|
||||
m_NumPlanes = 0;
|
||||
}
|
||||
|
||||
CFrustum::~CFrustum ()
|
||||
{
|
||||
}
|
||||
|
||||
void CFrustum::SetNumPlanes (int num)
|
||||
{
|
||||
m_NumPlanes = num;
|
||||
|
||||
//clip it
|
||||
if (m_NumPlanes >= MAX_NUM_FRUSTUM_PLANES)
|
||||
m_NumPlanes = MAX_NUM_FRUSTUM_PLANES-1;
|
||||
else if (m_NumPlanes < 0)
|
||||
m_NumPlanes = 0;
|
||||
}
|
||||
|
||||
bool CFrustum::IsPointVisible (CVector3D &point)
|
||||
{
|
||||
PLANESIDE Side;
|
||||
|
||||
for (int i=0; i<m_NumPlanes; i++)
|
||||
{
|
||||
Side = m_aPlanes[i].ClassifyPoint (point);
|
||||
|
||||
if (Side == PS_BACK)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFrustum::IsSphereVisible (CVector3D ¢er, float radius)
|
||||
{
|
||||
for (int i=0; i<m_NumPlanes; i++)
|
||||
{
|
||||
float Dist = m_aPlanes[i].DistanceToPlane (center);
|
||||
|
||||
//is it behind the plane
|
||||
if (Dist < 0)
|
||||
{
|
||||
//if non of it falls in front its outside the
|
||||
//frustum
|
||||
if (-Dist > radius)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CFrustum::IsBoxVisible (CVector3D &position, SBoundingBox &bounds)
|
||||
{
|
||||
//basically for every plane we calculate the furthust point
|
||||
//in the box to that plane. If that point is beyond the plane
|
||||
//then the box is not visible
|
||||
CVector3D FarPoint;
|
||||
PLANESIDE Side;
|
||||
CVector3D Min = position+bounds.m_BoxMin;
|
||||
CVector3D Max = position+bounds.m_BoxMax;
|
||||
|
||||
for (int i=0; i<m_NumPlanes; i++)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.X > 0.0f)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Y > 0.0f)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Max.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Max.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Min.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Min.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Y > 0.0f)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Max.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Max.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Min.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Min.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Side = m_aPlanes[i].ClassifyPoint (FarPoint);
|
||||
|
||||
if (Side == PS_BACK)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Frustum.H
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CFrustum is a collection of planes which define
|
||||
// a viewing space. Usually associated with the
|
||||
// camera, there are 6 planes which define the
|
||||
// view pyramid. But we allow more planes per
|
||||
// frustum which maybe used for portal rendering,
|
||||
// where a portal may have 3 or more edges.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef FRUSTUM_H
|
||||
#define FRUSTUM_H
|
||||
|
||||
#include "Plane.H"
|
||||
|
||||
//10 planes should be enough
|
||||
#define MAX_NUM_FRUSTUM_PLANES (10)
|
||||
|
||||
|
||||
struct SBoundingBox
|
||||
{
|
||||
CVector3D m_BoxMin;
|
||||
CVector3D m_BoxMax;
|
||||
};
|
||||
|
||||
class CFrustum
|
||||
{
|
||||
public:
|
||||
CFrustum ();
|
||||
~CFrustum ();
|
||||
|
||||
//Set the number of planes to use for
|
||||
//calculations. This is clipped to
|
||||
//[0,MAX_NUM_FRUSTUM_PLANES]
|
||||
void SetNumPlanes (int num);
|
||||
|
||||
//The following methods return true if the shape is
|
||||
//partially or completely in front of the frustum planes
|
||||
bool IsPointVisible (CVector3D &point);
|
||||
bool IsSphereVisible (CVector3D ¢er, float radius);
|
||||
bool IsBoxVisible (CVector3D &position, SBoundingBox &bounds);
|
||||
|
||||
public:
|
||||
//make the planes public for ease of use
|
||||
CPlane m_aPlanes[MAX_NUM_FRUSTUM_PLANES];
|
||||
|
||||
private:
|
||||
int m_NumPlanes;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,26 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: MathUtil.H
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This file contains some maths related
|
||||
// utility macros and fucntions.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef MATHUTIL_H
|
||||
#define MATHUTIL_H
|
||||
|
||||
#define PI 3.14159265358979323846f
|
||||
|
||||
#define DEGTORAD(a) (((a) * PI) / 180.0f)
|
||||
#define SQR(x) ((x) * (x))
|
||||
#define MAX(a,b) ((a < b) ? (b) : (a))
|
||||
#define MIN(a,b) ((a < b) ? (a) : (b))
|
||||
#define MAX3(a,b,c) ( MAX (MAX(a,b), c) )
|
||||
#define ABS(a) ((a > 0) ? (a) : (-a))
|
||||
|
||||
//extern unsigned int F2DW (float f);
|
||||
|
||||
#endif
|
@ -1,384 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Matrix3D.Cpp
|
||||
// Last Update: 31/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Matrix class used for holding and
|
||||
// manipulating transformation info.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Matrix3D.H"
|
||||
|
||||
CMatrix3D::CMatrix3D ()
|
||||
{
|
||||
SetIdentity ();
|
||||
}
|
||||
|
||||
//Matrix multiplication
|
||||
CMatrix3D CMatrix3D::operator * (CMatrix3D &matrix)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
|
||||
Temp._11 = _11*matrix._11 +
|
||||
_12*matrix._21 +
|
||||
_13*matrix._31 +
|
||||
_14*matrix._41;
|
||||
|
||||
Temp._12 = _11*matrix._12 +
|
||||
_12*matrix._22 +
|
||||
_13*matrix._32 +
|
||||
_14*matrix._42;
|
||||
|
||||
Temp._13 = _11*matrix._13 +
|
||||
_12*matrix._23 +
|
||||
_13*matrix._33 +
|
||||
_14*matrix._43;
|
||||
|
||||
Temp._14 = _11*matrix._14 +
|
||||
_12*matrix._24 +
|
||||
_13*matrix._34 +
|
||||
_14*matrix._44;
|
||||
|
||||
Temp._21 = _21*matrix._11 +
|
||||
_22*matrix._21 +
|
||||
_23*matrix._31 +
|
||||
_24*matrix._41;
|
||||
|
||||
Temp._22 = _21*matrix._12 +
|
||||
_22*matrix._22 +
|
||||
_23*matrix._32 +
|
||||
_24*matrix._42;
|
||||
|
||||
Temp._23 = _21*matrix._13 +
|
||||
_22*matrix._23 +
|
||||
_23*matrix._33 +
|
||||
_24*matrix._43;
|
||||
|
||||
Temp._24 = _21*matrix._14 +
|
||||
_22*matrix._24 +
|
||||
_23*matrix._34 +
|
||||
_24*matrix._44;
|
||||
|
||||
Temp._31 = _31*matrix._11 +
|
||||
_32*matrix._21 +
|
||||
_33*matrix._31 +
|
||||
_34*matrix._41;
|
||||
|
||||
Temp._32 = _31*matrix._12 +
|
||||
_32*matrix._22 +
|
||||
_33*matrix._32 +
|
||||
_34*matrix._42;
|
||||
|
||||
Temp._33 = _31*matrix._13 +
|
||||
_32*matrix._23 +
|
||||
_33*matrix._33 +
|
||||
_34*matrix._43;
|
||||
|
||||
Temp._34 = _31*matrix._14 +
|
||||
_32*matrix._24 +
|
||||
_33*matrix._34 +
|
||||
_34*matrix._44;
|
||||
|
||||
Temp._41 = _41*matrix._11 +
|
||||
_42*matrix._21 +
|
||||
_43*matrix._31 +
|
||||
_44*matrix._41;
|
||||
|
||||
Temp._42 = _41*matrix._12 +
|
||||
_42*matrix._22 +
|
||||
_43*matrix._32 +
|
||||
_44*matrix._42;
|
||||
|
||||
Temp._43 = _41*matrix._13 +
|
||||
_42*matrix._23 +
|
||||
_43*matrix._33 +
|
||||
_44*matrix._43;
|
||||
|
||||
Temp._44 = _41*matrix._14 +
|
||||
_42*matrix._24 +
|
||||
_43*matrix._34 +
|
||||
_44*matrix._44;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Matrix multiplication/assignment
|
||||
CMatrix3D &CMatrix3D::operator *= (CMatrix3D &matrix)
|
||||
{
|
||||
CMatrix3D &Temp = (*this) * matrix;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Sets the identity matrix
|
||||
void CMatrix3D::SetIdentity ()
|
||||
{
|
||||
_11=1.0f; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=1.0f; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=1.0f; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//Sets the zero matrix
|
||||
void CMatrix3D::SetZero ()
|
||||
{
|
||||
_11=0.0f; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=0.0f; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=0.0f; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=0.0f;
|
||||
}
|
||||
|
||||
//The following clear the matrix and set the
|
||||
//rotation of each of the 3 axes
|
||||
|
||||
void CMatrix3D::SetXRotation (float angle)
|
||||
{
|
||||
float Cos = cosf (angle);
|
||||
float Sin = sinf (angle);
|
||||
|
||||
_11=1.0f; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=Cos; _23=-Sin; _24=0.0f;
|
||||
_31=0.0f; _32=Sin; _33=Cos; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
void CMatrix3D::SetYRotation (float angle)
|
||||
{
|
||||
float Cos = cosf (angle);
|
||||
float Sin = sinf (angle);
|
||||
|
||||
_11=Cos; _12=0.0f; _13=Sin; _14=0.0f;
|
||||
_21=0.0f; _22=1.0f; _23=0.0f; _24=0.0f;
|
||||
_31=-Sin; _32=0.0f; _33=Cos; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
void CMatrix3D::SetZRotation (float angle)
|
||||
{
|
||||
float Cos = cosf (angle);
|
||||
float Sin = sinf (angle);
|
||||
|
||||
_11=Cos; _12=-Sin; _13=0.0f; _14=0.0f;
|
||||
_21=Sin; _22=Cos; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=1.0f; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//The following apply a rotation to the matrix
|
||||
//about each of the axes;
|
||||
|
||||
void CMatrix3D::RotateX (float angle)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetXRotation (angle);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
void CMatrix3D::RotateY (float angle)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetYRotation (angle);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
void CMatrix3D::RotateZ (float angle)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetZRotation (angle);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
//Sets the translation of the matrix
|
||||
void CMatrix3D::SetTranslation (float x, float y, float z)
|
||||
{
|
||||
_11=1.0f; _12=0.0f; _13=0.0f; _14=x;
|
||||
_21=0.0f; _22=1.0f; _23=0.0f; _24=y;
|
||||
_31=0.0f; _32=0.0f; _33=1.0f; _34=z;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
void CMatrix3D::SetTranslation (CVector3D &vector)
|
||||
{
|
||||
SetTranslation (vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
//Applies a translation to the matrix
|
||||
void CMatrix3D::Translate (float x, float y, float z)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetTranslation (x, y, z);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
void CMatrix3D::Translate (CVector3D &vector)
|
||||
{
|
||||
Translate (vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
CVector3D CMatrix3D::GetTranslation ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _14;
|
||||
Temp.Y = _24;
|
||||
Temp.Z = _34;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Clears and sets the scaling of the matrix
|
||||
void CMatrix3D::SetScaling (float x_scale, float y_scale, float z_scale)
|
||||
{
|
||||
_11=x_scale; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=y_scale; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=z_scale; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//Scales the matrix
|
||||
void CMatrix3D::Scale (float x_scale, float y_scale, float z_scale)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetScaling (x_scale, y_scale, z_scale);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
//Returns the transpose of the matrix. For orthonormal
|
||||
//matrices, this is the same is the inverse matrix
|
||||
CMatrix3D CMatrix3D::GetTranspose ()
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
|
||||
Temp._11 = _11;
|
||||
Temp._21 = _12;
|
||||
Temp._31 = _13;
|
||||
Temp._41 = 0.0f;
|
||||
|
||||
Temp._12 = _21;
|
||||
Temp._22 = _22;
|
||||
Temp._32 = _23;
|
||||
Temp._42 = 0.0f;
|
||||
|
||||
Temp._13 = _31;
|
||||
Temp._23 = _32;
|
||||
Temp._33 = _33;
|
||||
Temp._43 = 0.0f;
|
||||
|
||||
Temp._14 = 0.0f;
|
||||
Temp._24 = 0.0f;
|
||||
Temp._34 = 0.0f;
|
||||
Temp._44 = 1.0f;
|
||||
|
||||
CMatrix3D Trans;
|
||||
Trans.SetTranslation (-_14, -_24, -_34);
|
||||
|
||||
Temp = Temp * Trans;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Get a vector which points to the left of the matrix
|
||||
CVector3D CMatrix3D::GetLeft ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = -_11;
|
||||
Temp.Y = -_21;
|
||||
Temp.Z = -_31;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Get a vector which points up from the matrix
|
||||
CVector3D CMatrix3D::GetUp ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _12;
|
||||
Temp.Y = _22;
|
||||
Temp.Z = _32;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Get a vector which points to front of the matrix
|
||||
CVector3D CMatrix3D::GetIn ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _13;
|
||||
Temp.Y = _23;
|
||||
Temp.Z = _33;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Set the matrix from two vectors (Up and In)
|
||||
void CMatrix3D::SetFromUpIn (CVector3D &up, CVector3D &in, float scale)
|
||||
{
|
||||
CVector3D u = up;
|
||||
CVector3D i = in;
|
||||
|
||||
CVector3D r;
|
||||
|
||||
r = up.Cross (in);
|
||||
|
||||
u.Normalize (); u *= scale;
|
||||
i.Normalize (); i *= scale;
|
||||
r.Normalize (); r *= scale;
|
||||
|
||||
_11=r.X; _12=u.X; _13=i.X; _14=0.0f;
|
||||
_21=r.Y; _22=u.Y; _23=i.Y; _24=0.0f;
|
||||
_31=r.Z; _32=u.Z; _33=i.Z; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//Transform a vector by this matrix
|
||||
CVector3D CMatrix3D::Transform (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _11*vector.X +
|
||||
_12*vector.Y +
|
||||
_13*vector.Z +
|
||||
_14;
|
||||
|
||||
Temp.Y = _21*vector.X +
|
||||
_22*vector.Y +
|
||||
_23*vector.Z +
|
||||
_24;
|
||||
|
||||
Temp.Z = _31*vector.X +
|
||||
_32*vector.Y +
|
||||
_33*vector.Z +
|
||||
_34;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Only rotate (not translate) a vector by this matrix
|
||||
CVector3D CMatrix3D::Rotate (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _11*vector.X +
|
||||
_12*vector.Y +
|
||||
_13*vector.Z;
|
||||
|
||||
Temp.Y = _21*vector.X +
|
||||
_22*vector.Y +
|
||||
_23*vector.Z;
|
||||
|
||||
Temp.Z = _31*vector.X +
|
||||
_32*vector.Y +
|
||||
_33*vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Matrix3D.H
|
||||
// Last Update: 31/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Matrix class used for holding and
|
||||
// manipulating transformation info.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef MATRIX3D_H
|
||||
#define MATRIX3D_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "Vector3D.H"
|
||||
|
||||
class CMatrix3D
|
||||
{
|
||||
public:
|
||||
float _11, _12, _13, _14;
|
||||
float _21, _22, _23, _24;
|
||||
float _31, _32, _33, _34;
|
||||
float _41, _42, _43, _44;
|
||||
|
||||
public:
|
||||
CMatrix3D ();
|
||||
|
||||
//Matrix multiplication
|
||||
CMatrix3D operator * (CMatrix3D &matrix);
|
||||
//Matrix multiplication/assignment
|
||||
CMatrix3D &operator *= (CMatrix3D &matrix);
|
||||
|
||||
//Sets the identity matrix
|
||||
void SetIdentity ();
|
||||
//Sets the zero matrix
|
||||
void SetZero ();
|
||||
|
||||
//The following clear the matrix and set the
|
||||
//rotation of each of the 3 axes
|
||||
void SetXRotation (float angle);
|
||||
void SetYRotation (float angle);
|
||||
void SetZRotation (float angle);
|
||||
|
||||
//The following apply a rotation to the matrix
|
||||
//about each of the axes;
|
||||
void RotateX (float angle);
|
||||
void RotateY (float angle);
|
||||
void RotateZ (float angle);
|
||||
|
||||
//Sets the translation of the matrix
|
||||
void SetTranslation (float x, float y, float z);
|
||||
void SetTranslation (CVector3D &vector);
|
||||
|
||||
//Applies a translation to the matrix
|
||||
void Translate (float x, float y, float z);
|
||||
void Translate (CVector3D &vector);
|
||||
|
||||
CVector3D GetTranslation ();
|
||||
|
||||
//Clears and sets the scaling of the matrix
|
||||
void SetScaling (float x_scale, float y_scale, float z_scale);
|
||||
//Scales the matrix
|
||||
void Scale (float x_scale, float y_scale, float z_scale);
|
||||
|
||||
//Returns the transpose of the matrix. For orthonormal
|
||||
//matrices, this is the same is the inverse matrix
|
||||
CMatrix3D GetTranspose ();
|
||||
|
||||
//Get a vector which points to the left of the matrix
|
||||
CVector3D GetLeft ();
|
||||
//Get a vector which points up from the matrix
|
||||
CVector3D GetUp ();
|
||||
//Get a vector which points to front of the matrix
|
||||
CVector3D GetIn ();
|
||||
|
||||
//Set the matrix from two vectors (Up and In)
|
||||
void SetFromUpIn (CVector3D &up, CVector3D &in, float scale);
|
||||
|
||||
public: //Vector manipulation methods
|
||||
//Transform a vector by this matrix
|
||||
CVector3D Transform (CVector3D &vector);
|
||||
//Only rotate (not translate) a vector by this matrix
|
||||
CVector3D Rotate (CVector3D &vector);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
#include "MiniPatch.H"
|
||||
|
||||
CMiniPatch::CMiniPatch()
|
||||
{
|
||||
Tex1 = Tex2 = 0;
|
||||
m_AlphaMap = 0;
|
||||
m_pRightNeighbor = NULL;
|
||||
m_pParrent = NULL;
|
||||
m_Rotation = 0;
|
||||
m_RenderStage = 0;
|
||||
m_LastRenderedFrame = 0;
|
||||
}
|
||||
|
||||
CMiniPatch::~CMiniPatch()
|
||||
{
|
||||
}
|
||||
|
||||
void CMiniPatch::Initialize (STerrainVertex *first_vertex)
|
||||
{
|
||||
m_pVertices = first_vertex;
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#ifndef MINIPATCH_H
|
||||
#define MINIPATCH_H
|
||||
|
||||
#include "Vector3D.H"
|
||||
#include "res.h"
|
||||
|
||||
struct STerrainVertex
|
||||
{
|
||||
CVector3D m_Position;
|
||||
float m_Color[2][3];
|
||||
};
|
||||
|
||||
|
||||
class CMiniPatch
|
||||
{
|
||||
public:
|
||||
CMiniPatch();
|
||||
~CMiniPatch();
|
||||
|
||||
void Initialize (STerrainVertex *first_vertex);
|
||||
|
||||
Handle Tex1, Tex2;
|
||||
Handle m_AlphaMap;
|
||||
CMiniPatch *m_pRightNeighbor;
|
||||
CPatch *m_pParrent;
|
||||
unsigned char m_RenderStage;
|
||||
unsigned int m_LastRenderedFrame;
|
||||
|
||||
unsigned char m_Rotation;
|
||||
|
||||
STerrainVertex *m_pVertices;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,61 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Patch.Cpp
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CPatch is a smaller portion of the terrain.
|
||||
// It handles the ROAM implementation and its
|
||||
// own rendering.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Patch.H"
|
||||
|
||||
|
||||
CPatch::CPatch ()
|
||||
{
|
||||
m_pVertices = NULL;
|
||||
}
|
||||
|
||||
CPatch::~CPatch ()
|
||||
{
|
||||
}
|
||||
|
||||
//Initialize the patch
|
||||
void CPatch::Initialize (STerrainVertex *first_vertex)
|
||||
{
|
||||
m_pVertices = first_vertex;
|
||||
|
||||
m_Bounds.m_BoxMin.X = m_pVertices[0].m_Position.X;
|
||||
m_Bounds.m_BoxMin.Z = m_pVertices[0].m_Position.Z;
|
||||
|
||||
m_Bounds.m_BoxMax.X = m_Bounds.m_BoxMin.X + PATCH_SIZE*CELL_SIZE;
|
||||
m_Bounds.m_BoxMax.Z = m_Bounds.m_BoxMin.Z + PATCH_SIZE*CELL_SIZE;
|
||||
|
||||
m_Bounds.m_BoxMin.Y = m_Bounds.m_BoxMin.Y = m_pVertices[0].m_Position.Y;
|
||||
|
||||
for (int j=0; j<PATCH_SIZE+1; j++)
|
||||
{
|
||||
for (int i=0; i<PATCH_SIZE+1; i++)
|
||||
{
|
||||
int pos = j*MAP_SIZE + i;
|
||||
|
||||
if (m_pVertices[pos].m_Position.Y < m_Bounds.m_BoxMin.Y)
|
||||
m_Bounds.m_BoxMin.Y = m_pVertices[pos].m_Position.Y;
|
||||
|
||||
if (m_pVertices[pos].m_Position.Y > m_Bounds.m_BoxMax.Y)
|
||||
m_Bounds.m_BoxMax.Y = m_pVertices[pos].m_Position.Y;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<16; j++)
|
||||
{
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
int pos = (j*MAP_SIZE) + (i);
|
||||
m_MiniPatches[j][i].Initialize ( &m_pVertices[pos] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Patch.H
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CPatch is a smaller portion of the terrain.
|
||||
// It handles its own rendering
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef PATCH_H
|
||||
#define PATCH_H
|
||||
|
||||
#include "Matrix3D.H"
|
||||
#include "Camera.H"
|
||||
#include "TerrGlobals.H"
|
||||
#include "MiniPatch.H"
|
||||
|
||||
class CPatch
|
||||
{
|
||||
public:
|
||||
CPatch ();
|
||||
~CPatch ();
|
||||
|
||||
//initialize the patch
|
||||
void Initialize (STerrainVertex *first_vertex);
|
||||
|
||||
// protected:
|
||||
CMiniPatch m_MiniPatches[16][16];
|
||||
|
||||
SBoundingBox m_Bounds;
|
||||
unsigned int m_LastVisFrame;
|
||||
|
||||
STerrainVertex *m_pVertices;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,138 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Plane.Cpp
|
||||
// Last Update: 17/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Plane in R3 and several utility methods.
|
||||
// Note that the format used for the plane
|
||||
// equation is Ax + By + Cz + D = 0, where
|
||||
// <A,B,C> is the normal vector.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Plane.H"
|
||||
|
||||
CPlane::CPlane ()
|
||||
{
|
||||
m_Norm.Clear ();
|
||||
m_Dist = 0.0f;
|
||||
}
|
||||
|
||||
//sets the plane equation from 3 points on that plane
|
||||
void CPlane::Set (CVector3D &p1, CVector3D &p2, CVector3D &p3)
|
||||
{
|
||||
CVector3D D1, D2;
|
||||
CVector3D Norm;
|
||||
|
||||
//calculate two vectors on the surface of the plane
|
||||
D1 = p2-p1;
|
||||
D2 = p3-p1;
|
||||
|
||||
//cross multiply gives normal
|
||||
Norm = D2.Cross(D1);
|
||||
|
||||
Set (Norm, p1);
|
||||
}
|
||||
|
||||
//sets the plane equation from a normal and a point on
|
||||
//that plane
|
||||
void CPlane::Set (CVector3D &norm, CVector3D &point)
|
||||
{
|
||||
m_Norm = norm;
|
||||
|
||||
m_Dist = - (norm.X * point.X +
|
||||
norm.Y * point.Y +
|
||||
norm.Z * point.Z);
|
||||
|
||||
// Normalize ();
|
||||
}
|
||||
|
||||
//normalizes the plane equation
|
||||
void CPlane::Normalize ()
|
||||
{
|
||||
float Scale;
|
||||
|
||||
Scale = 1.0f/m_Norm.GetLength ();
|
||||
|
||||
m_Norm.X *= Scale;
|
||||
m_Norm.Y *= Scale;
|
||||
m_Norm.Z *= Scale;
|
||||
m_Dist *= Scale;
|
||||
}
|
||||
|
||||
//returns the side of the plane on which this point
|
||||
//lies.
|
||||
PLANESIDE CPlane::ClassifyPoint (CVector3D &point)
|
||||
{
|
||||
float Dist;
|
||||
|
||||
Dist = m_Norm.X * point.X +
|
||||
m_Norm.Y * point.Y +
|
||||
m_Norm.Z * point.Z +
|
||||
m_Dist;
|
||||
|
||||
if (Dist > 0.0f)
|
||||
return PS_FRONT;
|
||||
else if (Dist < 0.0f)
|
||||
return PS_BACK;
|
||||
|
||||
return PS_ON;
|
||||
}
|
||||
|
||||
//solves the plane equation for a particular point
|
||||
float CPlane::DistanceToPlane (CVector3D &point)
|
||||
{
|
||||
float Dist;
|
||||
|
||||
Dist = m_Norm.X * point.X +
|
||||
m_Norm.Y * point.Y +
|
||||
m_Norm.Z * point.Z +
|
||||
m_Dist;
|
||||
|
||||
return Dist;
|
||||
}
|
||||
|
||||
//calculates the intersection point of a line with this
|
||||
//plane. Returns false if there is no intersection
|
||||
bool CPlane::FindLineSegIntersection (CVector3D &start, CVector3D &end, CVector3D *intsect)
|
||||
{
|
||||
PLANESIDE StartS, EndS;
|
||||
CVector3D Dir;
|
||||
float Length;
|
||||
|
||||
//work out where each point is
|
||||
StartS = ClassifyPoint (start);
|
||||
EndS = ClassifyPoint (end);
|
||||
|
||||
//if they are not on opposite sides of the plane return false
|
||||
if (StartS == EndS)
|
||||
return false;
|
||||
|
||||
//work out a normalized vector in the direction start to end
|
||||
Dir = end - start;
|
||||
Dir.Normalize ();
|
||||
|
||||
//a bit of algebra to work out how much we need to scale
|
||||
//this direction vector to get to the plane
|
||||
Length = -m_Norm.Dot(start)/m_Norm.Dot(Dir);
|
||||
|
||||
//scale it by this amount
|
||||
Dir *= Length;
|
||||
|
||||
//workout actual position vector of impact
|
||||
*intsect = start + Dir;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPlane::FindRayIntersection (CVector3D &start, CVector3D &direction, CVector3D *intsect)
|
||||
{
|
||||
float dot = m_Norm.Dot (direction);
|
||||
if (dot == 0.0f)
|
||||
return false;
|
||||
|
||||
CVector3D a;
|
||||
*intsect = start - (direction * (DistanceToPlane (start)/dot));
|
||||
return true;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Plane.H
|
||||
// Last Update: 17/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Plane in R3 and several utility methods.
|
||||
// Note that the format used for the plane
|
||||
// equation is Ax + By + Cz + D = 0, where
|
||||
// <A,B,C> is the normal vector.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef PLANE_H
|
||||
#define PLANE_H
|
||||
|
||||
#include "Vector3D.H"
|
||||
|
||||
enum PLANESIDE
|
||||
{
|
||||
PS_FRONT,
|
||||
PS_BACK,
|
||||
PS_ON
|
||||
};
|
||||
|
||||
class CPlane
|
||||
{
|
||||
public:
|
||||
CPlane ();
|
||||
|
||||
//sets the plane equation from 3 points on that plane
|
||||
void Set (CVector3D &p1, CVector3D &p2, CVector3D &p3);
|
||||
|
||||
//sets the plane equation from a normal and a point on
|
||||
//that plane
|
||||
void Set (CVector3D &norm, CVector3D &point);
|
||||
|
||||
//normalizes the plane equation
|
||||
void Normalize ();
|
||||
|
||||
//returns the side of the plane on which this point
|
||||
//lies.
|
||||
PLANESIDE ClassifyPoint (CVector3D &point);
|
||||
|
||||
//solves the plane equation for a particular point
|
||||
float DistanceToPlane (CVector3D &point);
|
||||
|
||||
//calculates the intersection point of a line with this
|
||||
//plane. Returns false if there is no intersection
|
||||
bool FindLineSegIntersection (CVector3D &start, CVector3D &end, CVector3D *intsect);
|
||||
bool FindRayIntersection (CVector3D &start, CVector3D &direction, CVector3D *intsect);
|
||||
|
||||
public:
|
||||
CVector3D m_Norm; //normal vector of the plane
|
||||
float m_Dist; //Plane distance (ie D in the plane eq.)
|
||||
};
|
||||
|
||||
#endif
|
@ -1,467 +0,0 @@
|
||||
#include "Renderer.H"
|
||||
#include "Matrix3D.H"
|
||||
#include "Camera.H"
|
||||
|
||||
#include "types.h"
|
||||
#include "ogl.h"
|
||||
#include "tex.h"
|
||||
|
||||
#define RENDER_STAGE_BASE (1)
|
||||
#define RENDER_STAGE_TRANS (2)
|
||||
|
||||
bool g_WireFrame = false;
|
||||
unsigned int g_FrameCounter = 0;
|
||||
|
||||
CRenderer::CRenderer ()
|
||||
{
|
||||
m_Timer = 0;
|
||||
m_CurrentSeason = 0;
|
||||
}
|
||||
|
||||
CRenderer::~CRenderer ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool CRenderer::Initialize (HWND hwnd, int width, int height, int depth)
|
||||
{
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Depth = depth;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CRenderer::Shutdown ()
|
||||
{
|
||||
|
||||
}
|
||||
/*
|
||||
struct Tile
|
||||
{
|
||||
u32 pri_tex : 5;
|
||||
u32 sec_tex : 5;
|
||||
u32 alpha_map : 6;
|
||||
};
|
||||
|
||||
|
||||
void render_terrain()
|
||||
{
|
||||
CMatrix3D view = camera->m_Orientation.GetTranspose();
|
||||
CMatrix3D proj = camera->GetProjection();
|
||||
|
||||
float gl_view[16] = {view._11, view._21, view._31, view._41,
|
||||
view._12, view._22, view._32, view._42,
|
||||
view._13, view._23, view._33, view._43,
|
||||
view._14, view._24, view._34, view._44};
|
||||
|
||||
float gl_proj[16] = {proj._11, proj._21, proj._31, proj._41,
|
||||
proj._12, proj._22, proj._32, proj._42,
|
||||
proj._13, proj._23, proj._33, proj._43,
|
||||
proj._14, proj._24, proj._34, proj._44};
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadMatrixf (gl_view);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadMatrixf (gl_proj);
|
||||
|
||||
SViewPort vp = camera->GetViewPort();
|
||||
glViewport (vp.m_X, vp.m_Y, vp.m_Width, vp.m_Height);
|
||||
|
||||
if (g_WireFrame)
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
else
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
|
||||
for (int j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (camera->GetFustum().IsBoxVisible (CVector3D(0,0,0), terrain->m_Patches[j][i].m_Bounds))
|
||||
terrain->m_Patches[j][i].m_LastVisFrame = g_FrameCounter;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (terrain->m_Patches[j][i].m_LastVisFrame == g_FrameCounter)
|
||||
render_patch(&terrain->m_Patches[j][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
void CRenderer::RenderTerrain (CTerrain *terrain, CCamera *camera)
|
||||
{
|
||||
// m_Timer += 0.001f;
|
||||
|
||||
if (m_Timer > 1.0f)
|
||||
{
|
||||
m_Timer = 0;
|
||||
|
||||
if (m_CurrentSeason == 0)
|
||||
m_CurrentSeason = 1;
|
||||
else
|
||||
m_CurrentSeason = 0;
|
||||
}
|
||||
|
||||
CMatrix3D view = camera->m_Orientation.GetTranspose();
|
||||
CMatrix3D proj = camera->GetProjection();
|
||||
|
||||
float gl_view[16] = {view._11, view._21, view._31, view._41,
|
||||
view._12, view._22, view._32, view._42,
|
||||
view._13, view._23, view._33, view._43,
|
||||
view._14, view._24, view._34, view._44};
|
||||
|
||||
float gl_proj[16] = {proj._11, proj._21, proj._31, proj._41,
|
||||
proj._12, proj._22, proj._32, proj._42,
|
||||
proj._13, proj._23, proj._33, proj._43,
|
||||
proj._14, proj._24, proj._34, proj._44};
|
||||
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadMatrixf (gl_view);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadMatrixf (gl_proj);
|
||||
|
||||
SViewPort vp = camera->GetViewPort();
|
||||
glViewport (vp.m_X, vp.m_Y, vp.m_Width, vp.m_Height);
|
||||
|
||||
if (g_WireFrame)
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
else
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
|
||||
for (int j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (camera->GetFustum().IsBoxVisible (CVector3D(0,0,0), terrain->m_Patches[j][i].m_Bounds))
|
||||
terrain->m_Patches[j][i].m_LastVisFrame = g_FrameCounter;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (terrain->m_Patches[j][i].m_LastVisFrame == g_FrameCounter)
|
||||
RenderPatchBase (&terrain->m_Patches[j][i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (terrain->m_Patches[j][i].m_LastVisFrame == g_FrameCounter)
|
||||
RenderPatchTrans (&terrain->m_Patches[j][i]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CRenderer::RenderPatchBase (CPatch *patch)
|
||||
{
|
||||
CMiniPatch *MPatch, *MPCurrent;
|
||||
|
||||
float StartU, StartV;
|
||||
|
||||
|
||||
for (int j=0; j<16; j++)
|
||||
{
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
MPatch = &(patch->m_MiniPatches[j][i]);
|
||||
|
||||
if (MPatch->m_LastRenderedFrame == g_FrameCounter)
|
||||
continue;
|
||||
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
tex_bind(MPatch->Tex1);
|
||||
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
/////////////////////////////////////
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
||||
/////////////////////////////////////
|
||||
|
||||
StartU = 0.125f * (float)(i%8);
|
||||
StartV = 0.125f * (float)(j%8);
|
||||
|
||||
float tu[2], tv[2];
|
||||
tu[0] = tu[1] = StartU;
|
||||
tv[0] = StartV+0.125f;
|
||||
tv[1] = StartV;
|
||||
|
||||
MPCurrent = MPatch;
|
||||
glBegin (GL_TRIANGLE_STRIP);
|
||||
|
||||
int start = 0;
|
||||
|
||||
while (MPCurrent)
|
||||
{
|
||||
for (int x=start; x<2; x++)
|
||||
{
|
||||
int v1 = MAP_SIZE + x;
|
||||
int v2 = x;
|
||||
|
||||
float factor = m_Timer;
|
||||
if (m_CurrentSeason == 1)
|
||||
factor = 1.0f - factor;
|
||||
|
||||
float color1[3] = {MPCurrent->m_pVertices[v1].m_Color[0][0]*factor + MPCurrent->m_pVertices[v1].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][1]*factor + MPCurrent->m_pVertices[v1].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][2]*factor + MPCurrent->m_pVertices[v1].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
float color2[3] = {MPCurrent->m_pVertices[v2].m_Color[0][0]*factor + MPCurrent->m_pVertices[v2].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][1]*factor + MPCurrent->m_pVertices[v2].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][2]*factor + MPCurrent->m_pVertices[v2].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
glTexCoord2f (tu[0], tv[0]);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color1[0],color1[1],color1[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v1].m_Position.X,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Z);
|
||||
|
||||
glTexCoord2f (tu[1], tv[1]);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color2[0],color2[1],color2[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v2].m_Position.X,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Z);
|
||||
|
||||
tu[0]+=0.125f;
|
||||
tu[1]+=0.125f;
|
||||
}
|
||||
|
||||
MPCurrent->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPCurrent->m_RenderStage = RENDER_STAGE_BASE;
|
||||
|
||||
if (!MPCurrent->m_pRightNeighbor)
|
||||
break;
|
||||
else
|
||||
{
|
||||
if (MPCurrent->m_pRightNeighbor->Tex1 != MPCurrent->Tex1 ||
|
||||
MPCurrent->m_pRightNeighbor->m_pParrent->m_LastVisFrame != g_FrameCounter)
|
||||
break;
|
||||
}
|
||||
|
||||
MPCurrent = MPCurrent->m_pRightNeighbor;
|
||||
start = 1;
|
||||
}
|
||||
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CRenderer::RenderPatchTrans (CPatch *patch)
|
||||
{
|
||||
CMiniPatch *MPatch, *MPCurrent;
|
||||
|
||||
float StartU, StartV;
|
||||
|
||||
glEnable (GL_BLEND);
|
||||
glDepthFunc (GL_EQUAL);
|
||||
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
for (int j=0; j<16; j++)
|
||||
{
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
MPatch = &(patch->m_MiniPatches[j][i]);
|
||||
|
||||
if (MPatch->m_LastRenderedFrame == g_FrameCounter &&
|
||||
MPatch->m_RenderStage == RENDER_STAGE_TRANS)
|
||||
continue;
|
||||
|
||||
//now for transition
|
||||
if (MPatch->Tex2 && MPatch->m_AlphaMap)
|
||||
{
|
||||
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
tex_bind(MPatch->Tex2);
|
||||
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
/////////////////////////////////////
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
||||
/////////////////////////////////////
|
||||
|
||||
|
||||
glActiveTexture (GL_TEXTURE1);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
tex_bind(MPatch->m_AlphaMap);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
/////////////////////////////////////
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
||||
/////////////////////////////////////
|
||||
|
||||
StartU = 0.125f * (float)(i%8);
|
||||
StartV = 0.125f * (float)(j%8);
|
||||
|
||||
float tu[2], tv[2];
|
||||
tu[0] = tu[1] = StartU;
|
||||
tv[0] = StartV+0.125f;
|
||||
tv[1] = StartV;
|
||||
|
||||
glBegin (GL_TRIANGLE_STRIP);
|
||||
MPCurrent = MPatch;
|
||||
|
||||
int start = 0;
|
||||
|
||||
while (MPCurrent)
|
||||
{
|
||||
for (int x=start; x<2; x++)
|
||||
{
|
||||
int v1 = MAP_SIZE + x;
|
||||
int v2 = x;
|
||||
|
||||
float factor = m_Timer;
|
||||
if (m_CurrentSeason == 1)
|
||||
factor = 1.0f - factor;
|
||||
|
||||
float color1[3] = {MPCurrent->m_pVertices[v1].m_Color[0][0]*factor + MPCurrent->m_pVertices[v1].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][1]*factor + MPCurrent->m_pVertices[v1].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][2]*factor + MPCurrent->m_pVertices[v1].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
float color2[3] = {MPCurrent->m_pVertices[v2].m_Color[0][0]*factor + MPCurrent->m_pVertices[v2].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][1]*factor + MPCurrent->m_pVertices[v2].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][2]*factor + MPCurrent->m_pVertices[v2].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
glMultiTexCoord2f (GL_TEXTURE0_ARB, tu[0], tv[0]);
|
||||
glMultiTexCoord2f (GL_TEXTURE1_ARB, tu[0]*2, tv[0]*2);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color1[0],color1[1],color1[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v1].m_Position.X,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Z);
|
||||
|
||||
glMultiTexCoord2f (GL_TEXTURE0_ARB, tu[1], tv[1]);
|
||||
glMultiTexCoord2f (GL_TEXTURE1_ARB, tu[1]*2, tv[1]*2);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color2[0],color2[1],color2[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v2].m_Position.X,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Z);
|
||||
|
||||
tu[0]+=0.125f;
|
||||
tu[1]+=0.125f;
|
||||
}
|
||||
|
||||
MPCurrent->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPCurrent->m_RenderStage = RENDER_STAGE_TRANS;
|
||||
|
||||
if (!MPCurrent->m_pRightNeighbor)
|
||||
break;
|
||||
else
|
||||
{
|
||||
if (MPCurrent->m_pRightNeighbor->Tex2 != MPCurrent->Tex2 ||
|
||||
MPCurrent->m_pRightNeighbor->m_AlphaMap != MPCurrent->m_AlphaMap ||
|
||||
MPCurrent->m_pRightNeighbor->m_pParrent->m_LastVisFrame != g_FrameCounter)
|
||||
break;
|
||||
}
|
||||
|
||||
MPCurrent = MPCurrent->m_pRightNeighbor;
|
||||
start=1;
|
||||
}
|
||||
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
glDisable (GL_BLEND);
|
||||
glActiveTexture (GL_TEXTURE1);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void CRenderer::RenderTileOutline (CMiniPatch *mpatch)
|
||||
{
|
||||
if(!mpatch->m_pVertices)
|
||||
return;
|
||||
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glLineWidth (4);
|
||||
|
||||
STerrainVertex V[4];
|
||||
V[0] = mpatch->m_pVertices[0];
|
||||
V[1] = mpatch->m_pVertices[1];
|
||||
V[2] = mpatch->m_pVertices[MAP_SIZE*1 + 1];
|
||||
V[3] = mpatch->m_pVertices[MAP_SIZE*1];
|
||||
|
||||
glColor3f (0,1.0f,0);
|
||||
|
||||
glBegin (GL_LINE_LOOP);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
glVertex3fv(&V[i].m_Position.X);
|
||||
|
||||
glEnd ();
|
||||
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
#include <windows.h>
|
||||
#include "ogl.h"
|
||||
|
||||
#include "Terrain.H"
|
||||
|
||||
extern bool g_WireFrame;
|
||||
extern unsigned int g_FrameCounter;
|
||||
|
||||
class CRenderer
|
||||
{
|
||||
public:
|
||||
CRenderer();
|
||||
~CRenderer();
|
||||
|
||||
bool Initialize (HWND hwnd, int width, int height, int depth);
|
||||
void Shutdown ();
|
||||
|
||||
void RenderTerrain (CTerrain *terrain, CCamera *camera);
|
||||
void RenderTileOutline (CMiniPatch *mpatch);
|
||||
|
||||
protected:
|
||||
void RenderPatchBase (CPatch *patch);
|
||||
void RenderPatchTrans (CPatch *patch);
|
||||
|
||||
protected:
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
int m_Depth;
|
||||
|
||||
///THERE ARE NOT SUPPOSED TO BE HERE
|
||||
float m_Timer;
|
||||
int m_CurrentSeason;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: TerrGlobals.H
|
||||
// Last Update: 27/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Some globals and macros, used by the CTerrain
|
||||
// and CPatch
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TERRGLOBALS_H
|
||||
#define TERRGLOBALS_H
|
||||
|
||||
const int PATCH_SIZE = 16;
|
||||
const int CELL_SIZE = 4; //horizontal scale of the patches
|
||||
const float HEIGHT_SCALE = 1.0f;
|
||||
|
||||
//only 3x3 patches loaded at a time
|
||||
const int NUM_PATCHES_PER_SIDE = 20;
|
||||
|
||||
//must be odd number of patches
|
||||
//#define TERRAIN_CHUNK_SIZE (PATCH_SIZE*NUM_PATCHES_PER_SIDE)
|
||||
const int MAP_SIZE = ( (NUM_PATCHES_PER_SIDE*PATCH_SIZE)+1 );
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,192 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Terrain.Cpp
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CTerrain handles the terrain portion of the
|
||||
// engine. It holds open the file to the terrain
|
||||
// information, so terrain data can be loaded
|
||||
// dynamically. We use a ROAM method to render
|
||||
// the terrain, ie using binary triangle trees.
|
||||
// The terrain consists of smaller PATCHS, which
|
||||
// do most of the work.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Terrain.H"
|
||||
#include "tex.h"
|
||||
|
||||
bool g_HillShading = true;
|
||||
|
||||
CVector3D SeasonLight[2];
|
||||
float SeasonColor[2][3];
|
||||
|
||||
CTerrain::CTerrain ()
|
||||
{
|
||||
m_pVertices = NULL;
|
||||
}
|
||||
|
||||
CTerrain::~CTerrain ()
|
||||
{
|
||||
delete [] m_pVertices;
|
||||
}
|
||||
|
||||
bool CTerrain::Initalize (char *filename)
|
||||
{
|
||||
SeasonLight[0].Set (3, -1, 3);
|
||||
SeasonLight[0].Normalize();
|
||||
SeasonColor[0][0] = 0.8f; SeasonColor[0][1] = 1.0f; SeasonColor[0][2] = 0.8f;
|
||||
|
||||
SeasonLight[1].Set (2, -1, -3);
|
||||
SeasonLight[1].Normalize();
|
||||
SeasonColor[1][0] = 1.0f; SeasonColor[1][1] = 0.9f; SeasonColor[1][2] = 0.9f;
|
||||
|
||||
TEX tex;
|
||||
Handle h = tex_load(filename, &tex);
|
||||
if(!h)
|
||||
return false;
|
||||
const u8* data = tex.ptr;
|
||||
|
||||
m_pVertices = new STerrainVertex[MAP_SIZE*MAP_SIZE];
|
||||
if (m_pVertices == NULL)
|
||||
return false;
|
||||
|
||||
for (int j=0; j<MAP_SIZE; j++)
|
||||
{
|
||||
for (int i=0; i<MAP_SIZE; i++)
|
||||
{
|
||||
int pos = j*MAP_SIZE + i;
|
||||
|
||||
m_pVertices[pos].m_Position.X = ((float)i)*CELL_SIZE;
|
||||
m_pVertices[pos].m_Position.Y = (*data++)*0.35f;
|
||||
m_pVertices[pos].m_Position.Z = ((float)j)*CELL_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
int pos = j*MAP_SIZE*PATCH_SIZE;
|
||||
pos += i*PATCH_SIZE;
|
||||
|
||||
m_Patches[j][i].Initialize ( &(m_pVertices[pos]) );
|
||||
}
|
||||
}
|
||||
|
||||
CalcLighting();
|
||||
SetNeighbors();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CTerrain::CalcLighting ()
|
||||
{
|
||||
CVector3D left, right, up, down, n[4];
|
||||
|
||||
for (int j=0; j<MAP_SIZE; j++)
|
||||
{
|
||||
for (int i=0; i<MAP_SIZE; i++)
|
||||
{
|
||||
left.Clear();
|
||||
right.Clear();
|
||||
up.Clear();
|
||||
down.Clear();
|
||||
|
||||
if (i>0)
|
||||
left = m_pVertices[j*MAP_SIZE + i - 1].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
if (i<MAP_SIZE-1)
|
||||
right = m_pVertices[j*MAP_SIZE + i + 1].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
if (j>0)
|
||||
up = m_pVertices[(j-1)*MAP_SIZE + i].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
if (j<MAP_SIZE-1)
|
||||
down = m_pVertices[(j+1)*MAP_SIZE + i].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
n[0] = up.Cross(left);
|
||||
n[1] = left.Cross(down);
|
||||
n[2] = down.Cross(right);
|
||||
n[3] = right.Cross(up);
|
||||
|
||||
n[0].Normalize();
|
||||
n[1].Normalize();
|
||||
n[2].Normalize();
|
||||
n[3].Normalize();
|
||||
|
||||
CVector3D Normal = n[0] + n[1] + n[2] + n[3];
|
||||
Normal.Normalize();
|
||||
|
||||
float Color1 = Normal.Dot(SeasonLight[0]*-1)/(Normal.GetLength() * SeasonLight[0].GetLength());
|
||||
Color1 = (Color1+1.0f)/1.4f;
|
||||
|
||||
if (Color1>1.0f)
|
||||
Color1=1.0f;
|
||||
if (Color1<0.0f)
|
||||
Color1=0.0f;
|
||||
|
||||
float Color2 = Normal.Dot(SeasonLight[1]*-1)/(Normal.GetLength() * SeasonLight[1].GetLength());
|
||||
Color2 = (Color2+1.0f)/1.4f;
|
||||
|
||||
if (Color2>1.0f)
|
||||
Color2=1.0f;
|
||||
if (Color2<0.0f)
|
||||
Color2=0.0f;
|
||||
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[0][0] = Color1*SeasonColor[0][0];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[0][1] = Color1*SeasonColor[0][1];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[0][2] = Color1*SeasonColor[0][2];
|
||||
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[1][0] = Color2*SeasonColor[1][0];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[1][1] = Color2*SeasonColor[1][1];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[1][2] = Color2*SeasonColor[1][2];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CTerrain::SetNeighbors ()
|
||||
{
|
||||
CPatch *ThisPatch, *RightPatch;
|
||||
|
||||
for (int pj=0; pj<NUM_PATCHES_PER_SIDE; pj++)
|
||||
{
|
||||
for (int pi=0; pi<NUM_PATCHES_PER_SIDE; pi++)
|
||||
{
|
||||
ThisPatch = &m_Patches[pj][pi];
|
||||
|
||||
if (pi < NUM_PATCHES_PER_SIDE-1)
|
||||
RightPatch = &m_Patches[pj][pi+1];
|
||||
else
|
||||
RightPatch = NULL;
|
||||
|
||||
|
||||
for (int tj=0; tj<16; tj++)
|
||||
{
|
||||
for (int ti=0; ti<16; ti++)
|
||||
{
|
||||
CMiniPatch *MPatch = &ThisPatch->m_MiniPatches[tj][ti];
|
||||
|
||||
MPatch->m_pParrent = ThisPatch;
|
||||
|
||||
if (ti < 15)
|
||||
MPatch->m_pRightNeighbor = &ThisPatch->m_MiniPatches[tj][ti+1];
|
||||
else
|
||||
{
|
||||
if (RightPatch)
|
||||
MPatch->m_pRightNeighbor = &RightPatch->m_MiniPatches[tj][0];
|
||||
else
|
||||
MPatch->m_pRightNeighbor = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Terrain.H
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CTerrain handles the terrain portion of the
|
||||
// engine. It holds open the file to the terrain
|
||||
// information, so terrain data can be loaded
|
||||
// dynamically. We use a ROAM method to render
|
||||
// the terrain, ie using binary triangle trees.
|
||||
// The terrain consists of smaller PATCHS, which
|
||||
// do most of the work.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TERRAIN_H
|
||||
#define TERRAIN_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Patch.H"
|
||||
#include "Vector3D.H"
|
||||
|
||||
extern bool g_HillShading;
|
||||
|
||||
class CTerrain
|
||||
{
|
||||
public:
|
||||
CTerrain ();
|
||||
~CTerrain ();
|
||||
|
||||
bool Initalize (char *filename);
|
||||
|
||||
// protected:
|
||||
//the patches currently loaded
|
||||
CPatch m_Patches[NUM_PATCHES_PER_SIDE][NUM_PATCHES_PER_SIDE];
|
||||
STerrainVertex *m_pVertices;
|
||||
|
||||
|
||||
// protected:
|
||||
void CalcLighting();
|
||||
void SetNeighbors();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,88 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Types.H
|
||||
// Last Update: 25/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: The basic types used by the engine
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//basic return types
|
||||
enum FRESULT
|
||||
{
|
||||
R_OK = 0,
|
||||
R_FAIL, //use if nothing else matches the return type
|
||||
|
||||
R_BADPARAMS, //one or more of the parameters were invalid
|
||||
|
||||
R_NOMEMORY, //not enough memory for an operation
|
||||
|
||||
R_FILE_NOOPEN, //file could not be opened
|
||||
R_FILE_NOREAD, //file could not be read
|
||||
R_FILE_INVALID //file is corrupt or not supported
|
||||
};
|
||||
|
||||
//string related
|
||||
#define MAX_NAME_LENGTH (50)
|
||||
#define MAX_PATH_LENGTH (100)
|
||||
|
||||
//color structures
|
||||
struct SColor4ub
|
||||
{
|
||||
unsigned char R;
|
||||
unsigned char G;
|
||||
unsigned char B;
|
||||
unsigned char A;
|
||||
};
|
||||
|
||||
struct SColor4f
|
||||
{
|
||||
float R;
|
||||
float G;
|
||||
float B;
|
||||
float A;
|
||||
};
|
||||
|
||||
//all the major classes:
|
||||
class CBitmap;
|
||||
|
||||
class CCamera;
|
||||
|
||||
class CDiesel3DVertex;
|
||||
|
||||
class CGameResource;
|
||||
|
||||
class CEngine;
|
||||
class CEntity;
|
||||
|
||||
class CFrustum;
|
||||
|
||||
class CMatrix3D;
|
||||
class CMesh;
|
||||
class CMeshPoly;
|
||||
class CShadyMesh;
|
||||
class CShadyMeshPoly;
|
||||
|
||||
class CNode;
|
||||
|
||||
class CPatch;
|
||||
class CPlane;
|
||||
|
||||
class CRenderer;
|
||||
|
||||
class CTerrain;
|
||||
class CTexture;
|
||||
|
||||
class CVector3D;
|
||||
|
||||
class CWorld;
|
||||
|
||||
|
||||
#endif
|
@ -1,181 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Vector3D.Cpp
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Provides an interface for a vector in R3 and
|
||||
// allows vector and scalar operations on it
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Vector3D.H"
|
||||
|
||||
CVector3D::CVector3D ()
|
||||
{
|
||||
X = Y = Z = 0.0f;
|
||||
}
|
||||
|
||||
CVector3D::CVector3D (float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
int CVector3D::operator == (CVector3D &vector)
|
||||
{
|
||||
if (X != vector.X ||
|
||||
Y != vector.Y ||
|
||||
Z != vector.Z)
|
||||
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CVector3D::operator != (CVector3D &vector)
|
||||
{
|
||||
if (X != vector.X ||
|
||||
Y != vector.Y ||
|
||||
Z != vector.Z)
|
||||
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CVector3D::operator ! ()
|
||||
{
|
||||
if (X != 0.0f ||
|
||||
Y != 0.0f ||
|
||||
Z != 0.0f)
|
||||
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//vector addition
|
||||
CVector3D CVector3D::operator + (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X + vector.X;
|
||||
Temp.Y = Y + vector.Y;
|
||||
Temp.Z = Z + vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//vector addition/assignment
|
||||
CVector3D &CVector3D::operator += (CVector3D &vector)
|
||||
{
|
||||
X += vector.X;
|
||||
Y += vector.Y;
|
||||
Z += vector.Z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//vector subtraction
|
||||
CVector3D CVector3D::operator - (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X - vector.X;
|
||||
Temp.Y = Y - vector.Y;
|
||||
Temp.Z = Z - vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//vector subtrcation/assignment
|
||||
CVector3D &CVector3D::operator -= (CVector3D &vector)
|
||||
{
|
||||
X -= vector.X;
|
||||
Y -= vector.Y;
|
||||
Z -= vector.Z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//scalar multiplication
|
||||
CVector3D CVector3D::operator * (float value)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X * value;
|
||||
Temp.Y = Y * value;
|
||||
Temp.Z = Z * value;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//scalar multiplication/assignment
|
||||
CVector3D CVector3D::operator *= (float value)
|
||||
{
|
||||
X *= value;
|
||||
Y *= value;
|
||||
Z *= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CVector3D::Set (float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
void CVector3D::Clear ()
|
||||
{
|
||||
X = Y = Z = 0.0f;
|
||||
}
|
||||
|
||||
//Dot product
|
||||
float CVector3D::Dot (CVector3D &vector)
|
||||
{
|
||||
return ( X * vector.X +
|
||||
Y * vector.Y +
|
||||
Z * vector.Z );
|
||||
}
|
||||
|
||||
//Cross product
|
||||
CVector3D CVector3D::Cross (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = (Y * vector.Z) - (Z * vector.Y);
|
||||
Temp.Y = (Z * vector.X) - (X * vector.Z);
|
||||
Temp.Z = (X * vector.Y) - (Y * vector.X);
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
float CVector3D::GetLength ()
|
||||
{
|
||||
return sqrtf ( SQR(X) + SQR(Y) + SQR(Z) );
|
||||
}
|
||||
|
||||
void CVector3D::Normalize ()
|
||||
{
|
||||
float scale = 1.0f/GetLength ();
|
||||
|
||||
X *= scale;
|
||||
Y *= scale;
|
||||
Z *= scale;
|
||||
}
|
||||
|
||||
SColor4ub CVector3D::ConvertToColor (float alpha_factor)
|
||||
{
|
||||
SColor4ub color;
|
||||
|
||||
color.R = (unsigned char)(127.0f * X + 128.0f);
|
||||
color.G = (unsigned char)(127.0f * Y + 128.0f);
|
||||
color.B = (unsigned char)(127.0f * Z + 128.0f);
|
||||
color.A = (unsigned char)(255.0f * alpha_factor);
|
||||
|
||||
return color;
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Vector3D.H
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Provides an interface for a vector in R3 and
|
||||
// allows vector and scalar operations on it
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef VECTOR3D_H
|
||||
#define VECTOR3D_H
|
||||
|
||||
#include <math.h>
|
||||
#include "MathUtil.H"
|
||||
#include "Types.H"
|
||||
|
||||
class CVector3D
|
||||
{
|
||||
public:
|
||||
float X, Y, Z;
|
||||
|
||||
public:
|
||||
CVector3D ();
|
||||
CVector3D (float x, float y, float z);
|
||||
|
||||
int operator == (CVector3D &vector);
|
||||
int operator != (CVector3D &vector);
|
||||
int operator ! ();
|
||||
|
||||
//vector addition
|
||||
CVector3D operator + (CVector3D &vector);
|
||||
//vector addition/assignment
|
||||
CVector3D &operator += (CVector3D &vector);
|
||||
|
||||
//vector subtraction
|
||||
CVector3D operator - (CVector3D &vector);
|
||||
//vector subtraction/assignment
|
||||
CVector3D &operator -= (CVector3D &vector);
|
||||
|
||||
//scalar multiplication
|
||||
CVector3D operator * (float value);
|
||||
//scalar multiplication/assignment
|
||||
CVector3D operator *= (float value);
|
||||
|
||||
public:
|
||||
void Set (float x, float y, float z);
|
||||
void Clear ();
|
||||
|
||||
//Dot product
|
||||
float Dot (CVector3D &vector);
|
||||
//Cross product
|
||||
CVector3D Cross (CVector3D &vector);
|
||||
|
||||
//Returns length of the vector
|
||||
float GetLength ();
|
||||
void Normalize ();
|
||||
|
||||
//Returns a color which describes the vector
|
||||
SColor4ub ConvertToColor (float alpha_factor);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,361 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Bitmap.Cpp
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CBitmap operates on a bitmap. Currently it
|
||||
// can load BMPs and TGAs. All bitmaps (even 8-bit
|
||||
// ones) are converted into full RGBAs.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Bitmap.H"
|
||||
#include "RenderPrims.H"
|
||||
|
||||
CBitmap::CBitmap ()
|
||||
{
|
||||
//everthing is 0
|
||||
m_pBits = NULL;
|
||||
m_Height = m_Width = 0;
|
||||
}
|
||||
|
||||
CBitmap::~CBitmap ()
|
||||
{
|
||||
//destroy the data
|
||||
DestroyData ();
|
||||
}
|
||||
|
||||
//Load the image from a file
|
||||
FRESULT CBitmap::LoadBitmap (char *path, RESOURCETYPE type)
|
||||
{
|
||||
FILE *ImageFile = NULL;
|
||||
int ImageType;
|
||||
FRESULT Result;
|
||||
|
||||
CFileResource::SetupParams (path, type);
|
||||
|
||||
//clean up
|
||||
DestroyData ();
|
||||
|
||||
ImageFile = fopen (path, "rb");
|
||||
|
||||
if (!ImageFile)
|
||||
{
|
||||
return R_FILE_NOOPEN;
|
||||
}
|
||||
|
||||
ImageType = GetImageType (ImageFile);
|
||||
|
||||
switch (ImageType)
|
||||
{
|
||||
case FILE_TYPE_BMP:
|
||||
//try to load as a BMP
|
||||
Result = LoadBMP (ImageFile);
|
||||
break;
|
||||
|
||||
case FILE_TYPE_TGA:
|
||||
//try to load as a TGA
|
||||
Result = LoadTGA (ImageFile);
|
||||
break;
|
||||
|
||||
default:
|
||||
return R_BADPARAMS;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Result != R_OK)
|
||||
return R_FAIL;
|
||||
|
||||
|
||||
return R_OK;
|
||||
}
|
||||
|
||||
FRESULT CBitmap::CreateBitmap (RESOURCETYPE type, char *name, int width, int height)
|
||||
{
|
||||
//clean any old data
|
||||
DestroyData ();
|
||||
|
||||
strcpy (m_Name, name);
|
||||
m_Type = type;
|
||||
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
|
||||
m_pBits = new unsigned char [m_Width*m_Height*4];
|
||||
|
||||
if (!m_pBits)
|
||||
return R_NOMEMORY;
|
||||
|
||||
return R_OK;
|
||||
}
|
||||
|
||||
//Get the file format
|
||||
int CBitmap::GetImageType (FILE *file)
|
||||
{
|
||||
short int type;
|
||||
|
||||
//is the file valid ?
|
||||
if (!file)
|
||||
{
|
||||
fclose(file);
|
||||
return FILE_TYPE_NOSUPPORT;
|
||||
}
|
||||
|
||||
// Read the first 2 bytes of the file
|
||||
if (fread (&type, 2, 1, file) != 1)
|
||||
{
|
||||
fclose(file);
|
||||
return FILE_TYPE_NOSUPPORT;
|
||||
}
|
||||
|
||||
rewind(file);
|
||||
|
||||
// Is it a bitmap ?
|
||||
if (type == 0x4d42)
|
||||
{
|
||||
rewind (file);
|
||||
return FILE_TYPE_BMP;
|
||||
}
|
||||
|
||||
// TGA's don't have a header ID, so just take a guess
|
||||
rewind(file);
|
||||
return FILE_TYPE_TGA;
|
||||
}
|
||||
|
||||
//Load a bmp file
|
||||
FRESULT CBitmap::LoadBMP (FILE *file)
|
||||
{
|
||||
BITMAPFILEHEADER bmfileh;
|
||||
BITMAPINFOHEADER bminfoh;
|
||||
RGBQUAD bmColors[256];
|
||||
|
||||
//Note: the file format of a BMP file is:
|
||||
|
||||
// BITMAPFILEHEADER
|
||||
// BITMAPINFOHEADER
|
||||
// RGBQUAD[2^bitcount]
|
||||
// the actual bits (indices in case of an 8 bit bitmap)
|
||||
|
||||
fread (&bmfileh, sizeof (BITMAPFILEHEADER), 1, file);
|
||||
//read the file header
|
||||
fread (&bminfoh, sizeof (BITMAPINFOHEADER), 1, file);
|
||||
//read the bitmap header
|
||||
|
||||
m_Width = bminfoh.biWidth;
|
||||
m_Height = abs(bminfoh.biHeight);
|
||||
|
||||
//read the color table if indexed
|
||||
if (bminfoh.biBitCount < 24)
|
||||
fread (&bmColors, sizeof (RGBQUAD), 256, file);
|
||||
|
||||
//move to the point where the actual bit data start
|
||||
fseek (file, bmfileh.bfOffBits, SEEK_SET);
|
||||
|
||||
//load the data
|
||||
return LoadData (file, bminfoh.biBitCount, bmColors);
|
||||
}
|
||||
|
||||
//Load a TGA file
|
||||
FRESULT CBitmap::LoadTGA (FILE *file)
|
||||
{
|
||||
TGAHeader tgaHeader;
|
||||
|
||||
int loadedOK = 1;
|
||||
int i, temp;
|
||||
|
||||
// We have to load the header explicitly, due to some time
|
||||
// weird memory aligning thing that goes on at compile
|
||||
loadedOK &= fread(&tgaHeader.IDLength, 1, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.MapType, 1, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.ImageType, 1, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.MapOrigin, 2, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.MapLength, 2, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.MapEntrySize, 1, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.XOrigin, 2, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.YOrigin, 2, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.Width, 2, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.Height, 2, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.BPP, 1, 1, file);
|
||||
loadedOK &= fread(&tgaHeader.Descriptor, 1, 1, file);
|
||||
|
||||
// Ensure all elements of the file header were loaded
|
||||
if (!loadedOK)
|
||||
{
|
||||
fclose(file);
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
// Check the image type
|
||||
if (tgaHeader.ImageType != 1 && tgaHeader.ImageType != 2 && tgaHeader.ImageType != 3)
|
||||
{
|
||||
fclose(file);
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
if (tgaHeader.BPP != 24 && tgaHeader.BPP != 32)
|
||||
{
|
||||
fclose(file);
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
// Skip any identification data in the header (we're not interested in that)
|
||||
for (i=0; i<tgaHeader.IDLength; i++)
|
||||
fread(&temp, sizeof(unsigned char), 1, file);
|
||||
|
||||
// Skip the colour look up tables
|
||||
for (i=0; i<tgaHeader.MapLength*(tgaHeader.MapEntrySize>>3); i++)
|
||||
fread(&temp, sizeof(unsigned char), 1, file);
|
||||
|
||||
m_Width = tgaHeader.Width;
|
||||
m_Height = tgaHeader.Height;
|
||||
|
||||
return LoadData (file, tgaHeader.BPP, NULL);
|
||||
}
|
||||
|
||||
//Load the actual bits from a file. the table is NULL
|
||||
//unless the image is 8-bit
|
||||
FRESULT CBitmap::LoadData (FILE *file, int bpp, RGBQUAD *table)
|
||||
{
|
||||
unsigned char *TempBits = NULL;
|
||||
//temporary bits which are read straight from the file
|
||||
|
||||
m_pBits = new unsigned char[m_Width*m_Height*4];
|
||||
//allocate memory for the bits
|
||||
|
||||
//this is rather bad: no memory
|
||||
if (!m_pBits)
|
||||
{
|
||||
fclose (file);
|
||||
return R_NOMEMORY;
|
||||
}
|
||||
|
||||
//read the bits
|
||||
switch (bpp)
|
||||
{
|
||||
case 8:
|
||||
{
|
||||
TempBits = new unsigned char[m_Width*m_Height];
|
||||
//allocate some memory for temporary bits
|
||||
break;
|
||||
}
|
||||
|
||||
case 24:
|
||||
{
|
||||
TempBits = new unsigned char[m_Width*m_Height*3];
|
||||
//allocate some memory for temporary bits
|
||||
break;
|
||||
}
|
||||
|
||||
case 32:
|
||||
{
|
||||
TempBits = new unsigned char[m_Width*m_Height*4];
|
||||
//allocate some memory for temporary bits
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
fclose (file);
|
||||
return R_FILE_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//no memory
|
||||
if (!TempBits)
|
||||
{
|
||||
fclose (file);
|
||||
return R_NOMEMORY;
|
||||
}
|
||||
|
||||
//now lets actually read the bits from the file and copy them into
|
||||
//Bits in the proper fashion
|
||||
switch (bpp)
|
||||
{
|
||||
case 8:
|
||||
{
|
||||
//only one channel (8-bit) so there are Width*Height values to read
|
||||
if (fread (TempBits, sizeof (unsigned char), m_Width*m_Height, file) != (unsigned int)(m_Width*m_Height))
|
||||
{
|
||||
fclose (file);
|
||||
return R_FILE_NOREAD;
|
||||
}
|
||||
|
||||
//the following loop converts the index data of TempBits,
|
||||
//into actual color data (read from the color table) and
|
||||
//stores it to Bits
|
||||
int i;
|
||||
|
||||
for (int index=0;index<m_Width*m_Height;index++)
|
||||
{
|
||||
i = TempBits[index];
|
||||
m_pBits[index*4 ] = table[i].rgbRed;
|
||||
m_pBits[index*4 + 1] = table[i].rgbGreen;
|
||||
m_pBits[index*4 + 2] = table[i].rgbBlue;
|
||||
m_pBits[index*4 + 3] = 255;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 24:
|
||||
{
|
||||
//3 channels (24-bit) so there are Width*Height*3 values to read
|
||||
if (fread (TempBits, sizeof (unsigned char), m_Width*m_Height*3, file) != (unsigned int)(m_Width*m_Height*3))
|
||||
{
|
||||
fclose (file);
|
||||
return R_FILE_NOREAD;
|
||||
}
|
||||
|
||||
//we have no palette so just read all the color values
|
||||
for (int index=0;index<m_Width*m_Height;index++)
|
||||
{
|
||||
//since data is stored in BGR we convert it to RGB
|
||||
m_pBits[index*4 ] = TempBits[index*3 ];
|
||||
m_pBits[index*4 + 1] = TempBits[index*3+1];
|
||||
m_pBits[index*4 + 2] = TempBits[index*3+2];
|
||||
m_pBits[index*4 + 3] = 255;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 32:
|
||||
{
|
||||
//4 channels (32-bit) so there are Width*Height*4 values to read
|
||||
if (fread (TempBits, sizeof (unsigned char), m_Width*m_Height*4, file) != (unsigned int)(m_Width*m_Height*4))
|
||||
{
|
||||
fclose (file);
|
||||
return R_FILE_NOREAD;
|
||||
}
|
||||
|
||||
//load a 32 bit image. The 4th channel is the alpha data
|
||||
//again we convert from BGRA to RGBA
|
||||
for (int index=0;index<m_Width*m_Height;index++)
|
||||
{
|
||||
m_pBits[index*4 ] = TempBits[index*4 ];
|
||||
m_pBits[index*4 + 1] = TempBits[index*4+1];
|
||||
m_pBits[index*4 + 2] = TempBits[index*4+2];
|
||||
m_pBits[index*4 + 3] = TempBits[index*4+3];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//delete all the unwanted:
|
||||
delete [] TempBits;
|
||||
|
||||
return R_OK;
|
||||
}
|
||||
|
||||
void CBitmap::DestroyData ()
|
||||
{
|
||||
if (m_pBits)
|
||||
{
|
||||
delete [] m_pBits;
|
||||
m_pBits = NULL;
|
||||
}
|
||||
|
||||
m_Width = m_Height = 0;
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Bitmap.H
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CBitmap operates on a bitmap. Currently it
|
||||
// can load BMPs and TGAs. All bitmaps (even 8-bit
|
||||
// ones) are converted into full RGBAs.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef BITMAP_H
|
||||
#define BITMAP_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "Types.H"
|
||||
#include "FileResource.H"
|
||||
|
||||
|
||||
//image types
|
||||
#define FILE_TYPE_NOSUPPORT (0)
|
||||
#define FILE_TYPE_BMP (1)
|
||||
#define FILE_TYPE_TGA (2)
|
||||
|
||||
//this structure holds header data for a TGA file
|
||||
typedef struct
|
||||
{
|
||||
unsigned char IDLength;
|
||||
unsigned char MapType;
|
||||
unsigned char ImageType;
|
||||
unsigned short MapOrigin;
|
||||
unsigned short MapLength;
|
||||
unsigned char MapEntrySize;
|
||||
unsigned short XOrigin;
|
||||
unsigned short YOrigin;
|
||||
unsigned short Width;
|
||||
unsigned short Height;
|
||||
unsigned char BPP;
|
||||
unsigned char Descriptor;
|
||||
} TGAHeader;
|
||||
|
||||
class CBitmap : public CFileResource
|
||||
{
|
||||
public:
|
||||
CBitmap ();
|
||||
virtual ~CBitmap ();
|
||||
|
||||
//Load the image from a file
|
||||
virtual FRESULT LoadBitmap (char *path, RESOURCETYPE type);
|
||||
|
||||
//Creates the bits for the bitmap
|
||||
virtual FRESULT CreateBitmap (RESOURCETYPE type, char *name, int width, int height);
|
||||
|
||||
//Get the pointer to the image data
|
||||
unsigned char *GetBits () { return m_pBits; }
|
||||
|
||||
//Get width and height
|
||||
int GetWidth () { return m_Width; }
|
||||
int GetHeight () { return m_Height; }
|
||||
|
||||
private:
|
||||
//Get the file format
|
||||
int GetImageType (FILE *file);
|
||||
//Load a bmp file
|
||||
FRESULT LoadBMP (FILE *file);
|
||||
//Load a TGA file
|
||||
FRESULT LoadTGA (FILE *file);
|
||||
//Load the actual bits from a file. the table is NULL
|
||||
//unless the image is 8-bit
|
||||
FRESULT LoadData (FILE *file, int bpp, RGBQUAD *table);
|
||||
|
||||
protected:
|
||||
//release the memory of the bits
|
||||
void DestroyData ();
|
||||
|
||||
protected:
|
||||
unsigned char *m_pBits; //Bitmap's bits
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,108 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Camera.Cpp
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CCamera holds a view and a projection matrix.
|
||||
// It also has a frustum which can be used to
|
||||
// cull objects for rendering.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Camera.H"
|
||||
|
||||
extern int xres, yres;
|
||||
|
||||
CCamera::CCamera ()
|
||||
{
|
||||
m_ViewPort.m_Width = 1280;
|
||||
m_ViewPort.m_Height = 1024;
|
||||
m_ViewPort.m_X = 0;
|
||||
m_ViewPort.m_Y = 0;
|
||||
}
|
||||
|
||||
CCamera::~CCamera ()
|
||||
{
|
||||
}
|
||||
|
||||
void CCamera::SetProjection (float nearp, float farp, float fov)
|
||||
{
|
||||
float h, w, Q;
|
||||
|
||||
m_NearPlane = nearp;
|
||||
m_FarPlane = farp;
|
||||
m_FOV = fov;
|
||||
|
||||
float Aspect = (float)m_ViewPort.m_Width/(float)m_ViewPort.m_Height;
|
||||
|
||||
w = 1/tanf (fov*0.5f*Aspect);
|
||||
h = 1/tanf (fov*0.5f);
|
||||
Q = m_FarPlane / (m_FarPlane - m_NearPlane);
|
||||
|
||||
m_ProjMat.SetZero ();
|
||||
m_ProjMat._11 = w;
|
||||
m_ProjMat._22 = h;
|
||||
m_ProjMat._33 = Q;
|
||||
m_ProjMat._34 = -Q*m_NearPlane;
|
||||
m_ProjMat._43 = 1.0f;
|
||||
}
|
||||
|
||||
//Updates the frustum planes. Should be called
|
||||
//everytime the view or projection matrices are
|
||||
//altered.
|
||||
void CCamera::UpdateFrustum ()
|
||||
{
|
||||
CMatrix3D MatFinal;
|
||||
CMatrix3D MatView;
|
||||
|
||||
MatView = m_Orientation.GetTranspose ();
|
||||
|
||||
MatFinal = m_ProjMat * MatView;
|
||||
|
||||
//get the RIGHT plane
|
||||
m_ViewFrustum.SetNumPlanes (6);
|
||||
|
||||
m_ViewFrustum.m_aPlanes[0].m_Norm.X = MatFinal._41-MatFinal._11;
|
||||
m_ViewFrustum.m_aPlanes[0].m_Norm.Y = MatFinal._42-MatFinal._12;
|
||||
m_ViewFrustum.m_aPlanes[0].m_Norm.Z = MatFinal._43-MatFinal._13;
|
||||
m_ViewFrustum.m_aPlanes[0].m_Dist = MatFinal._44-MatFinal._14;
|
||||
|
||||
//get the LEFT plane
|
||||
m_ViewFrustum.m_aPlanes[1].m_Norm.X = MatFinal._41+MatFinal._11;
|
||||
m_ViewFrustum.m_aPlanes[1].m_Norm.Y = MatFinal._42+MatFinal._12;
|
||||
m_ViewFrustum.m_aPlanes[1].m_Norm.Z = MatFinal._43+MatFinal._13;
|
||||
m_ViewFrustum.m_aPlanes[1].m_Dist = MatFinal._44+MatFinal._14;
|
||||
|
||||
//get the BOTTOM plane
|
||||
m_ViewFrustum.m_aPlanes[2].m_Norm.X = MatFinal._41+MatFinal._21;
|
||||
m_ViewFrustum.m_aPlanes[2].m_Norm.Y = MatFinal._42+MatFinal._22;
|
||||
m_ViewFrustum.m_aPlanes[2].m_Norm.Z = MatFinal._43+MatFinal._23;
|
||||
m_ViewFrustum.m_aPlanes[2].m_Dist = MatFinal._44+MatFinal._24;
|
||||
|
||||
//get the TOP plane
|
||||
m_ViewFrustum.m_aPlanes[3].m_Norm.X = MatFinal._41-MatFinal._21;
|
||||
m_ViewFrustum.m_aPlanes[3].m_Norm.Y = MatFinal._42-MatFinal._22;
|
||||
m_ViewFrustum.m_aPlanes[3].m_Norm.Z = MatFinal._43-MatFinal._23;
|
||||
m_ViewFrustum.m_aPlanes[3].m_Dist = MatFinal._44-MatFinal._24;
|
||||
|
||||
//get the FAR plane
|
||||
m_ViewFrustum.m_aPlanes[4].m_Norm.X = MatFinal._41-MatFinal._31;
|
||||
m_ViewFrustum.m_aPlanes[4].m_Norm.Y = MatFinal._42-MatFinal._32;
|
||||
m_ViewFrustum.m_aPlanes[4].m_Norm.Z = MatFinal._43-MatFinal._33;
|
||||
m_ViewFrustum.m_aPlanes[4].m_Dist = MatFinal._44-MatFinal._34;
|
||||
|
||||
//get the NEAR plane
|
||||
m_ViewFrustum.m_aPlanes[5].m_Norm.X = MatFinal._41+MatFinal._31;
|
||||
m_ViewFrustum.m_aPlanes[5].m_Norm.Y = MatFinal._42+MatFinal._32;
|
||||
m_ViewFrustum.m_aPlanes[5].m_Norm.Z = MatFinal._43+MatFinal._33;
|
||||
m_ViewFrustum.m_aPlanes[5].m_Dist = MatFinal._44+MatFinal._34;
|
||||
}
|
||||
|
||||
void CCamera::SetViewPort (SViewPort *viewport)
|
||||
{
|
||||
m_ViewPort.m_X = viewport->m_X;
|
||||
m_ViewPort.m_Y = viewport->m_Y;
|
||||
m_ViewPort.m_Width = viewport->m_Width;
|
||||
m_ViewPort.m_Height = viewport->m_Height;
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Camera.H
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CCamera holds a view and a projection matrix.
|
||||
// It also has a frustum which can be used to
|
||||
// cull objects for rendering.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include "Frustum.H"
|
||||
#include "Matrix3D.H"
|
||||
|
||||
//view port
|
||||
struct SViewPort
|
||||
{
|
||||
unsigned int m_X;
|
||||
unsigned int m_Y;
|
||||
unsigned int m_Width;
|
||||
unsigned int m_Height;
|
||||
};
|
||||
|
||||
|
||||
class CCamera
|
||||
{
|
||||
public:
|
||||
CCamera ();
|
||||
~CCamera ();
|
||||
|
||||
//Methods for projection
|
||||
void SetProjection (CMatrix3D *proj) { m_ProjMat = *proj; }
|
||||
void SetProjection (float nearp, float farp, float fov);
|
||||
CMatrix3D GetProjection () { return m_ProjMat; }
|
||||
|
||||
//Updates the frustum planes. Should be called
|
||||
//everytime the view or projection matrices are
|
||||
//altered.
|
||||
void UpdateFrustum ();
|
||||
CFrustum GetFustum () { return m_ViewFrustum; }
|
||||
|
||||
void SetViewPort (SViewPort *viewport);
|
||||
SViewPort GetViewPort () { return m_ViewPort; }
|
||||
|
||||
//getters
|
||||
float GetNearPlane () { return m_NearPlane; }
|
||||
float GetFarPlane () { return m_FarPlane; }
|
||||
float GetFOV () { return m_FOV; }
|
||||
|
||||
public:
|
||||
//This is the orientation matrix. The inverse of this
|
||||
//is the view matrix
|
||||
CMatrix3D m_Orientation;
|
||||
|
||||
private:
|
||||
//keep the projection matrix private
|
||||
//so we can't fiddle with it.
|
||||
CMatrix3D m_ProjMat;
|
||||
|
||||
float m_NearPlane;
|
||||
float m_FarPlane;
|
||||
float m_FOV;
|
||||
SViewPort m_ViewPort;
|
||||
|
||||
CFrustum m_ViewFrustum;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,166 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: DynamicArray.H
|
||||
// Last Update: 2/3/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This is a template class which provides an
|
||||
// an interface for a dynamic array of any
|
||||
// type. ie new objects of the same type maybe
|
||||
// added, or can be removed. For speed, this
|
||||
// class does not support sorting.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef DYNAMICARRAY_H
|
||||
#define DYNAMICARRAY_H
|
||||
|
||||
#include "Memory.H"
|
||||
#include "Types.H"
|
||||
|
||||
template<class Type>
|
||||
class CDynamicArray
|
||||
{
|
||||
public:
|
||||
CDynamicArray ();
|
||||
~CDynamicArray ();
|
||||
|
||||
//Add new object(s) to the array, and return the pointer
|
||||
//to the first one.
|
||||
Type *New (unsigned int count);
|
||||
//Delete an object from the array
|
||||
void Delete (Type *object);
|
||||
|
||||
//Clear the entire array
|
||||
void Clear ();
|
||||
|
||||
//For getting an object from the array
|
||||
inline Type &operator[] (int index);
|
||||
|
||||
//Get a pointer from the array
|
||||
Type *GetPointer (int index);
|
||||
|
||||
//Get the size of the array
|
||||
int GetCount () { return m_Count; }
|
||||
|
||||
protected:
|
||||
unsigned int m_Count; //Number of objects in the array
|
||||
|
||||
Type **m_ppObjects; //Double pointer to the object array
|
||||
};
|
||||
|
||||
|
||||
//--------------------- Definitions
|
||||
|
||||
template<class Type>
|
||||
CDynamicArray<Type>::CDynamicArray ()
|
||||
{
|
||||
m_ppObjects = NULL;
|
||||
m_Count = 0;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
CDynamicArray<Type>::~CDynamicArray ()
|
||||
{
|
||||
Clear ();
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
Type *CDynamicArray<Type>::New (unsigned int count)
|
||||
{
|
||||
Type *pBlock;
|
||||
int OldCount = m_Count;
|
||||
|
||||
//No array already exists
|
||||
if (m_Count == 0)
|
||||
{
|
||||
m_Count = count;
|
||||
m_ppObjects = (Type**)Alloc (count*sizeof(Type*));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Count += count;
|
||||
m_ppObjects = (Type**)Realloc ((void*)&m_ppObjects, count*sizeof(Type*));
|
||||
}
|
||||
|
||||
//create the required block
|
||||
pBlock = new Type[count];
|
||||
|
||||
//assign the pointers
|
||||
for (unsigned int i=0; i<m_Count; i++)
|
||||
m_ppObjects[i] = pBlock + i;
|
||||
|
||||
//return the first pointer
|
||||
return pBlock;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
void CDynamicArray<Type>::Delete (Type *object)
|
||||
{
|
||||
if (m_Count == 0 || object == NULL)
|
||||
return;
|
||||
|
||||
//find the object we want
|
||||
for (int i=0; i<m_Count; i++)
|
||||
{
|
||||
if (m_ppObjects[i] == object)
|
||||
{
|
||||
//swap the last element with this
|
||||
m_ppObjects[i] = m_ppObjects[m_Count-1];
|
||||
//destroy it
|
||||
delete object;
|
||||
object = NULL;
|
||||
|
||||
m_Count--;
|
||||
|
||||
if (m_Count == 0)
|
||||
{
|
||||
FreeMem ((void*)&m_ppObjects);
|
||||
m_ppObjects = NULL;
|
||||
}
|
||||
else
|
||||
m_ppObjects = (Type**)Realloc ((void*)&m_ppObjects, m_Count);
|
||||
|
||||
//we won't have another match
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
void CDynamicArray<Type>::Clear ()
|
||||
{
|
||||
if (m_Count == 0)
|
||||
return;
|
||||
|
||||
//delete each pointer distinctively
|
||||
for (unsigned int i=0; i<m_Count; i++)
|
||||
{
|
||||
delete m_ppObjects[i];
|
||||
m_ppObjects[i] = NULL;
|
||||
}
|
||||
|
||||
//free the array
|
||||
FreeMem ((void*)&m_ppObjects);
|
||||
m_ppObjects = NULL;
|
||||
|
||||
m_Count = 0;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
Type *CDynamicArray<Type>::GetPointer (int index)
|
||||
{
|
||||
if (index < 0 || index >= (int)m_Count)
|
||||
return NULL;
|
||||
|
||||
return m_ppObjects[index];
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
Type &CDynamicArray<Type>::operator [] (int index)
|
||||
{
|
||||
|
||||
return *GetPointer(index);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,110 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: DynamicContainer.H
|
||||
// Last Update: 7/3/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This template class is similar to DynamicArray
|
||||
// template, except here we do not create and
|
||||
// destroy the pointer, but simply hold the
|
||||
// user created pointers of a type. ie User is
|
||||
// responsible for creating and destroying the
|
||||
// pointers;
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef DYNAMICCONTAINER_H
|
||||
#define DYNAMICCONTAINER_H
|
||||
|
||||
#include "Memory.H"
|
||||
|
||||
template<class Type>
|
||||
class CDynamicContainer
|
||||
{
|
||||
public:
|
||||
CDynamicContainer ();
|
||||
~CDynamicContainer ();
|
||||
|
||||
//Add/Remove a pointer from the container
|
||||
void Add (Type *object);
|
||||
void Remove (Type *object);
|
||||
|
||||
//Remove all pointers from the array
|
||||
void RemoveAll ();
|
||||
|
||||
//Get a pointer from the array
|
||||
Type *operator [] (unsigned int index);
|
||||
|
||||
int GetCount () { return m_Count; }
|
||||
|
||||
protected:
|
||||
Type **m_ppObjects; //Pointer to the array of objects
|
||||
|
||||
unsigned int m_Count; //Number of objects in the array
|
||||
};
|
||||
|
||||
|
||||
//--------------------- Definitions
|
||||
|
||||
template<class Type>
|
||||
CDynamicContainer<Type>::CDynamicContainer ()
|
||||
{
|
||||
m_ppObjects = NULL;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
CDynamicContainer<Type>::~CDynamicContainer ()
|
||||
{
|
||||
RemoveAll ();
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
void CDynamicContainer<Type>::Add (Type *object)
|
||||
{
|
||||
m_Count++;
|
||||
|
||||
//No array already exists
|
||||
if (m_Count-1 == 0)
|
||||
m_ppObjects = (Type**)Alloc (m_Count*sizeof(Type*));
|
||||
else
|
||||
m_ppObjects = (Type**)Realloc ((void**)&m_ppObjects, m_Count*sizeof(Type*));
|
||||
|
||||
m_ppObjects[m_Count-1] = object;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
void CDynamicContainer<Type>::Remove (Type *object)
|
||||
{
|
||||
for (int i=0; i<m_Count; i++)
|
||||
{
|
||||
//look for a match
|
||||
if (m_ppObjects[i] == object)
|
||||
{
|
||||
m_Count--;
|
||||
//switch the last pointer with this one
|
||||
m_ppObjects[i] = m_ppObjects[m_Count];
|
||||
m_ppObjects[m_Count] = NULL;
|
||||
|
||||
//shrink the array
|
||||
m_ppObjects = (Type**)Realloc ((void**)&m_ppObjects, m_Count*sizeof(Type*));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
void CDynamicContainer<Type>::RemoveAll ()
|
||||
{
|
||||
m_Count = 0;
|
||||
FreeMem (m_ppObjects);
|
||||
m_ppObjects = NULL;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
Type *CDynamicContainer<Type>::operator [] (unsigned int index)
|
||||
{
|
||||
return m_ppObjects[index];
|
||||
}
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: FileResource.Cpp
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A File resource is directly loaded from a data
|
||||
// file, like a BMP or WAV file.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "FileResource.H"
|
||||
|
||||
void CFileResource::SetupParams (char *path, RESOURCETYPE type)
|
||||
{
|
||||
m_Type = type;
|
||||
char Extention[10];
|
||||
|
||||
strcpy (m_Path, path);
|
||||
|
||||
_splitpath (m_Path, NULL, NULL, m_Name, Extention);
|
||||
strcat (m_Name, Extention);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: FileResource.H
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A File resource is directly loaded from a data
|
||||
// file, like a BMP or WAV file.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef FILERESOURCE_H
|
||||
#define FILERESOURCE_H
|
||||
|
||||
#include "Types.H"
|
||||
#include "Resource.H"
|
||||
|
||||
|
||||
#define MAX_PATH_LENGTH (100)
|
||||
|
||||
|
||||
class CFileResource : public CResource
|
||||
{
|
||||
public:
|
||||
char *GetPath() { return m_Path; }
|
||||
|
||||
protected:
|
||||
void SetupParams (char *path, RESOURCETYPE type);
|
||||
char m_Path[MAX_PATH_LENGTH];
|
||||
};
|
||||
|
||||
#endif
|
@ -1,144 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Frustum.Cpp
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CFrustum is a collection of planes which define
|
||||
// a viewing space. Usually associated with the
|
||||
// camera, there are 6 planes which define the
|
||||
// view pyramid. But we allow more planes per
|
||||
// frustum which maybe used for portal rendering,
|
||||
// where a portal may have 3 or more edges.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Frustum.H"
|
||||
|
||||
CFrustum::CFrustum ()
|
||||
{
|
||||
m_NumPlanes = 0;
|
||||
}
|
||||
|
||||
CFrustum::~CFrustum ()
|
||||
{
|
||||
}
|
||||
|
||||
void CFrustum::SetNumPlanes (int num)
|
||||
{
|
||||
m_NumPlanes = num;
|
||||
|
||||
//clip it
|
||||
if (m_NumPlanes >= MAX_NUM_FRUSTUM_PLANES)
|
||||
m_NumPlanes = MAX_NUM_FRUSTUM_PLANES-1;
|
||||
else if (m_NumPlanes < 0)
|
||||
m_NumPlanes = 0;
|
||||
}
|
||||
|
||||
bool CFrustum::IsPointVisible (CVector3D &point)
|
||||
{
|
||||
PLANESIDE Side;
|
||||
|
||||
for (int i=0; i<m_NumPlanes; i++)
|
||||
{
|
||||
Side = m_aPlanes[i].ClassifyPoint (point);
|
||||
|
||||
if (Side == PS_BACK)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFrustum::IsSphereVisible (CVector3D ¢er, float radius)
|
||||
{
|
||||
for (int i=0; i<m_NumPlanes; i++)
|
||||
{
|
||||
float Dist = m_aPlanes[i].DistanceToPlane (center);
|
||||
|
||||
//is it behind the plane
|
||||
if (Dist < 0)
|
||||
{
|
||||
//if non of it falls in front its outside the
|
||||
//frustum
|
||||
if (-Dist > radius)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CFrustum::IsBoxVisible (CVector3D &position, SBoundingBox &bounds)
|
||||
{
|
||||
//basically for every plane we calculate the furthust point
|
||||
//in the box to that plane. If that point is beyond the plane
|
||||
//then the box is not visible
|
||||
CVector3D FarPoint;
|
||||
PLANESIDE Side;
|
||||
CVector3D Min = position+bounds.m_BoxMin;
|
||||
CVector3D Max = position+bounds.m_BoxMax;
|
||||
|
||||
for (int i=0; i<m_NumPlanes; i++)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.X > 0.0f)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Y > 0.0f)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Max.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Max.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Min.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Min.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Y > 0.0f)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Max.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Max.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Min.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Min.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Side = m_aPlanes[i].ClassifyPoint (FarPoint);
|
||||
|
||||
if (Side == PS_BACK)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Frustum.H
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CFrustum is a collection of planes which define
|
||||
// a viewing space. Usually associated with the
|
||||
// camera, there are 6 planes which define the
|
||||
// view pyramid. But we allow more planes per
|
||||
// frustum which maybe used for portal rendering,
|
||||
// where a portal may have 3 or more edges.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef FRUSTUM_H
|
||||
#define FRUSTUM_H
|
||||
|
||||
#include "Plane.H"
|
||||
|
||||
//10 planes should be enough
|
||||
#define MAX_NUM_FRUSTUM_PLANES (10)
|
||||
|
||||
|
||||
struct SBoundingBox
|
||||
{
|
||||
CVector3D m_BoxMin;
|
||||
CVector3D m_BoxMax;
|
||||
};
|
||||
|
||||
class CFrustum
|
||||
{
|
||||
public:
|
||||
CFrustum ();
|
||||
~CFrustum ();
|
||||
|
||||
//Set the number of planes to use for
|
||||
//calculations. This is clipped to
|
||||
//[0,MAX_NUM_FRUSTUM_PLANES]
|
||||
void SetNumPlanes (int num);
|
||||
|
||||
//The following methods return true if the shape is
|
||||
//partially or completely in front of the frustum planes
|
||||
bool IsPointVisible (CVector3D &point);
|
||||
bool IsSphereVisible (CVector3D ¢er, float radius);
|
||||
bool IsBoxVisible (CVector3D &position, SBoundingBox &bounds);
|
||||
|
||||
public:
|
||||
//make the planes public for ease of use
|
||||
CPlane m_aPlanes[MAX_NUM_FRUSTUM_PLANES];
|
||||
|
||||
private:
|
||||
int m_NumPlanes;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,12 +0,0 @@
|
||||
#include "GameResource.H"
|
||||
|
||||
FRESULT CGameResource::LoadResource (char *filename, RESOURCETYPE type)
|
||||
{
|
||||
m_Type = type;
|
||||
|
||||
strcpy (m_Path, filename);
|
||||
|
||||
_splitpath (m_Path, NULL, NULL, m_Name, NULL);
|
||||
|
||||
return R_OK;
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: GameResource.H
|
||||
// Last Update: 7/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A game resource provides an interface for a
|
||||
// game resource type, ie ModelDefs, Bitmap and
|
||||
// Textures, Sounds and Music. These can be
|
||||
// accessed through a ResourceLibrary
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef GAMERESOURCE_H
|
||||
#define GAMERESOURCE_H
|
||||
|
||||
#include "Types.H"
|
||||
|
||||
enum RESOURCETYPE
|
||||
{
|
||||
RST_BITMAP,
|
||||
RST_TEXTURE,
|
||||
RST_MODELDEF,
|
||||
RST_SOUND,
|
||||
};
|
||||
|
||||
class CGameResource
|
||||
{
|
||||
public:
|
||||
virtual FRESULT LoadResource (char *filename, RESOURCETYPE type);
|
||||
|
||||
char *GetName() { return m_Name; }
|
||||
char *GetPath() { return m_Path; }
|
||||
int GetType() { return m_Type; }
|
||||
|
||||
protected:
|
||||
char m_Name[MAX_NAME_LENGTH];
|
||||
char m_Path[MAX_PATH_LENGTH];
|
||||
int m_Type;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: MathUtil.Cpp
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This file contains some maths related
|
||||
// utility macros and fucntions.
|
||||
//
|
||||
//***********************************************************
|
||||
unsigned int F2DW (float f)
|
||||
{
|
||||
return *((unsigned int*)&f);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: MathUtil.H
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This file contains some maths related
|
||||
// utility macros and fucntions.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef MATHUTIL_H
|
||||
#define MATHUTIL_H
|
||||
|
||||
#define PI 3.14159265358979323846f
|
||||
|
||||
#define DEGTORAD(a) (((a) * PI) / 180.0f)
|
||||
#define SQR(x) ((x) * (x))
|
||||
#define MAX(a,b) ((a < b) ? (b) : (a))
|
||||
#define MIN(a,b) ((a < b) ? (a) : (b))
|
||||
#define MAX3(a,b,c) ( MAX (MAX(a,b), c) )
|
||||
#define ABS(a) ((a > 0) ? (a) : (-a))
|
||||
|
||||
//extern unsigned int F2DW (float f);
|
||||
|
||||
#endif
|
@ -1,384 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Matrix3D.Cpp
|
||||
// Last Update: 31/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Matrix class used for holding and
|
||||
// manipulating transformation info.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Matrix3D.H"
|
||||
|
||||
CMatrix3D::CMatrix3D ()
|
||||
{
|
||||
SetIdentity ();
|
||||
}
|
||||
|
||||
//Matrix multiplication
|
||||
CMatrix3D CMatrix3D::operator * (CMatrix3D &matrix)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
|
||||
Temp._11 = _11*matrix._11 +
|
||||
_12*matrix._21 +
|
||||
_13*matrix._31 +
|
||||
_14*matrix._41;
|
||||
|
||||
Temp._12 = _11*matrix._12 +
|
||||
_12*matrix._22 +
|
||||
_13*matrix._32 +
|
||||
_14*matrix._42;
|
||||
|
||||
Temp._13 = _11*matrix._13 +
|
||||
_12*matrix._23 +
|
||||
_13*matrix._33 +
|
||||
_14*matrix._43;
|
||||
|
||||
Temp._14 = _11*matrix._14 +
|
||||
_12*matrix._24 +
|
||||
_13*matrix._34 +
|
||||
_14*matrix._44;
|
||||
|
||||
Temp._21 = _21*matrix._11 +
|
||||
_22*matrix._21 +
|
||||
_23*matrix._31 +
|
||||
_24*matrix._41;
|
||||
|
||||
Temp._22 = _21*matrix._12 +
|
||||
_22*matrix._22 +
|
||||
_23*matrix._32 +
|
||||
_24*matrix._42;
|
||||
|
||||
Temp._23 = _21*matrix._13 +
|
||||
_22*matrix._23 +
|
||||
_23*matrix._33 +
|
||||
_24*matrix._43;
|
||||
|
||||
Temp._24 = _21*matrix._14 +
|
||||
_22*matrix._24 +
|
||||
_23*matrix._34 +
|
||||
_24*matrix._44;
|
||||
|
||||
Temp._31 = _31*matrix._11 +
|
||||
_32*matrix._21 +
|
||||
_33*matrix._31 +
|
||||
_34*matrix._41;
|
||||
|
||||
Temp._32 = _31*matrix._12 +
|
||||
_32*matrix._22 +
|
||||
_33*matrix._32 +
|
||||
_34*matrix._42;
|
||||
|
||||
Temp._33 = _31*matrix._13 +
|
||||
_32*matrix._23 +
|
||||
_33*matrix._33 +
|
||||
_34*matrix._43;
|
||||
|
||||
Temp._34 = _31*matrix._14 +
|
||||
_32*matrix._24 +
|
||||
_33*matrix._34 +
|
||||
_34*matrix._44;
|
||||
|
||||
Temp._41 = _41*matrix._11 +
|
||||
_42*matrix._21 +
|
||||
_43*matrix._31 +
|
||||
_44*matrix._41;
|
||||
|
||||
Temp._42 = _41*matrix._12 +
|
||||
_42*matrix._22 +
|
||||
_43*matrix._32 +
|
||||
_44*matrix._42;
|
||||
|
||||
Temp._43 = _41*matrix._13 +
|
||||
_42*matrix._23 +
|
||||
_43*matrix._33 +
|
||||
_44*matrix._43;
|
||||
|
||||
Temp._44 = _41*matrix._14 +
|
||||
_42*matrix._24 +
|
||||
_43*matrix._34 +
|
||||
_44*matrix._44;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Matrix multiplication/assignment
|
||||
CMatrix3D &CMatrix3D::operator *= (CMatrix3D &matrix)
|
||||
{
|
||||
CMatrix3D &Temp = (*this) * matrix;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Sets the identity matrix
|
||||
void CMatrix3D::SetIdentity ()
|
||||
{
|
||||
_11=1.0f; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=1.0f; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=1.0f; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//Sets the zero matrix
|
||||
void CMatrix3D::SetZero ()
|
||||
{
|
||||
_11=0.0f; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=0.0f; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=0.0f; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=0.0f;
|
||||
}
|
||||
|
||||
//The following clear the matrix and set the
|
||||
//rotation of each of the 3 axes
|
||||
|
||||
void CMatrix3D::SetXRotation (float angle)
|
||||
{
|
||||
float Cos = cosf (angle);
|
||||
float Sin = sinf (angle);
|
||||
|
||||
_11=1.0f; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=Cos; _23=-Sin; _24=0.0f;
|
||||
_31=0.0f; _32=Sin; _33=Cos; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
void CMatrix3D::SetYRotation (float angle)
|
||||
{
|
||||
float Cos = cosf (angle);
|
||||
float Sin = sinf (angle);
|
||||
|
||||
_11=Cos; _12=0.0f; _13=Sin; _14=0.0f;
|
||||
_21=0.0f; _22=1.0f; _23=0.0f; _24=0.0f;
|
||||
_31=-Sin; _32=0.0f; _33=Cos; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
void CMatrix3D::SetZRotation (float angle)
|
||||
{
|
||||
float Cos = cosf (angle);
|
||||
float Sin = sinf (angle);
|
||||
|
||||
_11=Cos; _12=-Sin; _13=0.0f; _14=0.0f;
|
||||
_21=Sin; _22=Cos; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=1.0f; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//The following apply a rotation to the matrix
|
||||
//about each of the axes;
|
||||
|
||||
void CMatrix3D::RotateX (float angle)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetXRotation (angle);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
void CMatrix3D::RotateY (float angle)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetYRotation (angle);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
void CMatrix3D::RotateZ (float angle)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetZRotation (angle);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
//Sets the translation of the matrix
|
||||
void CMatrix3D::SetTranslation (float x, float y, float z)
|
||||
{
|
||||
_11=1.0f; _12=0.0f; _13=0.0f; _14=x;
|
||||
_21=0.0f; _22=1.0f; _23=0.0f; _24=y;
|
||||
_31=0.0f; _32=0.0f; _33=1.0f; _34=z;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
void CMatrix3D::SetTranslation (CVector3D &vector)
|
||||
{
|
||||
SetTranslation (vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
//Applies a translation to the matrix
|
||||
void CMatrix3D::Translate (float x, float y, float z)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetTranslation (x, y, z);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
void CMatrix3D::Translate (CVector3D &vector)
|
||||
{
|
||||
Translate (vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
CVector3D CMatrix3D::GetTranslation ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _14;
|
||||
Temp.Y = _24;
|
||||
Temp.Z = _34;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Clears and sets the scaling of the matrix
|
||||
void CMatrix3D::SetScaling (float x_scale, float y_scale, float z_scale)
|
||||
{
|
||||
_11=x_scale; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=y_scale; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=z_scale; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//Scales the matrix
|
||||
void CMatrix3D::Scale (float x_scale, float y_scale, float z_scale)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetScaling (x_scale, y_scale, z_scale);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
//Returns the transpose of the matrix. For orthonormal
|
||||
//matrices, this is the same is the inverse matrix
|
||||
CMatrix3D CMatrix3D::GetTranspose ()
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
|
||||
Temp._11 = _11;
|
||||
Temp._21 = _12;
|
||||
Temp._31 = _13;
|
||||
Temp._41 = 0.0f;
|
||||
|
||||
Temp._12 = _21;
|
||||
Temp._22 = _22;
|
||||
Temp._32 = _23;
|
||||
Temp._42 = 0.0f;
|
||||
|
||||
Temp._13 = _31;
|
||||
Temp._23 = _32;
|
||||
Temp._33 = _33;
|
||||
Temp._43 = 0.0f;
|
||||
|
||||
Temp._14 = 0.0f;
|
||||
Temp._24 = 0.0f;
|
||||
Temp._34 = 0.0f;
|
||||
Temp._44 = 1.0f;
|
||||
|
||||
CMatrix3D Trans;
|
||||
Trans.SetTranslation (-_14, -_24, -_34);
|
||||
|
||||
Temp = Temp * Trans;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Get a vector which points to the left of the matrix
|
||||
CVector3D CMatrix3D::GetLeft ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = -_11;
|
||||
Temp.Y = -_21;
|
||||
Temp.Z = -_31;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Get a vector which points up from the matrix
|
||||
CVector3D CMatrix3D::GetUp ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _12;
|
||||
Temp.Y = _22;
|
||||
Temp.Z = _32;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Get a vector which points to front of the matrix
|
||||
CVector3D CMatrix3D::GetIn ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _13;
|
||||
Temp.Y = _23;
|
||||
Temp.Z = _33;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Set the matrix from two vectors (Up and In)
|
||||
void CMatrix3D::SetFromUpIn (CVector3D &up, CVector3D &in, float scale)
|
||||
{
|
||||
CVector3D u = up;
|
||||
CVector3D i = in;
|
||||
|
||||
CVector3D r;
|
||||
|
||||
r = up.Cross (in);
|
||||
|
||||
u.Normalize (); u *= scale;
|
||||
i.Normalize (); i *= scale;
|
||||
r.Normalize (); r *= scale;
|
||||
|
||||
_11=r.X; _12=u.X; _13=i.X; _14=0.0f;
|
||||
_21=r.Y; _22=u.Y; _23=i.Y; _24=0.0f;
|
||||
_31=r.Z; _32=u.Z; _33=i.Z; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//Transform a vector by this matrix
|
||||
CVector3D CMatrix3D::Transform (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _11*vector.X +
|
||||
_12*vector.Y +
|
||||
_13*vector.Z +
|
||||
_14;
|
||||
|
||||
Temp.Y = _21*vector.X +
|
||||
_22*vector.Y +
|
||||
_23*vector.Z +
|
||||
_24;
|
||||
|
||||
Temp.Z = _31*vector.X +
|
||||
_32*vector.Y +
|
||||
_33*vector.Z +
|
||||
_34;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Only rotate (not translate) a vector by this matrix
|
||||
CVector3D CMatrix3D::Rotate (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _11*vector.X +
|
||||
_12*vector.Y +
|
||||
_13*vector.Z;
|
||||
|
||||
Temp.Y = _21*vector.X +
|
||||
_22*vector.Y +
|
||||
_23*vector.Z;
|
||||
|
||||
Temp.Z = _31*vector.X +
|
||||
_32*vector.Y +
|
||||
_33*vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Matrix3D.H
|
||||
// Last Update: 31/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Matrix class used for holding and
|
||||
// manipulating transformation info.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef MATRIX3D_H
|
||||
#define MATRIX3D_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "Vector3D.H"
|
||||
|
||||
class CMatrix3D
|
||||
{
|
||||
public:
|
||||
float _11, _12, _13, _14;
|
||||
float _21, _22, _23, _24;
|
||||
float _31, _32, _33, _34;
|
||||
float _41, _42, _43, _44;
|
||||
|
||||
public:
|
||||
CMatrix3D ();
|
||||
|
||||
//Matrix multiplication
|
||||
CMatrix3D operator * (CMatrix3D &matrix);
|
||||
//Matrix multiplication/assignment
|
||||
CMatrix3D &operator *= (CMatrix3D &matrix);
|
||||
|
||||
//Sets the identity matrix
|
||||
void SetIdentity ();
|
||||
//Sets the zero matrix
|
||||
void SetZero ();
|
||||
|
||||
//The following clear the matrix and set the
|
||||
//rotation of each of the 3 axes
|
||||
void SetXRotation (float angle);
|
||||
void SetYRotation (float angle);
|
||||
void SetZRotation (float angle);
|
||||
|
||||
//The following apply a rotation to the matrix
|
||||
//about each of the axes;
|
||||
void RotateX (float angle);
|
||||
void RotateY (float angle);
|
||||
void RotateZ (float angle);
|
||||
|
||||
//Sets the translation of the matrix
|
||||
void SetTranslation (float x, float y, float z);
|
||||
void SetTranslation (CVector3D &vector);
|
||||
|
||||
//Applies a translation to the matrix
|
||||
void Translate (float x, float y, float z);
|
||||
void Translate (CVector3D &vector);
|
||||
|
||||
CVector3D GetTranslation ();
|
||||
|
||||
//Clears and sets the scaling of the matrix
|
||||
void SetScaling (float x_scale, float y_scale, float z_scale);
|
||||
//Scales the matrix
|
||||
void Scale (float x_scale, float y_scale, float z_scale);
|
||||
|
||||
//Returns the transpose of the matrix. For orthonormal
|
||||
//matrices, this is the same is the inverse matrix
|
||||
CMatrix3D GetTranspose ();
|
||||
|
||||
//Get a vector which points to the left of the matrix
|
||||
CVector3D GetLeft ();
|
||||
//Get a vector which points up from the matrix
|
||||
CVector3D GetUp ();
|
||||
//Get a vector which points to front of the matrix
|
||||
CVector3D GetIn ();
|
||||
|
||||
//Set the matrix from two vectors (Up and In)
|
||||
void SetFromUpIn (CVector3D &up, CVector3D &in, float scale);
|
||||
|
||||
public: //Vector manipulation methods
|
||||
//Transform a vector by this matrix
|
||||
CVector3D Transform (CVector3D &vector);
|
||||
//Only rotate (not translate) a vector by this matrix
|
||||
CVector3D Rotate (CVector3D &vector);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,41 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Memory.Cpp
|
||||
// Last Update: 2/3/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Simple Functions for memory alloc/reallocation
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Memory.H"
|
||||
|
||||
//Allocates memory
|
||||
void *Alloc (unsigned int size)
|
||||
{
|
||||
//no memory allocation required
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
return malloc (size);
|
||||
}
|
||||
|
||||
//Reallocates a chunk of memory
|
||||
void *Realloc (void *ptr, unsigned int size)
|
||||
{
|
||||
//allocate new memory
|
||||
if (ptr == NULL)
|
||||
return Alloc (size);
|
||||
|
||||
//shrink to zero, ie free all of the memory
|
||||
if (size == 0)
|
||||
free (ptr);
|
||||
|
||||
return realloc (ptr, size);
|
||||
}
|
||||
|
||||
//Frees the memory for allocation
|
||||
void FreeMem (void *ptr)
|
||||
{
|
||||
free (ptr);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Memory.H
|
||||
// Last Update: 2/3/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Simple Functions for memory alloc/reallocation
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
//Allocates memory
|
||||
extern void *Alloc (unsigned int size);
|
||||
//Reallocates a chunk of memory
|
||||
extern void *Realloc (void *ptr, unsigned int size);
|
||||
//Frees the memory for allocation
|
||||
extern void FreeMem (void *ptr);
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
#include "MiniPatch.H"
|
||||
|
||||
CMiniPatch::CMiniPatch()
|
||||
{
|
||||
Tex1 = Tex2 = 0;
|
||||
m_AlphaMap = 0;
|
||||
m_pRightNeighbor = NULL;
|
||||
m_pParrent = NULL;
|
||||
m_Rotation = 0;
|
||||
m_RenderStage = 0;
|
||||
m_LastRenderedFrame = 0;
|
||||
}
|
||||
|
||||
CMiniPatch::~CMiniPatch()
|
||||
{
|
||||
}
|
||||
|
||||
void CMiniPatch::Initialize (STerrainVertex *first_vertex)
|
||||
{
|
||||
m_pVertices = first_vertex;
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#ifndef MINIPATCH_H
|
||||
#define MINIPATCH_H
|
||||
|
||||
#include "Vector3D.H"
|
||||
#include "res.h"
|
||||
|
||||
struct STerrainVertex
|
||||
{
|
||||
CVector3D m_Position;
|
||||
float m_Color[2][3];
|
||||
};
|
||||
|
||||
|
||||
class CMiniPatch
|
||||
{
|
||||
public:
|
||||
CMiniPatch();
|
||||
~CMiniPatch();
|
||||
|
||||
void Initialize (STerrainVertex *first_vertex);
|
||||
|
||||
Handle Tex1, Tex2;
|
||||
Handle m_AlphaMap;
|
||||
CMiniPatch *m_pRightNeighbor;
|
||||
CPatch *m_pParrent;
|
||||
unsigned char m_RenderStage;
|
||||
unsigned int m_LastRenderedFrame;
|
||||
|
||||
unsigned char m_Rotation;
|
||||
|
||||
STerrainVertex *m_pVertices;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,82 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: OGLTexture.Cpp
|
||||
// Last Update: 14/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This class represents a OpenGL Texture.
|
||||
// When a CTexture gets registered with the
|
||||
// renderer, one of these is created and added
|
||||
// to the renderer's list of registered textures
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "OGLTexture.H"
|
||||
|
||||
COGLTexture::COGLTexture ()
|
||||
{
|
||||
m_TextureID = 0;
|
||||
m_pTextureBK = NULL;
|
||||
}
|
||||
|
||||
COGLTexture::~COGLTexture ()
|
||||
{
|
||||
glDeleteTextures (1, &m_TextureID);
|
||||
m_pTextureBK = NULL;
|
||||
}
|
||||
|
||||
FRESULT COGLTexture::CreateTexture (CTexture *texture)
|
||||
{
|
||||
// unsigned int *NewBits;
|
||||
|
||||
//create and set the texture name
|
||||
glGenTextures (1, &m_TextureID);
|
||||
glBindTexture (GL_TEXTURE_2D, m_TextureID);
|
||||
|
||||
if (!texture->GetMipMapFlag ())
|
||||
{
|
||||
// NewBits = new unsigned int [texture->GetWidth()*texture->GetHeight()];
|
||||
|
||||
//resize the image for the next mip level
|
||||
// if (gluScaleImage (GL_RGBA,
|
||||
// texture->GetWidth (),
|
||||
// texture->GetHeight (),
|
||||
// GL_UNSIGNED_INT,
|
||||
// texture->GetBits (),
|
||||
// texture->GetWidth (),
|
||||
// texture->GetHeight (),
|
||||
// GL_UNSIGNED_INT,
|
||||
// NewBits) != 0)
|
||||
// return R_FAIL;
|
||||
|
||||
//create the texture
|
||||
glTexImage2D (GL_TEXTURE_2D,
|
||||
0,
|
||||
4,
|
||||
texture->GetWidth (),
|
||||
texture->GetHeight (),
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
texture->GetBits());
|
||||
|
||||
// if (NewBits)
|
||||
// delete [] NewBits;
|
||||
}
|
||||
else
|
||||
{
|
||||
//build full mipmap table
|
||||
if (gluBuild2DMipmaps (GL_TEXTURE_2D,
|
||||
4,
|
||||
texture->GetWidth (),
|
||||
texture->GetHeight (),
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
texture->GetBits()) != 0)
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
m_pTextureBK = texture;
|
||||
|
||||
return R_OK;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: OGLTexture.H
|
||||
// Last Update: 14/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This class represents a OpenGL Texture.
|
||||
// When a CTexture gets registered with the
|
||||
// renderer, one of these is created and added
|
||||
// to the renderer's list of registered textures
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef OGLTEXTURE_H
|
||||
#define OGLTEXTURE_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <gl\gl.h>
|
||||
#include <gl\glu.h>
|
||||
|
||||
#include "Texture.H"
|
||||
|
||||
#define MAX_REG_TEXTURES (100)
|
||||
|
||||
class COGLTexture
|
||||
{
|
||||
public:
|
||||
COGLTexture ();
|
||||
~COGLTexture ();
|
||||
|
||||
GLuint m_TextureID;
|
||||
|
||||
//a back pointer to the CTexture which owns this
|
||||
//D3DTexture.
|
||||
CTexture *m_pTextureBK;
|
||||
|
||||
//create the D3DTexture from a normal CTexture
|
||||
FRESULT CreateTexture (CTexture *texture);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,62 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Patch.Cpp
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CPatch is a smaller portion of the terrain.
|
||||
// It handles the ROAM implementation and its
|
||||
// own rendering.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Patch.H"
|
||||
|
||||
|
||||
CPatch::CPatch ()
|
||||
{
|
||||
m_pVertices = NULL;
|
||||
}
|
||||
|
||||
CPatch::~CPatch ()
|
||||
{
|
||||
}
|
||||
|
||||
//Initialize the patch
|
||||
void CPatch::Initialize (STerrainVertex *first_vertex)
|
||||
{
|
||||
m_pVertices = first_vertex;
|
||||
|
||||
m_Bounds.m_BoxMin.X = m_pVertices[0].m_Position.X;
|
||||
m_Bounds.m_BoxMin.Z = m_pVertices[0].m_Position.Z;
|
||||
|
||||
m_Bounds.m_BoxMax.X = m_Bounds.m_BoxMin.X + PATCH_SIZE*CELL_SIZE;
|
||||
m_Bounds.m_BoxMax.Z = m_Bounds.m_BoxMin.Z + PATCH_SIZE*CELL_SIZE;
|
||||
|
||||
m_Bounds.m_BoxMin.Y = m_Bounds.m_BoxMin.Y = m_pVertices[0].m_Position.Y;
|
||||
|
||||
for (int j=0; j<PATCH_SIZE+1; j++)
|
||||
{
|
||||
for (int i=0; i<PATCH_SIZE+1; i++)
|
||||
{
|
||||
int pos = j*MAP_SIZE + i;
|
||||
|
||||
if (m_pVertices[pos].m_Position.Y < m_Bounds.m_BoxMin.Y)
|
||||
m_Bounds.m_BoxMin.Y = m_pVertices[pos].m_Position.Y;
|
||||
|
||||
if (m_pVertices[pos].m_Position.Y > m_Bounds.m_BoxMax.Y)
|
||||
m_Bounds.m_BoxMax.Y = m_pVertices[pos].m_Position.Y;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (int i=0; i<4; i++)
|
||||
{
|
||||
int pos = (j*4*MAP_SIZE) + (i*4);
|
||||
|
||||
m_MiniPatches[j][i].Initialize ( &m_pVertices[pos] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Patch.H
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CPatch is a smaller portion of the terrain.
|
||||
// It handles its own rendering
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef PATCH_H
|
||||
#define PATCH_H
|
||||
|
||||
#include "Matrix3D.H"
|
||||
#include "Camera.H"
|
||||
#include "TerrGlobals.H"
|
||||
#include "MiniPatch.H"
|
||||
|
||||
class CPatch
|
||||
{
|
||||
public:
|
||||
CPatch ();
|
||||
~CPatch ();
|
||||
|
||||
//initialize the patch
|
||||
void Initialize (STerrainVertex *first_vertex);
|
||||
|
||||
// protected:
|
||||
CMiniPatch m_MiniPatches[4][4];
|
||||
|
||||
SBoundingBox m_Bounds;
|
||||
unsigned int m_LastVisFrame;
|
||||
|
||||
STerrainVertex *m_pVertices;
|
||||
};
|
||||
|
||||
|
||||
typedef CPatch *LPPATCH;
|
||||
|
||||
#endif
|
@ -1,138 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Plane.Cpp
|
||||
// Last Update: 17/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Plane in R3 and several utility methods.
|
||||
// Note that the format used for the plane
|
||||
// equation is Ax + By + Cz + D = 0, where
|
||||
// <A,B,C> is the normal vector.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Plane.H"
|
||||
|
||||
CPlane::CPlane ()
|
||||
{
|
||||
m_Norm.Clear ();
|
||||
m_Dist = 0.0f;
|
||||
}
|
||||
|
||||
//sets the plane equation from 3 points on that plane
|
||||
void CPlane::Set (CVector3D &p1, CVector3D &p2, CVector3D &p3)
|
||||
{
|
||||
CVector3D D1, D2;
|
||||
CVector3D Norm;
|
||||
|
||||
//calculate two vectors on the surface of the plane
|
||||
D1 = p2-p1;
|
||||
D2 = p3-p1;
|
||||
|
||||
//cross multiply gives normal
|
||||
Norm = D2.Cross(D1);
|
||||
|
||||
Set (Norm, p1);
|
||||
}
|
||||
|
||||
//sets the plane equation from a normal and a point on
|
||||
//that plane
|
||||
void CPlane::Set (CVector3D &norm, CVector3D &point)
|
||||
{
|
||||
m_Norm = norm;
|
||||
|
||||
m_Dist = - (norm.X * point.X +
|
||||
norm.Y * point.Y +
|
||||
norm.Z * point.Z);
|
||||
|
||||
// Normalize ();
|
||||
}
|
||||
|
||||
//normalizes the plane equation
|
||||
void CPlane::Normalize ()
|
||||
{
|
||||
float Scale;
|
||||
|
||||
Scale = 1.0f/m_Norm.GetLength ();
|
||||
|
||||
m_Norm.X *= Scale;
|
||||
m_Norm.Y *= Scale;
|
||||
m_Norm.Z *= Scale;
|
||||
m_Dist *= Scale;
|
||||
}
|
||||
|
||||
//returns the side of the plane on which this point
|
||||
//lies.
|
||||
PLANESIDE CPlane::ClassifyPoint (CVector3D &point)
|
||||
{
|
||||
float Dist;
|
||||
|
||||
Dist = m_Norm.X * point.X +
|
||||
m_Norm.Y * point.Y +
|
||||
m_Norm.Z * point.Z +
|
||||
m_Dist;
|
||||
|
||||
if (Dist > 0.0f)
|
||||
return PS_FRONT;
|
||||
else if (Dist < 0.0f)
|
||||
return PS_BACK;
|
||||
|
||||
return PS_ON;
|
||||
}
|
||||
|
||||
//solves the plane equation for a particular point
|
||||
float CPlane::DistanceToPlane (CVector3D &point)
|
||||
{
|
||||
float Dist;
|
||||
|
||||
Dist = m_Norm.X * point.X +
|
||||
m_Norm.Y * point.Y +
|
||||
m_Norm.Z * point.Z +
|
||||
m_Dist;
|
||||
|
||||
return Dist;
|
||||
}
|
||||
|
||||
//calculates the intersection point of a line with this
|
||||
//plane. Returns false if there is no intersection
|
||||
bool CPlane::FindLineSegIntersection (CVector3D &start, CVector3D &end, CVector3D *intsect)
|
||||
{
|
||||
PLANESIDE StartS, EndS;
|
||||
CVector3D Dir;
|
||||
float Length;
|
||||
|
||||
//work out where each point is
|
||||
StartS = ClassifyPoint (start);
|
||||
EndS = ClassifyPoint (end);
|
||||
|
||||
//if they are not on opposite sides of the plane return false
|
||||
if (StartS == EndS)
|
||||
return false;
|
||||
|
||||
//work out a normalized vector in the direction start to end
|
||||
Dir = end - start;
|
||||
Dir.Normalize ();
|
||||
|
||||
//a bit of algebra to work out how much we need to scale
|
||||
//this direction vector to get to the plane
|
||||
Length = -m_Norm.Dot(start)/m_Norm.Dot(Dir);
|
||||
|
||||
//scale it by this amount
|
||||
Dir *= Length;
|
||||
|
||||
//workout actual position vector of impact
|
||||
*intsect = start + Dir;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPlane::FindRayIntersection (CVector3D &start, CVector3D &direction, CVector3D *intsect)
|
||||
{
|
||||
float dot = m_Norm.Dot (direction);
|
||||
if (dot == 0.0f)
|
||||
return false;
|
||||
|
||||
CVector3D a;
|
||||
*intsect = start - (direction * (DistanceToPlane (start)/dot));
|
||||
return true;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Plane.H
|
||||
// Last Update: 17/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Plane in R3 and several utility methods.
|
||||
// Note that the format used for the plane
|
||||
// equation is Ax + By + Cz + D = 0, where
|
||||
// <A,B,C> is the normal vector.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef PLANE_H
|
||||
#define PLANE_H
|
||||
|
||||
#include "Vector3D.H"
|
||||
|
||||
enum PLANESIDE
|
||||
{
|
||||
PS_FRONT,
|
||||
PS_BACK,
|
||||
PS_ON
|
||||
};
|
||||
|
||||
class CPlane
|
||||
{
|
||||
public:
|
||||
CPlane ();
|
||||
|
||||
//sets the plane equation from 3 points on that plane
|
||||
void Set (CVector3D &p1, CVector3D &p2, CVector3D &p3);
|
||||
|
||||
//sets the plane equation from a normal and a point on
|
||||
//that plane
|
||||
void Set (CVector3D &norm, CVector3D &point);
|
||||
|
||||
//normalizes the plane equation
|
||||
void Normalize ();
|
||||
|
||||
//returns the side of the plane on which this point
|
||||
//lies.
|
||||
PLANESIDE ClassifyPoint (CVector3D &point);
|
||||
|
||||
//solves the plane equation for a particular point
|
||||
float DistanceToPlane (CVector3D &point);
|
||||
|
||||
//calculates the intersection point of a line with this
|
||||
//plane. Returns false if there is no intersection
|
||||
bool FindLineSegIntersection (CVector3D &start, CVector3D &end, CVector3D *intsect);
|
||||
bool FindRayIntersection (CVector3D &start, CVector3D &direction, CVector3D *intsect);
|
||||
|
||||
public:
|
||||
CVector3D m_Norm; //normal vector of the plane
|
||||
float m_Dist; //Plane distance (ie D in the plane eq.)
|
||||
};
|
||||
|
||||
#endif
|
@ -1,52 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: RenderPrims.H
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Primitive classes for rendering
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef RENDERPRIMS_H
|
||||
#define RENDERPRIMS_H
|
||||
|
||||
#include "Vector3D.H"
|
||||
#include "Types.H"
|
||||
|
||||
|
||||
//shader register constants
|
||||
#define CONST_VERTREG_WORLDMATRIX (0)
|
||||
#define CONST_VERTREG_WVPMATRIX (4)
|
||||
#define CONST_VERTREG_LIGHTPOS (10)
|
||||
#define CONST_VERTREG_LIGHTRANGE (11)
|
||||
#define CONST_VERTREG_ZERO (14)
|
||||
#define CONST_VERTREG_HALF (15)
|
||||
#define CONST_VERTREG_ONE (16)
|
||||
#define CONST_VERTREG_EIGHT (17)
|
||||
#define CONST_VERTREG_EYEPOS (18)
|
||||
|
||||
#define CONST_PIXREG_A (0)
|
||||
#define CONST_PIXREG_B (1)
|
||||
|
||||
#define CONST_PIXREG_GAMB (2)
|
||||
#define CONST_PIXREG_MAMB (3)
|
||||
#define CONST_PIXREG_MEMM (4)
|
||||
|
||||
#define CONST_PIXREG_MDIFF (3)
|
||||
#define CONST_PIXREG_MSPEC (4)
|
||||
#define CONST_PIXREG_LDIFF (5)
|
||||
#define CONST_PIXREG_LSPEC (6)
|
||||
|
||||
|
||||
extern inline DWORD RGBA (BYTE B, BYTE G, BYTE R, BYTE A)
|
||||
{
|
||||
return (A << 24 | B << 16 | G << 8 | R);
|
||||
}
|
||||
|
||||
extern inline DWORD BGRA (BYTE B, BYTE G, BYTE R, BYTE A)
|
||||
{
|
||||
return (A << 24 | R << 16 | G << 8 | B);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,453 +0,0 @@
|
||||
#include "Renderer.H"
|
||||
#include "Matrix3D.H"
|
||||
#include "Camera.H"
|
||||
|
||||
#include "ogl.h"
|
||||
#include "tex.h"
|
||||
|
||||
#define RENDER_STAGE_BASE (1)
|
||||
#define RENDER_STAGE_TRANS (2)
|
||||
|
||||
bool g_WireFrame = false;
|
||||
unsigned int g_FrameCounter = 0;
|
||||
|
||||
CRenderer::CRenderer ()
|
||||
{
|
||||
m_Timer = 0;
|
||||
m_CurrentSeason = 0;
|
||||
}
|
||||
|
||||
CRenderer::~CRenderer ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool CRenderer::Initialize (HWND hwnd, int width, int height, int depth)
|
||||
{
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Depth = depth;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CRenderer::Shutdown ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CRenderer::RenderTerrain (CTerrain *terrain, CCamera *camera)
|
||||
{
|
||||
// m_Timer += 0.001f;
|
||||
|
||||
if (m_Timer > 1.0f)
|
||||
{
|
||||
m_Timer = 0;
|
||||
|
||||
if (m_CurrentSeason == 0)
|
||||
m_CurrentSeason = 1;
|
||||
else
|
||||
m_CurrentSeason = 0;
|
||||
}
|
||||
|
||||
CMatrix3D view = camera->m_Orientation.GetTranspose();
|
||||
CMatrix3D proj = camera->GetProjection();
|
||||
|
||||
float gl_view[16] = {view._11, view._21, view._31, view._41,
|
||||
view._12, view._22, view._32, view._42,
|
||||
view._13, view._23, view._33, view._43,
|
||||
view._14, view._24, view._34, view._44};
|
||||
|
||||
float gl_proj[16] = {proj._11, proj._21, proj._31, proj._41,
|
||||
proj._12, proj._22, proj._32, proj._42,
|
||||
proj._13, proj._23, proj._33, proj._43,
|
||||
proj._14, proj._24, proj._34, proj._44};
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadMatrixf (gl_view);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadMatrixf (gl_proj);
|
||||
|
||||
SViewPort vp = camera->GetViewPort();
|
||||
glViewport (vp.m_X, vp.m_Y, vp.m_Width, vp.m_Height);
|
||||
|
||||
if (g_WireFrame)
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
else
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
|
||||
for (int j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (camera->GetFustum().IsBoxVisible (CVector3D(0,0,0), terrain->m_Patches[j][i].m_Bounds))
|
||||
terrain->m_Patches[j][i].m_LastVisFrame = g_FrameCounter;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (terrain->m_Patches[j][i].m_LastVisFrame == g_FrameCounter)
|
||||
RenderPatchBase (&terrain->m_Patches[j][i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (terrain->m_Patches[j][i].m_LastVisFrame == g_FrameCounter)
|
||||
RenderPatchTrans (&terrain->m_Patches[j][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CRenderer::RenderPatchBase (CPatch *patch)
|
||||
{
|
||||
CMiniPatch *MPatch, *MPCurrent;
|
||||
|
||||
float StartU, StartV;
|
||||
|
||||
|
||||
for (int j=0; j<4; j++)
|
||||
{
|
||||
for (int i=0; i<4; i++)
|
||||
{
|
||||
MPatch = &(patch->m_MiniPatches[j][i]);
|
||||
|
||||
if (MPatch->m_LastRenderedFrame == g_FrameCounter)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
MPatch->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPatch->m_RenderStage = RENDER_STAGE_BASE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
tex_bind(MPatch->Tex1);
|
||||
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
/////////////////////////////////////
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
||||
/////////////////////////////////////
|
||||
|
||||
StartU = 0.5f * (float)(i%2);
|
||||
StartV = 0.5f * (float)(j%2);
|
||||
|
||||
float tu[2], tv[2];
|
||||
tu[0] = tu[1] = StartU;
|
||||
tv[0] = StartV+0.125f;
|
||||
tv[1] = StartV;
|
||||
|
||||
for (int row=0; row<4; row++)
|
||||
{
|
||||
MPCurrent = MPatch;
|
||||
glBegin (GL_TRIANGLE_STRIP);
|
||||
|
||||
int start = 0;
|
||||
|
||||
while (MPCurrent)
|
||||
{
|
||||
bool ExitFlag;
|
||||
|
||||
if (!MPCurrent->m_pRightNeighbor)
|
||||
ExitFlag = true;
|
||||
else
|
||||
{
|
||||
if (MPCurrent->m_pRightNeighbor->Tex1 == MPCurrent->Tex1 &&
|
||||
MPCurrent->m_pRightNeighbor->m_pParrent->m_LastVisFrame == g_FrameCounter)
|
||||
ExitFlag = false;
|
||||
else
|
||||
ExitFlag = true;
|
||||
}
|
||||
|
||||
for (int x=start; x<5; x++)
|
||||
{
|
||||
int v1 = ((row+1)*MAP_SIZE) + x;
|
||||
int v2 = (row*MAP_SIZE) + x;
|
||||
|
||||
float factor = m_Timer;
|
||||
if (m_CurrentSeason == 1)
|
||||
factor = 1.0f - factor;
|
||||
|
||||
float color1[3] = {MPCurrent->m_pVertices[v1].m_Color[0][0]*factor + MPCurrent->m_pVertices[v1].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][1]*factor + MPCurrent->m_pVertices[v1].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][2]*factor + MPCurrent->m_pVertices[v1].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
float color2[3] = {MPCurrent->m_pVertices[v2].m_Color[0][0]*factor + MPCurrent->m_pVertices[v2].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][1]*factor + MPCurrent->m_pVertices[v2].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][2]*factor + MPCurrent->m_pVertices[v2].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
glTexCoord2f (tu[0], tv[0]);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color1[0],color1[1],color1[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v1].m_Position.X,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Z);
|
||||
|
||||
glTexCoord2f (tu[1], tv[1]);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color2[0],color2[1],color2[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v2].m_Position.X,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Z);
|
||||
|
||||
tu[0]+=0.125f;
|
||||
tu[1]+=0.125f;
|
||||
}
|
||||
|
||||
if (ExitFlag)
|
||||
break;
|
||||
|
||||
MPCurrent = MPCurrent->m_pRightNeighbor;
|
||||
MPCurrent->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPCurrent->m_RenderStage = RENDER_STAGE_BASE;
|
||||
start = 1;
|
||||
}
|
||||
|
||||
tv[0]+=0.125f;
|
||||
tv[1]+=0.125f;
|
||||
|
||||
tu[0] = StartU;
|
||||
tu[1] = StartU;
|
||||
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CRenderer::RenderPatchTrans (CPatch *patch)
|
||||
{
|
||||
CMiniPatch *MPatch, *MPCurrent;
|
||||
|
||||
float StartU, StartV;
|
||||
|
||||
glEnable (GL_BLEND);
|
||||
glDepthFunc (GL_EQUAL);
|
||||
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
for (int j=0; j<4; j++)
|
||||
{
|
||||
for (int i=0; i<4; i++)
|
||||
{
|
||||
MPatch = &(patch->m_MiniPatches[j][i]);
|
||||
|
||||
if (MPatch->m_LastRenderedFrame == g_FrameCounter &&
|
||||
MPatch->m_RenderStage == RENDER_STAGE_TRANS)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
MPatch->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPatch->m_RenderStage = RENDER_STAGE_TRANS;
|
||||
}
|
||||
|
||||
//now for transition
|
||||
if (MPatch->Tex2 && MPatch->m_AlphaMap)
|
||||
{
|
||||
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
tex_bind(MPatch->Tex2);
|
||||
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
/////////////////////////////////////
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
||||
/////////////////////////////////////
|
||||
|
||||
|
||||
glActiveTexture (GL_TEXTURE1);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
tex_bind(MPatch->m_AlphaMap);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
/////////////////////////////////////
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
||||
/////////////////////////////////////
|
||||
|
||||
StartU = 0.5f * (float)(i%2);
|
||||
StartV = 0.5f * (float)(j%2);
|
||||
|
||||
float tu[2], tv[2];
|
||||
tu[0] = tu[1] = StartU;
|
||||
tv[0] = StartV+0.125f;
|
||||
tv[1] = StartV;
|
||||
|
||||
for (int row=0; row<4; row++)
|
||||
{
|
||||
glBegin (GL_TRIANGLE_STRIP);
|
||||
MPCurrent = MPatch;
|
||||
|
||||
while (MPCurrent)
|
||||
{
|
||||
int count;
|
||||
bool ExitFlag;
|
||||
|
||||
if (!MPCurrent->m_pRightNeighbor)
|
||||
{
|
||||
count = 5;
|
||||
ExitFlag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MPCurrent->m_pRightNeighbor->Tex2 == MPCurrent->Tex2 &&
|
||||
MPCurrent->m_pRightNeighbor->m_AlphaMap == MPCurrent->m_AlphaMap &&
|
||||
MPCurrent->m_pRightNeighbor->m_pParrent->m_LastVisFrame == g_FrameCounter)
|
||||
{
|
||||
count = 4;
|
||||
ExitFlag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 5;
|
||||
ExitFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int x=0; x<count; x++)
|
||||
{
|
||||
int v1 = ((row+1)*MAP_SIZE) + x;
|
||||
int v2 = (row*MAP_SIZE) + x;
|
||||
|
||||
float factor = m_Timer;
|
||||
if (m_CurrentSeason == 1)
|
||||
factor = 1.0f - factor;
|
||||
|
||||
float color1[3] = {MPCurrent->m_pVertices[v1].m_Color[0][0]*factor + MPCurrent->m_pVertices[v1].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][1]*factor + MPCurrent->m_pVertices[v1].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][2]*factor + MPCurrent->m_pVertices[v1].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
float color2[3] = {MPCurrent->m_pVertices[v2].m_Color[0][0]*factor + MPCurrent->m_pVertices[v2].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][1]*factor + MPCurrent->m_pVertices[v2].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][2]*factor + MPCurrent->m_pVertices[v2].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
glMultiTexCoord2f (GL_TEXTURE0_ARB, tu[0], tv[0]);
|
||||
glMultiTexCoord2f (GL_TEXTURE1_ARB, tu[0]*2, tv[0]*2);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color1[0],color1[1],color1[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v1].m_Position.X,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Z);
|
||||
|
||||
glMultiTexCoord2f (GL_TEXTURE0_ARB, tu[1], tv[1]);
|
||||
glMultiTexCoord2f (GL_TEXTURE1_ARB, tu[1]*2, tv[1]*2);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color2[0],color2[1],color2[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v2].m_Position.X,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Z);
|
||||
|
||||
tu[0]+=0.125f;
|
||||
tu[1]+=0.125f;
|
||||
}
|
||||
|
||||
if (ExitFlag)
|
||||
break;
|
||||
|
||||
MPCurrent = MPCurrent->m_pRightNeighbor;
|
||||
MPCurrent->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPCurrent->m_RenderStage = RENDER_STAGE_TRANS;
|
||||
}
|
||||
|
||||
tv[0]+=0.125f;
|
||||
tv[1]+=0.125f;
|
||||
tu[0] = tu[1] = StartU;
|
||||
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
glDisable (GL_BLEND);
|
||||
glActiveTexture (GL_TEXTURE1);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void CRenderer::RenderTileOutline (CMiniPatch *mpatch)
|
||||
{
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glLineWidth (4);
|
||||
|
||||
STerrainVertex V[4];
|
||||
V[0] = mpatch->m_pVertices[0];
|
||||
V[1] = mpatch->m_pVertices[4];
|
||||
V[2] = mpatch->m_pVertices[MAP_SIZE*4 + 4];
|
||||
V[3] = mpatch->m_pVertices[MAP_SIZE*4];
|
||||
|
||||
glBegin (GL_LINE_STRIP);
|
||||
|
||||
glColor3f (0,1.0f,0);
|
||||
|
||||
glVertex3f (V[0].m_Position.X, V[0].m_Position.Y, V[0].m_Position.Z);
|
||||
glVertex3f (V[1].m_Position.X, V[1].m_Position.Y, V[1].m_Position.Z);
|
||||
glVertex3f (V[2].m_Position.X, V[2].m_Position.Y, V[2].m_Position.Z);
|
||||
glVertex3f (V[3].m_Position.X, V[3].m_Position.Y, V[3].m_Position.Z);
|
||||
glVertex3f (V[0].m_Position.X, V[0].m_Position.Y, V[0].m_Position.Z);
|
||||
|
||||
glEnd ();
|
||||
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
#include <windows.h>
|
||||
#include "ogl.h"
|
||||
|
||||
#include "Terrain.H"
|
||||
|
||||
extern bool g_WireFrame;
|
||||
extern unsigned int g_FrameCounter;
|
||||
|
||||
class CRenderer
|
||||
{
|
||||
public:
|
||||
CRenderer();
|
||||
~CRenderer();
|
||||
|
||||
bool Initialize (HWND hwnd, int width, int height, int depth);
|
||||
void Shutdown ();
|
||||
|
||||
void RenderTerrain (CTerrain *terrain, CCamera *camera);
|
||||
void RenderTileOutline (CMiniPatch *mpatch);
|
||||
|
||||
protected:
|
||||
void RenderPatchBase (CPatch *patch);
|
||||
void RenderPatchTrans (CPatch *patch);
|
||||
|
||||
protected:
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
int m_Depth;
|
||||
|
||||
///THERE ARE NOT SUPPOSED TO BE HERE
|
||||
float m_Timer;
|
||||
int m_CurrentSeason;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Resource.Cpp
|
||||
// Last Update: 7/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A game resource provides an interface for a
|
||||
// game resource type, ie ModelDefs, Bitmap and
|
||||
// Textures, Sounds and Music. These can be
|
||||
// accessed through a ResourceLibrary
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Resource.H"
|
@ -1,47 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Resource.H
|
||||
// Last Update: 7/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A game resource provides an interface for a
|
||||
// game resource type, ie ModelDefs, Bitmap and
|
||||
// Textures, Sounds and Music. These can be
|
||||
// accessed through a ResourceLibrary.
|
||||
// IMPORTANT NOTE: This is an abstract class. It
|
||||
// Must ONLY instantiated with a child class.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef RESOURCE_H
|
||||
#define RESOURCE_H
|
||||
|
||||
#include "Types.H"
|
||||
|
||||
#define MAX_RSNAME_LENGTH (64)
|
||||
|
||||
enum RESOURCETYPE
|
||||
{
|
||||
RST_BITMAP,
|
||||
RST_TEXTURE,
|
||||
RST_CUBETEXTURE,
|
||||
RST_MODELDEF,
|
||||
RST_SOUND,
|
||||
RST_VERTEXSHADER,
|
||||
RST_PIXELSHADER,
|
||||
};
|
||||
|
||||
class CResource
|
||||
{
|
||||
public:
|
||||
virtual ~CResource() {};
|
||||
|
||||
char *GetName() { return m_Name; }
|
||||
int GetType() { return m_Type; }
|
||||
|
||||
protected:
|
||||
char m_Name[MAX_RSNAME_LENGTH];
|
||||
unsigned int m_Type;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: TerrGlobals.H
|
||||
// Last Update: 27/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Some globals and macros, used by the CTerrain
|
||||
// and CPatch
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TERRGLOBALS_H
|
||||
#define TERRGLOBALS_H
|
||||
|
||||
const int PATCH_SIZE = 16;
|
||||
const int CELL_SIZE = 4; //horizontal scale of the patches
|
||||
const float HEIGHT_SCALE = 1.0f;
|
||||
|
||||
//only 3x3 patches loaded at a time
|
||||
const int NUM_PATCHES_PER_SIDE = 20;
|
||||
|
||||
//must be odd number of patches
|
||||
//#define TERRAIN_CHUNK_SIZE (PATCH_SIZE*NUM_PATCHES_PER_SIDE)
|
||||
const int MAP_SIZE = ( (NUM_PATCHES_PER_SIDE*PATCH_SIZE)+1 );
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,190 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Terrain.Cpp
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CTerrain handles the terrain portion of the
|
||||
// engine. It holds open the file to the terrain
|
||||
// information, so terrain data can be loaded
|
||||
// dynamically. We use a ROAM method to render
|
||||
// the terrain, ie using binary triangle trees.
|
||||
// The terrain consists of smaller PATCHS, which
|
||||
// do most of the work.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Terrain.H"
|
||||
#include "tex.h"
|
||||
|
||||
bool g_HillShading = true;
|
||||
|
||||
CVector3D SeasonLight[2];
|
||||
float SeasonColor[2][3];
|
||||
|
||||
CTerrain::CTerrain ()
|
||||
{
|
||||
m_pVertices = NULL;
|
||||
}
|
||||
|
||||
CTerrain::~CTerrain ()
|
||||
{
|
||||
delete [] m_pVertices;
|
||||
}
|
||||
|
||||
bool CTerrain::Initalize (char *filename)
|
||||
{
|
||||
SeasonLight[0].Set (3, -1, 3);
|
||||
SeasonLight[0].Normalize();
|
||||
SeasonColor[0][0] = 0.8f; SeasonColor[0][1] = 1.0f; SeasonColor[0][2] = 0.8f;
|
||||
|
||||
SeasonLight[1].Set (2, -1, -3);
|
||||
SeasonLight[1].Normalize();
|
||||
SeasonColor[1][0] = 1.0f; SeasonColor[1][1] = 0.9f; SeasonColor[1][2] = 0.9f;
|
||||
|
||||
TEX tex;
|
||||
tex_load(filename, &tex);
|
||||
const u8* data = tex.ptr;
|
||||
|
||||
m_pVertices = new STerrainVertex[MAP_SIZE*MAP_SIZE];
|
||||
if (m_pVertices == NULL)
|
||||
return false;
|
||||
|
||||
for (int j=0; j<MAP_SIZE; j++)
|
||||
{
|
||||
for (int i=0; i<MAP_SIZE; i++)
|
||||
{
|
||||
int pos = j*MAP_SIZE + i;
|
||||
|
||||
m_pVertices[pos].m_Position.X = ((float)i)*CELL_SIZE;
|
||||
m_pVertices[pos].m_Position.Y = (*data++)*0.35f;
|
||||
m_pVertices[pos].m_Position.Z = ((float)j)*CELL_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
int pos = j*MAP_SIZE*PATCH_SIZE;
|
||||
pos += i*PATCH_SIZE;
|
||||
|
||||
m_Patches[j][i].Initialize ( &(m_pVertices[pos]) );
|
||||
}
|
||||
}
|
||||
|
||||
CalcLighting();
|
||||
SetNeighbors();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CTerrain::CalcLighting ()
|
||||
{
|
||||
CVector3D left, right, up, down, n[4];
|
||||
|
||||
for (int j=0; j<MAP_SIZE; j++)
|
||||
{
|
||||
for (int i=0; i<MAP_SIZE; i++)
|
||||
{
|
||||
left.Clear();
|
||||
right.Clear();
|
||||
up.Clear();
|
||||
down.Clear();
|
||||
|
||||
if (i>0)
|
||||
left = m_pVertices[j*MAP_SIZE + i - 1].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
if (i<MAP_SIZE-1)
|
||||
right = m_pVertices[j*MAP_SIZE + i + 1].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
if (j>0)
|
||||
up = m_pVertices[(j-1)*MAP_SIZE + i].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
if (j<MAP_SIZE-1)
|
||||
down = m_pVertices[(j+1)*MAP_SIZE + i].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
n[0] = up.Cross(left);
|
||||
n[1] = left.Cross(down);
|
||||
n[2] = down.Cross(right);
|
||||
n[3] = right.Cross(up);
|
||||
|
||||
n[0].Normalize();
|
||||
n[1].Normalize();
|
||||
n[2].Normalize();
|
||||
n[3].Normalize();
|
||||
|
||||
CVector3D Normal = n[0] + n[1] + n[2] + n[3];
|
||||
Normal.Normalize();
|
||||
|
||||
float Color1 = Normal.Dot(SeasonLight[0]*-1)/(Normal.GetLength() * SeasonLight[0].GetLength());
|
||||
Color1 = (Color1+1.0f)/1.4f;
|
||||
|
||||
if (Color1>1.0f)
|
||||
Color1=1.0f;
|
||||
if (Color1<0.0f)
|
||||
Color1=0.0f;
|
||||
|
||||
float Color2 = Normal.Dot(SeasonLight[1]*-1)/(Normal.GetLength() * SeasonLight[1].GetLength());
|
||||
Color2 = (Color2+1.0f)/1.4f;
|
||||
|
||||
if (Color2>1.0f)
|
||||
Color2=1.0f;
|
||||
if (Color2<0.0f)
|
||||
Color2=0.0f;
|
||||
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[0][0] = Color1*SeasonColor[0][0];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[0][1] = Color1*SeasonColor[0][1];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[0][2] = Color1*SeasonColor[0][2];
|
||||
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[1][0] = Color2*SeasonColor[1][0];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[1][1] = Color2*SeasonColor[1][1];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[1][2] = Color2*SeasonColor[1][2];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CTerrain::SetNeighbors ()
|
||||
{
|
||||
CPatch *ThisPatch, *RightPatch;
|
||||
|
||||
for (int pj=0; pj<NUM_PATCHES_PER_SIDE; pj++)
|
||||
{
|
||||
for (int pi=0; pi<NUM_PATCHES_PER_SIDE; pi++)
|
||||
{
|
||||
ThisPatch = &m_Patches[pj][pi];
|
||||
|
||||
if (pi < NUM_PATCHES_PER_SIDE)
|
||||
RightPatch = &m_Patches[pj][pi+1];
|
||||
else
|
||||
RightPatch = NULL;
|
||||
|
||||
|
||||
for (int tj=0; tj<4; tj++)
|
||||
{
|
||||
for (int ti=0; ti<4; ti++)
|
||||
{
|
||||
CMiniPatch *MPatch = &ThisPatch->m_MiniPatches[tj][ti];
|
||||
|
||||
MPatch->m_pParrent = ThisPatch;
|
||||
|
||||
if (ti < 3)
|
||||
MPatch->m_pRightNeighbor = &ThisPatch->m_MiniPatches[tj][ti+1];
|
||||
else
|
||||
{
|
||||
if (RightPatch)
|
||||
MPatch->m_pRightNeighbor = &RightPatch->m_MiniPatches[tj][0];
|
||||
else
|
||||
MPatch->m_pRightNeighbor = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Terrain.H
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CTerrain handles the terrain portion of the
|
||||
// engine. It holds open the file to the terrain
|
||||
// information, so terrain data can be loaded
|
||||
// dynamically. We use a ROAM method to render
|
||||
// the terrain, ie using binary triangle trees.
|
||||
// The terrain consists of smaller PATCHS, which
|
||||
// do most of the work.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TERRAIN_H
|
||||
#define TERRAIN_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Patch.H"
|
||||
#include "Vector3D.H"
|
||||
|
||||
extern bool g_HillShading;
|
||||
|
||||
class CTerrain
|
||||
{
|
||||
public:
|
||||
CTerrain ();
|
||||
~CTerrain ();
|
||||
|
||||
bool Initalize (char *filename);
|
||||
|
||||
// protected:
|
||||
//the patches currently loaded
|
||||
CPatch m_Patches[NUM_PATCHES_PER_SIDE][NUM_PATCHES_PER_SIDE];
|
||||
STerrainVertex *m_pVertices;
|
||||
|
||||
|
||||
// protected:
|
||||
void CalcLighting();
|
||||
void SetNeighbors();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,98 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Texture.Cpp
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: The texture class holds data about a texture,
|
||||
// and certain flags descibing the filtering used
|
||||
// for the texture. It must be registered with the
|
||||
// renderer before being used.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Texture.H"
|
||||
|
||||
CTexture::CTexture ()
|
||||
{
|
||||
m_MipMap = true;
|
||||
m_RegisterID = -1;
|
||||
}
|
||||
|
||||
CTexture::~CTexture ()
|
||||
{
|
||||
CBitmap::~CBitmap ();
|
||||
}
|
||||
|
||||
FRESULT CTexture::LoadBitmap (char *path, RESOURCETYPE type)
|
||||
{
|
||||
FRESULT result;
|
||||
//load the image
|
||||
result = CBitmap::LoadBitmap (path, type);
|
||||
|
||||
if (result != R_OK)
|
||||
return result;
|
||||
|
||||
int w = m_Width;
|
||||
int h = m_Height;
|
||||
|
||||
//width must be a power of 2
|
||||
while (w > 1)
|
||||
{
|
||||
if (w%2 != 0)
|
||||
{
|
||||
DestroyData ();
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
w /= 2;
|
||||
}
|
||||
|
||||
//height must be a power of 2
|
||||
while (h > 1)
|
||||
{
|
||||
if (h%2 != 0)
|
||||
{
|
||||
DestroyData ();
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
h /= 2;
|
||||
}
|
||||
|
||||
return R_OK;
|
||||
}
|
||||
|
||||
FRESULT CTexture::CreateBitmap (RESOURCETYPE type, char *name, int width, int height)
|
||||
{
|
||||
//must be square
|
||||
if (width != height)
|
||||
return R_BADPARAMS;
|
||||
|
||||
int w = width;
|
||||
int h = height;
|
||||
|
||||
//width must be a power of 2
|
||||
while (w > 1)
|
||||
{
|
||||
if (w%2 != 0)
|
||||
{
|
||||
DestroyData ();
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
w /= 2;
|
||||
}
|
||||
|
||||
//height must be a power of 2
|
||||
while (h > 1)
|
||||
{
|
||||
if (h%2 != 0)
|
||||
{
|
||||
DestroyData ();
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
h /= 2;
|
||||
}
|
||||
return CBitmap::CreateBitmap (type, name, width, height);
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Texture.H
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: The texture class holds data about a texture,
|
||||
// and certain flags descibing the filtering used
|
||||
// for the texture. It must be registered with the
|
||||
// renderer before being used. The flags must be set
|
||||
// before registering for them to have an effect
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
#include "Types.H"
|
||||
#include "Bitmap.H"
|
||||
|
||||
class CTexture : public CBitmap
|
||||
{
|
||||
public:
|
||||
CTexture ();
|
||||
virtual ~CTexture ();
|
||||
|
||||
virtual FRESULT LoadBitmap (char *path, RESOURCETYPE type);
|
||||
virtual FRESULT CreateBitmap (RESOURCETYPE type, char *name, int width, int height);
|
||||
|
||||
//set number of mip mapping flag
|
||||
void SetMipMapFlag (bool flag) { m_MipMap = flag; }
|
||||
int GetMipMapFlag () { return m_MipMap; }
|
||||
|
||||
//registry stuff
|
||||
void SetRegisterID (int id) { m_RegisterID = id; }
|
||||
int GetRegisterID () { return m_RegisterID; }
|
||||
|
||||
private:
|
||||
//An id which is given to the texture when registered.
|
||||
//It is equal to -1 if not registered
|
||||
int m_RegisterID;
|
||||
|
||||
//A full mipmap table is built when creating
|
||||
bool m_MipMap;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,88 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Types.H
|
||||
// Last Update: 25/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: The basic types used by the engine
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//basic return types
|
||||
enum FRESULT
|
||||
{
|
||||
R_OK = 0,
|
||||
R_FAIL, //use if nothing else matches the return type
|
||||
|
||||
R_BADPARAMS, //one or more of the parameters were invalid
|
||||
|
||||
R_NOMEMORY, //not enough memory for an operation
|
||||
|
||||
R_FILE_NOOPEN, //file could not be opened
|
||||
R_FILE_NOREAD, //file could not be read
|
||||
R_FILE_INVALID //file is corrupt or not supported
|
||||
};
|
||||
|
||||
//string related
|
||||
#define MAX_NAME_LENGTH (50)
|
||||
#define MAX_PATH_LENGTH (100)
|
||||
|
||||
//color structures
|
||||
struct SColor4ub
|
||||
{
|
||||
unsigned char R;
|
||||
unsigned char G;
|
||||
unsigned char B;
|
||||
unsigned char A;
|
||||
};
|
||||
|
||||
struct SColor4f
|
||||
{
|
||||
float R;
|
||||
float G;
|
||||
float B;
|
||||
float A;
|
||||
};
|
||||
|
||||
//all the major classes:
|
||||
class CBitmap;
|
||||
|
||||
class CCamera;
|
||||
|
||||
class CDiesel3DVertex;
|
||||
|
||||
class CGameResource;
|
||||
|
||||
class CEngine;
|
||||
class CEntity;
|
||||
|
||||
class CFrustum;
|
||||
|
||||
class CMatrix3D;
|
||||
class CMesh;
|
||||
class CMeshPoly;
|
||||
class CShadyMesh;
|
||||
class CShadyMeshPoly;
|
||||
|
||||
class CNode;
|
||||
|
||||
class CPatch;
|
||||
class CPlane;
|
||||
|
||||
class CRenderer;
|
||||
|
||||
class CTerrain;
|
||||
class CTexture;
|
||||
|
||||
class CVector3D;
|
||||
|
||||
class CWorld;
|
||||
|
||||
|
||||
#endif
|
@ -1,181 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Vector3D.Cpp
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Provides an interface for a vector in R3 and
|
||||
// allows vector and scalar operations on it
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Vector3D.H"
|
||||
|
||||
CVector3D::CVector3D ()
|
||||
{
|
||||
X = Y = Z = 0.0f;
|
||||
}
|
||||
|
||||
CVector3D::CVector3D (float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
int CVector3D::operator == (CVector3D &vector)
|
||||
{
|
||||
if (X != vector.X ||
|
||||
Y != vector.Y ||
|
||||
Z != vector.Z)
|
||||
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CVector3D::operator != (CVector3D &vector)
|
||||
{
|
||||
if (X != vector.X ||
|
||||
Y != vector.Y ||
|
||||
Z != vector.Z)
|
||||
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CVector3D::operator ! ()
|
||||
{
|
||||
if (X != 0.0f ||
|
||||
Y != 0.0f ||
|
||||
Z != 0.0f)
|
||||
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//vector addition
|
||||
CVector3D CVector3D::operator + (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X + vector.X;
|
||||
Temp.Y = Y + vector.Y;
|
||||
Temp.Z = Z + vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//vector addition/assignment
|
||||
CVector3D &CVector3D::operator += (CVector3D &vector)
|
||||
{
|
||||
X += vector.X;
|
||||
Y += vector.Y;
|
||||
Z += vector.Z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//vector subtraction
|
||||
CVector3D CVector3D::operator - (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X - vector.X;
|
||||
Temp.Y = Y - vector.Y;
|
||||
Temp.Z = Z - vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//vector subtrcation/assignment
|
||||
CVector3D &CVector3D::operator -= (CVector3D &vector)
|
||||
{
|
||||
X -= vector.X;
|
||||
Y -= vector.Y;
|
||||
Z -= vector.Z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//scalar multiplication
|
||||
CVector3D CVector3D::operator * (float value)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X * value;
|
||||
Temp.Y = Y * value;
|
||||
Temp.Z = Z * value;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//scalar multiplication/assignment
|
||||
CVector3D CVector3D::operator *= (float value)
|
||||
{
|
||||
X *= value;
|
||||
Y *= value;
|
||||
Z *= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CVector3D::Set (float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
void CVector3D::Clear ()
|
||||
{
|
||||
X = Y = Z = 0.0f;
|
||||
}
|
||||
|
||||
//Dot product
|
||||
float CVector3D::Dot (CVector3D &vector)
|
||||
{
|
||||
return ( X * vector.X +
|
||||
Y * vector.Y +
|
||||
Z * vector.Z );
|
||||
}
|
||||
|
||||
//Cross product
|
||||
CVector3D CVector3D::Cross (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = (Y * vector.Z) - (Z * vector.Y);
|
||||
Temp.Y = (Z * vector.X) - (X * vector.Z);
|
||||
Temp.Z = (X * vector.Y) - (Y * vector.X);
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
float CVector3D::GetLength ()
|
||||
{
|
||||
return sqrtf ( SQR(X) + SQR(Y) + SQR(Z) );
|
||||
}
|
||||
|
||||
void CVector3D::Normalize ()
|
||||
{
|
||||
float scale = 1.0f/GetLength ();
|
||||
|
||||
X *= scale;
|
||||
Y *= scale;
|
||||
Z *= scale;
|
||||
}
|
||||
|
||||
SColor4ub CVector3D::ConvertToColor (float alpha_factor)
|
||||
{
|
||||
SColor4ub color;
|
||||
|
||||
color.R = (unsigned char)(127.0f * X + 128.0f);
|
||||
color.G = (unsigned char)(127.0f * Y + 128.0f);
|
||||
color.B = (unsigned char)(127.0f * Z + 128.0f);
|
||||
color.A = (unsigned char)(255.0f * alpha_factor);
|
||||
|
||||
return color;
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Vector3D.H
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Provides an interface for a vector in R3 and
|
||||
// allows vector and scalar operations on it
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef VECTOR3D_H
|
||||
#define VECTOR3D_H
|
||||
|
||||
#include <math.h>
|
||||
#include "MathUtil.H"
|
||||
#include "Types.H"
|
||||
|
||||
class CVector3D
|
||||
{
|
||||
public:
|
||||
float X, Y, Z;
|
||||
|
||||
public:
|
||||
CVector3D ();
|
||||
CVector3D (float x, float y, float z);
|
||||
|
||||
int operator == (CVector3D &vector);
|
||||
int operator != (CVector3D &vector);
|
||||
int operator ! ();
|
||||
|
||||
//vector addition
|
||||
CVector3D operator + (CVector3D &vector);
|
||||
//vector addition/assignment
|
||||
CVector3D &operator += (CVector3D &vector);
|
||||
|
||||
//vector subtraction
|
||||
CVector3D operator - (CVector3D &vector);
|
||||
//vector subtraction/assignment
|
||||
CVector3D &operator -= (CVector3D &vector);
|
||||
|
||||
//scalar multiplication
|
||||
CVector3D operator * (float value);
|
||||
//scalar multiplication/assignment
|
||||
CVector3D operator *= (float value);
|
||||
|
||||
public:
|
||||
void Set (float x, float y, float z);
|
||||
void Clear ();
|
||||
|
||||
//Dot product
|
||||
float Dot (CVector3D &vector);
|
||||
//Cross product
|
||||
CVector3D Cross (CVector3D &vector);
|
||||
|
||||
//Returns length of the vector
|
||||
float GetLength ();
|
||||
void Normalize ();
|
||||
|
||||
//Returns a color which describes the vector
|
||||
SColor4ub ConvertToColor (float alpha_factor);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,255 +0,0 @@
|
||||
#ifndef __glext_h_
|
||||
#define __glext_h_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Copyright 1992-1999 Silicon Graphics, Inc.
|
||||
** All Rights Reserved.
|
||||
**
|
||||
** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
|
||||
** the contents of this file may not be disclosed to third parties, copied or
|
||||
** duplicated in any form, in whole or in part, without the prior written
|
||||
** permission of Silicon Graphics, Inc.
|
||||
**
|
||||
** RESTRICTED RIGHTS LEGEND:
|
||||
** Use, duplication or disclosure by the Government is subject to restrictions
|
||||
** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
|
||||
** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
|
||||
** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
|
||||
** rights reserved under the Copyright Laws of the United States.
|
||||
*/
|
||||
|
||||
#ifndef APIENTRY
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define GL_ARB_multitexture 1
|
||||
#define GL_EXT_abgr 1
|
||||
#define GL_EXT_bgra 1
|
||||
#define GL_EXT_clip_volume_hint 1
|
||||
#define GL_EXT_compiled_vertex_array 1
|
||||
#define GL_EXT_cull_vertex 1
|
||||
#define GL_EXT_packed_pixels 1
|
||||
#define GL_EXT_point_parameters 1
|
||||
#define GL_EXT_stencil_wrap 1
|
||||
#define GL_EXT_texture_env_add 1
|
||||
#define GL_EXT_texture_env_combine 1
|
||||
#define GL_EXT_vertex_array 1
|
||||
#define GL_NV_texgen_reflection 1
|
||||
#define GL_NV_texture_env_combine4 1
|
||||
#define GL_WIN_swap_hint 1
|
||||
|
||||
/* EXT_abgr */
|
||||
#define GL_ABGR_EXT 0x8000
|
||||
|
||||
/* EXT_packed_pixels */
|
||||
#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032
|
||||
#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033
|
||||
#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034
|
||||
#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035
|
||||
#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036
|
||||
|
||||
/* EXT_vertex_array */
|
||||
#define GL_VERTEX_ARRAY_EXT 0x8074
|
||||
#define GL_NORMAL_ARRAY_EXT 0x8075
|
||||
#define GL_COLOR_ARRAY_EXT 0x8076
|
||||
#define GL_INDEX_ARRAY_EXT 0x8077
|
||||
#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078
|
||||
#define GL_EDGE_FLAG_ARRAY_EXT 0x8079
|
||||
#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A
|
||||
#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B
|
||||
#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C
|
||||
#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D
|
||||
#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E
|
||||
#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F
|
||||
#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080
|
||||
#define GL_COLOR_ARRAY_SIZE_EXT 0x8081
|
||||
#define GL_COLOR_ARRAY_TYPE_EXT 0x8082
|
||||
#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083
|
||||
#define GL_COLOR_ARRAY_COUNT_EXT 0x8084
|
||||
#define GL_INDEX_ARRAY_TYPE_EXT 0x8085
|
||||
#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086
|
||||
#define GL_INDEX_ARRAY_COUNT_EXT 0x8087
|
||||
#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088
|
||||
#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089
|
||||
#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A
|
||||
#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B
|
||||
#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C
|
||||
#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D
|
||||
#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E
|
||||
#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F
|
||||
#define GL_COLOR_ARRAY_POINTER_EXT 0x8090
|
||||
#define GL_INDEX_ARRAY_POINTER_EXT 0x8091
|
||||
#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092
|
||||
#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093
|
||||
|
||||
/* EXT_bgra */
|
||||
#define GL_BGR_EXT 0x80E0
|
||||
#define GL_BGRA_EXT 0x80E1
|
||||
|
||||
/* EXT_clip_volume_hint */
|
||||
#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0
|
||||
|
||||
/* EXT_point_parameters */
|
||||
#define GL_POINT_SIZE_MIN_EXT 0x8126
|
||||
#define GL_POINT_SIZE_MAX_EXT 0x8127
|
||||
#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128
|
||||
#define GL_DISTANCE_ATTENUATION_EXT 0x8129
|
||||
|
||||
/* EXT_compiled_vertex_array */
|
||||
#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8
|
||||
#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9
|
||||
|
||||
/* EXT_cull_vertex */
|
||||
#define GL_CULL_VERTEX_EXT 0x81AA
|
||||
#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB
|
||||
#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC
|
||||
|
||||
/* ARB_multitexture */
|
||||
#define GL_ACTIVE_TEXTURE_ARB 0x84E0
|
||||
#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1
|
||||
#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2
|
||||
#define GL_TEXTURE0_ARB 0x84C0
|
||||
#define GL_TEXTURE1_ARB 0x84C1
|
||||
#define GL_TEXTURE2_ARB 0x84C2
|
||||
#define GL_TEXTURE3_ARB 0x84C3
|
||||
#define GL_TEXTURE4_ARB 0x84C4
|
||||
#define GL_TEXTURE5_ARB 0x84C5
|
||||
#define GL_TEXTURE6_ARB 0x84C6
|
||||
#define GL_TEXTURE7_ARB 0x84C7
|
||||
#define GL_TEXTURE8_ARB 0x84C8
|
||||
#define GL_TEXTURE9_ARB 0x84C9
|
||||
#define GL_TEXTURE10_ARB 0x84CA
|
||||
#define GL_TEXTURE11_ARB 0x84CB
|
||||
#define GL_TEXTURE12_ARB 0x84CC
|
||||
#define GL_TEXTURE13_ARB 0x84CD
|
||||
#define GL_TEXTURE14_ARB 0x84CE
|
||||
#define GL_TEXTURE15_ARB 0x84CF
|
||||
#define GL_TEXTURE16_ARB 0x84D0
|
||||
#define GL_TEXTURE17_ARB 0x84D1
|
||||
#define GL_TEXTURE18_ARB 0x84D2
|
||||
#define GL_TEXTURE19_ARB 0x84D3
|
||||
#define GL_TEXTURE20_ARB 0x84D4
|
||||
#define GL_TEXTURE21_ARB 0x84D5
|
||||
#define GL_TEXTURE22_ARB 0x84D6
|
||||
#define GL_TEXTURE23_ARB 0x84D7
|
||||
#define GL_TEXTURE24_ARB 0x84D8
|
||||
#define GL_TEXTURE25_ARB 0x84D9
|
||||
#define GL_TEXTURE26_ARB 0x84DA
|
||||
#define GL_TEXTURE27_ARB 0x84DB
|
||||
#define GL_TEXTURE28_ARB 0x84DC
|
||||
#define GL_TEXTURE29_ARB 0x84DD
|
||||
#define GL_TEXTURE30_ARB 0x84DE
|
||||
#define GL_TEXTURE31_ARB 0x84DF
|
||||
|
||||
/* EXT_stencil_wrap */
|
||||
#define GL_INCR_WRAP_EXT 0x8507
|
||||
#define GL_DECR_WRAP_EXT 0x8508
|
||||
|
||||
/* NV_texgen_reflection */
|
||||
#define GL_NORMAL_MAP_NV 0x8511
|
||||
#define GL_REFLECTION_MAP_NV 0x8512
|
||||
|
||||
/* EXT_texture_env_combine */
|
||||
#define GL_COMBINE_EXT 0x8570
|
||||
#define GL_COMBINE_RGB_EXT 0x8571
|
||||
#define GL_COMBINE_ALPHA_EXT 0x8572
|
||||
#define GL_RGB_SCALE_EXT 0x8573
|
||||
#define GL_ADD_SIGNED_EXT 0x8574
|
||||
#define GL_INTERPOLATE_EXT 0x8575
|
||||
#define GL_CONSTANT_EXT 0x8576
|
||||
#define GL_PRIMARY_COLOR_EXT 0x8577
|
||||
#define GL_PREVIOUS_EXT 0x8578
|
||||
#define GL_SOURCE0_RGB_EXT 0x8580
|
||||
#define GL_SOURCE1_RGB_EXT 0x8581
|
||||
#define GL_SOURCE2_RGB_EXT 0x8582
|
||||
#define GL_SOURCE0_ALPHA_EXT 0x8588
|
||||
#define GL_SOURCE1_ALPHA_EXT 0x8589
|
||||
#define GL_SOURCE2_ALPHA_EXT 0x858A
|
||||
#define GL_OPERAND0_RGB_EXT 0x8590
|
||||
#define GL_OPERAND1_RGB_EXT 0x8591
|
||||
#define GL_OPERAND2_RGB_EXT 0x8592
|
||||
#define GL_OPERAND0_ALPHA_EXT 0x8598
|
||||
#define GL_OPERAND1_ALPHA_EXT 0x8599
|
||||
#define GL_OPERAND2_ALPHA_EXT 0x859A
|
||||
|
||||
/* NV_texture_env_combine4 */
|
||||
#define GL_COMBINE4_NV 0x8503
|
||||
#define GL_SOURCE3_RGB_NV 0x8583
|
||||
#define GL_SOURCE3_ALPHA_NV 0x858B
|
||||
#define GL_OPERAND3_RGB_NV 0x8593
|
||||
#define GL_OPERAND3_ALPHA_NV 0x859B
|
||||
|
||||
/*************************************************************/
|
||||
|
||||
/* EXT_vertex_array */
|
||||
typedef void (APIENTRY * PFNGLARRAYELEMENTEXTPROC) (GLint i);
|
||||
typedef void (APIENTRY * PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer);
|
||||
typedef void (APIENTRY * PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count);
|
||||
typedef void (APIENTRY * PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer);
|
||||
typedef void (APIENTRY * PFNGLGETPOINTERVEXTPROC) (GLenum pname, GLvoid* *params);
|
||||
typedef void (APIENTRY * PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer);
|
||||
typedef void (APIENTRY * PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer);
|
||||
typedef void (APIENTRY * PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer);
|
||||
typedef void (APIENTRY * PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer);
|
||||
|
||||
/* ARB_multitexture */
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
|
||||
typedef void (APIENTRY * PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v);
|
||||
typedef void (APIENTRY * PFNGLACTIVETEXTUREARBPROC) (GLenum target);
|
||||
typedef void (APIENTRY * PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum target);
|
||||
|
||||
/* EXT_compiled_vertex_array */
|
||||
typedef void (APIENTRY * PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count);
|
||||
typedef void (APIENTRY * PFNGLUNLOCKARRAYSEXTPROC) (void);
|
||||
|
||||
/* EXT_cull_vertex */
|
||||
typedef void (APIENTRY * PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble* params);
|
||||
typedef void (APIENTRY * PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat* params);
|
||||
|
||||
/* WIN_swap_hint */
|
||||
typedef void (APIENTRY * PFNGLADDSWAPHINTRECTWINPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
|
||||
/* EXT_point_parameter */
|
||||
typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param);
|
||||
typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __glext_h_ */
|
File diff suppressed because it is too large
Load Diff
@ -1,332 +0,0 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include "Matrix3D.H"
|
||||
#include "Renderer.H"
|
||||
#include "Terrain.H"
|
||||
|
||||
#include "time.h"
|
||||
#include "wsdl.h"
|
||||
#include "tex.h"
|
||||
|
||||
|
||||
HWND InitializeGame (HINSTANCE hInstance);
|
||||
void DestroyGame();
|
||||
|
||||
void InitScene ();
|
||||
void InitResources ();
|
||||
void RenderScene ();
|
||||
|
||||
extern bool keys[256];
|
||||
|
||||
|
||||
HWND GameWindow;
|
||||
|
||||
CMatrix3D g_WorldMat;
|
||||
CRenderer g_Renderer;
|
||||
CTerrain g_Terrain;
|
||||
CCamera g_Camera;
|
||||
|
||||
int SelPX, SelPY, SelTX, SelTY;
|
||||
int g_BaseTexCounter = 0;
|
||||
int g_SecTexCounter = 1;
|
||||
int g_TransTexCounter = 0;
|
||||
|
||||
int g_TickCounter = 0;
|
||||
double g_LastTime;
|
||||
|
||||
|
||||
const int NUM_ALPHA_MAPS = 13;
|
||||
|
||||
//CTexture g_BaseTexture[5];
|
||||
Handle BaseTexs[5];
|
||||
|
||||
Handle AlphaMaps[NUM_ALPHA_MAPS];
|
||||
//CTexture g_TransitionTexture[NUM_ALPHA_MAPS];
|
||||
|
||||
int mouse_x=50, mouse_y=50;
|
||||
|
||||
extern int xres, yres;
|
||||
|
||||
|
||||
void terr_init()
|
||||
{
|
||||
g_Renderer.Initialize (GameWindow, 1280, 1024, 32);
|
||||
|
||||
InitResources ();
|
||||
InitScene ();
|
||||
}
|
||||
|
||||
void terr_update()
|
||||
{
|
||||
g_FrameCounter++;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
POINT MousePos;
|
||||
|
||||
GetCursorPos (&MousePos);
|
||||
CVector3D right(1,0,1);
|
||||
CVector3D up(1,0,-1);
|
||||
right.Normalize ();
|
||||
up.Normalize ();
|
||||
|
||||
if (mouse_x >= xres-2)
|
||||
g_Camera.m_Orientation.Translate (right);
|
||||
if (mouse_x <= 3)
|
||||
g_Camera.m_Orientation.Translate (right*-1);
|
||||
|
||||
if (mouse_y >= yres-2)
|
||||
g_Camera.m_Orientation.Translate (up);
|
||||
if (mouse_y <= 3)
|
||||
g_Camera.m_Orientation.Translate (up*-1);
|
||||
|
||||
|
||||
|
||||
float fov = g_Camera.GetFOV();
|
||||
float d = DEGTORAD(0.4f);
|
||||
if(keys[SDLK_KP_MINUS])
|
||||
if (fov+d < DEGTORAD(90))
|
||||
g_Camera.SetProjection (1, 1000, fov + d);
|
||||
if(keys[SDLK_KP_ADD])
|
||||
if (fov-d > DEGTORAD(20))
|
||||
g_Camera.SetProjection (1, 1000, fov - d);
|
||||
|
||||
g_Camera.UpdateFrustum ();
|
||||
/////////////////////////////////////////////
|
||||
|
||||
|
||||
g_Renderer.RenderTerrain (&g_Terrain, &g_Camera);
|
||||
g_Renderer.RenderTileOutline (&(g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX]));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool terr_handler(const SDL_Event& ev)
|
||||
{
|
||||
switch(ev.type)
|
||||
{
|
||||
case SDL_MOUSEMOTION:
|
||||
mouse_x = ev.motion.x;
|
||||
mouse_y = ev.motion.y;
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
switch(ev.key.keysym.sym)
|
||||
{
|
||||
case 'W':
|
||||
g_WireFrame = !g_WireFrame;
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
g_HillShading = !g_HillShading;
|
||||
break;
|
||||
|
||||
// tile selection
|
||||
case SDLK_DOWN:
|
||||
if(++SelTX > 3)
|
||||
if(SelPX == NUM_PATCHES_PER_SIDE-1)
|
||||
SelTX = 3;
|
||||
else
|
||||
SelTX = 0, SelPX++;
|
||||
break;
|
||||
|
||||
case SDLK_UP:
|
||||
if(--SelTX < 0)
|
||||
if(SelPX == 0)
|
||||
SelTX = 0;
|
||||
else
|
||||
SelTX = 3, SelPX--;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
if(++SelTY > 3)
|
||||
if(SelPY == NUM_PATCHES_PER_SIDE-1)
|
||||
SelTY = 3;
|
||||
else
|
||||
SelTY = 0, SelPY++;
|
||||
break;
|
||||
|
||||
case SDLK_LEFT:
|
||||
if(--SelTY < 0)
|
||||
if(SelPY == 0)
|
||||
SelTY = 0;
|
||||
else
|
||||
SelTY = 3, SelPY--;
|
||||
break;
|
||||
|
||||
|
||||
case SDLK_KP0:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
if (!MPatch->Tex2)
|
||||
{
|
||||
MPatch->m_AlphaMap = AlphaMaps[g_TransTexCounter];
|
||||
MPatch->Tex2 = BaseTexs[g_SecTexCounter];
|
||||
}
|
||||
else
|
||||
{
|
||||
MPatch->Tex2 = 0;
|
||||
MPatch->m_AlphaMap = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_KP1:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
|
||||
g_BaseTexCounter++;
|
||||
if (g_BaseTexCounter > 4)
|
||||
g_BaseTexCounter = 0;
|
||||
|
||||
MPatch->Tex1 = BaseTexs[g_BaseTexCounter];
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_KP2:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
|
||||
if (MPatch->Tex2)
|
||||
{
|
||||
g_SecTexCounter++;
|
||||
if (g_SecTexCounter > 4)
|
||||
g_SecTexCounter = 0;
|
||||
|
||||
MPatch->Tex2 = BaseTexs[g_SecTexCounter];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_KP3:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
|
||||
if (MPatch->/*m_pTransitionTexture*/m_AlphaMap)
|
||||
{
|
||||
g_TransTexCounter++;
|
||||
if (g_TransTexCounter >= NUM_ALPHA_MAPS)
|
||||
g_TransTexCounter = 0;
|
||||
|
||||
MPatch->m_AlphaMap = AlphaMaps[g_TransTexCounter];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void InitScene ()
|
||||
{
|
||||
g_Terrain.Initalize ("terrain.raw");
|
||||
|
||||
for (int pj=0; pj<NUM_PATCHES_PER_SIDE; pj++)
|
||||
{
|
||||
for (int pi=0; pi<NUM_PATCHES_PER_SIDE; pi++)
|
||||
{
|
||||
for (int tj=0; tj<4; tj++)
|
||||
{
|
||||
for (int ti=0; ti<4; ti++)
|
||||
{
|
||||
g_Terrain.m_Patches[pj][pi].m_MiniPatches[tj][ti].Tex1 = BaseTexs[0];//rand()%5];
|
||||
g_Terrain.m_Patches[pj][pi].m_MiniPatches[tj][ti].Tex2 = NULL;//&g_BaseTexture[rand()%5];
|
||||
g_Terrain.m_Patches[pj][pi].m_MiniPatches[tj][ti].m_AlphaMap = 0;//&g_TransitionTexture[rand()%5];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_Camera.SetProjection (1, 1000, DEGTORAD(20));
|
||||
g_Camera.m_Orientation.SetXRotation(DEGTORAD(30));
|
||||
g_Camera.m_Orientation.RotateY(DEGTORAD(-45));
|
||||
|
||||
g_Camera.m_Orientation.Translate (100, 150, -100);
|
||||
|
||||
SelPX = SelPY = SelTX = SelTY = 0;
|
||||
}
|
||||
|
||||
void InitResources()
|
||||
{
|
||||
int i;
|
||||
char* base_fns[] =
|
||||
{
|
||||
"Base1.bmp",
|
||||
"Base2.bmp",
|
||||
"Base3.bmp",
|
||||
"Base4.bmp",
|
||||
"Base5.bmp"
|
||||
};
|
||||
|
||||
for(i = 0; i < 5; i++)
|
||||
{
|
||||
BaseTexs[i] = tex_load(base_fns[i]);
|
||||
tex_upload(BaseTexs[i], GL_LINEAR_MIPMAP_LINEAR);
|
||||
}
|
||||
|
||||
|
||||
int cnt;
|
||||
#if 1
|
||||
|
||||
char* fns[NUM_ALPHA_MAPS] = {
|
||||
"blendcircle.raw",
|
||||
"blendcorner.raw",
|
||||
"blendedge.raw",
|
||||
"blendedgecorner.raw",
|
||||
"blendedgetwocorners.raw",
|
||||
"blendfourcorners.raw",
|
||||
"blendlshape.raw",
|
||||
"blendlshapecorner.raw",
|
||||
"blendthreecorners.raw",
|
||||
"blendtwocorners.raw",
|
||||
"blendtwoedges.raw",
|
||||
"blendtwooppositecorners.raw",
|
||||
"blendushape.raw"
|
||||
};
|
||||
/*
|
||||
//for(i = 0; i < NUM_ALPHA_MAPS;i++)
|
||||
i=5;
|
||||
{
|
||||
FILE* f = fopen(fns[i],"rb");
|
||||
u8 buf[5000],buf2[5000];
|
||||
fread(buf,5000,1,f);
|
||||
fclose(f);
|
||||
for(int j = 0; j < 1024; j++)
|
||||
buf2[2*j] = buf2[2*j+1] = buf[j];
|
||||
f=fopen(fns[i],"wb");
|
||||
fwrite(buf2,2048,1,f);
|
||||
fclose(f);
|
||||
}
|
||||
/**/
|
||||
cnt=13;
|
||||
#else
|
||||
|
||||
char* fns[NUM_ALPHA_MAPS] = {
|
||||
"Transition1.bmp",
|
||||
"Transition2.bmp",
|
||||
"Transition3.bmp",
|
||||
"Transition4.bmp",
|
||||
"Transition5.bmp",
|
||||
};
|
||||
cnt=5;
|
||||
#endif
|
||||
|
||||
for(i = 0; i < cnt; i++)
|
||||
{
|
||||
AlphaMaps[i] = tex_load(fns[i]);
|
||||
tex_upload(AlphaMaps[i], GL_LINEAR, GL_INTENSITY4);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,108 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Camera.Cpp
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CCamera holds a view and a projection matrix.
|
||||
// It also has a frustum which can be used to
|
||||
// cull objects for rendering.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Camera.H"
|
||||
|
||||
extern int xres, yres;
|
||||
|
||||
CCamera::CCamera ()
|
||||
{
|
||||
m_ViewPort.m_Width = 1280;
|
||||
m_ViewPort.m_Height = 1024;
|
||||
m_ViewPort.m_X = 0;
|
||||
m_ViewPort.m_Y = 0;
|
||||
}
|
||||
|
||||
CCamera::~CCamera ()
|
||||
{
|
||||
}
|
||||
|
||||
void CCamera::SetProjection (float nearp, float farp, float fov)
|
||||
{
|
||||
float h, w, Q;
|
||||
|
||||
m_NearPlane = nearp;
|
||||
m_FarPlane = farp;
|
||||
m_FOV = fov;
|
||||
|
||||
float Aspect = (float)m_ViewPort.m_Width/(float)m_ViewPort.m_Height;
|
||||
|
||||
w = 1/tanf (fov*0.5f*Aspect);
|
||||
h = 1/tanf (fov*0.5f);
|
||||
Q = m_FarPlane / (m_FarPlane - m_NearPlane);
|
||||
|
||||
m_ProjMat.SetZero ();
|
||||
m_ProjMat._11 = w;
|
||||
m_ProjMat._22 = h;
|
||||
m_ProjMat._33 = Q;
|
||||
m_ProjMat._34 = -Q*m_NearPlane;
|
||||
m_ProjMat._43 = 1.0f;
|
||||
}
|
||||
|
||||
//Updates the frustum planes. Should be called
|
||||
//everytime the view or projection matrices are
|
||||
//altered.
|
||||
void CCamera::UpdateFrustum ()
|
||||
{
|
||||
CMatrix3D MatFinal;
|
||||
CMatrix3D MatView;
|
||||
|
||||
MatView = m_Orientation.GetTranspose ();
|
||||
|
||||
MatFinal = m_ProjMat * MatView;
|
||||
|
||||
//get the RIGHT plane
|
||||
m_ViewFrustum.SetNumPlanes (6);
|
||||
|
||||
m_ViewFrustum.m_aPlanes[0].m_Norm.X = MatFinal._41-MatFinal._11;
|
||||
m_ViewFrustum.m_aPlanes[0].m_Norm.Y = MatFinal._42-MatFinal._12;
|
||||
m_ViewFrustum.m_aPlanes[0].m_Norm.Z = MatFinal._43-MatFinal._13;
|
||||
m_ViewFrustum.m_aPlanes[0].m_Dist = MatFinal._44-MatFinal._14;
|
||||
|
||||
//get the LEFT plane
|
||||
m_ViewFrustum.m_aPlanes[1].m_Norm.X = MatFinal._41+MatFinal._11;
|
||||
m_ViewFrustum.m_aPlanes[1].m_Norm.Y = MatFinal._42+MatFinal._12;
|
||||
m_ViewFrustum.m_aPlanes[1].m_Norm.Z = MatFinal._43+MatFinal._13;
|
||||
m_ViewFrustum.m_aPlanes[1].m_Dist = MatFinal._44+MatFinal._14;
|
||||
|
||||
//get the BOTTOM plane
|
||||
m_ViewFrustum.m_aPlanes[2].m_Norm.X = MatFinal._41+MatFinal._21;
|
||||
m_ViewFrustum.m_aPlanes[2].m_Norm.Y = MatFinal._42+MatFinal._22;
|
||||
m_ViewFrustum.m_aPlanes[2].m_Norm.Z = MatFinal._43+MatFinal._23;
|
||||
m_ViewFrustum.m_aPlanes[2].m_Dist = MatFinal._44+MatFinal._24;
|
||||
|
||||
//get the TOP plane
|
||||
m_ViewFrustum.m_aPlanes[3].m_Norm.X = MatFinal._41-MatFinal._21;
|
||||
m_ViewFrustum.m_aPlanes[3].m_Norm.Y = MatFinal._42-MatFinal._22;
|
||||
m_ViewFrustum.m_aPlanes[3].m_Norm.Z = MatFinal._43-MatFinal._23;
|
||||
m_ViewFrustum.m_aPlanes[3].m_Dist = MatFinal._44-MatFinal._24;
|
||||
|
||||
//get the FAR plane
|
||||
m_ViewFrustum.m_aPlanes[4].m_Norm.X = MatFinal._41-MatFinal._31;
|
||||
m_ViewFrustum.m_aPlanes[4].m_Norm.Y = MatFinal._42-MatFinal._32;
|
||||
m_ViewFrustum.m_aPlanes[4].m_Norm.Z = MatFinal._43-MatFinal._33;
|
||||
m_ViewFrustum.m_aPlanes[4].m_Dist = MatFinal._44-MatFinal._34;
|
||||
|
||||
//get the NEAR plane
|
||||
m_ViewFrustum.m_aPlanes[5].m_Norm.X = MatFinal._41+MatFinal._31;
|
||||
m_ViewFrustum.m_aPlanes[5].m_Norm.Y = MatFinal._42+MatFinal._32;
|
||||
m_ViewFrustum.m_aPlanes[5].m_Norm.Z = MatFinal._43+MatFinal._33;
|
||||
m_ViewFrustum.m_aPlanes[5].m_Dist = MatFinal._44+MatFinal._34;
|
||||
}
|
||||
|
||||
void CCamera::SetViewPort (SViewPort *viewport)
|
||||
{
|
||||
m_ViewPort.m_X = viewport->m_X;
|
||||
m_ViewPort.m_Y = viewport->m_Y;
|
||||
m_ViewPort.m_Width = viewport->m_Width;
|
||||
m_ViewPort.m_Height = viewport->m_Height;
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Camera.H
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CCamera holds a view and a projection matrix.
|
||||
// It also has a frustum which can be used to
|
||||
// cull objects for rendering.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include "Frustum.H"
|
||||
#include "Matrix3D.H"
|
||||
|
||||
//view port
|
||||
struct SViewPort
|
||||
{
|
||||
unsigned int m_X;
|
||||
unsigned int m_Y;
|
||||
unsigned int m_Width;
|
||||
unsigned int m_Height;
|
||||
};
|
||||
|
||||
|
||||
class CCamera
|
||||
{
|
||||
public:
|
||||
CCamera ();
|
||||
~CCamera ();
|
||||
|
||||
//Methods for projection
|
||||
void SetProjection (CMatrix3D *proj) { m_ProjMat = *proj; }
|
||||
void SetProjection (float nearp, float farp, float fov);
|
||||
CMatrix3D GetProjection () { return m_ProjMat; }
|
||||
|
||||
//Updates the frustum planes. Should be called
|
||||
//everytime the view or projection matrices are
|
||||
//altered.
|
||||
void UpdateFrustum ();
|
||||
CFrustum GetFustum () { return m_ViewFrustum; }
|
||||
|
||||
void SetViewPort (SViewPort *viewport);
|
||||
SViewPort GetViewPort () { return m_ViewPort; }
|
||||
|
||||
//getters
|
||||
float GetNearPlane () { return m_NearPlane; }
|
||||
float GetFarPlane () { return m_FarPlane; }
|
||||
float GetFOV () { return m_FOV; }
|
||||
|
||||
public:
|
||||
//This is the orientation matrix. The inverse of this
|
||||
//is the view matrix
|
||||
CMatrix3D m_Orientation;
|
||||
|
||||
private:
|
||||
//keep the projection matrix private
|
||||
//so we can't fiddle with it.
|
||||
CMatrix3D m_ProjMat;
|
||||
|
||||
float m_NearPlane;
|
||||
float m_FarPlane;
|
||||
float m_FOV;
|
||||
SViewPort m_ViewPort;
|
||||
|
||||
CFrustum m_ViewFrustum;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,144 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Frustum.Cpp
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CFrustum is a collection of planes which define
|
||||
// a viewing space. Usually associated with the
|
||||
// camera, there are 6 planes which define the
|
||||
// view pyramid. But we allow more planes per
|
||||
// frustum which maybe used for portal rendering,
|
||||
// where a portal may have 3 or more edges.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Frustum.H"
|
||||
|
||||
CFrustum::CFrustum ()
|
||||
{
|
||||
m_NumPlanes = 0;
|
||||
}
|
||||
|
||||
CFrustum::~CFrustum ()
|
||||
{
|
||||
}
|
||||
|
||||
void CFrustum::SetNumPlanes (int num)
|
||||
{
|
||||
m_NumPlanes = num;
|
||||
|
||||
//clip it
|
||||
if (m_NumPlanes >= MAX_NUM_FRUSTUM_PLANES)
|
||||
m_NumPlanes = MAX_NUM_FRUSTUM_PLANES-1;
|
||||
else if (m_NumPlanes < 0)
|
||||
m_NumPlanes = 0;
|
||||
}
|
||||
|
||||
bool CFrustum::IsPointVisible (CVector3D &point)
|
||||
{
|
||||
PLANESIDE Side;
|
||||
|
||||
for (int i=0; i<m_NumPlanes; i++)
|
||||
{
|
||||
Side = m_aPlanes[i].ClassifyPoint (point);
|
||||
|
||||
if (Side == PS_BACK)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFrustum::IsSphereVisible (CVector3D ¢er, float radius)
|
||||
{
|
||||
for (int i=0; i<m_NumPlanes; i++)
|
||||
{
|
||||
float Dist = m_aPlanes[i].DistanceToPlane (center);
|
||||
|
||||
//is it behind the plane
|
||||
if (Dist < 0)
|
||||
{
|
||||
//if non of it falls in front its outside the
|
||||
//frustum
|
||||
if (-Dist > radius)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CFrustum::IsBoxVisible (CVector3D &position, SBoundingBox &bounds)
|
||||
{
|
||||
//basically for every plane we calculate the furthust point
|
||||
//in the box to that plane. If that point is beyond the plane
|
||||
//then the box is not visible
|
||||
CVector3D FarPoint;
|
||||
PLANESIDE Side;
|
||||
CVector3D Min = position+bounds.m_BoxMin;
|
||||
CVector3D Max = position+bounds.m_BoxMax;
|
||||
|
||||
for (int i=0; i<m_NumPlanes; i++)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.X > 0.0f)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Y > 0.0f)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Max.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Max.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Min.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Max.X; FarPoint.Y = Min.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Y > 0.0f)
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Max.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Max.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_aPlanes[i].m_Norm.Z > 0.0f)
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Min.Y; FarPoint.Z = Max.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
FarPoint.X = Min.X; FarPoint.Y = Min.Y; FarPoint.Z = Min.Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Side = m_aPlanes[i].ClassifyPoint (FarPoint);
|
||||
|
||||
if (Side == PS_BACK)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Frustum.H
|
||||
// Last Update: 24/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CFrustum is a collection of planes which define
|
||||
// a viewing space. Usually associated with the
|
||||
// camera, there are 6 planes which define the
|
||||
// view pyramid. But we allow more planes per
|
||||
// frustum which maybe used for portal rendering,
|
||||
// where a portal may have 3 or more edges.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef FRUSTUM_H
|
||||
#define FRUSTUM_H
|
||||
|
||||
#include "Plane.H"
|
||||
|
||||
//10 planes should be enough
|
||||
#define MAX_NUM_FRUSTUM_PLANES (10)
|
||||
|
||||
|
||||
struct SBoundingBox
|
||||
{
|
||||
CVector3D m_BoxMin;
|
||||
CVector3D m_BoxMax;
|
||||
};
|
||||
|
||||
class CFrustum
|
||||
{
|
||||
public:
|
||||
CFrustum ();
|
||||
~CFrustum ();
|
||||
|
||||
//Set the number of planes to use for
|
||||
//calculations. This is clipped to
|
||||
//[0,MAX_NUM_FRUSTUM_PLANES]
|
||||
void SetNumPlanes (int num);
|
||||
|
||||
//The following methods return true if the shape is
|
||||
//partially or completely in front of the frustum planes
|
||||
bool IsPointVisible (CVector3D &point);
|
||||
bool IsSphereVisible (CVector3D ¢er, float radius);
|
||||
bool IsBoxVisible (CVector3D &position, SBoundingBox &bounds);
|
||||
|
||||
public:
|
||||
//make the planes public for ease of use
|
||||
CPlane m_aPlanes[MAX_NUM_FRUSTUM_PLANES];
|
||||
|
||||
private:
|
||||
int m_NumPlanes;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: MathUtil.Cpp
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This file contains some maths related
|
||||
// utility macros and fucntions.
|
||||
//
|
||||
//***********************************************************
|
||||
unsigned int F2DW (float f)
|
||||
{
|
||||
return *((unsigned int*)&f);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: MathUtil.H
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This file contains some maths related
|
||||
// utility macros and fucntions.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef MATHUTIL_H
|
||||
#define MATHUTIL_H
|
||||
|
||||
#define PI 3.14159265358979323846f
|
||||
|
||||
#define DEGTORAD(a) (((a) * PI) / 180.0f)
|
||||
#define SQR(x) ((x) * (x))
|
||||
#define MAX(a,b) ((a < b) ? (b) : (a))
|
||||
#define MIN(a,b) ((a < b) ? (a) : (b))
|
||||
#define MAX3(a,b,c) ( MAX (MAX(a,b), c) )
|
||||
#define ABS(a) ((a > 0) ? (a) : (-a))
|
||||
|
||||
//extern unsigned int F2DW (float f);
|
||||
|
||||
#endif
|
@ -1,384 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Matrix3D.Cpp
|
||||
// Last Update: 31/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Matrix class used for holding and
|
||||
// manipulating transformation info.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Matrix3D.H"
|
||||
|
||||
CMatrix3D::CMatrix3D ()
|
||||
{
|
||||
SetIdentity ();
|
||||
}
|
||||
|
||||
//Matrix multiplication
|
||||
CMatrix3D CMatrix3D::operator * (CMatrix3D &matrix)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
|
||||
Temp._11 = _11*matrix._11 +
|
||||
_12*matrix._21 +
|
||||
_13*matrix._31 +
|
||||
_14*matrix._41;
|
||||
|
||||
Temp._12 = _11*matrix._12 +
|
||||
_12*matrix._22 +
|
||||
_13*matrix._32 +
|
||||
_14*matrix._42;
|
||||
|
||||
Temp._13 = _11*matrix._13 +
|
||||
_12*matrix._23 +
|
||||
_13*matrix._33 +
|
||||
_14*matrix._43;
|
||||
|
||||
Temp._14 = _11*matrix._14 +
|
||||
_12*matrix._24 +
|
||||
_13*matrix._34 +
|
||||
_14*matrix._44;
|
||||
|
||||
Temp._21 = _21*matrix._11 +
|
||||
_22*matrix._21 +
|
||||
_23*matrix._31 +
|
||||
_24*matrix._41;
|
||||
|
||||
Temp._22 = _21*matrix._12 +
|
||||
_22*matrix._22 +
|
||||
_23*matrix._32 +
|
||||
_24*matrix._42;
|
||||
|
||||
Temp._23 = _21*matrix._13 +
|
||||
_22*matrix._23 +
|
||||
_23*matrix._33 +
|
||||
_24*matrix._43;
|
||||
|
||||
Temp._24 = _21*matrix._14 +
|
||||
_22*matrix._24 +
|
||||
_23*matrix._34 +
|
||||
_24*matrix._44;
|
||||
|
||||
Temp._31 = _31*matrix._11 +
|
||||
_32*matrix._21 +
|
||||
_33*matrix._31 +
|
||||
_34*matrix._41;
|
||||
|
||||
Temp._32 = _31*matrix._12 +
|
||||
_32*matrix._22 +
|
||||
_33*matrix._32 +
|
||||
_34*matrix._42;
|
||||
|
||||
Temp._33 = _31*matrix._13 +
|
||||
_32*matrix._23 +
|
||||
_33*matrix._33 +
|
||||
_34*matrix._43;
|
||||
|
||||
Temp._34 = _31*matrix._14 +
|
||||
_32*matrix._24 +
|
||||
_33*matrix._34 +
|
||||
_34*matrix._44;
|
||||
|
||||
Temp._41 = _41*matrix._11 +
|
||||
_42*matrix._21 +
|
||||
_43*matrix._31 +
|
||||
_44*matrix._41;
|
||||
|
||||
Temp._42 = _41*matrix._12 +
|
||||
_42*matrix._22 +
|
||||
_43*matrix._32 +
|
||||
_44*matrix._42;
|
||||
|
||||
Temp._43 = _41*matrix._13 +
|
||||
_42*matrix._23 +
|
||||
_43*matrix._33 +
|
||||
_44*matrix._43;
|
||||
|
||||
Temp._44 = _41*matrix._14 +
|
||||
_42*matrix._24 +
|
||||
_43*matrix._34 +
|
||||
_44*matrix._44;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Matrix multiplication/assignment
|
||||
CMatrix3D &CMatrix3D::operator *= (CMatrix3D &matrix)
|
||||
{
|
||||
CMatrix3D &Temp = (*this) * matrix;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Sets the identity matrix
|
||||
void CMatrix3D::SetIdentity ()
|
||||
{
|
||||
_11=1.0f; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=1.0f; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=1.0f; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//Sets the zero matrix
|
||||
void CMatrix3D::SetZero ()
|
||||
{
|
||||
_11=0.0f; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=0.0f; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=0.0f; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=0.0f;
|
||||
}
|
||||
|
||||
//The following clear the matrix and set the
|
||||
//rotation of each of the 3 axes
|
||||
|
||||
void CMatrix3D::SetXRotation (float angle)
|
||||
{
|
||||
float Cos = cosf (angle);
|
||||
float Sin = sinf (angle);
|
||||
|
||||
_11=1.0f; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=Cos; _23=-Sin; _24=0.0f;
|
||||
_31=0.0f; _32=Sin; _33=Cos; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
void CMatrix3D::SetYRotation (float angle)
|
||||
{
|
||||
float Cos = cosf (angle);
|
||||
float Sin = sinf (angle);
|
||||
|
||||
_11=Cos; _12=0.0f; _13=Sin; _14=0.0f;
|
||||
_21=0.0f; _22=1.0f; _23=0.0f; _24=0.0f;
|
||||
_31=-Sin; _32=0.0f; _33=Cos; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
void CMatrix3D::SetZRotation (float angle)
|
||||
{
|
||||
float Cos = cosf (angle);
|
||||
float Sin = sinf (angle);
|
||||
|
||||
_11=Cos; _12=-Sin; _13=0.0f; _14=0.0f;
|
||||
_21=Sin; _22=Cos; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=1.0f; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//The following apply a rotation to the matrix
|
||||
//about each of the axes;
|
||||
|
||||
void CMatrix3D::RotateX (float angle)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetXRotation (angle);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
void CMatrix3D::RotateY (float angle)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetYRotation (angle);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
void CMatrix3D::RotateZ (float angle)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetZRotation (angle);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
//Sets the translation of the matrix
|
||||
void CMatrix3D::SetTranslation (float x, float y, float z)
|
||||
{
|
||||
_11=1.0f; _12=0.0f; _13=0.0f; _14=x;
|
||||
_21=0.0f; _22=1.0f; _23=0.0f; _24=y;
|
||||
_31=0.0f; _32=0.0f; _33=1.0f; _34=z;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
void CMatrix3D::SetTranslation (CVector3D &vector)
|
||||
{
|
||||
SetTranslation (vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
//Applies a translation to the matrix
|
||||
void CMatrix3D::Translate (float x, float y, float z)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetTranslation (x, y, z);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
void CMatrix3D::Translate (CVector3D &vector)
|
||||
{
|
||||
Translate (vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
CVector3D CMatrix3D::GetTranslation ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _14;
|
||||
Temp.Y = _24;
|
||||
Temp.Z = _34;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Clears and sets the scaling of the matrix
|
||||
void CMatrix3D::SetScaling (float x_scale, float y_scale, float z_scale)
|
||||
{
|
||||
_11=x_scale; _12=0.0f; _13=0.0f; _14=0.0f;
|
||||
_21=0.0f; _22=y_scale; _23=0.0f; _24=0.0f;
|
||||
_31=0.0f; _32=0.0f; _33=z_scale; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//Scales the matrix
|
||||
void CMatrix3D::Scale (float x_scale, float y_scale, float z_scale)
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
Temp.SetScaling (x_scale, y_scale, z_scale);
|
||||
|
||||
(*this) = Temp * (*this);
|
||||
}
|
||||
|
||||
//Returns the transpose of the matrix. For orthonormal
|
||||
//matrices, this is the same is the inverse matrix
|
||||
CMatrix3D CMatrix3D::GetTranspose ()
|
||||
{
|
||||
CMatrix3D Temp;
|
||||
|
||||
Temp._11 = _11;
|
||||
Temp._21 = _12;
|
||||
Temp._31 = _13;
|
||||
Temp._41 = 0.0f;
|
||||
|
||||
Temp._12 = _21;
|
||||
Temp._22 = _22;
|
||||
Temp._32 = _23;
|
||||
Temp._42 = 0.0f;
|
||||
|
||||
Temp._13 = _31;
|
||||
Temp._23 = _32;
|
||||
Temp._33 = _33;
|
||||
Temp._43 = 0.0f;
|
||||
|
||||
Temp._14 = 0.0f;
|
||||
Temp._24 = 0.0f;
|
||||
Temp._34 = 0.0f;
|
||||
Temp._44 = 1.0f;
|
||||
|
||||
CMatrix3D Trans;
|
||||
Trans.SetTranslation (-_14, -_24, -_34);
|
||||
|
||||
Temp = Temp * Trans;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Get a vector which points to the left of the matrix
|
||||
CVector3D CMatrix3D::GetLeft ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = -_11;
|
||||
Temp.Y = -_21;
|
||||
Temp.Z = -_31;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Get a vector which points up from the matrix
|
||||
CVector3D CMatrix3D::GetUp ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _12;
|
||||
Temp.Y = _22;
|
||||
Temp.Z = _32;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Get a vector which points to front of the matrix
|
||||
CVector3D CMatrix3D::GetIn ()
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _13;
|
||||
Temp.Y = _23;
|
||||
Temp.Z = _33;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Set the matrix from two vectors (Up and In)
|
||||
void CMatrix3D::SetFromUpIn (CVector3D &up, CVector3D &in, float scale)
|
||||
{
|
||||
CVector3D u = up;
|
||||
CVector3D i = in;
|
||||
|
||||
CVector3D r;
|
||||
|
||||
r = up.Cross (in);
|
||||
|
||||
u.Normalize (); u *= scale;
|
||||
i.Normalize (); i *= scale;
|
||||
r.Normalize (); r *= scale;
|
||||
|
||||
_11=r.X; _12=u.X; _13=i.X; _14=0.0f;
|
||||
_21=r.Y; _22=u.Y; _23=i.Y; _24=0.0f;
|
||||
_31=r.Z; _32=u.Z; _33=i.Z; _34=0.0f;
|
||||
_41=0.0f; _42=0.0f; _43=0.0f; _44=1.0f;
|
||||
}
|
||||
|
||||
//Transform a vector by this matrix
|
||||
CVector3D CMatrix3D::Transform (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _11*vector.X +
|
||||
_12*vector.Y +
|
||||
_13*vector.Z +
|
||||
_14;
|
||||
|
||||
Temp.Y = _21*vector.X +
|
||||
_22*vector.Y +
|
||||
_23*vector.Z +
|
||||
_24;
|
||||
|
||||
Temp.Z = _31*vector.X +
|
||||
_32*vector.Y +
|
||||
_33*vector.Z +
|
||||
_34;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//Only rotate (not translate) a vector by this matrix
|
||||
CVector3D CMatrix3D::Rotate (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = _11*vector.X +
|
||||
_12*vector.Y +
|
||||
_13*vector.Z;
|
||||
|
||||
Temp.Y = _21*vector.X +
|
||||
_22*vector.Y +
|
||||
_23*vector.Z;
|
||||
|
||||
Temp.Z = _31*vector.X +
|
||||
_32*vector.Y +
|
||||
_33*vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Matrix3D.H
|
||||
// Last Update: 31/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Matrix class used for holding and
|
||||
// manipulating transformation info.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef MATRIX3D_H
|
||||
#define MATRIX3D_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "Vector3D.H"
|
||||
|
||||
class CMatrix3D
|
||||
{
|
||||
public:
|
||||
float _11, _12, _13, _14;
|
||||
float _21, _22, _23, _24;
|
||||
float _31, _32, _33, _34;
|
||||
float _41, _42, _43, _44;
|
||||
|
||||
public:
|
||||
CMatrix3D ();
|
||||
|
||||
//Matrix multiplication
|
||||
CMatrix3D operator * (CMatrix3D &matrix);
|
||||
//Matrix multiplication/assignment
|
||||
CMatrix3D &operator *= (CMatrix3D &matrix);
|
||||
|
||||
//Sets the identity matrix
|
||||
void SetIdentity ();
|
||||
//Sets the zero matrix
|
||||
void SetZero ();
|
||||
|
||||
//The following clear the matrix and set the
|
||||
//rotation of each of the 3 axes
|
||||
void SetXRotation (float angle);
|
||||
void SetYRotation (float angle);
|
||||
void SetZRotation (float angle);
|
||||
|
||||
//The following apply a rotation to the matrix
|
||||
//about each of the axes;
|
||||
void RotateX (float angle);
|
||||
void RotateY (float angle);
|
||||
void RotateZ (float angle);
|
||||
|
||||
//Sets the translation of the matrix
|
||||
void SetTranslation (float x, float y, float z);
|
||||
void SetTranslation (CVector3D &vector);
|
||||
|
||||
//Applies a translation to the matrix
|
||||
void Translate (float x, float y, float z);
|
||||
void Translate (CVector3D &vector);
|
||||
|
||||
CVector3D GetTranslation ();
|
||||
|
||||
//Clears and sets the scaling of the matrix
|
||||
void SetScaling (float x_scale, float y_scale, float z_scale);
|
||||
//Scales the matrix
|
||||
void Scale (float x_scale, float y_scale, float z_scale);
|
||||
|
||||
//Returns the transpose of the matrix. For orthonormal
|
||||
//matrices, this is the same is the inverse matrix
|
||||
CMatrix3D GetTranspose ();
|
||||
|
||||
//Get a vector which points to the left of the matrix
|
||||
CVector3D GetLeft ();
|
||||
//Get a vector which points up from the matrix
|
||||
CVector3D GetUp ();
|
||||
//Get a vector which points to front of the matrix
|
||||
CVector3D GetIn ();
|
||||
|
||||
//Set the matrix from two vectors (Up and In)
|
||||
void SetFromUpIn (CVector3D &up, CVector3D &in, float scale);
|
||||
|
||||
public: //Vector manipulation methods
|
||||
//Transform a vector by this matrix
|
||||
CVector3D Transform (CVector3D &vector);
|
||||
//Only rotate (not translate) a vector by this matrix
|
||||
CVector3D Rotate (CVector3D &vector);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
#include "MiniPatch.H"
|
||||
|
||||
CMiniPatch::CMiniPatch()
|
||||
{
|
||||
Tex1 = Tex2 = 0;
|
||||
m_AlphaMap = 0;
|
||||
m_pRightNeighbor = NULL;
|
||||
m_pParrent = NULL;
|
||||
m_Rotation = 0;
|
||||
m_RenderStage = 0;
|
||||
m_LastRenderedFrame = 0;
|
||||
}
|
||||
|
||||
CMiniPatch::~CMiniPatch()
|
||||
{
|
||||
}
|
||||
|
||||
void CMiniPatch::Initialize (STerrainVertex *first_vertex)
|
||||
{
|
||||
m_pVertices = first_vertex;
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#ifndef MINIPATCH_H
|
||||
#define MINIPATCH_H
|
||||
|
||||
#include "Vector3D.H"
|
||||
#include "res.h"
|
||||
|
||||
struct STerrainVertex
|
||||
{
|
||||
CVector3D m_Position;
|
||||
float m_Color[2][3];
|
||||
};
|
||||
|
||||
|
||||
class CMiniPatch
|
||||
{
|
||||
public:
|
||||
CMiniPatch();
|
||||
~CMiniPatch();
|
||||
|
||||
void Initialize (STerrainVertex *first_vertex);
|
||||
|
||||
Handle Tex1, Tex2;
|
||||
Handle m_AlphaMap;
|
||||
CMiniPatch *m_pRightNeighbor;
|
||||
CPatch *m_pParrent;
|
||||
unsigned char m_RenderStage;
|
||||
unsigned int m_LastRenderedFrame;
|
||||
|
||||
unsigned char m_Rotation;
|
||||
|
||||
STerrainVertex *m_pVertices;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,61 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Patch.Cpp
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CPatch is a smaller portion of the terrain.
|
||||
// It handles the ROAM implementation and its
|
||||
// own rendering.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Patch.H"
|
||||
|
||||
|
||||
CPatch::CPatch ()
|
||||
{
|
||||
m_pVertices = NULL;
|
||||
}
|
||||
|
||||
CPatch::~CPatch ()
|
||||
{
|
||||
}
|
||||
|
||||
//Initialize the patch
|
||||
void CPatch::Initialize (STerrainVertex *first_vertex)
|
||||
{
|
||||
m_pVertices = first_vertex;
|
||||
|
||||
m_Bounds.m_BoxMin.X = m_pVertices[0].m_Position.X;
|
||||
m_Bounds.m_BoxMin.Z = m_pVertices[0].m_Position.Z;
|
||||
|
||||
m_Bounds.m_BoxMax.X = m_Bounds.m_BoxMin.X + PATCH_SIZE*CELL_SIZE;
|
||||
m_Bounds.m_BoxMax.Z = m_Bounds.m_BoxMin.Z + PATCH_SIZE*CELL_SIZE;
|
||||
|
||||
m_Bounds.m_BoxMin.Y = m_Bounds.m_BoxMin.Y = m_pVertices[0].m_Position.Y;
|
||||
|
||||
for (int j=0; j<PATCH_SIZE+1; j++)
|
||||
{
|
||||
for (int i=0; i<PATCH_SIZE+1; i++)
|
||||
{
|
||||
int pos = j*MAP_SIZE + i;
|
||||
|
||||
if (m_pVertices[pos].m_Position.Y < m_Bounds.m_BoxMin.Y)
|
||||
m_Bounds.m_BoxMin.Y = m_pVertices[pos].m_Position.Y;
|
||||
|
||||
if (m_pVertices[pos].m_Position.Y > m_Bounds.m_BoxMax.Y)
|
||||
m_Bounds.m_BoxMax.Y = m_pVertices[pos].m_Position.Y;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<16; j++)
|
||||
{
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
int pos = (j*MAP_SIZE) + (i);
|
||||
m_MiniPatches[j][i].Initialize ( &m_pVertices[pos] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Patch.H
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CPatch is a smaller portion of the terrain.
|
||||
// It handles its own rendering
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef PATCH_H
|
||||
#define PATCH_H
|
||||
|
||||
#include "Matrix3D.H"
|
||||
#include "Camera.H"
|
||||
#include "TerrGlobals.H"
|
||||
#include "MiniPatch.H"
|
||||
|
||||
class CPatch
|
||||
{
|
||||
public:
|
||||
CPatch ();
|
||||
~CPatch ();
|
||||
|
||||
//initialize the patch
|
||||
void Initialize (STerrainVertex *first_vertex);
|
||||
|
||||
// protected:
|
||||
CMiniPatch m_MiniPatches[16][16];
|
||||
|
||||
SBoundingBox m_Bounds;
|
||||
unsigned int m_LastVisFrame;
|
||||
|
||||
STerrainVertex *m_pVertices;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,138 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Plane.Cpp
|
||||
// Last Update: 17/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Plane in R3 and several utility methods.
|
||||
// Note that the format used for the plane
|
||||
// equation is Ax + By + Cz + D = 0, where
|
||||
// <A,B,C> is the normal vector.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Plane.H"
|
||||
|
||||
CPlane::CPlane ()
|
||||
{
|
||||
m_Norm.Clear ();
|
||||
m_Dist = 0.0f;
|
||||
}
|
||||
|
||||
//sets the plane equation from 3 points on that plane
|
||||
void CPlane::Set (CVector3D &p1, CVector3D &p2, CVector3D &p3)
|
||||
{
|
||||
CVector3D D1, D2;
|
||||
CVector3D Norm;
|
||||
|
||||
//calculate two vectors on the surface of the plane
|
||||
D1 = p2-p1;
|
||||
D2 = p3-p1;
|
||||
|
||||
//cross multiply gives normal
|
||||
Norm = D2.Cross(D1);
|
||||
|
||||
Set (Norm, p1);
|
||||
}
|
||||
|
||||
//sets the plane equation from a normal and a point on
|
||||
//that plane
|
||||
void CPlane::Set (CVector3D &norm, CVector3D &point)
|
||||
{
|
||||
m_Norm = norm;
|
||||
|
||||
m_Dist = - (norm.X * point.X +
|
||||
norm.Y * point.Y +
|
||||
norm.Z * point.Z);
|
||||
|
||||
// Normalize ();
|
||||
}
|
||||
|
||||
//normalizes the plane equation
|
||||
void CPlane::Normalize ()
|
||||
{
|
||||
float Scale;
|
||||
|
||||
Scale = 1.0f/m_Norm.GetLength ();
|
||||
|
||||
m_Norm.X *= Scale;
|
||||
m_Norm.Y *= Scale;
|
||||
m_Norm.Z *= Scale;
|
||||
m_Dist *= Scale;
|
||||
}
|
||||
|
||||
//returns the side of the plane on which this point
|
||||
//lies.
|
||||
PLANESIDE CPlane::ClassifyPoint (CVector3D &point)
|
||||
{
|
||||
float Dist;
|
||||
|
||||
Dist = m_Norm.X * point.X +
|
||||
m_Norm.Y * point.Y +
|
||||
m_Norm.Z * point.Z +
|
||||
m_Dist;
|
||||
|
||||
if (Dist > 0.0f)
|
||||
return PS_FRONT;
|
||||
else if (Dist < 0.0f)
|
||||
return PS_BACK;
|
||||
|
||||
return PS_ON;
|
||||
}
|
||||
|
||||
//solves the plane equation for a particular point
|
||||
float CPlane::DistanceToPlane (CVector3D &point)
|
||||
{
|
||||
float Dist;
|
||||
|
||||
Dist = m_Norm.X * point.X +
|
||||
m_Norm.Y * point.Y +
|
||||
m_Norm.Z * point.Z +
|
||||
m_Dist;
|
||||
|
||||
return Dist;
|
||||
}
|
||||
|
||||
//calculates the intersection point of a line with this
|
||||
//plane. Returns false if there is no intersection
|
||||
bool CPlane::FindLineSegIntersection (CVector3D &start, CVector3D &end, CVector3D *intsect)
|
||||
{
|
||||
PLANESIDE StartS, EndS;
|
||||
CVector3D Dir;
|
||||
float Length;
|
||||
|
||||
//work out where each point is
|
||||
StartS = ClassifyPoint (start);
|
||||
EndS = ClassifyPoint (end);
|
||||
|
||||
//if they are not on opposite sides of the plane return false
|
||||
if (StartS == EndS)
|
||||
return false;
|
||||
|
||||
//work out a normalized vector in the direction start to end
|
||||
Dir = end - start;
|
||||
Dir.Normalize ();
|
||||
|
||||
//a bit of algebra to work out how much we need to scale
|
||||
//this direction vector to get to the plane
|
||||
Length = -m_Norm.Dot(start)/m_Norm.Dot(Dir);
|
||||
|
||||
//scale it by this amount
|
||||
Dir *= Length;
|
||||
|
||||
//workout actual position vector of impact
|
||||
*intsect = start + Dir;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPlane::FindRayIntersection (CVector3D &start, CVector3D &direction, CVector3D *intsect)
|
||||
{
|
||||
float dot = m_Norm.Dot (direction);
|
||||
if (dot == 0.0f)
|
||||
return false;
|
||||
|
||||
CVector3D a;
|
||||
*intsect = start - (direction * (DistanceToPlane (start)/dot));
|
||||
return true;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Plane.H
|
||||
// Last Update: 17/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: A Plane in R3 and several utility methods.
|
||||
// Note that the format used for the plane
|
||||
// equation is Ax + By + Cz + D = 0, where
|
||||
// <A,B,C> is the normal vector.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef PLANE_H
|
||||
#define PLANE_H
|
||||
|
||||
#include "Vector3D.H"
|
||||
|
||||
enum PLANESIDE
|
||||
{
|
||||
PS_FRONT,
|
||||
PS_BACK,
|
||||
PS_ON
|
||||
};
|
||||
|
||||
class CPlane
|
||||
{
|
||||
public:
|
||||
CPlane ();
|
||||
|
||||
//sets the plane equation from 3 points on that plane
|
||||
void Set (CVector3D &p1, CVector3D &p2, CVector3D &p3);
|
||||
|
||||
//sets the plane equation from a normal and a point on
|
||||
//that plane
|
||||
void Set (CVector3D &norm, CVector3D &point);
|
||||
|
||||
//normalizes the plane equation
|
||||
void Normalize ();
|
||||
|
||||
//returns the side of the plane on which this point
|
||||
//lies.
|
||||
PLANESIDE ClassifyPoint (CVector3D &point);
|
||||
|
||||
//solves the plane equation for a particular point
|
||||
float DistanceToPlane (CVector3D &point);
|
||||
|
||||
//calculates the intersection point of a line with this
|
||||
//plane. Returns false if there is no intersection
|
||||
bool FindLineSegIntersection (CVector3D &start, CVector3D &end, CVector3D *intsect);
|
||||
bool FindRayIntersection (CVector3D &start, CVector3D &direction, CVector3D *intsect);
|
||||
|
||||
public:
|
||||
CVector3D m_Norm; //normal vector of the plane
|
||||
float m_Dist; //Plane distance (ie D in the plane eq.)
|
||||
};
|
||||
|
||||
#endif
|
@ -1,509 +0,0 @@
|
||||
#include "Renderer.H"
|
||||
#include "Matrix3D.H"
|
||||
#include "Camera.H"
|
||||
|
||||
#include "types.h"
|
||||
#include "ogl.h"
|
||||
#include "tex.h"
|
||||
|
||||
#define RENDER_STAGE_BASE (1)
|
||||
#define RENDER_STAGE_TRANS (2)
|
||||
|
||||
bool g_WireFrame = false;
|
||||
unsigned int g_FrameCounter = 0;
|
||||
|
||||
CRenderer::CRenderer ()
|
||||
{
|
||||
m_Timer = 0;
|
||||
m_CurrentSeason = 0;
|
||||
}
|
||||
|
||||
CRenderer::~CRenderer ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool CRenderer::Initialize (HWND hwnd, int width, int height, int depth)
|
||||
{
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Depth = depth;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CRenderer::Shutdown ()
|
||||
{
|
||||
|
||||
}
|
||||
/*
|
||||
struct Tile
|
||||
{
|
||||
u32 pri_tex : 5;
|
||||
u32 sec_tex : 5;
|
||||
u32 alpha_map : 6;
|
||||
};
|
||||
|
||||
|
||||
void render_terrain()
|
||||
{
|
||||
CMatrix3D view = camera->m_Orientation.GetTranspose();
|
||||
CMatrix3D proj = camera->GetProjection();
|
||||
|
||||
float gl_view[16] = {view._11, view._21, view._31, view._41,
|
||||
view._12, view._22, view._32, view._42,
|
||||
view._13, view._23, view._33, view._43,
|
||||
view._14, view._24, view._34, view._44};
|
||||
|
||||
float gl_proj[16] = {proj._11, proj._21, proj._31, proj._41,
|
||||
proj._12, proj._22, proj._32, proj._42,
|
||||
proj._13, proj._23, proj._33, proj._43,
|
||||
proj._14, proj._24, proj._34, proj._44};
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadMatrixf (gl_view);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadMatrixf (gl_proj);
|
||||
|
||||
SViewPort vp = camera->GetViewPort();
|
||||
glViewport (vp.m_X, vp.m_Y, vp.m_Width, vp.m_Height);
|
||||
|
||||
if (g_WireFrame)
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
else
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
|
||||
for (int j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (camera->GetFustum().IsBoxVisible (CVector3D(0,0,0), terrain->m_Patches[j][i].m_Bounds))
|
||||
terrain->m_Patches[j][i].m_LastVisFrame = g_FrameCounter;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (terrain->m_Patches[j][i].m_LastVisFrame == g_FrameCounter)
|
||||
render_patch(&terrain->m_Patches[j][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
void CRenderer::RenderTerrain (CTerrain *terrain, CCamera *camera)
|
||||
{
|
||||
// m_Timer += 0.001f;
|
||||
|
||||
if (m_Timer > 1.0f)
|
||||
{
|
||||
m_Timer = 0;
|
||||
|
||||
if (m_CurrentSeason == 0)
|
||||
m_CurrentSeason = 1;
|
||||
else
|
||||
m_CurrentSeason = 0;
|
||||
}
|
||||
|
||||
CMatrix3D view = camera->m_Orientation.GetTranspose();
|
||||
CMatrix3D proj = camera->GetProjection();
|
||||
|
||||
float gl_view[16] = {view._11, view._21, view._31, view._41,
|
||||
view._12, view._22, view._32, view._42,
|
||||
view._13, view._23, view._33, view._43,
|
||||
view._14, view._24, view._34, view._44};
|
||||
|
||||
float gl_proj[16] = {proj._11, proj._21, proj._31, proj._41,
|
||||
proj._12, proj._22, proj._32, proj._42,
|
||||
proj._13, proj._23, proj._33, proj._43,
|
||||
proj._14, proj._24, proj._34, proj._44};
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadMatrixf (gl_view);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadMatrixf (gl_proj);
|
||||
|
||||
SViewPort vp = camera->GetViewPort();
|
||||
glViewport (vp.m_X, vp.m_Y, vp.m_Width, vp.m_Height);
|
||||
|
||||
if (g_WireFrame)
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
else
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
|
||||
for (int j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (camera->GetFustum().IsBoxVisible (CVector3D(0,0,0), terrain->m_Patches[j][i].m_Bounds))
|
||||
terrain->m_Patches[j][i].m_LastVisFrame = g_FrameCounter;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (terrain->m_Patches[j][i].m_LastVisFrame == g_FrameCounter)
|
||||
RenderPatchBase (&terrain->m_Patches[j][i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
if (terrain->m_Patches[j][i].m_LastVisFrame == g_FrameCounter)
|
||||
RenderPatchTrans (&terrain->m_Patches[j][i]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CRenderer::RenderPatchBase (CPatch *patch)
|
||||
{
|
||||
CMiniPatch *MPatch, *MPCurrent;
|
||||
|
||||
float StartU, StartV;
|
||||
|
||||
|
||||
for (int j=0; j<16; j++)
|
||||
{
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
MPatch = &(patch->m_MiniPatches[j][i]);
|
||||
|
||||
if (MPatch->m_LastRenderedFrame == g_FrameCounter)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
MPatch->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPatch->m_RenderStage = RENDER_STAGE_BASE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
tex_bind(MPatch->Tex1);
|
||||
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
/////////////////////////////////////
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
||||
/////////////////////////////////////
|
||||
|
||||
StartU = 0.5f * (float)(i%2);
|
||||
StartV = 0.5f * (float)(j%2);
|
||||
|
||||
float tu[2], tv[2];
|
||||
tu[0] = tu[1] = StartU;
|
||||
tv[0] = StartV+0.125f;
|
||||
tv[1] = StartV;
|
||||
|
||||
for (int row=0; row<16; row++)
|
||||
{
|
||||
MPCurrent = MPatch;
|
||||
glBegin (GL_TRIANGLE_STRIP);
|
||||
|
||||
int start = 0;
|
||||
|
||||
while (MPCurrent)
|
||||
{
|
||||
bool ExitFlag;
|
||||
|
||||
if (!MPCurrent->m_pRightNeighbor)
|
||||
ExitFlag = true;
|
||||
else
|
||||
{
|
||||
if (MPCurrent->m_pRightNeighbor->Tex1 == MPCurrent->Tex1 &&
|
||||
MPCurrent->m_pRightNeighbor->m_pParrent->m_LastVisFrame == g_FrameCounter)
|
||||
ExitFlag = false;
|
||||
else
|
||||
ExitFlag = true;
|
||||
}
|
||||
|
||||
for (int x=start; x<16; x++)
|
||||
{
|
||||
int v1 = ((row+1)*MAP_SIZE) + x;
|
||||
int v2 = (row*MAP_SIZE) + x;
|
||||
|
||||
float factor = m_Timer;
|
||||
if (m_CurrentSeason == 1)
|
||||
factor = 1.0f - factor;
|
||||
|
||||
float color1[3] = {MPCurrent->m_pVertices[v1].m_Color[0][0]*factor + MPCurrent->m_pVertices[v1].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][1]*factor + MPCurrent->m_pVertices[v1].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][2]*factor + MPCurrent->m_pVertices[v1].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
float color2[3] = {MPCurrent->m_pVertices[v2].m_Color[0][0]*factor + MPCurrent->m_pVertices[v2].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][1]*factor + MPCurrent->m_pVertices[v2].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][2]*factor + MPCurrent->m_pVertices[v2].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
glTexCoord2f (tu[0], tv[0]);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color1[0],color1[1],color1[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v1].m_Position.X,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Z);
|
||||
|
||||
glTexCoord2f (tu[1], tv[1]);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color2[0],color2[1],color2[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v2].m_Position.X,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Z);
|
||||
|
||||
tu[0]+=0.125f;
|
||||
tu[1]+=0.125f;
|
||||
}
|
||||
|
||||
if (ExitFlag)
|
||||
break;
|
||||
|
||||
MPCurrent = MPCurrent->m_pRightNeighbor;
|
||||
MPCurrent->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPCurrent->m_RenderStage = RENDER_STAGE_BASE;
|
||||
start = 1;
|
||||
}
|
||||
|
||||
tv[0]+=0.125f;
|
||||
tv[1]+=0.125f;
|
||||
|
||||
tu[0] = StartU;
|
||||
tu[1] = StartU;
|
||||
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CRenderer::RenderPatchTrans (CPatch *patch)
|
||||
{
|
||||
CMiniPatch *MPatch, *MPCurrent;
|
||||
|
||||
float StartU, StartV;
|
||||
|
||||
glEnable (GL_BLEND);
|
||||
glDepthFunc (GL_EQUAL);
|
||||
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
for (int j=0; j<16; j++)
|
||||
{
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
MPatch = &(patch->m_MiniPatches[j][i]);
|
||||
|
||||
if (MPatch->m_LastRenderedFrame == g_FrameCounter &&
|
||||
MPatch->m_RenderStage == RENDER_STAGE_TRANS)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
MPatch->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPatch->m_RenderStage = RENDER_STAGE_TRANS;
|
||||
}
|
||||
|
||||
//now for transition
|
||||
if (MPatch->Tex2 && MPatch->m_AlphaMap)
|
||||
{
|
||||
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
tex_bind(MPatch->Tex2);
|
||||
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
/////////////////////////////////////
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
||||
/////////////////////////////////////
|
||||
|
||||
|
||||
glActiveTexture (GL_TEXTURE1);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
tex_bind(MPatch->m_AlphaMap);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
/////////////////////////////////////
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
||||
/////////////////////////////////////
|
||||
|
||||
StartU = 0.5f * (float)(i%2);
|
||||
StartV = 0.5f * (float)(j%2);
|
||||
|
||||
float tu[2], tv[2];
|
||||
tu[0] = tu[1] = StartU;
|
||||
tv[0] = StartV+0.125f;
|
||||
tv[1] = StartV;
|
||||
|
||||
for (int row=0; row<16; row++)
|
||||
{
|
||||
glBegin (GL_TRIANGLE_STRIP);
|
||||
MPCurrent = MPatch;
|
||||
|
||||
while (MPCurrent)
|
||||
{
|
||||
int count;
|
||||
bool ExitFlag;
|
||||
|
||||
if (!MPCurrent->m_pRightNeighbor)
|
||||
{
|
||||
count = 17;
|
||||
ExitFlag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MPCurrent->m_pRightNeighbor->Tex2 == MPCurrent->Tex2 &&
|
||||
MPCurrent->m_pRightNeighbor->m_AlphaMap == MPCurrent->m_AlphaMap &&
|
||||
MPCurrent->m_pRightNeighbor->m_pParrent->m_LastVisFrame == g_FrameCounter)
|
||||
{
|
||||
count = 16;
|
||||
ExitFlag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 17;
|
||||
ExitFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int x=0; x<count; x++)
|
||||
{
|
||||
int v1 = ((row+1)*MAP_SIZE) + x;
|
||||
int v2 = (row*MAP_SIZE) + x;
|
||||
|
||||
float factor = m_Timer;
|
||||
if (m_CurrentSeason == 1)
|
||||
factor = 1.0f - factor;
|
||||
|
||||
float color1[3] = {MPCurrent->m_pVertices[v1].m_Color[0][0]*factor + MPCurrent->m_pVertices[v1].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][1]*factor + MPCurrent->m_pVertices[v1].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v1].m_Color[0][2]*factor + MPCurrent->m_pVertices[v1].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
float color2[3] = {MPCurrent->m_pVertices[v2].m_Color[0][0]*factor + MPCurrent->m_pVertices[v2].m_Color[1][0]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][1]*factor + MPCurrent->m_pVertices[v2].m_Color[1][1]*(1.0f-factor),
|
||||
MPCurrent->m_pVertices[v2].m_Color[0][2]*factor + MPCurrent->m_pVertices[v2].m_Color[1][2]*(1.0f-factor)};
|
||||
|
||||
glMultiTexCoord2f (GL_TEXTURE0_ARB, tu[0], tv[0]);
|
||||
glMultiTexCoord2f (GL_TEXTURE1_ARB, tu[0]*2, tv[0]*2);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color1[0],color1[1],color1[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v1].m_Position.X,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v1].m_Position.Z);
|
||||
|
||||
glMultiTexCoord2f (GL_TEXTURE0_ARB, tu[1], tv[1]);
|
||||
glMultiTexCoord2f (GL_TEXTURE1_ARB, tu[1]*2, tv[1]*2);
|
||||
|
||||
if (g_HillShading)
|
||||
glColor3f (color2[0],color2[1],color2[2]);
|
||||
else
|
||||
glColor3f (1,1,1);
|
||||
|
||||
glVertex3f (MPCurrent->m_pVertices[v2].m_Position.X,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Y,
|
||||
MPCurrent->m_pVertices[v2].m_Position.Z);
|
||||
|
||||
tu[0]+=0.125f;
|
||||
tu[1]+=0.125f;
|
||||
}
|
||||
|
||||
if (ExitFlag)
|
||||
break;
|
||||
|
||||
MPCurrent = MPCurrent->m_pRightNeighbor;
|
||||
MPCurrent->m_LastRenderedFrame = g_FrameCounter;
|
||||
MPCurrent->m_RenderStage = RENDER_STAGE_TRANS;
|
||||
}
|
||||
|
||||
tv[0]+=0.125f;
|
||||
tv[1]+=0.125f;
|
||||
tu[0] = tu[1] = StartU;
|
||||
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
glDisable (GL_BLEND);
|
||||
glActiveTexture (GL_TEXTURE1);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void CRenderer::RenderTileOutline (CMiniPatch *mpatch)
|
||||
{
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glLineWidth (4);
|
||||
|
||||
STerrainVertex V[4];
|
||||
V[0] = mpatch->m_pVertices[0];
|
||||
V[1] = mpatch->m_pVertices[1];
|
||||
V[2] = mpatch->m_pVertices[MAP_SIZE*1 + 1];
|
||||
V[3] = mpatch->m_pVertices[MAP_SIZE*1];
|
||||
|
||||
glColor3f (0,1.0f,0);
|
||||
|
||||
glBegin (GL_LINE_LOOP);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
glVertex3fv(&V[i].m_Position.X);
|
||||
|
||||
glEnd ();
|
||||
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
#include <windows.h>
|
||||
#include "ogl.h"
|
||||
|
||||
#include "Terrain.H"
|
||||
|
||||
extern bool g_WireFrame;
|
||||
extern unsigned int g_FrameCounter;
|
||||
|
||||
class CRenderer
|
||||
{
|
||||
public:
|
||||
CRenderer();
|
||||
~CRenderer();
|
||||
|
||||
bool Initialize (HWND hwnd, int width, int height, int depth);
|
||||
void Shutdown ();
|
||||
|
||||
void RenderTerrain (CTerrain *terrain, CCamera *camera);
|
||||
void RenderTileOutline (CMiniPatch *mpatch);
|
||||
|
||||
protected:
|
||||
void RenderPatchBase (CPatch *patch);
|
||||
void RenderPatchTrans (CPatch *patch);
|
||||
|
||||
protected:
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
int m_Depth;
|
||||
|
||||
///THERE ARE NOT SUPPOSED TO BE HERE
|
||||
float m_Timer;
|
||||
int m_CurrentSeason;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: TerrGlobals.H
|
||||
// Last Update: 27/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Some globals and macros, used by the CTerrain
|
||||
// and CPatch
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TERRGLOBALS_H
|
||||
#define TERRGLOBALS_H
|
||||
|
||||
const int PATCH_SIZE = 16;
|
||||
const int CELL_SIZE = 4; //horizontal scale of the patches
|
||||
const float HEIGHT_SCALE = 1.0f;
|
||||
|
||||
//only 3x3 patches loaded at a time
|
||||
const int NUM_PATCHES_PER_SIDE = 20;
|
||||
|
||||
//must be odd number of patches
|
||||
//#define TERRAIN_CHUNK_SIZE (PATCH_SIZE*NUM_PATCHES_PER_SIDE)
|
||||
const int MAP_SIZE = ( (NUM_PATCHES_PER_SIDE*PATCH_SIZE)+1 );
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,192 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Terrain.Cpp
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CTerrain handles the terrain portion of the
|
||||
// engine. It holds open the file to the terrain
|
||||
// information, so terrain data can be loaded
|
||||
// dynamically. We use a ROAM method to render
|
||||
// the terrain, ie using binary triangle trees.
|
||||
// The terrain consists of smaller PATCHS, which
|
||||
// do most of the work.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Terrain.H"
|
||||
#include "tex.h"
|
||||
|
||||
bool g_HillShading = true;
|
||||
|
||||
CVector3D SeasonLight[2];
|
||||
float SeasonColor[2][3];
|
||||
|
||||
CTerrain::CTerrain ()
|
||||
{
|
||||
m_pVertices = NULL;
|
||||
}
|
||||
|
||||
CTerrain::~CTerrain ()
|
||||
{
|
||||
delete [] m_pVertices;
|
||||
}
|
||||
|
||||
bool CTerrain::Initalize (char *filename)
|
||||
{
|
||||
SeasonLight[0].Set (3, -1, 3);
|
||||
SeasonLight[0].Normalize();
|
||||
SeasonColor[0][0] = 0.8f; SeasonColor[0][1] = 1.0f; SeasonColor[0][2] = 0.8f;
|
||||
|
||||
SeasonLight[1].Set (2, -1, -3);
|
||||
SeasonLight[1].Normalize();
|
||||
SeasonColor[1][0] = 1.0f; SeasonColor[1][1] = 0.9f; SeasonColor[1][2] = 0.9f;
|
||||
|
||||
TEX tex;
|
||||
Handle h = tex_load(filename, &tex);
|
||||
if(!h)
|
||||
return false;
|
||||
const u8* data = tex.ptr;
|
||||
|
||||
m_pVertices = new STerrainVertex[MAP_SIZE*MAP_SIZE];
|
||||
if (m_pVertices == NULL)
|
||||
return false;
|
||||
|
||||
for (int j=0; j<MAP_SIZE; j++)
|
||||
{
|
||||
for (int i=0; i<MAP_SIZE; i++)
|
||||
{
|
||||
int pos = j*MAP_SIZE + i;
|
||||
|
||||
m_pVertices[pos].m_Position.X = ((float)i)*CELL_SIZE;
|
||||
m_pVertices[pos].m_Position.Y = (*data++)*0.35f;
|
||||
m_pVertices[pos].m_Position.Z = ((float)j)*CELL_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
for (j=0; j<NUM_PATCHES_PER_SIDE; j++)
|
||||
{
|
||||
for (int i=0; i<NUM_PATCHES_PER_SIDE; i++)
|
||||
{
|
||||
int pos = j*MAP_SIZE*PATCH_SIZE;
|
||||
pos += i*PATCH_SIZE;
|
||||
|
||||
m_Patches[j][i].Initialize ( &(m_pVertices[pos]) );
|
||||
}
|
||||
}
|
||||
|
||||
CalcLighting();
|
||||
SetNeighbors();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CTerrain::CalcLighting ()
|
||||
{
|
||||
CVector3D left, right, up, down, n[4];
|
||||
|
||||
for (int j=0; j<MAP_SIZE; j++)
|
||||
{
|
||||
for (int i=0; i<MAP_SIZE; i++)
|
||||
{
|
||||
left.Clear();
|
||||
right.Clear();
|
||||
up.Clear();
|
||||
down.Clear();
|
||||
|
||||
if (i>0)
|
||||
left = m_pVertices[j*MAP_SIZE + i - 1].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
if (i<MAP_SIZE-1)
|
||||
right = m_pVertices[j*MAP_SIZE + i + 1].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
if (j>0)
|
||||
up = m_pVertices[(j-1)*MAP_SIZE + i].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
if (j<MAP_SIZE-1)
|
||||
down = m_pVertices[(j+1)*MAP_SIZE + i].m_Position -
|
||||
m_pVertices[j*MAP_SIZE + i].m_Position;
|
||||
|
||||
n[0] = up.Cross(left);
|
||||
n[1] = left.Cross(down);
|
||||
n[2] = down.Cross(right);
|
||||
n[3] = right.Cross(up);
|
||||
|
||||
n[0].Normalize();
|
||||
n[1].Normalize();
|
||||
n[2].Normalize();
|
||||
n[3].Normalize();
|
||||
|
||||
CVector3D Normal = n[0] + n[1] + n[2] + n[3];
|
||||
Normal.Normalize();
|
||||
|
||||
float Color1 = Normal.Dot(SeasonLight[0]*-1)/(Normal.GetLength() * SeasonLight[0].GetLength());
|
||||
Color1 = (Color1+1.0f)/1.4f;
|
||||
|
||||
if (Color1>1.0f)
|
||||
Color1=1.0f;
|
||||
if (Color1<0.0f)
|
||||
Color1=0.0f;
|
||||
|
||||
float Color2 = Normal.Dot(SeasonLight[1]*-1)/(Normal.GetLength() * SeasonLight[1].GetLength());
|
||||
Color2 = (Color2+1.0f)/1.4f;
|
||||
|
||||
if (Color2>1.0f)
|
||||
Color2=1.0f;
|
||||
if (Color2<0.0f)
|
||||
Color2=0.0f;
|
||||
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[0][0] = Color1*SeasonColor[0][0];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[0][1] = Color1*SeasonColor[0][1];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[0][2] = Color1*SeasonColor[0][2];
|
||||
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[1][0] = Color2*SeasonColor[1][0];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[1][1] = Color2*SeasonColor[1][1];
|
||||
m_pVertices[j*MAP_SIZE + i].m_Color[1][2] = Color2*SeasonColor[1][2];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CTerrain::SetNeighbors ()
|
||||
{
|
||||
CPatch *ThisPatch, *RightPatch;
|
||||
|
||||
for (int pj=0; pj<NUM_PATCHES_PER_SIDE; pj++)
|
||||
{
|
||||
for (int pi=0; pi<NUM_PATCHES_PER_SIDE; pi++)
|
||||
{
|
||||
ThisPatch = &m_Patches[pj][pi];
|
||||
|
||||
if (pi < NUM_PATCHES_PER_SIDE-1)
|
||||
RightPatch = &m_Patches[pj][pi+1];
|
||||
else
|
||||
RightPatch = NULL;
|
||||
|
||||
|
||||
for (int tj=0; tj<16; tj++)
|
||||
{
|
||||
for (int ti=0; ti<16; ti++)
|
||||
{
|
||||
CMiniPatch *MPatch = &ThisPatch->m_MiniPatches[tj][ti];
|
||||
|
||||
MPatch->m_pParrent = ThisPatch;
|
||||
|
||||
if (ti < 15)
|
||||
MPatch->m_pRightNeighbor = &ThisPatch->m_MiniPatches[tj][ti+1];
|
||||
else
|
||||
{
|
||||
if (RightPatch)
|
||||
MPatch->m_pRightNeighbor = &RightPatch->m_MiniPatches[tj][0];
|
||||
else
|
||||
MPatch->m_pRightNeighbor = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Terrain.H
|
||||
// Last Update: 23/2/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: CTerrain handles the terrain portion of the
|
||||
// engine. It holds open the file to the terrain
|
||||
// information, so terrain data can be loaded
|
||||
// dynamically. We use a ROAM method to render
|
||||
// the terrain, ie using binary triangle trees.
|
||||
// The terrain consists of smaller PATCHS, which
|
||||
// do most of the work.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TERRAIN_H
|
||||
#define TERRAIN_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Patch.H"
|
||||
#include "Vector3D.H"
|
||||
|
||||
extern bool g_HillShading;
|
||||
|
||||
class CTerrain
|
||||
{
|
||||
public:
|
||||
CTerrain ();
|
||||
~CTerrain ();
|
||||
|
||||
bool Initalize (char *filename);
|
||||
|
||||
// protected:
|
||||
//the patches currently loaded
|
||||
CPatch m_Patches[NUM_PATCHES_PER_SIDE][NUM_PATCHES_PER_SIDE];
|
||||
STerrainVertex *m_pVertices;
|
||||
|
||||
|
||||
// protected:
|
||||
void CalcLighting();
|
||||
void SetNeighbors();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,88 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Types.H
|
||||
// Last Update: 25/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: The basic types used by the engine
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//basic return types
|
||||
enum FRESULT
|
||||
{
|
||||
R_OK = 0,
|
||||
R_FAIL, //use if nothing else matches the return type
|
||||
|
||||
R_BADPARAMS, //one or more of the parameters were invalid
|
||||
|
||||
R_NOMEMORY, //not enough memory for an operation
|
||||
|
||||
R_FILE_NOOPEN, //file could not be opened
|
||||
R_FILE_NOREAD, //file could not be read
|
||||
R_FILE_INVALID //file is corrupt or not supported
|
||||
};
|
||||
|
||||
//string related
|
||||
#define MAX_NAME_LENGTH (50)
|
||||
#define MAX_PATH_LENGTH (100)
|
||||
|
||||
//color structures
|
||||
struct SColor4ub
|
||||
{
|
||||
unsigned char R;
|
||||
unsigned char G;
|
||||
unsigned char B;
|
||||
unsigned char A;
|
||||
};
|
||||
|
||||
struct SColor4f
|
||||
{
|
||||
float R;
|
||||
float G;
|
||||
float B;
|
||||
float A;
|
||||
};
|
||||
|
||||
//all the major classes:
|
||||
class CBitmap;
|
||||
|
||||
class CCamera;
|
||||
|
||||
class CDiesel3DVertex;
|
||||
|
||||
class CGameResource;
|
||||
|
||||
class CEngine;
|
||||
class CEntity;
|
||||
|
||||
class CFrustum;
|
||||
|
||||
class CMatrix3D;
|
||||
class CMesh;
|
||||
class CMeshPoly;
|
||||
class CShadyMesh;
|
||||
class CShadyMeshPoly;
|
||||
|
||||
class CNode;
|
||||
|
||||
class CPatch;
|
||||
class CPlane;
|
||||
|
||||
class CRenderer;
|
||||
|
||||
class CTerrain;
|
||||
class CTexture;
|
||||
|
||||
class CVector3D;
|
||||
|
||||
class CWorld;
|
||||
|
||||
|
||||
#endif
|
@ -1,181 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Vector3D.Cpp
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Provides an interface for a vector in R3 and
|
||||
// allows vector and scalar operations on it
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Vector3D.H"
|
||||
|
||||
CVector3D::CVector3D ()
|
||||
{
|
||||
X = Y = Z = 0.0f;
|
||||
}
|
||||
|
||||
CVector3D::CVector3D (float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
int CVector3D::operator == (CVector3D &vector)
|
||||
{
|
||||
if (X != vector.X ||
|
||||
Y != vector.Y ||
|
||||
Z != vector.Z)
|
||||
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CVector3D::operator != (CVector3D &vector)
|
||||
{
|
||||
if (X != vector.X ||
|
||||
Y != vector.Y ||
|
||||
Z != vector.Z)
|
||||
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CVector3D::operator ! ()
|
||||
{
|
||||
if (X != 0.0f ||
|
||||
Y != 0.0f ||
|
||||
Z != 0.0f)
|
||||
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//vector addition
|
||||
CVector3D CVector3D::operator + (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X + vector.X;
|
||||
Temp.Y = Y + vector.Y;
|
||||
Temp.Z = Z + vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//vector addition/assignment
|
||||
CVector3D &CVector3D::operator += (CVector3D &vector)
|
||||
{
|
||||
X += vector.X;
|
||||
Y += vector.Y;
|
||||
Z += vector.Z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//vector subtraction
|
||||
CVector3D CVector3D::operator - (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X - vector.X;
|
||||
Temp.Y = Y - vector.Y;
|
||||
Temp.Z = Z - vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//vector subtrcation/assignment
|
||||
CVector3D &CVector3D::operator -= (CVector3D &vector)
|
||||
{
|
||||
X -= vector.X;
|
||||
Y -= vector.Y;
|
||||
Z -= vector.Z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//scalar multiplication
|
||||
CVector3D CVector3D::operator * (float value)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X * value;
|
||||
Temp.Y = Y * value;
|
||||
Temp.Z = Z * value;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//scalar multiplication/assignment
|
||||
CVector3D CVector3D::operator *= (float value)
|
||||
{
|
||||
X *= value;
|
||||
Y *= value;
|
||||
Z *= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CVector3D::Set (float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
void CVector3D::Clear ()
|
||||
{
|
||||
X = Y = Z = 0.0f;
|
||||
}
|
||||
|
||||
//Dot product
|
||||
float CVector3D::Dot (CVector3D &vector)
|
||||
{
|
||||
return ( X * vector.X +
|
||||
Y * vector.Y +
|
||||
Z * vector.Z );
|
||||
}
|
||||
|
||||
//Cross product
|
||||
CVector3D CVector3D::Cross (CVector3D &vector)
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = (Y * vector.Z) - (Z * vector.Y);
|
||||
Temp.Y = (Z * vector.X) - (X * vector.Z);
|
||||
Temp.Z = (X * vector.Y) - (Y * vector.X);
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
float CVector3D::GetLength ()
|
||||
{
|
||||
return sqrtf ( SQR(X) + SQR(Y) + SQR(Z) );
|
||||
}
|
||||
|
||||
void CVector3D::Normalize ()
|
||||
{
|
||||
float scale = 1.0f/GetLength ();
|
||||
|
||||
X *= scale;
|
||||
Y *= scale;
|
||||
Z *= scale;
|
||||
}
|
||||
|
||||
SColor4ub CVector3D::ConvertToColor (float alpha_factor)
|
||||
{
|
||||
SColor4ub color;
|
||||
|
||||
color.R = (unsigned char)(127.0f * X + 128.0f);
|
||||
color.G = (unsigned char)(127.0f * Y + 128.0f);
|
||||
color.B = (unsigned char)(127.0f * Z + 128.0f);
|
||||
color.A = (unsigned char)(255.0f * alpha_factor);
|
||||
|
||||
return color;
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Vector3D.H
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Provides an interface for a vector in R3 and
|
||||
// allows vector and scalar operations on it
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef VECTOR3D_H
|
||||
#define VECTOR3D_H
|
||||
|
||||
#include <math.h>
|
||||
#include "MathUtil.H"
|
||||
#include "Types.H"
|
||||
|
||||
class CVector3D
|
||||
{
|
||||
public:
|
||||
float X, Y, Z;
|
||||
|
||||
public:
|
||||
CVector3D ();
|
||||
CVector3D (float x, float y, float z);
|
||||
|
||||
int operator == (CVector3D &vector);
|
||||
int operator != (CVector3D &vector);
|
||||
int operator ! ();
|
||||
|
||||
//vector addition
|
||||
CVector3D operator + (CVector3D &vector);
|
||||
//vector addition/assignment
|
||||
CVector3D &operator += (CVector3D &vector);
|
||||
|
||||
//vector subtraction
|
||||
CVector3D operator - (CVector3D &vector);
|
||||
//vector subtraction/assignment
|
||||
CVector3D &operator -= (CVector3D &vector);
|
||||
|
||||
//scalar multiplication
|
||||
CVector3D operator * (float value);
|
||||
//scalar multiplication/assignment
|
||||
CVector3D operator *= (float value);
|
||||
|
||||
public:
|
||||
void Set (float x, float y, float z);
|
||||
void Clear ();
|
||||
|
||||
//Dot product
|
||||
float Dot (CVector3D &vector);
|
||||
//Cross product
|
||||
CVector3D Cross (CVector3D &vector);
|
||||
|
||||
//Returns length of the vector
|
||||
float GetLength ();
|
||||
void Normalize ();
|
||||
|
||||
//Returns a color which describes the vector
|
||||
SColor4ub ConvertToColor (float alpha_factor);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,332 +0,0 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include "Matrix3D.H"
|
||||
#include "Renderer.H"
|
||||
#include "Terrain.H"
|
||||
|
||||
#include "time.h"
|
||||
#include "wsdl.h"
|
||||
#include "tex.h"
|
||||
|
||||
|
||||
HWND InitializeGame (HINSTANCE hInstance);
|
||||
void DestroyGame();
|
||||
|
||||
void InitScene ();
|
||||
void InitResources ();
|
||||
void RenderScene ();
|
||||
|
||||
extern bool keys[256];
|
||||
|
||||
|
||||
HWND GameWindow;
|
||||
|
||||
CMatrix3D g_WorldMat;
|
||||
CRenderer g_Renderer;
|
||||
CTerrain g_Terrain;
|
||||
CCamera g_Camera;
|
||||
|
||||
int SelPX, SelPY, SelTX, SelTY;
|
||||
int g_BaseTexCounter = 0;
|
||||
int g_SecTexCounter = 1;
|
||||
int g_TransTexCounter = 0;
|
||||
|
||||
int g_TickCounter = 0;
|
||||
double g_LastTime;
|
||||
|
||||
|
||||
const int NUM_ALPHA_MAPS = 13;
|
||||
|
||||
//CTexture g_BaseTexture[5];
|
||||
Handle BaseTexs[5];
|
||||
|
||||
Handle AlphaMaps[NUM_ALPHA_MAPS];
|
||||
//CTexture g_TransitionTexture[NUM_ALPHA_MAPS];
|
||||
|
||||
int mouse_x=50, mouse_y=50;
|
||||
|
||||
extern int xres, yres;
|
||||
|
||||
|
||||
void terr_init()
|
||||
{
|
||||
g_Renderer.Initialize (GameWindow, 1280, 1024, 32);
|
||||
|
||||
InitResources ();
|
||||
InitScene ();
|
||||
}
|
||||
|
||||
void terr_update()
|
||||
{
|
||||
g_FrameCounter++;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
POINT MousePos;
|
||||
|
||||
GetCursorPos (&MousePos);
|
||||
CVector3D right(1,0,1);
|
||||
CVector3D up(1,0,-1);
|
||||
right.Normalize ();
|
||||
up.Normalize ();
|
||||
|
||||
if (mouse_x >= xres-2)
|
||||
g_Camera.m_Orientation.Translate (right);
|
||||
if (mouse_x <= 3)
|
||||
g_Camera.m_Orientation.Translate (right*-1);
|
||||
|
||||
if (mouse_y >= yres-2)
|
||||
g_Camera.m_Orientation.Translate (up);
|
||||
if (mouse_y <= 3)
|
||||
g_Camera.m_Orientation.Translate (up*-1);
|
||||
|
||||
|
||||
|
||||
float fov = g_Camera.GetFOV();
|
||||
float d = DEGTORAD(0.4f);
|
||||
if(keys[SDLK_KP_MINUS])
|
||||
if (fov+d < DEGTORAD(90))
|
||||
g_Camera.SetProjection (1, 1000, fov + d);
|
||||
if(keys[SDLK_KP_ADD])
|
||||
if (fov-d > DEGTORAD(20))
|
||||
g_Camera.SetProjection (1, 1000, fov - d);
|
||||
|
||||
g_Camera.UpdateFrustum ();
|
||||
/////////////////////////////////////////////
|
||||
|
||||
|
||||
g_Renderer.RenderTerrain (&g_Terrain, &g_Camera);
|
||||
g_Renderer.RenderTileOutline (&(g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX]));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool terr_handler(const SDL_Event& ev)
|
||||
{
|
||||
switch(ev.type)
|
||||
{
|
||||
case SDL_MOUSEMOTION:
|
||||
mouse_x = ev.motion.x;
|
||||
mouse_y = ev.motion.y;
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
switch(ev.key.keysym.sym)
|
||||
{
|
||||
case 'W':
|
||||
g_WireFrame = !g_WireFrame;
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
g_HillShading = !g_HillShading;
|
||||
break;
|
||||
|
||||
// tile selection
|
||||
case SDLK_DOWN:
|
||||
if(++SelTX > 15)
|
||||
if(SelPX == NUM_PATCHES_PER_SIDE-1)
|
||||
SelTX = 15;
|
||||
else
|
||||
SelTX = 0, SelPX++;
|
||||
break;
|
||||
|
||||
case SDLK_UP:
|
||||
if(--SelTX < 0)
|
||||
if(SelPX == 0)
|
||||
SelTX = 0;
|
||||
else
|
||||
SelTX = 15, SelPX--;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
if(++SelTY > 15)
|
||||
if(SelPY == NUM_PATCHES_PER_SIDE-1)
|
||||
SelTY = 15;
|
||||
else
|
||||
SelTY = 0, SelPY++;
|
||||
break;
|
||||
|
||||
case SDLK_LEFT:
|
||||
if(--SelTY < 0)
|
||||
if(SelPY == 0)
|
||||
SelTY = 0;
|
||||
else
|
||||
SelTY = 15, SelPY--;
|
||||
break;
|
||||
|
||||
|
||||
case SDLK_KP0:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
if (!MPatch->Tex2)
|
||||
{
|
||||
MPatch->m_AlphaMap = AlphaMaps[g_TransTexCounter];
|
||||
MPatch->Tex2 = BaseTexs[g_SecTexCounter];
|
||||
}
|
||||
else
|
||||
{
|
||||
MPatch->Tex2 = 0;
|
||||
MPatch->m_AlphaMap = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_KP1:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
|
||||
g_BaseTexCounter++;
|
||||
if (g_BaseTexCounter > 4)
|
||||
g_BaseTexCounter = 0;
|
||||
|
||||
MPatch->Tex1 = BaseTexs[g_BaseTexCounter];
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_KP2:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
|
||||
if (MPatch->Tex2)
|
||||
{
|
||||
g_SecTexCounter++;
|
||||
if (g_SecTexCounter > 4)
|
||||
g_SecTexCounter = 0;
|
||||
|
||||
MPatch->Tex2 = BaseTexs[g_SecTexCounter];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_KP3:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
|
||||
if (MPatch->/*m_pTransitionTexture*/m_AlphaMap)
|
||||
{
|
||||
g_TransTexCounter++;
|
||||
if (g_TransTexCounter >= NUM_ALPHA_MAPS)
|
||||
g_TransTexCounter = 0;
|
||||
|
||||
MPatch->m_AlphaMap = AlphaMaps[g_TransTexCounter];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void InitScene ()
|
||||
{
|
||||
g_Terrain.Initalize ("terrain.raw");
|
||||
|
||||
for (int pj=0; pj<NUM_PATCHES_PER_SIDE; pj++)
|
||||
{
|
||||
for (int pi=0; pi<NUM_PATCHES_PER_SIDE; pi++)
|
||||
{
|
||||
for (int tj=0; tj<16; tj++)
|
||||
{
|
||||
for (int ti=0; ti<16; ti++)
|
||||
{
|
||||
g_Terrain.m_Patches[pj][pi].m_MiniPatches[tj][ti].Tex1 = BaseTexs[0];//rand()%5];
|
||||
g_Terrain.m_Patches[pj][pi].m_MiniPatches[tj][ti].Tex2 = NULL;//&g_BaseTexture[rand()%5];
|
||||
g_Terrain.m_Patches[pj][pi].m_MiniPatches[tj][ti].m_AlphaMap = 0;//&g_TransitionTexture[rand()%5];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_Camera.SetProjection (1, 1000, DEGTORAD(20));
|
||||
g_Camera.m_Orientation.SetXRotation(DEGTORAD(30));
|
||||
g_Camera.m_Orientation.RotateY(DEGTORAD(-45));
|
||||
|
||||
g_Camera.m_Orientation.Translate (100, 150, -100);
|
||||
|
||||
SelPX = SelPY = SelTX = SelTY = 0;
|
||||
}
|
||||
|
||||
void InitResources()
|
||||
{
|
||||
int i;
|
||||
char* base_fns[] =
|
||||
{
|
||||
"Base1.bmp",
|
||||
"Base2.bmp",
|
||||
"Base3.bmp",
|
||||
"Base4.bmp",
|
||||
"Base5.bmp"
|
||||
};
|
||||
|
||||
for(i = 0; i < 5; i++)
|
||||
{
|
||||
BaseTexs[i] = tex_load(base_fns[i]);
|
||||
tex_upload(BaseTexs[i], GL_LINEAR_MIPMAP_LINEAR);
|
||||
}
|
||||
|
||||
|
||||
int cnt;
|
||||
#if 1
|
||||
|
||||
char* fns[NUM_ALPHA_MAPS] = {
|
||||
"blendcircle.raw",
|
||||
"blendcorner.raw",
|
||||
"blendedge.raw",
|
||||
"blendedgecorner.raw",
|
||||
"blendedgetwocorners.raw",
|
||||
"blendfourcorners.raw",
|
||||
"blendlshape.raw",
|
||||
"blendlshapecorner.raw",
|
||||
"blendthreecorners.raw",
|
||||
"blendtwocorners.raw",
|
||||
"blendtwoedges.raw",
|
||||
"blendtwooppositecorners.raw",
|
||||
"blendushape.raw"
|
||||
};
|
||||
/*
|
||||
//for(i = 0; i < NUM_ALPHA_MAPS;i++)
|
||||
i=5;
|
||||
{
|
||||
FILE* f = fopen(fns[i],"rb");
|
||||
u8 buf[5000],buf2[5000];
|
||||
fread(buf,5000,1,f);
|
||||
fclose(f);
|
||||
for(int j = 0; j < 1024; j++)
|
||||
buf2[2*j] = buf2[2*j+1] = buf[j];
|
||||
f=fopen(fns[i],"wb");
|
||||
fwrite(buf2,2048,1,f);
|
||||
fclose(f);
|
||||
}
|
||||
/**/
|
||||
cnt=13;
|
||||
#else
|
||||
|
||||
char* fns[NUM_ALPHA_MAPS] = {
|
||||
"Transition1.bmp",
|
||||
"Transition2.bmp",
|
||||
"Transition3.bmp",
|
||||
"Transition4.bmp",
|
||||
"Transition5.bmp",
|
||||
};
|
||||
cnt=5;
|
||||
#endif
|
||||
|
||||
for(i = 0; i < cnt; i++)
|
||||
{
|
||||
AlphaMaps[i] = tex_load(fns[i]);
|
||||
tex_upload(AlphaMaps[i], GL_LINEAR, GL_INTENSITY4);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,340 +0,0 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include "Matrix3D.H"
|
||||
#include "Renderer.H"
|
||||
#include "Terrain.H"
|
||||
|
||||
#include "time.h"
|
||||
#include "wsdl.h"
|
||||
#include "tex.h"
|
||||
|
||||
|
||||
HWND InitializeGame (HINSTANCE hInstance);
|
||||
void DestroyGame();
|
||||
|
||||
void InitScene ();
|
||||
void InitResources ();
|
||||
void RenderScene ();
|
||||
|
||||
extern bool keys[256];
|
||||
|
||||
|
||||
HWND GameWindow;
|
||||
|
||||
CMatrix3D g_WorldMat;
|
||||
CRenderer g_Renderer;
|
||||
CTerrain g_Terrain;
|
||||
CCamera g_Camera;
|
||||
|
||||
int SelPX, SelPY, SelTX, SelTY;
|
||||
int g_BaseTexCounter = 0;
|
||||
int g_SecTexCounter = 1;
|
||||
int g_TransTexCounter = 0;
|
||||
|
||||
int g_TickCounter = 0;
|
||||
double g_LastTime;
|
||||
|
||||
|
||||
const int NUM_ALPHA_MAPS = 13;
|
||||
|
||||
//CTexture g_BaseTexture[5];
|
||||
Handle BaseTexs[5];
|
||||
|
||||
Handle AlphaMaps[NUM_ALPHA_MAPS];
|
||||
//CTexture g_TransitionTexture[NUM_ALPHA_MAPS];
|
||||
|
||||
int mouse_x=50, mouse_y=50;
|
||||
|
||||
extern int xres, yres;
|
||||
|
||||
|
||||
void terr_init()
|
||||
{
|
||||
g_Renderer.Initialize (GameWindow, 1280, 1024, 32);
|
||||
|
||||
InitResources ();
|
||||
InitScene ();
|
||||
}
|
||||
|
||||
void terr_update()
|
||||
{
|
||||
g_FrameCounter++;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
POINT MousePos;
|
||||
|
||||
GetCursorPos (&MousePos);
|
||||
CVector3D right(1,0,1);
|
||||
CVector3D up(1,0,-1);
|
||||
right.Normalize ();
|
||||
up.Normalize ();
|
||||
|
||||
if (mouse_x >= xres-2)
|
||||
g_Camera.m_Orientation.Translate (right);
|
||||
if (mouse_x <= 3)
|
||||
g_Camera.m_Orientation.Translate (right*-1);
|
||||
|
||||
if (mouse_y >= yres-2)
|
||||
g_Camera.m_Orientation.Translate (up);
|
||||
if (mouse_y <= 3)
|
||||
g_Camera.m_Orientation.Translate (up*-1);
|
||||
|
||||
|
||||
|
||||
float fov = g_Camera.GetFOV();
|
||||
float d = DEGTORAD(0.4f);
|
||||
if(keys[SDLK_KP_MINUS])
|
||||
if (fov+d < DEGTORAD(90))
|
||||
g_Camera.SetProjection (1, 1000, fov + d);
|
||||
if(keys[SDLK_KP_ADD])
|
||||
if (fov-d > DEGTORAD(20))
|
||||
g_Camera.SetProjection (1, 1000, fov - d);
|
||||
|
||||
g_Camera.UpdateFrustum ();
|
||||
/////////////////////////////////////////////
|
||||
|
||||
|
||||
g_Renderer.RenderTerrain (&g_Terrain, &g_Camera);
|
||||
g_Renderer.RenderTileOutline (&(g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX]));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool terr_handler(const SDL_Event& ev)
|
||||
{
|
||||
switch(ev.type)
|
||||
{
|
||||
case SDL_MOUSEMOTION:
|
||||
mouse_x = ev.motion.x;
|
||||
mouse_y = ev.motion.y;
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
switch(ev.key.keysym.sym)
|
||||
{
|
||||
case 'W':
|
||||
g_WireFrame = !g_WireFrame;
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
// quick hack to return camera home, for screenshots (after alt+tabbing)
|
||||
g_Camera.SetProjection (1, 1000, DEGTORAD(20));
|
||||
g_Camera.m_Orientation.SetXRotation(DEGTORAD(30));
|
||||
g_Camera.m_Orientation.RotateY(DEGTORAD(-45));
|
||||
g_Camera.m_Orientation.Translate (100, 150, -100);
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
g_HillShading = !g_HillShading;
|
||||
break;
|
||||
|
||||
// tile selection
|
||||
case SDLK_DOWN:
|
||||
if(++SelTX > 15)
|
||||
if(SelPX == NUM_PATCHES_PER_SIDE-1)
|
||||
SelTX = 15;
|
||||
else
|
||||
SelTX = 0, SelPX++;
|
||||
break;
|
||||
|
||||
case SDLK_UP:
|
||||
if(--SelTX < 0)
|
||||
if(SelPX == 0)
|
||||
SelTX = 0;
|
||||
else
|
||||
SelTX = 15, SelPX--;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
if(++SelTY > 15)
|
||||
if(SelPY == NUM_PATCHES_PER_SIDE-1)
|
||||
SelTY = 15;
|
||||
else
|
||||
SelTY = 0, SelPY++;
|
||||
break;
|
||||
|
||||
case SDLK_LEFT:
|
||||
if(--SelTY < 0)
|
||||
if(SelPY == 0)
|
||||
SelTY = 0;
|
||||
else
|
||||
SelTY = 15, SelPY--;
|
||||
break;
|
||||
|
||||
|
||||
case SDLK_KP0:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
if (!MPatch->Tex2)
|
||||
{
|
||||
MPatch->m_AlphaMap = AlphaMaps[g_TransTexCounter];
|
||||
MPatch->Tex2 = BaseTexs[g_SecTexCounter];
|
||||
}
|
||||
else
|
||||
{
|
||||
MPatch->Tex2 = 0;
|
||||
MPatch->m_AlphaMap = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_KP1:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
|
||||
g_BaseTexCounter++;
|
||||
if (g_BaseTexCounter > 4)
|
||||
g_BaseTexCounter = 0;
|
||||
|
||||
MPatch->Tex1 = BaseTexs[g_BaseTexCounter];
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_KP2:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
|
||||
if (MPatch->Tex2)
|
||||
{
|
||||
g_SecTexCounter++;
|
||||
if (g_SecTexCounter > 4)
|
||||
g_SecTexCounter = 0;
|
||||
|
||||
MPatch->Tex2 = BaseTexs[g_SecTexCounter];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_KP3:
|
||||
{
|
||||
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
|
||||
|
||||
if (MPatch->/*m_pTransitionTexture*/m_AlphaMap)
|
||||
{
|
||||
g_TransTexCounter++;
|
||||
if (g_TransTexCounter >= NUM_ALPHA_MAPS)
|
||||
g_TransTexCounter = 0;
|
||||
|
||||
MPatch->m_AlphaMap = AlphaMaps[g_TransTexCounter];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void InitScene ()
|
||||
{
|
||||
g_Terrain.Initalize ("terrain.raw");
|
||||
|
||||
for (int pj=0; pj<NUM_PATCHES_PER_SIDE; pj++)
|
||||
{
|
||||
for (int pi=0; pi<NUM_PATCHES_PER_SIDE; pi++)
|
||||
{
|
||||
for (int tj=0; tj<16; tj++)
|
||||
{
|
||||
for (int ti=0; ti<16; ti++)
|
||||
{
|
||||
g_Terrain.m_Patches[pj][pi].m_MiniPatches[tj][ti].Tex1 = BaseTexs[0];//rand()%5];
|
||||
g_Terrain.m_Patches[pj][pi].m_MiniPatches[tj][ti].Tex2 = NULL;//&g_BaseTexture[rand()%5];
|
||||
g_Terrain.m_Patches[pj][pi].m_MiniPatches[tj][ti].m_AlphaMap = 0;//&g_TransitionTexture[rand()%5];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_Camera.SetProjection (1, 1000, DEGTORAD(20));
|
||||
g_Camera.m_Orientation.SetXRotation(DEGTORAD(30));
|
||||
g_Camera.m_Orientation.RotateY(DEGTORAD(-45));
|
||||
|
||||
g_Camera.m_Orientation.Translate (100, 150, -100);
|
||||
|
||||
SelPX = SelPY = SelTX = SelTY = 0;
|
||||
}
|
||||
|
||||
void InitResources()
|
||||
{
|
||||
int i;
|
||||
char* base_fns[] =
|
||||
{
|
||||
"Base1.bmp",
|
||||
"Base2.bmp",
|
||||
"Base3.bmp",
|
||||
"Base4.bmp",
|
||||
"Base5.bmp"
|
||||
};
|
||||
|
||||
for(i = 0; i < 5; i++)
|
||||
{
|
||||
BaseTexs[i] = tex_load(base_fns[i]);
|
||||
tex_upload(BaseTexs[i], GL_LINEAR_MIPMAP_LINEAR);
|
||||
}
|
||||
|
||||
|
||||
int cnt;
|
||||
#if 1
|
||||
|
||||
char* fns[NUM_ALPHA_MAPS] = {
|
||||
"blendcircle.raw",
|
||||
"blendcorner.raw",
|
||||
"blendedge.raw",
|
||||
"blendedgecorner.raw",
|
||||
"blendedgetwocorners.raw",
|
||||
"blendfourcorners.raw",
|
||||
"blendlshape.raw",
|
||||
"blendlshapecorner.raw",
|
||||
"blendthreecorners.raw",
|
||||
"blendtwocorners.raw",
|
||||
"blendtwoedges.raw",
|
||||
"blendtwooppositecorners.raw",
|
||||
"blendushape.raw"
|
||||
};
|
||||
/*
|
||||
//for(i = 0; i < NUM_ALPHA_MAPS;i++)
|
||||
i=5;
|
||||
{
|
||||
FILE* f = fopen(fns[i],"rb");
|
||||
u8 buf[5000],buf2[5000];
|
||||
fread(buf,5000,1,f);
|
||||
fclose(f);
|
||||
for(int j = 0; j < 1024; j++)
|
||||
buf2[2*j] = buf2[2*j+1] = buf[j];
|
||||
f=fopen(fns[i],"wb");
|
||||
fwrite(buf2,2048,1,f);
|
||||
fclose(f);
|
||||
}
|
||||
/**/
|
||||
cnt=13;
|
||||
#else
|
||||
|
||||
char* fns[NUM_ALPHA_MAPS] = {
|
||||
"Transition1.bmp",
|
||||
"Transition2.bmp",
|
||||
"Transition3.bmp",
|
||||
"Transition4.bmp",
|
||||
"Transition5.bmp",
|
||||
};
|
||||
cnt=5;
|
||||
#endif
|
||||
|
||||
for(i = 0; i < cnt; i++)
|
||||
{
|
||||
AlphaMaps[i] = tex_load(fns[i]);
|
||||
tex_upload(AlphaMaps[i], GL_LINEAR, GL_INTENSITY4);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user