TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
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
55 bbox = shapePtr->bbox(curr);
56 lower[X].move(bbox.getLower(X));
57 lower[Y].move(bbox.getLower(Y));
58 lower[Z].move(bbox.getLower(Z));
59 upper[X].move(bbox.getUpper(X));
60 upper[Y].move(bbox.getUpper(Y));
61 upper[Z].move(bbox.getUpper(Z));
62}
63
65 prev = curr;
66}
67
70
71
72bool 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
78bool 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
84bool 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
97
98bool 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
105bool 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
111bool 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
117bool 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
130
131bool 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
138bool 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}
bool intersect(const BBox &a, const BBox &b)
Definition BBox.h:92
bool find_prim(const BBoxNode *tree, const Convex &c, const BBox &bb, const Transform &b2a, Vector &v, ShapePtr &p)
Definition BBoxTree.cpp:154
bool common_point(const BBoxNode *tree, const Convex &c, const BBox &bb, const Transform &b2a, Vector &v, Point &pa, Point &pb)
Definition BBoxTree.cpp:204
const Scalar INFINITY_
Definition Basic.h:41
@ Y
Definition Basic.h:58
@ X
Definition Basic.h:58
@ Z
Definition Basic.h:58
static Point p[4]
Definition Convex.cpp:54
void closest_points(const Convex &a, const Convex &b, const Transform &a2w, const Transform &b2w, Point &pa, Point &pb)
Definition Convex.cpp:386
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
AlgoTable< Common_point > Common_pointTable
Definition Object.cpp:69
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
Common_pointTable * common_pointInitialize()
Definition Object.cpp:123
bool intersect(const Object &a, const Object &b, Vector &v)
Definition Object.cpp:98
bool intersectComplexComplex(const Shape &a, const Shape &b, const Transform &a2w, const Transform &b2w, Vector &v)
Definition Object.cpp:84
AlgoTable< Intersect > IntersectTable
Definition Object.cpp:68
bool prev_closest_points(const Object &a, const Object &b, Vector &v, Point &pa, Point &pb)
Definition Object.cpp:138
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 intersectConvexConvex(const Shape &a, const Shape &b, const Transform &a2w, const Transform &b2w, Vector &v)
Definition Object.cpp:72
bool common_point(const Object &a, const Object &b, Vector &v, Point &pa, Point &pb)
Definition Object.cpp:131
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
bool(* Common_point)(const Shape &, const Shape &, const Transform &, const Transform &, Vector &, Point &, Point &)
Definition Shape.h:57
const Shape * ShapePtr
Definition Shape.h:51
@ COMPLEX
Definition Shape.h:40
@ CONVEX
Definition Shape.h:41
bool(* Intersect)(const Shape &, const Shape &, const Transform &, const Transform &, Vector &)
Definition Shape.h:53
Function lookup(ShapeType type1, ShapeType type2) const
Definition AlgoTable.h:46
DtObjectRef ref
Definition Object.h:64
BBox bbox
Definition Object.h:66
void move()
Definition Object.cpp:54
Transform curr
Definition Object.h:62
Transform prev
Definition Object.h:63
Endpoint upper[3]
Definition Object.h:68
Object(DtObjectRef obj, ShapePtr shape)
Definition Object.cpp:38
void proceed()
Definition Object.cpp:64
Endpoint lower[3]
Definition Object.h:67
ShapePtr shapePtr
Definition Object.h:65
Definition Point.h:34
Definition Shape.h:44
virtual ShapeType getType() const =0
void * DtObjectRef
Definition solid.h:39
#define MIN(x, y)
Definition tgf.h:56
#define MAX(x, y)
Definition tgf.h:52