Cafu Engine
SurfaceInfo.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_SURFACE_INFO_HPP_INCLUDED
8 #define CAFU_SURFACE_INFO_HPP_INCLUDED
9 
10 #include "Math3D/Plane3.hpp"
11 #include "Templates/Array.hpp"
12 
13 
14 class TextParserT;
15 
16 
17 /// This enum describes the technique that is used to generate texture-coordinates for the associated map primitive.
18 enum TexCoordGenModeT
19 {
20  Custom=0, ///< The tex-coords are freely specified (per vertex).
21  MatFit, ///< Texture coordinates are created, so the material fits exactly on the patch.
22  PlaneProj ///< Texture coordinates are created using a plane projection with UV axes.
23 };
24 
25 
26 class TexCoordT
27 {
28  public:
29 
30  TexCoordT() : u(0), v(0) { }
31 
32  float& operator [] (unsigned long Index)
33  {
34  assert(Index<2);
35  return Index==0 ? u : v;
36  }
37 
38  const float& operator [] (unsigned long Index) const
39  {
40  assert(Index<2);
41  return Index==0 ? u : v;
42  }
43 
44  float u;
45  float v;
46 };
47 
48 
49 /// This class holds all information that is needed in order to compute the UV texture-space
50 /// coordinates of (and thus to apply a material onto) a primitive surface.
52 {
53  public:
54 
55  /// The default constructor.
56  SurfaceInfoT();
57 
58  /// The constructor for creating a SurfaceInfoT in plane projection mode, matching the given plane.
59  SurfaceInfoT(const Plane3fT& Plane, bool FaceAligned);
60 
61  /// Named constructor for loading a SurfaceInfoT from a cmap file.
63 
64 
65  /// Serializes this instance into a cmap file.
66  void Save_cmap(std::ostream& OutFile) const;
67 
68  /// Resets the texture-space u- and v-axes as appropriate for the given plane.
69  /// @param Plane The plane with reference to which the axes are reset.
70  /// @param FaceAligned When true, the axes are re-initialized face-aligned, world-aligned otherwise.
71  void ResetUVAxes(const Plane3fT& Plane, bool FaceAligned);
72 
73  /// Wraps the Trans[] members so that they are in the interval [0, 1[.
74  void WrapTranslations();
75 
76  /// Rotates the texture-space u- and v-axes by the given angle.
77  /// @param Angle The angle of rotation, in degrees.
78  void RotateUVAxes(float Angle);
79 
80  /// Changes this SurfaceInfoT so that the material is aligned on the surface according to AlignKey.
81  /// @param AlignKey How the material is aligned wrt. the surface. Valid keys are "top", "bottom", "left", "right", "center" and "fit".
82  /// @param Vertices The vertices of the surface for which the alignment is to be computed.
83  void AlignMaterial(const char* AlignKey, const ArrayT<Vector3fT>& Vertices);
84 
85 
86  TexCoordGenModeT TexCoordGenMode; ///< Determines the algorithm that is used to generate texture-coordinates for the associated map primitive.
87  float Trans[2];
88  float Scale[2];
89  float Rotate;
90  Vector3fT UAxis;
91  Vector3fT VAxis;
92  float LightmapScale;
93 };
94 
95 #endif
Definition: SurfaceInfo.hpp:26
void Save_cmap(std::ostream &OutFile) const
Serializes this instance into a cmap file.
Definition: SurfaceInfo.cpp:111
This class holds all information that is needed in order to compute the UV texture-space coordinates ...
Definition: SurfaceInfo.hpp:51
void RotateUVAxes(float Angle)
Rotates the texture-space u- and v-axes by the given angle.
Definition: SurfaceInfo.cpp:197
void WrapTranslations()
Wraps the Trans[] members so that they are in the interval [0, 1[.
Definition: SurfaceInfo.cpp:188
static SurfaceInfoT Create_cmap(TextParserT &TP)
Named constructor for loading a SurfaceInfoT from a cmap file.
Definition: SurfaceInfo.cpp:48
void ResetUVAxes(const Plane3fT &Plane, bool FaceAligned)
Resets the texture-space u- and v-axes as appropriate for the given plane.
Definition: SurfaceInfo.cpp:164
SurfaceInfoT()
The default constructor.
Definition: SurfaceInfo.cpp:16
void AlignMaterial(const char *AlignKey, const ArrayT< Vector3fT > &Vertices)
Changes this SurfaceInfoT so that the material is aligned on the surface according to AlignKey...
Definition: SurfaceInfo.cpp:209
TexCoordGenModeT TexCoordGenMode
Determines the algorithm that is used to generate texture-coordinates for the associated map primitiv...
Definition: SurfaceInfo.hpp:86
Definition: Renderer.hpp:16
This is a class for parsing text.
Definition: TextParser.hpp:21