ScummVM API documentation
bball_collision_cylinder.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_CYLINDER_H
23 #define SCUMM_HE_BASKETBALL_COLLISION_BBALL_COLLISION_CYLINDER_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 #define MAX_STEP_HEIGHT 50
33 
34 // An object's velocity can either be carried
35 // out as straight or circular movement...
36 enum EMovementType {
37  kStraight = 0,
38  kCircular = 1 // 2D circular motion along the horizon plane
39 };
40 
41 class CCollisionCylinder : public ICollisionObject, public U32Cylinder {
42 public:
43  CCollisionCylinder() : ICollisionObject(kCylinder),
44  height(0),
45  _shieldRadius(0),
46  _movementType(EMovementType::kStraight),
47  _revCenter(nullptr),
48  _positionSaved(false) {}
49 
50  ~CCollisionCylinder() {}
51 
52  using ICollisionObject::getObjectDistance;
53  float getObjectDistance(const CCollisionSphere &targetObject) const override;
54  float getObjectDistance(const CCollisionBox &targetObject) const override;
55  float getObjectDistance(const CCollisionCylinder &targetObject) const override;
56 
57  using ICollisionObject::testObjectIntersection;
58  bool testObjectIntersection(const CCollisionSphere &targetObject, U32Distance3D *distance) const override;
59  bool testObjectIntersection(const CCollisionBox &targetObject, U32Distance3D *distance) const override;
60  bool testObjectIntersection(const CCollisionCylinder &targetObject, U32Distance3D *distance) const override;
61 
62  using ICollisionObject::validateCollision;
63  bool validateCollision(const CCollisionCylinder &targetObject, U32Distance3D *distance) override;
64 
65  using ICollisionObject::backOutOfObject;
66  bool backOutOfObject(const CCollisionBox &targetObject, U32Distance3D *distance, float *timeUsed) override;
67  bool backOutOfObject(const CCollisionCylinder &targetObject, U32Distance3D *distance, float *timeUsed) override;
68 
69  using ICollisionObject::nudgeObject;
70  bool nudgeObject(const CCollisionBox &targetObject, U32Distance3D *distance, float *timeUsed) override;
71  bool nudgeObject(const CCollisionCylinder &targetObject, U32Distance3D *distance, float *timeUsed) override;
72 
73  using ICollisionObject::isCollisionHandled;
74  bool isCollisionHandled(const CCollisionSphere &targetObject) const override { return false; };
75 
76  void handleCollisions(CCollisionObjectVector *collisionVector, float *timeUsed, bool advanceObject) override;
77  void handleCollision(const CCollisionCylinder &targetCylinder, float *timeUsed, U32Distance3D *distance, bool advanceObject) override;
78  void handleCollision(const CCollisionBox &targetBox, float *pTimeUsed, U32Distance3D *distance, bool advanceObject) override;
79 
80  using ICollisionObject::isOnObject;
81  bool isOnObject(const CCollisionSphere &targetObject, const U32Distance3D &distance) const override;
82  bool isOnObject(const CCollisionBox &targetObject, const U32Distance3D &distance) const override;
83  bool isOnObject(const CCollisionCylinder &targetObject, const U32Distance3D &distance) const override;
84 
85  U32FltPoint3D findNearestPoint(const U32FltPoint3D &testPoint) const override;
86  int getEquidistantPoint(U32FltPoint2D inPoint1, float distance1, U32FltPoint2D inPoint2, float distance2, U32FltPoint2D *outPoint1, U32FltPoint2D *outPoint2);
87 
88  U32BoundingBox getBoundingBox() const override;
89  U32BoundingBox getBigBoundingBox() const override;
90 
91  void save() override;
92  void restore() override;
93 
94  float height;
95  float _shieldRadius; // Sometimes we may want ot temporarily increase a player's
96  // effective collision radius. This value keeps track of
97  // how much their radius has been increased by.
98 
99  EMovementType _movementType;
100 
101  const ICollisionObject *_revCenter; // If an object is moving with circular motion,
102  // this is the object it is revolving around.
103  U32FltPoint2D _revCenterPt; // This is the center of the _revCenter.
104 
105 protected:
106  float getDimensionDistance(const CCollisionBox &targetObject, EDimension dimension) const;
107  float getDimensionDistance(const CCollisionSphere &targetObject, EDimension dimension) const;
108  float getDimensionDistance(const CCollisionCylinder &targetObject, EDimension dimension) const;
109 
110 private:
111  bool _positionSaved;
112  U32FltPoint3D _safetyPoint;
113  U32FltVector3D _safetyVelocity;
114 
115  bool backStraightOutOfObject(const ICollisionObject &targetObject, U32Distance3D *distance, float *timeUsed);
116 
117  bool circleOutOfObject(const CCollisionBox &targetObject, U32Distance3D *distance, float *timeUsed);
118  bool circleOutOfObject(const CCollisionCylinder &targetObject, U32Distance3D *distance, float *timeUsed);
119 
120  ERevDirection getRevDirection() const;
121 
122  using ICollisionObject::getPenetrationTime;
123  float getPenetrationTime(const CCollisionBox &targetObject, const U32Distance3D &distance, EDimension dimension) const override;
124  float getPenetrationTime(const CCollisionCylinder &targetObject, const U32Distance3D &distance, EDimension dimension) const override;
125 
126  float getPointOfCollision(const CCollisionBox &targetBox, U32Distance3D distance, EDimension dimension) const;
127 
128  void forceOutOfObject(const ICollisionObject &targetObject, U32Distance3D *distance);
129 
130  bool getCornerIntersection(const CCollisionBox &targetObject, const U32Distance3D &distance, U32FltPoint2D *intersection);
131 };
132 
133 } // End of namespace Scumm
134 
135 #endif // ENABLE_HE
136 
137 #endif // SCUMM_HE_BASKETBALL_COLLISION_BBALL_COLLISION_CYLINDER_H
Definition: actor.h:30