Minor additional functionality.
This was SVN commit r1218.
This commit is contained in:
parent
81c829ec4c
commit
17a4174505
@ -18,7 +18,7 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
CModel::CModel()
|
CModel::CModel()
|
||||||
: m_pModelDef(0), m_Anim(0), m_AnimTime(0),
|
: m_pModelDef(0), m_Flags(0), m_Anim(0), m_AnimTime(0),
|
||||||
m_BoneMatrices(0), m_InvBoneMatrices(0), m_BoneMatricesValid(false)
|
m_BoneMatrices(0), m_InvBoneMatrices(0), m_BoneMatricesValid(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -316,6 +316,7 @@ CModel* CModel::Clone() const
|
|||||||
clone->SetTexture(m_Texture);
|
clone->SetTexture(m_Texture);
|
||||||
clone->SetMaterial(m_Material);
|
clone->SetMaterial(m_Material);
|
||||||
clone->SetAnimation(m_Anim);
|
clone->SetAnimation(m_Anim);
|
||||||
|
clone->SetFlags(m_Flags);
|
||||||
for (uint i=0;i<m_Props.size();i++) {
|
for (uint i=0;i<m_Props.size();i++) {
|
||||||
// eek! TODO, RC - need to investigate shallow clone here
|
// eek! TODO, RC - need to investigate shallow clone here
|
||||||
clone->AddProp(m_Props[i].m_Point,m_Props[i].m_Model->Clone());
|
clone->AddProp(m_Props[i].m_Point,m_Props[i].m_Model->Clone());
|
||||||
@ -330,6 +331,7 @@ void CModel::SetTransform(const CMatrix3D& transform)
|
|||||||
{
|
{
|
||||||
// call base class to set transform on this object
|
// call base class to set transform on this object
|
||||||
CRenderableObject::SetTransform(transform);
|
CRenderableObject::SetTransform(transform);
|
||||||
|
m_BoneMatricesValid=false;
|
||||||
|
|
||||||
// now set transforms on props
|
// now set transforms on props
|
||||||
const CMatrix3D* bonematrices=GetBoneMatrices();
|
const CMatrix3D* bonematrices=GetBoneMatrices();
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "SkeletonAnim.h"
|
#include "SkeletonAnim.h"
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
|
|
||||||
|
#define MODELFLAG_CASTSHADOWS (1<<0)
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// CModel: basically, a mesh object - holds the texturing and skinning
|
// CModel: basically, a mesh object - holds the texturing and skinning
|
||||||
@ -25,6 +26,8 @@ class CModel : public CRenderableObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Prop {
|
struct Prop {
|
||||||
|
Prop() : m_Point(0), m_Model(0) {}
|
||||||
|
|
||||||
SPropPoint* m_Point;
|
SPropPoint* m_Point;
|
||||||
CModel* m_Model;
|
CModel* m_Model;
|
||||||
};
|
};
|
||||||
@ -59,6 +62,19 @@ public:
|
|||||||
// get the currently playing animation, if any
|
// get the currently playing animation, if any
|
||||||
CSkeletonAnim* GetAnimation() { return m_Anim; }
|
CSkeletonAnim* GetAnimation() { return m_Anim; }
|
||||||
|
|
||||||
|
// set object flags
|
||||||
|
void SetFlags(u32 flags) { m_Flags=flags; }
|
||||||
|
// get object flags
|
||||||
|
u32 GetFlags() const { return m_Flags; }
|
||||||
|
|
||||||
|
// recurse down tree setting dirty bits
|
||||||
|
void SetDirtyRec(u32 dirtyflags) {
|
||||||
|
SetDirty(dirtyflags);
|
||||||
|
for (size_t i=0;i<m_Props.size();i++) {
|
||||||
|
m_Props[i].m_Model->SetDirtyRec(dirtyflags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// calculate object space bounds of this model, based solely on vertex positions
|
// calculate object space bounds of this model, based solely on vertex positions
|
||||||
void CalcObjectBounds();
|
void CalcObjectBounds();
|
||||||
// calculate bounds encompassing all vertex positions for given animation
|
// calculate bounds encompassing all vertex positions for given animation
|
||||||
@ -89,7 +105,8 @@ public:
|
|||||||
// remove a prop from the given point
|
// remove a prop from the given point
|
||||||
void RemoveProp(SPropPoint* point);
|
void RemoveProp(SPropPoint* point);
|
||||||
// return prop list
|
// return prop list
|
||||||
const std::vector<Prop>& GetProps() { return m_Props; }
|
std::vector<Prop>& GetProps() { return m_Props; }
|
||||||
|
const std::vector<Prop>& GetProps() const { return m_Props; }
|
||||||
|
|
||||||
// return a clone of this model
|
// return a clone of this model
|
||||||
CModel* Clone() const;
|
CModel* Clone() const;
|
||||||
@ -100,6 +117,8 @@ private:
|
|||||||
// calculate necessary bone transformation matrices for skinning
|
// calculate necessary bone transformation matrices for skinning
|
||||||
void GenerateBoneMatrices();
|
void GenerateBoneMatrices();
|
||||||
|
|
||||||
|
// object flags
|
||||||
|
u32 m_Flags;
|
||||||
// texture used by model
|
// texture used by model
|
||||||
CTexture m_Texture;
|
CTexture m_Texture;
|
||||||
// model's material
|
// model's material
|
||||||
|
@ -94,15 +94,20 @@ public:
|
|||||||
public:
|
public:
|
||||||
// accessor: get vertex data
|
// accessor: get vertex data
|
||||||
int GetNumVertices() const { return m_NumVertices; }
|
int GetNumVertices() const { return m_NumVertices; }
|
||||||
SModelVertex *GetVertices() const { return m_pVertices; }
|
SModelVertex* GetVertices() const { return m_pVertices; }
|
||||||
|
|
||||||
// accessor: get face data
|
// accessor: get face data
|
||||||
int GetNumFaces() const { return m_NumFaces; }
|
int GetNumFaces() const { return m_NumFaces; }
|
||||||
SModelFace *GetFaces() const { return m_pFaces; }
|
SModelFace* GetFaces() const { return m_pFaces; }
|
||||||
|
|
||||||
// accessor: get bone data
|
// accessor: get bone data
|
||||||
int GetNumBones() const { return m_NumBones; }
|
int GetNumBones() const { return m_NumBones; }
|
||||||
CBoneState *GetBones() const { return m_Bones; }
|
CBoneState* GetBones() const { return m_Bones; }
|
||||||
|
|
||||||
|
|
||||||
|
// accessor: get prop data
|
||||||
|
int GetNumPropPoints() const { return m_NumPropPoints; }
|
||||||
|
SPropPoint* GetPropPoints() const { return m_PropPoints; }
|
||||||
|
|
||||||
// find and return pointer to prop point matching given name; return
|
// find and return pointer to prop point matching given name; return
|
||||||
// null if no match (case insensitive search)
|
// null if no match (case insensitive search)
|
||||||
|
@ -331,3 +331,36 @@ void CTerrain::SetHeightMap(u16* heightmap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// FlattenArea: flatten out an area of terrain (specified in world space
|
||||||
|
// coords); return the average height of the flattened area
|
||||||
|
float CTerrain::FlattenArea(float x0,float x1,float z0,float z1)
|
||||||
|
{
|
||||||
|
u32 tx0=u32(clamp(int(float(x0/CELL_SIZE)),0,int(m_MapSize)));
|
||||||
|
u32 tx1=u32(clamp(int(float(x1/CELL_SIZE)+1.0f),0,int(m_MapSize)));
|
||||||
|
u32 tz0=u32(clamp(int(float(z0/CELL_SIZE)),0,int(m_MapSize)));
|
||||||
|
u32 tz1=u32(clamp(int(float(z1/CELL_SIZE)+1.0f),0,int(m_MapSize)));
|
||||||
|
|
||||||
|
u32 count=0;
|
||||||
|
u32 y=0;
|
||||||
|
for (u32 x=tx0;x<=tx1;x++) {
|
||||||
|
for (u32 z=tz0;z<=tz1;z++) {
|
||||||
|
y+=m_Heightmap[z*m_MapSize + x];
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
y/=count;
|
||||||
|
|
||||||
|
for (u32 x=tx0;x<=tx1;x++) {
|
||||||
|
for (u32 z=tz0;z<=tz1;z++) {
|
||||||
|
m_Heightmap[z*m_MapSize + x]=y;
|
||||||
|
CPatch* patch=GetPatch(x/PATCH_SIZE,z/PATCH_SIZE);
|
||||||
|
patch->SetDirty(RENDERDATA_UPDATE_VERTICES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return y*HEIGHT_SCALE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,10 @@ public:
|
|||||||
// calculate the normal at a given vertex
|
// calculate the normal at a given vertex
|
||||||
void CalcNormal(u32 i,u32 j,CVector3D& normal);
|
void CalcNormal(u32 i,u32 j,CVector3D& normal);
|
||||||
|
|
||||||
|
// flatten out an area of terrain (specified in world space coords); return
|
||||||
|
// the average height of the flattened area
|
||||||
|
float FlattenArea(float x0,float x1,float z0,float z1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// delete any data allocated by this terrain
|
// delete any data allocated by this terrain
|
||||||
void ReleaseData();
|
void ReleaseData();
|
||||||
|
@ -46,6 +46,14 @@ void CUnitManager::RemoveUnit(CUnit* unit)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// DeleteUnit: remove given unit from world and delete it
|
||||||
|
void CUnitManager::DeleteUnit(CUnit* unit)
|
||||||
|
{
|
||||||
|
RemoveUnit(unit);
|
||||||
|
delete unit;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// DeleteAll: remove and delete all units
|
// DeleteAll: remove and delete all units
|
||||||
void CUnitManager::DeleteAll()
|
void CUnitManager::DeleteAll()
|
||||||
|
@ -31,6 +31,8 @@ public:
|
|||||||
void AddUnit(CUnit* unit);
|
void AddUnit(CUnit* unit);
|
||||||
// remove given unit from world, but don't delete it
|
// remove given unit from world, but don't delete it
|
||||||
void RemoveUnit(CUnit* unit);
|
void RemoveUnit(CUnit* unit);
|
||||||
|
// remove given unit from world and delete it
|
||||||
|
void DeleteUnit(CUnit* unit);
|
||||||
// remove and delete all units
|
// remove and delete all units
|
||||||
void DeleteAll();
|
void DeleteAll();
|
||||||
|
|
||||||
|
@ -17,6 +17,14 @@ T Interpolate( T& a, T& b, float l )
|
|||||||
return( a + ( b - a ) * l );
|
return( a + ( b - a ) * l );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T clamp(T value,T min,T max)
|
||||||
|
{
|
||||||
|
if (value<min) return min;
|
||||||
|
else if (value>max) return max;
|
||||||
|
else return value;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -15,8 +15,8 @@ const float EPSILON=0.0001f;
|
|||||||
|
|
||||||
CQuaternion::CQuaternion()
|
CQuaternion::CQuaternion()
|
||||||
{
|
{
|
||||||
m_V.Clear ();
|
m_V.Clear();
|
||||||
m_W = 0;
|
m_W = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//quaternion addition
|
//quaternion addition
|
||||||
@ -202,3 +202,16 @@ void CQuaternion::FromAxisAngle(const CVector3D& axis,float angle)
|
|||||||
m_V.Z=axis.Z*sinHalfTheta;
|
m_V.Z=axis.Z*sinHalfTheta;
|
||||||
m_W=cosHalfTheta;
|
m_W=cosHalfTheta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Normalize: normalize this quaternion
|
||||||
|
void CQuaternion::Normalize()
|
||||||
|
{
|
||||||
|
float lensqrd=SQR(m_V.X)+SQR(m_V.Y)+SQR(m_V.Z)+SQR(m_W);
|
||||||
|
if (lensqrd>0) {
|
||||||
|
float invlen=1.0f/float(sqrt(lensqrd));
|
||||||
|
m_V*=invlen;
|
||||||
|
m_W*=invlen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -42,6 +42,8 @@ public:
|
|||||||
// create a quaternion from axis/angle representation of a rotation
|
// create a quaternion from axis/angle representation of a rotation
|
||||||
void FromAxisAngle(const CVector3D& axis,float angle);
|
void FromAxisAngle(const CVector3D& axis,float angle);
|
||||||
|
|
||||||
|
// normalize this quaternion
|
||||||
|
void Normalize();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user