Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
coltest.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#ifndef TT_INCLUDE_COLTEST_H
13#define TT_INCLUDE_COLTEST_H
14#include "coltype.h"
15#include "castresultstruct.h"
16#include "LineSegClass.h"
17#include "AABoxClass.h"
18#include "OBBoxClass.h"
19class RenderObjClass;
20class TriClass;
21class SCRIPTS_API CollisionTestClass
22{
23public:
24 CollisionTestClass(CastResultStruct * res,Collision_Type collision_type);
25 CollisionTestClass(const CollisionTestClass & that);
26public:
27 CastResultStruct * Result; // 0000
28 Collision_Type CollisionType; // 0004
29 RenderObjClass * CollidedRenderObj; // 0008
30}; // 000C
31
32inline CollisionTestClass::CollisionTestClass(CastResultStruct * res,Collision_Type collision_type) :
33 Result(res),
34 CollisionType(collision_type),
35 CollidedRenderObj(NULL)
36{
37}
38
39inline CollisionTestClass::CollisionTestClass(const CollisionTestClass & that) :
40 Result(that.Result),
41 CollisionType(that.CollisionType),
42 CollidedRenderObj(that.CollidedRenderObj)
43{
44}
45
46class RayCollisionTestClass : public CollisionTestClass
47{
48public:
49 LineSegClass Ray;
50 bool IgnoreTranslucentMeshes;
51
52 RayCollisionTestClass(const LineSegClass& ray, CastResultStruct* res, Collision_Type collision_type = COLLISION_TYPE_0, bool ignore_translucent_meshes = false);
53 RayCollisionTestClass(const RayCollisionTestClass& raytest, const Matrix3D& tm);
54
55 bool Cull(const Vector3& min,const Vector3& max);
56 bool Cull(const AABoxClass& box);
57
58 bool Cast_To_Triangle(const TriClass& tri);
59
60private:
61 RayCollisionTestClass(const RayCollisionTestClass &);
62 RayCollisionTestClass & operator = (const RayCollisionTestClass &);
63};
64
65inline RayCollisionTestClass::RayCollisionTestClass(const LineSegClass& ray, CastResultStruct* res, Collision_Type collision_type, bool ignore_translucent_meshes) :
66 CollisionTestClass(res, collision_type),
67 Ray(ray),
68 IgnoreTranslucentMeshes(ignore_translucent_meshes)
69{
70}
71
72inline RayCollisionTestClass::RayCollisionTestClass(const RayCollisionTestClass& raytest, const Matrix3D& tm) :
73 CollisionTestClass(raytest),
74 Ray(raytest.Ray, tm),
75 IgnoreTranslucentMeshes(raytest.IgnoreTranslucentMeshes)
76{
77}
78
79class SCRIPTS_API AABoxCollisionTestClass : public CollisionTestClass
80{
81public:
82 AABoxCollisionTestClass(const AABoxClass & aabox,const Vector3 & move,CastResultStruct * res,Collision_Type collision_type = COLLISION_TYPE_0);
83 AABoxCollisionTestClass(const AABoxCollisionTestClass & that);
84 enum ROTATION_TYPE
85 {
86 ROTATE_NONE = 0,
87 ROTATE_Z90,
88 ROTATE_Z180,
89 ROTATE_Z270
90 };
91 bool Cull(const Vector3 & min,const Vector3 & max);
92 bool Cull(const AABoxClass & box);
93 void Translate(const Vector3 & translation);
94 void Rotate(ROTATION_TYPE rotation);
95 void Transform(const Matrix3D & tm);
96public:
97 AABoxClass Box; // 000C
98 Vector3 Move; // 0024
99 Vector3 SweepMin; // 0030
100 Vector3 SweepMax; // 003C
101private:
102 AABoxCollisionTestClass & operator = (const AABoxCollisionTestClass &);
103}; // 0048
104
105inline void AABoxCollisionTestClass::Translate(const Vector3 & translation)
106{
107 Box.Center += translation;
108 SweepMin += translation;
109 SweepMax += translation;
110}
111
112inline bool AABoxCollisionTestClass::Cull(const Vector3 & min,const Vector3 & max)
113{
114 if ((SweepMin.X > max.X) || (SweepMax.X < min.X))
115 {
116 return true;
117 }
118 if ((SweepMin.Y > max.Y) || (SweepMax.Y < min.Y))
119 {
120 return true;
121 }
122 if ((SweepMin.Z > max.Z) || (SweepMax.Z < min.Z))
123 {
124 return true;
125 }
126 return false;
127}
128
129class SCRIPTS_API OBBoxCollisionTestClass : public CollisionTestClass
130{
131public:
132 OBBoxCollisionTestClass(const OBBoxClass & obbox,const Vector3 & move,CastResultStruct * res,Collision_Type type = COLLISION_TYPE_0);
133 OBBoxCollisionTestClass(const OBBoxCollisionTestClass & that);
134 OBBoxCollisionTestClass(const OBBoxCollisionTestClass & that,const Matrix3D & tm);
135 OBBoxCollisionTestClass(const AABoxCollisionTestClass & that,const Matrix3D & tm);
136 bool Cull(const Vector3 & min,const Vector3 & max);
137 bool Cull(const AABoxClass & box);
138public:
139 OBBoxClass Box;
140 Vector3 Move;
141 Vector3 SweepMin;
142 Vector3 SweepMax;
143private:
144 OBBoxCollisionTestClass & operator = (const OBBoxCollisionTestClass &);
145};
146
147inline bool OBBoxCollisionTestClass::Cull(const Vector3 & min,const Vector3 & max)
148{
149 if ((SweepMin.X > max.X) || (SweepMax.X < min.X))
150 {
151 return true;
152 }
153 if ((SweepMin.Y > max.Y) || (SweepMax.Y < min.Y))
154 {
155 return true;
156 }
157 if ((SweepMin.Z > max.Z) || (SweepMax.Z < min.Z))
158 {
159 return true;
160 }
161 return false;
162}
163
164#endif