1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/* $Id: Collision.h,v 1.5 2003/02/14 05:21:18 mrq Exp $
**
** Ark - Libraries, Tools & Programs for MMORPG developpements.
** Copyright (C) 1999-2000 The Contributors of the Ark Project
** Please see the file "AUTHORS" for a list of contributors
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef COLLISION_H
#define COLLISION_H
#include <Ark/ArkModel.h>
#include <Ark/ArkCollision.h>
#include <vector>
#include "Opcode.h"
#undef Log
namespace Ark
{
class CDModel;
struct ARKCOLLISION_DLL_API CDSubmodel
{
Opcode::OPCODE_Model *m_CDModel;
SubModel *m_Model;
CDModel *m_ColModel;
VertexBuffer m_SkelVB; // filled only when the model is animated.
/// indices for triangles, (a,b,c)
std::vector<udword> m_Triangles;
std::vector<udword> m_Materials;
};
extern void CD_GetTriangle (uint triangleindex,
Vector3 *points,
int *mat,
CDSubmodel *mdl);
class ARKCOLLISION_DLL_API CDRaytrace
{
private:
CDSubmodel *m_SubMdl;
Ray m_Ray;
Vector3 m_CenterCoeff;
Vector3 m_ExtentCoeff;
// Result
Vector3 m_Triangle[3];
int m_Material;
Vector3 m_Pos;
bool RayTest (const Opcode::AABBQuantizedNoLeafNode *node);
bool RayTest (const Opcode::QuantizedAABB *ab);
bool RayTest (Opcode::AABBQuantizedNoLeafTree *tree,
CDSubmodel *submdl);
public:
CDRaytrace () : m_Ray (Vector3(0.0,0.0,0.0), Vector3(0.0,1.0,0.0))
{}
bool RayTest (const ModelState &ms,
const Ray &ray,
Collision &collision);
};
/** */
class ARKCOLLISION_DLL_API CDModel : public ColModel
{
friend class CDSystem;
friend class CDRaytrace;
friend void CD_GetTriangle (uint triangleindex,
Vector3 *points,
int *mat,
CDSubmodel *mdl);
std::vector<CDSubmodel*> m_SubModels;
Model *m_Model;
bool m_HasSkel;
Matrix44 *m_BoneMatrices;
public:
CDModel ();
virtual ~CDModel();
void Build (Model *model);
private:
CDSubmodel *BuildSubmodel (SubModel *mdl);
};
/**
*/
class ARKCOLLISION_DLL_API CDSystem : public ColSystem
{
Opcode::AABBTreeCollider m_TreeCollider;
CDRaytrace m_Raytracer;
public:
CDSystem();
/**
* Destroy the given collision system. The collision models won't
* be destroyed, so you have to be careful to delete them before
* you call this destructor. Otherwise the effects are unpredictable.
*/
virtual ~CDSystem ();
/**
* Returns true if a collision occurs between the two models
* given as arguments. In such a case, the function fills the fields
* of the pair structure.
*
* Remark : only the first collision is taken into account.
*/
virtual bool TestCollision (ModelState &m1, ModelState &m2,
ColPair &pair);
/**
* Returns true if the ray hits the model given as first argument.
*/
virtual bool RayTrace (ModelState &m1, const Ray &ray,
Collision &col);
/** Return true if the given bounding box hits the model.
*/
virtual bool BoxTest (ModelState &m1, const BBox &box);
/** Create a collision model from the given model. */
virtual ColModel *CreateModel (Model *from);
};
}
#include <Ark/ArkFactoryDef.h>
ARK_REGISTER_DEF(ARKCOLLISION_DLL_API);
#endif
|