ScummVM API documentation
floor.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 STARK_RESOURCES_FLOOR_H
23 #define STARK_RESOURCES_FLOOR_H
24 
25 #include "common/array.h"
26 #include "common/str.h"
27 
28 #include "math/line3d.h"
29 #include "math/ray.h"
30 #include "math/vector3d.h"
31 
32 #include "engines/stark/resources/object.h"
33 
34 namespace Stark {
35 
36 namespace Formats {
37 class XRCReadStream;
38 }
39 
40 namespace Resources {
41 
42 class Floor;
43 class FloorFace;
44 class FloorField;
45 
51 class FloorEdge {
52 public:
53  FloorEdge(uint16 vertexIndex1, uint16 vertexIndex2, uint32 faceIndex1);
54 
56  void buildNeighbours(const Floor *floor);
57 
59  void computeMiddle(const Floor *floor);
60 
62  void setOtherFace(uint32 faceIndex);
63 
65  bool hasVertices(uint16 vertexIndex1, uint16 vertexIndex2) const;
66 
68  Common::Array<FloorEdge *> getNeighbours() const;
69 
76  float costTo(const FloorEdge *other) const;
77 
83  Math::Vector3d getPosition() const;
84 
86  bool isFloorBorder() const;
87 
89  bool intersectsSegment(const Floor *floor, const Math::Line3d &segment) const;
90 
91  int32 getFaceIndex1() const;
92  int32 getFaceIndex2() const;
93 
95  void enable(bool enable);
96 
98  bool isEnabled() const;
99 
101  void saveLoad(ResourceSerializer *serializer);
102 
103 private:
104  void addNeighboursFromFace(const FloorFace *face);
105  static bool intersectLine2d(const Math::Line3d &s1, const Math::Line3d &s2);
106 
107  uint16 _vertexIndex1;
108  uint16 _vertexIndex2;
109  Math::Vector3d _middle;
110  int32 _faceIndex1;
111  int32 _faceIndex2;
112 
113  bool _enabled;
114 
115  Common::Array<FloorEdge *> _neighbours;
116 };
117 
124 class Floor : public Object {
125 public:
126  static const Type::ResourceType TYPE = Type::kFloor;
127 
128  Floor(Object *parent, byte subType, uint16 index, const Common::String &name);
129  virtual ~Floor();
130 
131  // Resource API
132  void onAllLoaded() override;
133  void saveLoad(ResourceSerializer *serializer) override;
134 
136  Math::Vector3d getVertex(uint32 index) const;
137 
144  int32 findFaceContainingPoint(const Math::Vector3d &point) const;
145 
147  void computePointHeightInFace(Math::Vector3d &point, uint32 faceIndex) const;
148 
158  int32 findFaceHitByRay(const Math::Ray &ray, Math::Vector3d &intersection) const;
159 
169  int32 findFaceClosestToRay(const Math::Ray &ray, Math::Vector3d &center) const;
170 
172  float getDistanceFromCamera(uint32 faceIndex) const;
173 
175  FloorFace *getFace(uint32 index) const;
176 
178  bool isSegmentInside(const Math::Line3d &segment) const;
179 
181  void enableFloorField(FloorField *floorfield, bool enable);
182 
183 protected:
184  void readData(Formats::XRCReadStream *stream) override;
185  void printData() override;
186 
187  void buildEdgeList();
188  void addFaceEdgeToList(uint32 faceIndex, uint32 index1, uint32 index2);
189 
190  uint32 _facesCount;
194 };
195 
196 } // End of namespace Resources
197 } // End of namespace Stark
198 
199 #endif // STARK_RESOURCES_FLOOR_H
Definition: str.h:59
Definition: array.h:52
Definition: floor.h:124
Definition: floor.h:51
Definition: console.h:27
Definition: floorface.h:46
Definition: object.h:143
Definition: floorfield.h:42
Definition: xrc.h:45
Definition: stateprovider.h:51