ScummVM API documentation
te_free_move_zone.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 TETRAEDGE_TE_TE_FREE_MOVE_ZONE_H
23 #define TETRAEDGE_TE_TE_FREE_MOVE_ZONE_H
24 
25 #include "common/array.h"
26 
27 #include "tetraedge/te/te_bezier_curve.h"
28 #include "tetraedge/te/te_camera.h"
29 #include "tetraedge/te/te_intrusive_ptr.h"
30 #include "tetraedge/te/te_obp.h"
31 #include "tetraedge/te/te_pick_mesh2.h"
32 #include "tetraedge/te/te_vector3f32.h"
33 #include "tetraedge/te/te_act_zone.h"
34 #include "tetraedge/te/te_timer.h"
35 
36 namespace Tetraedge {
37 
38 namespace micropather {
39  class MicroPather;
40 }
41 
42 // TODO: should these structs be moved to their own headers?
43 struct TeBlocker {
44  Common::String _s;
45  TeVector2f32 _pts[2];
46  bool _enabled;
47 };
48 
49 struct TeRectBlocker {
50  Common::String _s;
51  TeVector2f32 _pts[4];
52  bool _enabled;
53 };
54 
55 class TeFreeMoveZoneGraph;
56 
57 class TeFreeMoveZone : public TePickMesh2 {
58 public:
59  struct CollidePoint {
60  TeVector3f32 _point;
61  float _distance;
62  };
63 
65  ~TeFreeMoveZone();
66 
67  float bordersDistance() const;
68  void buildAStar();
69  void calcGridMatrix();
70  void clear();
71  Common::Array<TeVector3f32> collisions(const TeVector3f32 &v1, const TeVector3f32 &v2);
72  TeVector3f32 correctCharacterPosition(const TeVector3f32 &pos, bool *flagout, bool f);
73 
74  TeIntrusivePtr<TeBezierCurve> curve(const TeVector3f32 &startpt, const TeVector2s32 &endpt, float param_5, bool findMeshFlag);
75  TeIntrusivePtr<TeBezierCurve> curve(const TeVector3f32 &startpt, const TeVector3f32 &endpt);
76 
77  void draw() override;
78  TeVector3f32 findNearestPointOnBorder(const TeVector2f32 &pt);
79  byte hasBlockerIntersection(const TeVector2s32 &pt);
80  bool hasCellBorderIntersection(const TeVector2s32 &pt);
81 
82  TeActZone *isInZone(const TeVector3f32 &pt);
83 
84  bool loadAStar(const Common::Path &path, const TeVector2s32 &size);
85  bool loadBin(const Common::Path &path, const Common::Array<TeBlocker> *blockers,
86  const Common::Array<TeRectBlocker> *rectblockers, const Common::Array<TeActZone> *actzones,
87  const TeVector2f32 &gridSize);
88  bool loadBin(Common::ReadStream &stream, const Common::Array<TeBlocker> *blockers,
89  const Common::Array<TeRectBlocker> *rectblockers, const Common::Array<TeActZone> *actzones,
90  const TeVector2f32 &gridSize);
91 
92  // loadBin() 2 versions, seem unused
93 
94  // name(), onPositionChanged(), position(), rotate(), rotation(), scale(),
95  // setName(), setPosition(), setRotation(), setScale(), setVisible(),
96  // translate(), and visible() are all implemented in original, but all
97  // just do the same as super.
98 
99  bool onViewportChanged();
100  void preUpdateGrid();
101  TeVector2s32 projectOnAStarGrid(const TeVector3f32 &pt);
102  Common::Array<TeVector3f32> removeInsignificantPoints(const Common::Array<TeVector3f32> &points);
103  void setBordersDistance(float dist);
104  void setCamera(TeIntrusivePtr<TeCamera> &cam, bool noRecalcProjPoints);
105  void setNbTriangles(uint len);
106  void setPathFindingOccluder(const TeOBP &occluder);
107  void setVertex(uint offset, const TeVector3f32 &vertex);
108  TeVector3f32 transformAStarGridInWorldSpace(const TeVector2s32 &gridpt);
109  float transformHeightMin(float minval);
110  TeVector3f32 transformVectorInWorldSpace(float param_3, float param_4);
111  void updateBorders();
112  void updateGrid(bool force);
113  void updatePickMesh();
114  void updateProjectedPoints();
115  void updateTransformedVertices();
116 
117  static float normalizeAngle(float angle);
118  static void deserialize(Common::ReadStream &stream, TeFreeMoveZone &dest, const Common::Array<TeBlocker> *blockers,
119  const Common::Array<TeRectBlocker> *rectblockers, const Common::Array<TeActZone> *actzones);
120  static void serialize(Common::WriteStream &stream, const TeFreeMoveZone &src, bool updateFirst);
121 
122  static TePickMesh2 *findNearestMesh(TeIntrusivePtr<TeCamera> &camera, const TeVector2s32 &frompt,
123  Common::Array<TePickMesh2*> &pickMeshes, TeVector3f32 *outloc, bool lastHitFirst);
124 
125  const Common::Array<TeVector3f32> freeMoveZoneVerticies() const { return _freeMoveZoneVerticies; }
126 
127  static void setCollisionSlide(bool val) { _collisionSlide = val; }
128 
129 private:
130  TeVector2s32 aStarResolution() const;
131 
132  const Common::Array<TeActZone> *_actzones;
133  const Common::Array<TeBlocker> *_blockers;
134  const Common::Array<TeRectBlocker> *_rectBlockers;
135 
136  Common::Array<TeVector3f32> _freeMoveZoneVerticies;
137  Common::Array<uint> _pickMesh;
138  Common::Array<TeVector3f32> _transformedVerticies;
139  Common::Array<uint> _borders;
140  Common::Array<TeVector2f32> _projectedPoints;
141 
142  TeVector2f32 _gridSquareSize;
143  TeVector2f32 _gridTopLeft;
144  TeVector2f32 _gridBottomRight;
145  TeVector2f32 _loadGridSize; // At least, it seems unused?
146  TeMatrix4x4 _gridMatrix;
147  TeMatrix4x4 _inverseWorldTransform;
148 
149  float _gridWorldY;
150 
151  TeOBP _obp;
152  TeIntrusivePtr<TeCamera> _camera;
153  //static TeIntrusivePtr<TeCamera> _globalCamera;
154 
155  TeFreeMoveZoneGraph *_graph;
156 
157  bool _loadedFromBin;
158  bool _gridDirty;
159  bool _transformedVerticiesDirty;
160  bool _bordersDirty;
161  bool _pickMeshDirty;
162  bool _projectedPointsDirty;
163 
164  micropather::MicroPather *_micropather;
165  TeTimer _updateTimer;
166 
167  Common::Path _aszGridPath;
168 
169  static bool _collisionSlide;
170 };
171 
172 } // end namespace Tetraedge
173 
174 #endif // TETRAEDGE_TE_TE_FREE_MOVE_ZONE_H
Definition: te_free_move_zone.h:59
Definition: te_free_move_zone.h:49
Definition: str.h:59
Definition: detection.h:27
Definition: micropather.h:373
Definition: stream.h:77
Definition: array.h:52
Definition: te_free_move_zone.h:43
Definition: path.h:52
Definition: te_act_zone.h:30
Definition: te_free_move_zone.h:57
Definition: te_timer.h:33
Definition: te_matrix4x4.h:37
Definition: te_intrusive_ptr.h:31
Definition: te_vector2s32.h:31
Definition: te_vector3f32.h:33
Definition: te_pick_mesh2.h:32
Definition: stream.h:385
Definition: te_vector2f32.h:32
Definition: te_obp.h:31