Fix issue in Rocket.lua script.
[Cafu-Engine.git] / Libs / MapFile.hpp
blob2156a9f091fb7eaea5ecf1fcf0b15e92039e799b
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
7 #ifndef CAFU_MAPFILE_HPP_INCLUDED
8 #define CAFU_MAPFILE_HPP_INCLUDED
10 #include <map>
12 #include "Templates/Array.hpp"
13 #include "Math3D/Vector3.hpp"
14 #include "Math3D/Plane3.hpp"
15 #include "Math3D/BoundingBox.hpp"
16 #include "Math3D/Matrix.hpp"
19 class MaterialT;
20 class TextParserT;
23 namespace cf
25 /// This struct describes a plane (and thus one side) of a map brush.
26 /// The members U, V, ShiftU and ShiftV together define the planar projection
27 /// for computing the (u, v) texture coordinates at the vertices of the brush.
28 struct MapFilePlaneT
30 // ArrayT<VectorT> Points;
31 Plane3dT Plane;
32 MaterialT* Material; ///< The planes material.
33 Vector3dT U; ///< The first span vector of the texture projection plane.
34 Vector3dT V; ///< The second span vector of the texture projection plane.
35 double ShiftU; ///< Texture "scroll offset" in direction of U.
36 double ShiftV; ///< Texture "scroll offset" in direction of V.
40 struct MapFileBrushT
42 /// The default constructor.
43 MapFileBrushT() { }
45 /// @throws TextParserT::ParseError on problems.
46 MapFileBrushT(TextParserT& TP, unsigned long BrushNr);
49 ArrayT<MapFilePlaneT> MFPlanes;
53 struct MapFileBezierPatchT
55 /// The default constructor.
56 MapFileBezierPatchT() { }
58 /// @throws TextParserT::ParseError on problems.
59 MapFileBezierPatchT(TextParserT& TP);
62 // TODO: Remove the SizeX, SizeY and ControlsPoints members, use a cf::math::BezierPatchT<float> instead!
63 unsigned long SizeX; ///< Nr of columns.
64 unsigned long SizeY; ///< Nr of rows.
66 int SubdivsHorz; ///< Number of subdivisions in horizontal direction, or auto-detection if -1.
67 int SubdivsVert; ///< Number of subdivisions in vertical direction, or auto-detection if -1.
69 MaterialT* Material; ///< The patches material.
70 ArrayT<float> ControlPoints; ///< The SizeX*SizeY*5 control points.
74 struct MapFileTerrainT
76 /// The default constructor.
77 MapFileTerrainT() { }
79 /// @throws TextParserT::ParseError on problems.
80 MapFileTerrainT(TextParserT& TP);
82 /// Returns the spatial coordinate for the given (logical) height field position.
83 /// Note that for processing all vertices of a terrain quickly, specialized loops
84 /// should be preferred over this relatively slow (repetitive) method.
85 /// @param x The horizontal component of the logical height field position.
86 /// @param y The vertical component of the logical height field position.
87 /// @returns the spatial coordinate for the given (logical) height field position.
88 Vector3dT GetSpatial(unsigned long x, unsigned long y) const
90 Vector3dT Pos=Bounds.Min;
92 Pos.x+=(Bounds.Max.x-Bounds.Min.x)*double(x)/double(SideLength-1);
93 Pos.y+=(Bounds.Max.y-Bounds.Min.y)*double(y)/double(SideLength-1);
94 Pos.z+=(Bounds.Max.z-Bounds.Min.z)*double(HeightData[SideLength*y+x])/65535.0;
96 return Pos;
100 BoundingBox3dT Bounds; ///< The terrains bounds.
101 MaterialT* Material; ///< The terrains material.
102 unsigned long SideLength; ///< Side length of the terrains height data.
103 ArrayT<unsigned short> HeightData; ///< The SideLength*SideLength array of height data.
107 struct MapFilePlantT
109 /// The default constructor.
110 MapFilePlantT() { }
112 /// @throws TextParserT::ParseError on problems.
113 MapFilePlantT(TextParserT& TP);
116 std::string DescrFileName;
117 unsigned int RandomSeed;
118 Vector3dT Position;
119 Vector3fT Angles;
123 struct MapFileModelT
125 /// The default constructor.
126 MapFileModelT() { }
128 /// @throws TextParserT::ParseError on problems.
129 MapFileModelT(TextParserT& TP);
132 std::string Model;
133 std::string CollModel;
134 std::string Label;
135 Vector3fT Origin;
136 Vector3fT Angles;
137 float Scale;
138 int SeqNumber;
139 float FrameOffset;
140 float FrameTimeScale;
141 bool Animate;
145 struct MapFileEntityT
147 /// The default constructor.
148 MapFileEntityT() : MFIndex(0) { }
150 /// @throws TextParserT::ParseError on problems.
151 MapFileEntityT(unsigned long Index, TextParserT& TP);
153 /// Transforms all primitives in this entity by the given matrix.
154 void Transform(const Matrix4x4fT& Mat);
157 unsigned long MFIndex; ///< In the source cmap file, this was/is the MFIndex-th entity. Normally (e.g. immediately after loading the cmap file) this is identical to the index of this MapFileEntityT into the array of all entities. It is kept explicitly here in case the array of all entities is rearranged, as is done e.g. by the CaBSP loader.
158 ArrayT<MapFileBrushT> MFBrushes;
159 ArrayT<MapFileBezierPatchT> MFPatches;
160 ArrayT<MapFileTerrainT> MFTerrains;
161 ArrayT<MapFilePlantT> MFPlants;
162 ArrayT<MapFileModelT> MFModels;
163 std::map<std::string, std::string> MFProperties;
167 /// @throws TextParserT::ParseError on problems (and writes additional diagnostics to the console).
168 void MapFileReadHeader(TextParserT& TP);
171 #endif