12#ifndef TT_INCLUDE_INTTEST_H
13#define TT_INCLUDE_INTTEST_H
14#include "OBBoxClass.h"
15class IntersectionTestClass
18 IntersectionTestClass(
int collision_type) : CollisionType(collision_type) { }
19 IntersectionTestClass(
const IntersectionTestClass & that) : CollisionType(that.CollisionType) { }
23class AABoxIntersectionTestClass :
public IntersectionTestClass
26 AABoxIntersectionTestClass(
const AABoxClass & box,
int collision_type) :
27 IntersectionTestClass(collision_type),
31 AABoxIntersectionTestClass(
const AABoxIntersectionTestClass & that) :
32 IntersectionTestClass(that),
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);
42inline bool AABoxIntersectionTestClass::Cull(
const Vector3 & cull_min,
const Vector3 & cull_max)
45 Vector3::Subtract(Box.Center,Box.Extent,&box_min);
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;
52inline bool AABoxIntersectionTestClass::Cull(
const AABoxClass & cull_box)
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;
62class OBBoxIntersectionTestClass :
public IntersectionTestClass
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);
73 void update_bounding_box(
void);
76 AABoxClass BoundingBox;
78inline OBBoxIntersectionTestClass::OBBoxIntersectionTestClass(
const OBBoxClass & box,
int collision_type) :
79 IntersectionTestClass(collision_type),
82 update_bounding_box();
84inline OBBoxIntersectionTestClass::OBBoxIntersectionTestClass(
const OBBoxIntersectionTestClass & that) :
85 IntersectionTestClass(that),
88 update_bounding_box();
90inline OBBoxIntersectionTestClass::OBBoxIntersectionTestClass
92 const OBBoxIntersectionTestClass & that,
95 IntersectionTestClass(that)
97 OBBoxClass::Transform(tm,that.Box,&Box);
98 update_bounding_box();
100inline OBBoxIntersectionTestClass::OBBoxIntersectionTestClass
102 const AABoxIntersectionTestClass & that,
105 IntersectionTestClass(that)
107 Matrix3D::Transform_Vector(tm,that.Box.Center,&(Box.Center));
108 Box.Extent = that.Box.Extent;
110 update_bounding_box();
112inline bool OBBoxIntersectionTestClass::Cull(
const Vector3 & cull_min,
const Vector3 & cull_max)
115 Vector3::Subtract(BoundingBox.Center,BoundingBox.Extent,&box_min);
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;
123inline bool OBBoxIntersectionTestClass::Cull(
const AABoxClass & cull_box)
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;
134inline void OBBoxIntersectionTestClass::update_bounding_box(
void)
136 BoundingBox.Center = Box.Center;
137 Box.Basis.Rotate_AABox_Extent(Box.Extent,&BoundingBox.Extent);