TORCS  1.3.9
The Open Racing Car Simulator
Complex.cpp
Go to the documentation of this file.
1 /*
2  SOLID - Software Library for Interference Detection
3  Copyright (C) 1997-1998 Gino van den Bergen
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public
16  License along with this library; if not, write to the Free
17  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19  Please send remarks, questions and bug reports to gino@win.tue.nl,
20  or write to:
21  Gino van den Bergen
22  Department of Mathematics and Computing Science
23  Eindhoven University of Technology
24  P.O. Box 513, 5600 MB Eindhoven, The Netherlands
25 */
26 
27 #ifdef _MSC_VER
28 #pragma warning(disable:4786) // identifier was truncated to '255'
29 #endif // _MSC_VER
30 
31 #include "Complex.h"
32 #include "Transform.h"
33 #include "BBoxTree.h"
34 
35 #include <new>
36 
38 
40  if (count >= 2) delete [] root;
41  for (int i = 0; i < count; ++i) delete leaves[i].poly;
42  delete [] leaves;
43 #if (defined(_MSC_VER) && _MSC_VER < 1500)
44 #else
45  if (free_base) delete [] base.getPointer();
46 #endif
47 }
48 
49 BBox Complex::bbox(const Transform& t) const {
50  Matrix abs_b = absolute(t.getBasis());
51  BBox bb;
52  bb.setCenter(t(root->bbox.getCenter()));
53  bb.setExtent(Vector(dot(abs_b[X], root->bbox.getExtent()),
54  dot(abs_b[Y], root->bbox.getExtent()),
55  dot(abs_b[Z], root->bbox.getExtent())));
56  return bb;
57 }
58 
59 void Complex::changeBase(const Point *ptr) {
60  base = ptr;
61  for (int i = 0; i < count; ++i) leaves[i].fitBBox();
62  for (int j = count-1; j;) ((BBoxInternal *)root)[--j].refitBBox();
63 }
64 
65 void Complex::finish(int n, const Polytope **p) {
66  proceed();
67  leaves = new BBoxLeaf[n];
68  count = n;
69  for (int i = 0; i < n; ++i) new(&leaves[i]) BBoxLeaf(p[i]);
70  if (n >= 2) {
71  free_node = new BBoxInternal[n-1];
72  root = free_node;
73  new(free_node++) BBoxInternal(n, leaves);
74  }
75  else root = &leaves[0];
76 }
77 
78 
79 bool intersect(const Complex& a, const Convex& b,
80  const Transform& a2w, const Transform& b2w,
81  Vector& v) {
82  Transform b2a;
83  b2a.multInverseLeft(a2w, b2w);
84  BBox bb = b.bbox(b2a);
85  return intersect(a.root, b, bb, b2a, v);
86 }
87 
88 bool intersect(const Complex& a, const Complex& b,
89  const Transform& a2w, const Transform& b2w,
90  Vector& v) {
91  Transform b2a, a2b;
92  b2a.multInverseLeft(a2w, b2w);
93  a2b.invert(b2a);
94  Matrix abs_b2a = absolute(b2a.getBasis());
95  Matrix abs_a2b = absolute(a2b.getBasis());
96  return intersect(a.root, b.root, b2a, abs_b2a, a2b, abs_a2b, v);
97 }
98 
99 bool find_prim(const Complex& a, const Convex& b,
100  const Transform& a2w, const Transform& b2w,
101  Vector& v, ShapePtr& p) {
102  Transform b2a;
103  b2a.multInverseLeft(a2w, b2w);
104  BBox bb = b.bbox(b2a);
105  return find_prim(a.root, b, bb, b2a, v, p);
106 }
107 
108 bool find_prim(const Complex& a, const Complex& b,
109  const Transform& a2w, const Transform& b2w,
110  Vector& v, ShapePtr& pa, ShapePtr& pb) {
111  Transform b2a, a2b;
112  b2a.multInverseLeft(a2w, b2w);
113  a2b.invert(b2a);
114  Matrix abs_b2a = absolute(b2a.getBasis());
115  Matrix abs_a2b = absolute(a2b.getBasis());
116  return find_prim(a.root, b.root, b2a, abs_b2a, a2b, abs_a2b, v, pa, pb);
117 }
118 
119 bool common_point(const Complex& a, const Convex& b,
120  const Transform& a2w, const Transform& b2w,
121  Vector& v, Point& pa, Point& pb) {
122  Transform b2a;
123  b2a.multInverseLeft(a2w, b2w);
124  BBox bb = b.bbox(b2a);
125  return common_point(a.root, b, bb, b2a, v, pb, pa);
126 }
127 
128 bool common_point(const Complex& a, const Complex& b,
129  const Transform& a2w, const Transform& b2w,
130  Vector& v, Point& pa, Point& pb) {
131  Transform b2a, a2b;
132  b2a.multInverseLeft(a2w, b2w);
133  a2b.invert(b2a);
134  Matrix abs_b2a = absolute(b2a.getBasis());
135  Matrix abs_a2b = absolute(a2b.getBasis());
136  return common_point(a.root, b.root, b2a, abs_b2a, a2b, abs_a2b, v, pa, pb);
137 }
void finish(int n, const Polytope **p)
Definition: Complex.cpp:65
BBoxInternal * free_node
Definition: Complex.cpp:37
const Point & getCenter() const
Definition: BBox.h:41
const Matrix & getBasis() const
Definition: Transform.h:53
bool common_point(const Complex &a, const Convex &b, const Transform &a2w, const Transform &b2w, Vector &v, Point &pa, Point &pb)
Definition: Complex.cpp:119
Definition: Convex.h:39
void multInverseLeft(const Transform &t1, const Transform &t2)
Definition: Transform.cpp:87
Matrix absolute(const Matrix &m)
Definition: Matrix.h:220
Scalar dot(const Quaternion &q1, const Quaternion &q2)
Definition: Quaternion.h:163
void invert(const Transform &t)
Definition: Transform.cpp:73
Definition: Basic.h:58
int count
Definition: Complex.h:95
Definition: Basic.h:58
BBox bbox
Definition: BBoxTree.h:45
void setCenter(const Point &p)
Definition: BBox.h:44
bool intersect(const Complex &a, const Convex &b, const Transform &a2w, const Transform &b2w, Vector &v)
Definition: Complex.cpp:79
BBoxNode * root
Definition: Complex.h:94
static Point p[4]
Definition: Convex.cpp:54
Definition: Basic.h:58
Definition: Shape.h:44
Definition: BBox.h:36
VertexBase base
Definition: Complex.h:90
virtual BBox bbox(const Transform &t) const
Definition: Convex.cpp:38
BBox bbox(const Transform &t) const
Definition: Complex.cpp:49
bool free_base
Definition: Complex.h:92
Definition: Matrix.h:37
BBoxLeaf * leaves
Definition: Complex.h:93
~Complex()
Definition: Complex.cpp:39
void proceed()
Definition: Complex.h:60
const Vector & getExtent() const
Definition: BBox.h:42
Definition: Vector.h:32
void changeBase(const Point *ptr)
Definition: Complex.cpp:59
bool find_prim(const Complex &a, const Convex &b, const Transform &a2w, const Transform &b2w, Vector &v, ShapePtr &p)
Definition: Complex.cpp:99
Definition: Point.h:34
const Point * getPointer() const
Definition: VertexBase.h:40