Cafu Engine
TerrainNode.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_SCENEGRAPH_TERRAIN_HPP_INCLUDED
8 #define CAFU_SCENEGRAPH_TERRAIN_HPP_INCLUDED
9 
10 #include "Node.hpp"
11 
12 
13 namespace MatSys
14 {
15  class RenderMaterialT;
16  class TextureMapI;
17 }
18 
19 
20 namespace cf
21 {
22  namespace SceneGraph
23  {
24  class TerrainNodeT : public GenericNodeT
25  {
26  public:
27 
28  /// The constructor.
29  TerrainNodeT();
30 
31  /// Constructor for creating a TerrainNodeT from parameters.
32  /// @param BB_ The bounding box of the terrain node.
33  /// @param Terrain_ The TerrainT instance to create the TerrainNodeT from.
34  /// @param TerrainShareID_ Used for sharing common TerrainT instances across several TerrainNodeT's. (TODO: Needs better documentation!)
35  /// @param MaterialName_ Name of the material that is applied to this terrain.
36  /// @param LightMapPatchSize The size of the lightmap patches.
37  TerrainNodeT(const BoundingBox3dT& BB_, const TerrainT& Terrain_, unsigned long TerrainShareID_, const std::string& MaterialName_, const float LightMapPatchSize);
38 
39  /// Named constructor.
40  static TerrainNodeT* CreateFromFile_cw(std::istream& InFile, aux::PoolT& Pool, LightMapManT& LMM, SHLMapManT& SMM, const ArrayT<const TerrainT*>& ShTe);
41 
42  /// The destructor.
43  ~TerrainNodeT();
44 
45  // The NodeT interface.
46  void WriteTo(std::ostream& OutFile, aux::PoolT& Pool) const;
48 
49  // void InitDrawing();
50  bool IsOpaque() const;
51  void DrawAmbientContrib(const Vector3dT& ViewerPos) const;
52  void DrawStencilShadowVolumes(const Vector3dT& LightPos, const float LightRadius) const;
53  void DrawLightSourceContrib(const Vector3dT& ViewerPos, const Vector3dT& LightPos) const;
54  void DrawTranslucentContrib(const Vector3dT& ViewerPos) const;
55 
56 
57  private:
58 
59  void Init(); ///< Helper method for the constructors.
60  void Clean(); ///< Helper method for the destructor. Also called at the begin of Init().
61 
62  TerrainNodeT(const TerrainNodeT&); ///< Use of the Copy Constructor is not allowed.
63  void operator = (const TerrainNodeT&); ///< Use of the Assignment Operator is not allowed.
64 
65 
66  BoundingBox3T<double> BB; ///< The lateral dimensions of the terrain.
67  const TerrainT* Terrain; ///< The actual terrain. The instance is kept outside of the scene graph, because it is shared with the physics world.
68  unsigned long TerrainShareID; ///< The index of Terrain in the list of shared terrains.
69  std::string MaterialName;
70  ArrayT<char> LightMap; ///< The lightmap for this terrain. LightMap.Size()==3*p^2, where p is a power of 2 <= 256.
71  // float LightMapTruePatchSize; ///< The true patch size is obtained by (BB.Max.x-BB.Min.x)/p and (BB.Max.y-BB.Min.y)/p.
72  ArrayT<float> SHLMap; ///< The SHL map for this terrain. SHLMap.Size()==FaceT::SHLMapInfoT::NrOfBands^2 * q^2, where q is a power of 2 <= 256.
73  // float SHLMapTruePatchSize; ///< The true patch size is obtained by (BB.Max.x-BB.Min.x)/q and (BB.Max.y-BB.Min.y)/q.
74 
75  MatSys::RenderMaterialT* RenderMaterial;
76  MatSys::TextureMapI* LightMapTexture;
77  };
78  }
79 }
80 
81 #endif
This class manages lightmaps, e.g. by "allocating" rectangular areas in larger bitmaps.
Definition: LightMapMan.hpp:25
This class represents terrains, offering methods for LoD rendering and collision detection.
Definition: Terrain.hpp:17
This class represents a surface render material.
Definition: RenderMaterial.hpp:25
static TerrainNodeT * CreateFromFile_cw(std::istream &InFile, aux::PoolT &Pool, LightMapManT &LMM, SHLMapManT &SMM, const ArrayT< const TerrainT * > &ShTe)
Named constructor.
Definition: TerrainNode.cpp:71
void DrawAmbientContrib(const Vector3dT &ViewerPos) const
Draws the contents of this scene node.
Definition: TerrainNode.cpp:124
Definition: _aux.hpp:111
This class manages SHL maps, e.g. by "allocating" rectangular areas in larger coefficient maps...
Definition: SHLMapMan.hpp:25
This is an interface to a texture-map.
Definition: TextureMap.hpp:23
const BoundingBox3T< double > & GetBoundingBox() const
Returns the bounding box of the contents of this scene node.
Definition: TerrainNode.cpp:112
~TerrainNodeT()
The destructor.
Definition: TerrainNode.cpp:89
bool IsOpaque() const
TODO / FIXME: This method is a hot-fix for getting the render order with translucent Bezier Patches r...
Definition: TerrainNode.cpp:118
Definition: TerrainNode.hpp:24
TerrainNodeT()
The constructor.
Definition: TerrainNode.cpp:22
Definition: Renderer.hpp:16
Definition: Node.hpp:35