TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
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
49BBox 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
59void 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
65void 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];
73 new(free_node++) BBoxInternal(n, leaves);
74 }
75 else root = &leaves[0];
76}
77
78
79bool 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
88bool 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
99bool 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
108bool 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
119bool 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
128bool 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}
BBoxInternal * free_node
Definition Complex.cpp:37
@ Y
Definition Basic.h:58
@ X
Definition Basic.h:58
@ Z
Definition Basic.h:58
bool find_prim(const Complex &a, const Convex &b, const Transform &a2w, const Transform &b2w, Vector &v, ShapePtr &p)
Definition Complex.cpp:99
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
bool intersect(const Complex &a, const Convex &b, const Transform &a2w, const Transform &b2w, Vector &v)
Definition Complex.cpp:79
static Point p[4]
Definition Convex.cpp:54
Matrix absolute(const Matrix &m)
Definition Matrix.h:220
Scalar dot(const Quaternion &q1, const Quaternion &q2)
Definition Quaternion.h:163
const Shape * ShapePtr
Definition Shape.h:51
Definition BBox.h:36
void setExtent(const Vector &v)
Definition BBox.h:45
void setCenter(const Point &p)
Definition BBox.h:44
Complex()
Definition Complex.h:49
void changeBase(const Point *ptr)
Definition Complex.cpp:59
BBox bbox(const Transform &t) const
Definition Complex.cpp:49
VertexBase base
Definition Complex.h:90
BBoxLeaf * leaves
Definition Complex.h:93
~Complex()
Definition Complex.cpp:39
void finish(int n, const Polytope **p)
Definition Complex.cpp:65
void proceed()
Definition Complex.h:60
BBoxNode * root
Definition Complex.h:94
bool free_base
Definition Complex.h:92
int count
Definition Complex.h:95
virtual BBox bbox(const Transform &t) const
Definition Convex.cpp:38
Definition Point.h:34
void invert(const Transform &t)
Definition Transform.cpp:73
void multInverseLeft(const Transform &t1, const Transform &t2)
Definition Transform.cpp:87
const Matrix & getBasis() const
Definition Transform.h:53