ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
bball_collision_sphere.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_SPHERE_H
23 #define SCUMM_HE_BASKETBALL_COLLISION_BBALL_COLLISION_SPHERE_H
24 
25 #ifdef ENABLE_HE
26 
27 #include "scumm/he/basketball/collision/bball_collision_object.h"
28 #include "scumm/he/basketball/collision/bball_collision_stack.h"
29 
30 namespace Scumm {
31 
32 const int BOUNCE_SPEED_LIMIT = 20; // If the z-direction speed of the ball falls below this limit during a bounce, then the ball will begin to roll.
33 const int ROLL_SPEED_LIMIT = 20; // If the xy-direction speed of the ball falls below this limit during a roll, then the ball will stop.
34 const int ROLL_SLOWDOWN_FREQUENCY = 10; // The ball slows down every x frames while rolling.
35 
36 class CCollisionSphere : public ICollisionObject, public U32Sphere {
37 public:
38  CCollisionSphere() : ICollisionObject(kSphere),
39  _rollingCount(0),
40  _positionSaved(false) {}
41 
42  ~CCollisionSphere() {}
43 
44  using ICollisionObject::getObjectDistance;
45  float getObjectDistance(const CCollisionBox &targetObject) const override;
46  float getObjectDistance(const CCollisionCylinder &targetObject) const override;
47 
48  using ICollisionObject::testObjectIntersection;
49  bool testObjectIntersection(const CCollisionBox &targetObject, U32Distance3D *pDistance) const override;
50  bool testObjectIntersection(const CCollisionCylinder &targetObject, U32Distance3D *pDistance) const override;
51 
52  using ICollisionObject::validateCollision;
53  bool validateCollision(const CCollisionBox &targetObject, U32Distance3D *pDistance) override;
54  bool validateCollision(const CCollisionCylinder &targetObject, U32Distance3D *pDistance) override;
55 
56  using ICollisionObject::backOutOfObject;
57  bool backOutOfObject(const CCollisionBox &targetObject, U32Distance3D *pDistance, float *pTimeUsed) override;
58  bool backOutOfObject(const CCollisionCylinder &targetObject, U32Distance3D *pDistance, float *pTimeUsed) override;
59 
60  using ICollisionObject::nudgeObject;
61  bool nudgeObject(const CCollisionBox &targetObject, U32Distance3D *pDistance, float *pTimeUsed) override;
62  bool nudgeObject(const CCollisionCylinder &targetObject, U32Distance3D *pDistance, float *pTimeUsed) override;
63 
64  void handleCollisions(CCollisionObjectVector *pCollisionVector, float *pTimeUsed, bool advanceObject) override;
65 
66  using ICollisionObject::isOnObject;
67  bool isOnObject(const CCollisionBox &targetObject, const U32Distance3D &distance) const override;
68  bool isOnObject(const CCollisionCylinder &targetObject, const U32Distance3D &distance) const override;
69 
70  U32BoundingBox getBoundingBox() const override;
71  U32BoundingBox getBigBoundingBox() const override;
72 
73  void save() override;
74  void restore() override;
75 
76  int _rollingCount;
77 
78 
79 protected:
80  float getDimensionDistance(const CCollisionBox &targetObject, EDimension dimension) const;
81  float getDimensionDistance(const CCollisionCylinder &targetObject, EDimension dimension) const;
82 
83 private:
84  bool _positionSaved;
85  U32FltPoint3D _safetyPoint;
86  U32FltVector3D _safetyVelocity;
87 
88  bool backStraightOutOfObject(const ICollisionObject &targetObject, U32Distance3D *pDistance, float *pTimeUsed);
89 
90  using ICollisionObject::defineReflectionPlane;
91  void defineReflectionPlane(const CCollisionBox &targetObject, const U32Distance3D &distance, U32Plane *collisionPlane) const override;
92  void defineReflectionPlane(const CCollisionCylinder &targetObject, const U32Distance3D &distance, U32Plane *collisionPlane) const override;
93 
94  void reboundOffPlane(const U32Plane &collisionPlane, bool isOnPlane);
95 
96  using ICollisionObject::getPenetrationTime;
97  float getPenetrationTime(const CCollisionBox &targetObject, const U32Distance3D &distance, EDimension dimension) const override;
98  float getPenetrationTime(const CCollisionCylinder &targetObject, const U32Distance3D &distance, EDimension dimension) const override;
99 
100  void increaseVelocity(float minSpeed);
101 };
102 
103 
104 } // End of namespace Scumm
105 
106 #endif // ENABLE_HE
107 
108 #endif // SCUMM_HE_BASKETBALL_COLLISION_BBALL_COLLISION_SPHERE_H
Definition: actor.h:30