00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #pragma once
00026 #ifndef COLLISIONTOOLS_H
00027 #define COLLISIONTOOLS_H
00028
00029 #pragma warning (disable : 4530)
00030
00031 #include "../SCOLBasic/SO3Std.h"
00032
00033 using namespace Ogre;
00034
00035
00036 enum QueryFlags
00037 {
00038 WATER_MASK = 1<<7,
00039 ENTITY_MASK = 1<<8,
00040 ROAD_MASK = 1<<9,
00041 FOILAGE_MASK = 1<<10,
00042 MOBILE_MASK = 1<<11,
00043 };
00044
00048 class MFACEDATA
00049 {
00050 public:
00051 Vector3 point;
00052 int indexFace;
00053 Vector3 v1;
00054 Vector3 v2;
00055 Vector3 v3;
00056 Vector2 pReal1;
00057 Vector2 pReal2;
00058 Vector2 pReal3;
00059 Vector2 uvResult;
00060 protected:
00061 private:
00062
00063 public:
00066 MFACEDATA();
00067
00071 MFACEDATA(const MFACEDATA& faceData);
00072 protected:
00073 private:
00074 };
00075
00076 namespace MOC {
00077
00078 class CollisionTools {
00079 public:
00080 Ogre::RaySceneQuery* mRaySceneQuery;
00081 Ogre::RaySceneQuery* mTSMRaySceneQuery;
00082
00083 SceneManager* mSceneMgr;
00084
00085 CollisionTools(Ogre::SceneManager* sceneMgr);
00086 ~CollisionTools();
00087
00088 bool collidesWithEntity(const Vector3& fromPoint, const Vector3& toPoint, const float collisionRadius = 2.5f, const float rayHeightLevel = 0.0f, const uint32 queryMask = 0xFFFFFFFF);
00089
00090 void calculateY(SceneNode*n, const bool doTerrainCheck = true, const bool doGridCheck = true, const float gridWidth = 1.0f, const uint32 queryMask = 0xFFFFFFFF);
00091
00092 float getTSMHeightAt(const float x, const float z);
00093
00094 bool raycastFromPoint(const Vector3 &point, const Vector3 &normal, Vector3 &result,ulong &target,float &closest_distance, const uint32 queryMask = 0xFFFFFFFF);
00095
00096 bool raycast(const Ray &ray, Vector3 &result,ulong &target,float &closest_distance,int &indexSubEntity,MFACEDATA* faceData, const uint32 queryMask = 0xFFFFFFFF, bool extendedInfo = false);
00097 Vector3 GetBarycentricCoordinates(const Vector3 &P1, const Vector3 &P2, const Vector3 &P3, const Vector3 &P);
00098 void setHeightAdjust(const float heightadjust);
00099 float getHeightAdjust(void);
00100
00101 private:
00102
00103 float _heightAdjust;
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 void GetMeshInformation(const Entity*mEntity,
00115 size_t &vertex_count,
00116 Ogre::Vector4* &vertices,
00117 size_t &index_count,
00118 unsigned long* &indices,
00119 const Ogre::Vector3 &position,
00120 const Ogre::Quaternion &orient,
00121 const Ogre::Vector3 &scale);
00122
00123 void GetSubMeshInformation(SEntity* mEntity,
00124 Ogre::SubMesh* submesh,
00125 int i,
00126 size_t &vertex_count,
00127 Ogre::Vector3* &vertices,
00128 size_t &index_count,
00129 unsigned long* &indices,
00130 const Ogre::Vector3 &position,
00131 const Ogre::Quaternion &orient,
00132 const Ogre::Vector3 &scale);
00133
00134 };
00135
00136 };
00137
00138 #endif