ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
bball_collision_object.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SCUMM_HE_BASKETBALL_COLLISION_BBALL_COLLISION_OBJECT_H
23 #define SCUMM_HE_BASKETBALL_COLLISION_BBALL_COLLISION_OBJECT_H
24 
25 #ifdef ENABLE_HE
26 
27 #include "common/str.h"
28 
29 #include "scumm/he/basketball/collision/bball_collision_support_obj.h"
30 #include "scumm/he/basketball/collision/bball_collision_stack.h"
31 
32 namespace Scumm {
33 
34 #define COLLISION_EPSILON 0.5F
35 #define COLLISION_SMALL_TIME_INCREMENT 0.05F
36 #define COLLISION_BACK_OUT_TIME_LIMIT 20.0F
37 
38 class CCollisionSphere;
39 class CCollisionBox;
40 class CCollisionCylinder;
41 class CCollisionObjectStack;
42 class CCollisionObjectVector;
43 
44 enum EObjectShape {
45  kNoObjectShape = 0,
46  kSphere = 1,
47  kBox = 2,
48  kCylinder = 3
49 };
50 
51 enum EObjectType {
52  kNoObjectType = 0,
53  kBackboard = 1,
54  kRim = 2,
55  kOtherType = 3,
56  kFloor = 4,
57  kBall = 5,
58  kPlayer = 6
59 };
60 
61 class ICollisionObject {
62 public:
63  ICollisionObject(EObjectShape shape = kNoObjectShape);
64  virtual ~ICollisionObject() {}
65 
66  // Comparison operator
67  bool operator==(const ICollisionObject &otherObject) const;
68 
69  // Get the distance between the outside of this object and the outside of a target object
70  virtual float getObjectDistance(const ICollisionObject &targetObject) const;
71  virtual float getObjectDistance(const CCollisionSphere &targetObject) const { return 0.0F; }
72  virtual float getObjectDistance(const CCollisionBox &targetObject) const { return 0.0F; }
73  virtual float getObjectDistance(const CCollisionCylinder &targetObject) const { return 0.0F; }
74 
75  // testObjectIntersection is used to determine if this object is intersecting a target object
76  virtual bool testObjectIntersection(const ICollisionObject &targetObject, U32Distance3D *distance) const;
77  virtual bool testObjectIntersection(const CCollisionSphere &targetObject, U32Distance3D *distance) const { return false; }
78  virtual bool testObjectIntersection(const CCollisionBox &targetObject, U32Distance3D *distance) const { return false; }
79  virtual bool testObjectIntersection(const CCollisionCylinder &targetObject, U32Distance3D *distance) const { return false; }
80 
81  // Just because this object is intersecting another, doesn't mean that it collided with
82  // that object. That object could have collided with us. This function verifies, that
83  // we collided with another object...
84  virtual bool validateCollision(const ICollisionObject &targetObject, U32Distance3D *distance);
85  virtual bool validateCollision(const CCollisionSphere &targetObject, U32Distance3D *distance) { return true; }
86  virtual bool validateCollision(const CCollisionBox &targetObject, U32Distance3D *distance) { return true; }
87  virtual bool validateCollision(const CCollisionCylinder &targetObject, U32Distance3D *distance) { return true; }
88 
89  // backOutOfObject moves this object backwards along its velocity vector to a point
90  // where it is guaranteed not to be intersecting a target object
91  virtual bool backOutOfObject(const ICollisionObject &targetObject, U32Distance3D *distance, float *timeUsed);
92  virtual bool backOutOfObject(const CCollisionSphere &targetObject, U32Distance3D *distance, float *timeUsed) { return true; }
93  virtual bool backOutOfObject(const CCollisionBox &targetObject, U32Distance3D *distance, float *timeUsed) { return true; }
94  virtual bool backOutOfObject(const CCollisionCylinder &targetObject, U32Distance3D *distance, float *timeUsed) { return true; }
95 
96  // nudgeObject moves this object forward along its velocity vector to a point
97  // where it is guaranteed to be touching the target object at the exact point
98  // of collision
99  virtual bool nudgeObject(const ICollisionObject &targetObject, U32Distance3D *distance, float *timeUsed);
100  virtual bool nudgeObject(const CCollisionSphere &targetObject, U32Distance3D *distance, float *timeUsed) { return true; }
101  virtual bool nudgeObject(const CCollisionBox &targetObject, U32Distance3D *distance, float *timeUsed) { return true; }
102  virtual bool nudgeObject(const CCollisionCylinder &targetObject, U32Distance3D *distance, float *timeUsed) { return true; }
103 
104  // Some collisions between objects are recorded, but not handled physically. This
105  // function determines whether a collision gets handled or not...
106  virtual bool isCollisionHandled(const ICollisionObject &targetObject) const;
107  virtual bool isCollisionHandled(const CCollisionSphere &targetObject) const { return true; }
108  virtual bool isCollisionHandled(const CCollisionBox &targetObject) const { return true; }
109  virtual bool isCollisionHandled(const CCollisionCylinder &targetObject) const { return true; }
110 
111  // handleCollisions alters this objects velocity and position as a result of
112  // a collision with one or more target objects
113  virtual void handleCollisions(CCollisionObjectVector *pCollisionVector, float *timeUsed, bool advanceObject);
114  virtual void handleCollision(const CCollisionSphere &targetObject, float *timeUsed, U32Distance3D *distance, bool advanceObject) {}
115  virtual void handleCollision(const CCollisionBox &targetObject, float *timeUsed, U32Distance3D *distance, bool advanceObject) {}
116  virtual void handleCollision(const CCollisionCylinder &targetObject, float *timeUsed, U32Distance3D *distance, bool advanceObject) {}
117 
118  // Determine if this object is resting, running, or rolling on another object.
119  // An object doing this would not necessarily trigger an intersection...
120  virtual bool isOnObject(const ICollisionObject &targetObject, const U32Distance3D &distance) const;
121  virtual bool isOnObject(const CCollisionSphere &targetObject, const U32Distance3D &distance) const { return false; }
122  virtual bool isOnObject(const CCollisionBox &targetObject, const U32Distance3D &distance) const { return false; }
123  virtual bool isOnObject(const CCollisionCylinder &targetObject, const U32Distance3D &distance) const { return false; }
124 
125  // Return a 3-dimensional bounding box for this object
126  virtual U32BoundingBox getBoundingBox() const = 0;
127  virtual U32BoundingBox getBigBoundingBox() const = 0;
128 
129  // Return the point on the surface of the object that is closest to the input point
130  virtual U32FltPoint3D findNearestPoint(const U32FltPoint3D &testPoint) const;
131 
132  // Call this function when it is known that the object is at a legal location and is
133  // not intersecting any other objects
134  virtual void save() {}
135 
136  // Put the object at the last place that it was guaranteed to not be intersecting any
137  // other objects, and negate it's velocity vector
138  virtual void restore() {}
139 
140  Common::String _description;
141  EObjectShape _objectShape;
142  EObjectType _objectType;
143  int _objectID; // An identifier that uniquely identifies this object
144 
145  U32FltVector3D _velocity;
146 
147  float _collisionEfficiency; // A multiplier (range 0 to 1) that represents
148  // the percentage of velocity (perpendicular with
149  // the collision) that a target object retains
150  // when it collides with this object
151 
152  float _friction; // A multiplier (range 0 to 1) that represents
153  // the percentage of velocity (parallel with
154  // the collision) that a target object loses
155  // when it collides with this object
156 
157  int _soundNumber;
158 
159  bool _ignore; // There could be times when you want to ignore
160  // an object for collision purposes. This flag
161  // determines that.
162 
163  CCollisionObjectVector _objectCollisionHistory; // Stack with pointers to all the
164  // objects that this object collided
165  // with this frame
166 
167  CCollisionObjectVector _objectRollingHistory; // Stack with pointers to all the
168  // objects that this object rolled
169  // on this frame
170 
171 protected:
172  // Get the amount of time it took this sphere to penetrate whatever object it is
173  // currently intersecting in the given dimension
174  virtual float getPenetrationTime(const ICollisionObject &targetObject, const U32Distance3D &distance, EDimension dimension) const;
175  virtual float getPenetrationTime(const CCollisionSphere &targetObject, const U32Distance3D &distance, EDimension dimension) const { return 0.0F; }
176  virtual float getPenetrationTime(const CCollisionBox &targetObject, const U32Distance3D &distance, EDimension dimension) const { return 0.0F; }
177  virtual float getPenetrationTime(const CCollisionCylinder &targetObject, const U32Distance3D &distance, EDimension dimension) const { return 0.0F; }
178 
179  // Sometimes when this object collides with another object, it may want to treat
180  // the object at the point of collision like a plane. This can help simplify the
181  // collision. defineReflectionPlane defines a plane between this object and the
182  // target object at the point of collision...
183  virtual void defineReflectionPlane(const ICollisionObject &targetObject, const U32Distance3D &distance, U32Plane *collisionPlane) const;
184  virtual void defineReflectionPlane(const CCollisionSphere &targetObject, const U32Distance3D &distance, U32Plane *collisionPlane) const;
185  virtual void defineReflectionPlane(const CCollisionBox &targetObject, const U32Distance3D &distance, U32Plane *collisionPlane) const;
186  virtual void defineReflectionPlane(const CCollisionCylinder &targetObject, const U32Distance3D &distance, U32Plane *collisionPlane) const;
187 };
188 
189 } // End of namespace Scumm
190 
191 #endif // ENABLE_HE
192 
193 #endif // SCUMM_HE_BASKETBALL_COLLISION_BBALL_COLLISION_OBJECT_H
Definition: str.h:59
Definition: actor.h:30