TORCS  1.3.9
The Open Racing Car Simulator
Object.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 "Object.h"
32 #include "AlgoTable.h"
33 #include "Convex.h"
34 #include "Complex.h"
35 
36 #include <new>
37 
39  ref(obj),
40  shapePtr(shape),
43 {
44  curr.setIdentity();
45  new (&lower[X]) Endpoint(X, MIN, this);
46  new (&lower[Y]) Endpoint(Y, MIN, this);
47  new (&lower[Z]) Endpoint(Z, MIN, this);
48  new (&upper[X]) Endpoint(X, MAX, this);
49  new (&upper[Y]) Endpoint(Y, MAX, this);
50  new (&upper[Z]) Endpoint(Z, MAX, this);
51  proceed();
52 }
53 
54 void Object::move() {
55  bbox = shapePtr->bbox(curr);
62 }
63 
65  prev = curr;
66 }
67 
70 
71 
72 bool intersectConvexConvex(const Shape& a, const Shape& b,
73  const Transform& a2w, const Transform& b2w,
74  Vector& v) {
75  return intersect((const Convex&)a, (const Convex&)b, a2w, b2w, v);
76 }
77 
78 bool intersectComplexConvex(const Shape& a, const Shape& b,
79  const Transform& a2w, const Transform& b2w,
80  Vector& v) {
81  return intersect((const Complex&)a, (const Convex&)b, a2w, b2w, v);
82 }
83 
84 bool intersectComplexComplex(const Shape& a, const Shape& b,
85  const Transform& a2w, const Transform& b2w,
86  Vector& v) {
87  return intersect((const Complex&)a, (const Complex&)b, a2w, b2w, v);
88 }
89 
91  static IntersectTable p;
95  return &p;
96 }
97 
98 bool intersect(const Object& a, const Object& b, Vector& v) {
99  static IntersectTable *intersectTable = intersectInitialize();
101  intersectTable->lookup(a.shapePtr->getType(), b.shapePtr->getType());
102  return intersect(*a.shapePtr, *b.shapePtr, a.curr, b.curr, v);
103 }
104 
105 bool common_pointConvexConvex(const Shape& a, const Shape& b,
106  const Transform& a2w, const Transform& b2w,
107  Vector& v, Point& pa, Point& pb) {
108  return common_point((const Convex&)a, (const Convex&)b, a2w, b2w, v, pa, pb);
109 }
110 
111 bool common_pointComplexConvex(const Shape& a, const Shape& b,
112  const Transform& a2w, const Transform& b2w,
113  Vector& v, Point& pa, Point& pb) {
114  return common_point((const Complex&)a, (const Convex&)b, a2w, b2w, v, pa, pb);
115 }
116 
117 bool common_pointComplexComplex(const Shape& a, const Shape& b,
118  const Transform& a2w, const Transform& b2w,
119  Vector& v, Point& pa, Point& pb) {
120  return common_point((const Complex&)a, (const Complex&)b, a2w, b2w, v, pa, pb);
121 }
122 
124  static Common_pointTable p;
128  return &p;
129 }
130 
131 bool common_point(const Object& a, const Object& b, Vector& v, Point& pa, Point& pb) {
132  static Common_pointTable *common_pointTable = common_pointInitialize();
134  common_pointTable->lookup(a.shapePtr->getType(), b.shapePtr->getType());
135  return common_point(*a.shapePtr, *b.shapePtr, a.curr, b.curr, v, pa, pb);
136 }
137 
138 bool prev_closest_points(const Object& a, const Object& b,
139  Vector& v, Point& pa, Point& pb) {
140  ShapePtr sa, sb;
141  if (a.shapePtr->getType() == COMPLEX) {
142  if (b.shapePtr->getType() == COMPLEX) {
143  if (!find_prim((const Complex&)*a.shapePtr, (const Complex&)*b.shapePtr,
144  a.curr, b.curr, v, sa, sb)) return false;
145  ((Complex *)a.shapePtr)->swapBase();
146  if (b.shapePtr != a.shapePtr) ((Complex *)b.shapePtr)->swapBase();
147  closest_points((const Convex&)*sa, (const Convex&)*sb, a.prev, b.prev, pa, pb);
148  ((Complex *)a.shapePtr)->swapBase();
149  if (b.shapePtr != a.shapePtr) ((Complex *)b.shapePtr)->swapBase();
150  }
151  else {
152  if (!find_prim((const Complex&)*a.shapePtr, (const Convex&)*b.shapePtr,
153  a.curr, b.curr, v, sa)) return false;
154  ((Complex *)a.shapePtr)->swapBase();
155  closest_points((const Convex&)*sa, (const Convex&)*b.shapePtr, a.prev, b.prev, pa, pb);
156  ((Complex *)a.shapePtr)->swapBase();
157  }
158  }
159  else {
160  if (!intersect(a, b, v)) return false;
161  closest_points((const Convex&)*a.shapePtr, (const Convex&)*b.shapePtr, a.prev, b.prev, pa, pb);
162  }
163 
164  return true;
165 }
AlgoTable< Common_point > Common_pointTable
Definition: Object.cpp:69
virtual BBox bbox(const Transform &t) const =0
void closest_points(const Convex &a, const Convex &b, const Transform &a2w, const Transform &b2w, Point &pa, Point &pb)
Definition: Convex.cpp:386
Transform curr
Definition: Object.h:62
Object(DtObjectRef obj, ShapePtr shape)
Definition: Object.cpp:38
Definition: Shape.h:40
bool prev_closest_points(const Object &a, const Object &b, Vector &v, Point &pa, Point &pb)
Definition: Object.cpp:138
Endpoint upper[3]
Definition: Object.h:68
Definition: Convex.h:39
const Scalar INFINITY_
Definition: Basic.h:41
void move(Scalar x)
Definition: Endpoint.cpp:82
bool common_pointConvexConvex(const Shape &a, const Shape &b, const Transform &a2w, const Transform &b2w, Vector &v, Point &pa, Point &pb)
Definition: Object.cpp:105
Endpoint lower[3]
Definition: Object.h:67
Definition: Basic.h:58
bool(* Common_point)(const Shape &, const Shape &, const Transform &, const Transform &, Vector &, Point &, Point &)
Definition: Shape.h:57
virtual ShapeType getType() const =0
void move()
Definition: Object.cpp:54
Definition: Basic.h:58
bool intersect(const Object &a, const Object &b, Vector &v)
Definition: Object.cpp:98
bool common_pointComplexComplex(const Shape &a, const Shape &b, const Transform &a2w, const Transform &b2w, Vector &v, Point &pa, Point &pb)
Definition: Object.cpp:117
ShapePtr shapePtr
Definition: Object.h:65
BBox bbox
Definition: Object.h:66
Definition: Endpoint.h:36
Function lookup(ShapeType type1, ShapeType type2) const
Definition: AlgoTable.h:46
bool intersectComplexComplex(const Shape &a, const Shape &b, const Transform &a2w, const Transform &b2w, Vector &v)
Definition: Object.cpp:84
static Point p[4]
Definition: Convex.cpp:54
Definition: Basic.h:58
Definition: Shape.h:44
bool common_point(const Object &a, const Object &b, Vector &v, Point &pa, Point &pb)
Definition: Object.cpp:131
Transform prev
Definition: Object.h:63
bool intersectConvexConvex(const Shape &a, const Shape &b, const Transform &a2w, const Transform &b2w, Vector &v)
Definition: Object.cpp:72
void proceed()
Definition: Object.cpp:64
Definition: Shape.h:41
bool common_pointComplexConvex(const Shape &a, const Shape &b, const Transform &a2w, const Transform &b2w, Vector &v, Point &pa, Point &pb)
Definition: Object.cpp:111
bool intersectComplexConvex(const Shape &a, const Shape &b, const Transform &a2w, const Transform &b2w, Vector &v)
Definition: Object.cpp:78
IntersectTable * intersectInitialize()
Definition: Object.cpp:90
Scalar getLower(int i) const
Definition: BBox.h:79
void setIdentity()
Definition: Transform.cpp:67
Scalar getUpper(int i) const
Definition: BBox.h:80
bool(* Intersect)(const Shape &, const Shape &, const Transform &, const Transform &, Vector &)
Definition: Shape.h:53
Definition: Vector.h:32
Definition: Object.h:41
Definition: Endpoint.h:36
AlgoTable< Intersect > IntersectTable
Definition: Object.cpp:68
Common_pointTable * common_pointInitialize()
Definition: Object.cpp:123
void * DtObjectRef
Definition: solid.h:39
Definition: Point.h:34
bool find_prim(const BBoxNode *tree, const Convex &c, const BBox &bb, const Transform &b2a, Vector &v, ShapePtr &p)
Definition: BBoxTree.cpp:154