Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
inttest.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_INTTEST_H
13#define TT_INCLUDE_INTTEST_H
14#include "OBBoxClass.h"
15class IntersectionTestClass
16{
17public:
18 IntersectionTestClass(int collision_type) : CollisionType(collision_type) { }
19 IntersectionTestClass(const IntersectionTestClass & that) : CollisionType(that.CollisionType) { }
20public:
21 int CollisionType;
22};
23class AABoxIntersectionTestClass : public IntersectionTestClass
24{
25public:
26 AABoxIntersectionTestClass(const AABoxClass & box,int collision_type) :
27 IntersectionTestClass(collision_type),
28 Box(box)
29 {
30 }
31 AABoxIntersectionTestClass(const AABoxIntersectionTestClass & that) :
32 IntersectionTestClass(that),
33 Box(that.Box)
34 {
35 }
36 bool Cull(const Vector3 & cull_min,const Vector3 & cull_max);
37 bool Cull(const AABoxClass & cull_box);
38 bool Intersect_Triangle(const TriClass & tri);
39public:
40 AABoxClass Box;
41};
42inline bool AABoxIntersectionTestClass::Cull(const Vector3 & cull_min,const Vector3 & cull_max)
43{
44 Vector3 box_min;
45 Vector3::Subtract(Box.Center,Box.Extent,&box_min);
46 Vector3 box_max;
47 Vector3::Add(Box.Center,Box.Extent,&box_max);
48 if ((box_min.X > cull_max.X) || (box_max.X < cull_min.X)) return true;
49 if ((box_min.Y > cull_max.Y) || (box_max.Y < cull_min.Y)) return true;
50 if ((box_min.Z > cull_max.Z) || (box_max.Z < cull_min.Z)) return true;
51}
52inline bool AABoxIntersectionTestClass::Cull(const AABoxClass & cull_box)
53{
54 Vector3 dc;
55 Vector3 r;
56 Vector3::Subtract(cull_box.Center,Box.Center,&dc);
57 Vector3::Add(cull_box.Extent,Box.Extent,&r);
58 if (WWMath::Fabs(dc.X) > r.X) return true;
59 if (WWMath::Fabs(dc.Y) > r.Y) return true;
60 if (WWMath::Fabs(dc.Z) > r.Z) return true;
61}
62class OBBoxIntersectionTestClass : public IntersectionTestClass
63{
64public:
65 OBBoxIntersectionTestClass(const OBBoxClass & box,int collision_type);
66 OBBoxIntersectionTestClass(const OBBoxIntersectionTestClass & that);
67 OBBoxIntersectionTestClass(const OBBoxIntersectionTestClass & that,const Matrix3D & tm);
68 OBBoxIntersectionTestClass(const AABoxIntersectionTestClass & that,const Matrix3D & tm);
69 bool Cull(const Vector3 & min,const Vector3 & max);
70 bool Cull(const AABoxClass & box);
71 bool Intersect_Triangle(const TriClass & tri);
72protected:
73 void update_bounding_box(void);
74public:
75 OBBoxClass Box;
76 AABoxClass BoundingBox;
77};
78inline OBBoxIntersectionTestClass::OBBoxIntersectionTestClass(const OBBoxClass & box,int collision_type) :
79 IntersectionTestClass(collision_type),
80 Box(box)
81{
82 update_bounding_box();
83}
84inline OBBoxIntersectionTestClass::OBBoxIntersectionTestClass(const OBBoxIntersectionTestClass & that) :
85 IntersectionTestClass(that),
86 Box(that.Box)
87{
88 update_bounding_box();
89}
90inline OBBoxIntersectionTestClass::OBBoxIntersectionTestClass
91(
92 const OBBoxIntersectionTestClass & that,
93 const Matrix3D & tm
94) :
95 IntersectionTestClass(that)
96{
97 OBBoxClass::Transform(tm,that.Box,&Box);
98 update_bounding_box();
99}
100inline OBBoxIntersectionTestClass::OBBoxIntersectionTestClass
101(
102 const AABoxIntersectionTestClass & that,
103 const Matrix3D & tm
104) :
105 IntersectionTestClass(that)
106{
107 Matrix3D::Transform_Vector(tm,that.Box.Center,&(Box.Center));
108 Box.Extent = that.Box.Extent;
109 Box.Basis = tm; // copies the 3x3 rotation portion of the transform
110 update_bounding_box();
111}
112inline bool OBBoxIntersectionTestClass::Cull(const Vector3 & cull_min,const Vector3 & cull_max)
113{
114 Vector3 box_min;
115 Vector3::Subtract(BoundingBox.Center,BoundingBox.Extent,&box_min);
116 Vector3 box_max;
117 Vector3::Add(BoundingBox.Center,BoundingBox.Extent,&box_max);
118 if ((box_min.X > cull_max.X) || (box_max.X < cull_min.X)) return true;
119 if ((box_min.Y > cull_max.Y) || (box_max.Y < cull_min.Y)) return true;
120 if ((box_min.Z > cull_max.Z) || (box_max.Z < cull_min.Z)) return true;
121 return false;
122}
123inline bool OBBoxIntersectionTestClass::Cull(const AABoxClass & cull_box)
124{
125 Vector3 dc;
126 Vector3 r;
127 Vector3::Subtract(cull_box.Center,BoundingBox.Center,&dc);
128 Vector3::Add(cull_box.Extent,BoundingBox.Extent,&r);
129 if (WWMath::Fabs(dc.X) > r.X) return true;
130 if (WWMath::Fabs(dc.Y) > r.Y) return true;
131 if (WWMath::Fabs(dc.Z) > r.Z) return true;
132 return false;
133}
134inline void OBBoxIntersectionTestClass::update_bounding_box(void)
135{
136 BoundingBox.Center = Box.Center;
137 Box.Basis.Rotate_AABox_Extent(Box.Extent,&BoundingBox.Extent);
138}
139
140#endif