Cafu Engine
MapFile.hpp
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 */
6 
7 #ifndef CAFU_MAPFILE_HPP_INCLUDED
8 #define CAFU_MAPFILE_HPP_INCLUDED
9 
10 #include <map>
11 
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"
17 
18 
19 class MaterialT;
20 class TextParserT;
21 
22 
23 namespace cf
24 {
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.
29  {
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.
37  };
38 
39 
41  {
42  /// The default constructor.
44 
45  /// @throws TextParserT::ParseError on problems.
46  MapFileBrushT(TextParserT& TP, unsigned long BrushNr);
47 
48 
49  ArrayT<MapFilePlaneT> MFPlanes;
50  };
51 
52 
54  {
55  /// The default constructor.
57 
58  /// @throws TextParserT::ParseError on problems.
60 
61 
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.
65 
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.
68 
69  MaterialT* Material; ///< The patches material.
70  ArrayT<float> ControlPoints; ///< The SizeX*SizeY*5 control points.
71  };
72 
73 
75  {
76  /// The default constructor.
78 
79  /// @throws TextParserT::ParseError on problems.
81 
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
89  {
90  Vector3dT Pos=Bounds.Min;
91 
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;
95 
96  return Pos;
97  }
98 
99 
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.
104  };
105 
106 
108  {
109  /// The default constructor.
111 
112  /// @throws TextParserT::ParseError on problems.
114 
115 
116  std::string DescrFileName;
117  unsigned int RandomSeed;
118  Vector3dT Position;
119  Vector3fT Angles;
120  };
121 
122 
124  {
125  /// The default constructor.
127 
128  /// @throws TextParserT::ParseError on problems.
130 
131 
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;
142  };
143 
144 
146  {
147  /// The default constructor.
149 
150  /// @throws TextParserT::ParseError on problems.
151  MapFileEntityT(unsigned long Index, TextParserT& TP);
152 
153  /// Transforms all primitives in this entity by the given matrix.
154  void Transform(const Matrix4x4fT& Mat);
155 
156 
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;
164  };
165 
166 
167  /// @throws TextParserT::ParseError on problems (and writes additional diagnostics to the console).
168  void MapFileReadHeader(TextParserT& TP);
169 }
170 
171 #endif
MapFileTerrainT()
The default constructor.
Definition: MapFile.hpp:77
ArrayT< float > ControlPoints
The SizeX*SizeY*5 control points.
Definition: MapFile.hpp:70
Definition: MapFile.hpp:53
Definition: MapFile.hpp:145
MapFileBrushT()
The default constructor.
Definition: MapFile.hpp:43
Vector3T< T > Max
The maximum-coordinate corner of the bounding-box.
Definition: BoundingBox.hpp:210
BoundingBox3dT Bounds
The terrains bounds.
Definition: MapFile.hpp:100
T y
The y-component of this vector.
Definition: Vector3.hpp:41
ArrayT< unsigned short > HeightData
The SideLength*SideLength array of height data.
Definition: MapFile.hpp:103
Vector3T< T > Min
The minimum-coordinate corner of the bounding-box.
Definition: BoundingBox.hpp:209
Definition: MapFile.hpp:107
Vector3dT V
The second span vector of the texture projection plane.
Definition: MapFile.hpp:34
int SubdivsVert
Number of subdivisions in vertical direction, or auto-detection if -1.
Definition: MapFile.hpp:67
Definition: MapFile.hpp:123
MaterialT * Material
The patches material.
Definition: MapFile.hpp:69
double ShiftU
Texture "scroll offset" in direction of U.
Definition: MapFile.hpp:35
This class represents a surface material ("A datastructural representation of a scripts material def...
Definition: Material.hpp:22
unsigned long SizeY
Nr of rows.
Definition: MapFile.hpp:64
unsigned long SideLength
Side length of the terrains height data.
Definition: MapFile.hpp:102
MapFileBezierPatchT()
The default constructor.
Definition: MapFile.hpp:56
void Transform(const Matrix4x4fT &Mat)
Transforms all primitives in this entity by the given matrix.
Definition: MapFile.cpp:284
unsigned long MFIndex
In the source cmap file, this was/is the MFIndex-th entity. Normally (e.g. immediately after loading ...
Definition: MapFile.hpp:157
MapFileModelT()
The default constructor.
Definition: MapFile.hpp:126
Definition: MapFile.hpp:40
Definition: MapFile.hpp:74
MapFilePlantT()
The default constructor.
Definition: MapFile.hpp:110
double ShiftV
Texture "scroll offset" in direction of V.
Definition: MapFile.hpp:36
MapFileEntityT()
The default constructor.
Definition: MapFile.hpp:148
Vector3dT U
The first span vector of the texture projection plane.
Definition: MapFile.hpp:33
T z
The z-component of this vector.
Definition: Vector3.hpp:42
This struct describes a plane (and thus one side) of a map brush.
Definition: MapFile.hpp:28
unsigned long SizeX
Nr of columns.
Definition: MapFile.hpp:63
T x
The x-component of this vector.
Definition: Vector3.hpp:40
int SubdivsHorz
Number of subdivisions in horizontal direction, or auto-detection if -1.
Definition: MapFile.hpp:66
MaterialT * Material
The planes material.
Definition: MapFile.hpp:32
MaterialT * Material
The terrains material.
Definition: MapFile.hpp:101
Definition: Renderer.hpp:16
Vector3dT GetSpatial(unsigned long x, unsigned long y) const
Returns the spatial coordinate for the given (logical) height field position.
Definition: MapFile.hpp:88
This is a class for parsing text.
Definition: TextParser.hpp:21