Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Decal.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "Decal.h"
21 
22 #include "graphics/Terrain.h"
23 #include "maths/MathUtil.h"
24 
26 {
28  return clone;
29 }
30 
32 {
37 
38  corner0 = GetTransform().Transform(corner0);
39  corner1 = GetTransform().Transform(corner1);
40  corner2 = GetTransform().Transform(corner2);
41  corner3 = GetTransform().Transform(corner3);
42 
43  i0 = floor(std::min(std::min(corner0.X, corner1.X), std::min(corner2.X, corner3.X)) / TERRAIN_TILE_SIZE);
44  j0 = floor(std::min(std::min(corner0.Z, corner1.Z), std::min(corner2.Z, corner3.Z)) / TERRAIN_TILE_SIZE);
45  i1 = ceil(std::max(std::max(corner0.X, corner1.X), std::max(corner2.X, corner3.X)) / TERRAIN_TILE_SIZE);
46  j1 = ceil(std::max(std::max(corner0.Z, corner1.Z), std::max(corner2.Z, corner3.Z)) / TERRAIN_TILE_SIZE);
47 
48  i0 = clamp(i0, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1);
49  j0 = clamp(j0, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1);
50  i1 = clamp(i1, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1);
51  j1 = clamp(j1, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1);
52 }
53 
55 {
56  ssize_t i0, j0, i1, j1;
57  CalcVertexExtents(i0, j0, i1, j1);
58  m_WorldBounds = m_Terrain->GetVertexesBound(i0, j0, i1, j1);
59 }
60 
62 {
63  // Check if there's no intersection between the dirty range and this decal
64  ssize_t bi0, bj0, bi1, bj1;
65  CalcVertexExtents(bi0, bj0, bi1, bj1);
66  if (bi1 < i0 || bi0 > i1 || bj1 < j0 || bj0 > j1)
67  return;
68 
70 }
71 
73 {
74  m_PositionValid = false;
75 }
76 
78 {
79  if (m_PositionValid)
80  {
82  return;
83  }
84 
86  {
87  // Make sure we don't base our calculations on
88  // a parent animation state that is out of date.
90 
91  // Parent will recursively call our validation.
93  return;
94  }
95 
96  m_PositionValid = true;
97 }
98 
99 void CModelDecal::SetTransform(const CMatrix3D& transform)
100 {
101  // Since decals are assumed to be horizontal and projected downwards
102  // onto the terrain, use just the Y-axis rotation and the translation
103  CMatrix3D newTransform;
104  newTransform.SetYRotation(transform.GetYRotation() + m_Decal.m_Angle);
105  newTransform.Translate(transform.GetTranslation());
106 
107  CRenderableObject::SetTransform(newTransform);
109 }
110 
112 {
113  m_Decal.m_Material.AddShaderDefine(str_DISABLE_RECEIVE_SHADOWS, str_1);
115 }
virtual void InvalidatePosition()
Mark this model&#39;s position and bone matrices, and all props&#39; positions as invalid.
Definition: Decal.cpp:72
void Translate(float x, float y, float z)
Definition: Matrix3D.cpp:172
void AddShaderDefine(CStrIntern key, CStrIntern value)
Definition: Material.cpp:35
float GetYRotation() const
Definition: Matrix3D.cpp:403
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
Definition: Terrain.h:40
CMaterial m_Material
Definition: Decal.h:41
void SetYRotation(float angle)
Definition: Matrix3D.cpp:72
virtual void SetTerrainDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1)
Called when terrain has changed in the given inclusive bounds.
Definition: Decal.cpp:61
CBoundingBoxAligned GetVertexesBound(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1)
Returns a 3D bounding box encompassing the given vertex range (inclusive)
Definition: Terrain.cpp:645
virtual CModelAbstract * Clone() const
Definition: Decal.cpp:25
#define RENDERDATA_UPDATE_VERTICES
virtual void SetTransform(const CMatrix3D &transform)
float m_SizeZ
Definition: Decal.h:43
ssize_t GetVerticesPerSide() const
Definition: Terrain.h:65
CVector3D Transform(const CVector3D &vector) const
Definition: Matrix3D.h:272
float m_OffsetX
Definition: Decal.h:45
bool m_PositionValid
True if both transform and and bone matrices are valid.
SDecal m_Decal
Definition: Decal.h:89
#define ENSURE(expr)
ensure the expression &lt;expr&gt; evaluates to non-zero.
Definition: debug.h:282
CModelDecal(CTerrain *terrain, const SDecal &decal)
Definition: Decal.h:53
CBoundingBoxAligned m_WorldBounds
World-space bounds of this object.
float X
Definition: Vector3D.h:31
void SetDirty(u32 dirtyflags)
void CalcVertexExtents(ssize_t &i0, ssize_t &j0, ssize_t &i1, ssize_t &j1)
Compute the terrain vertex indexes that bound the decal&#39;s projection onto the terrain.
Definition: Decal.cpp:31
float m_Angle
Definition: Decal.h:44
intptr_t ssize_t
Definition: wposix_types.h:82
Abstract base class for graphical objects that are used by units, or as props attached to other CMode...
Definition: ModelAbstract.h:36
float m_SizeX
Definition: Decal.h:42
float Z
Definition: Vector3D.h:31
const CMatrix3D & GetTransform() const
virtual void SetTransform(const CMatrix3D &transform)
Definition: Decal.cpp:99
CTerrain * m_Terrain
Definition: Decal.h:88
virtual void CalcBounds()
(Re)calculates and stores any bounds or bound-dependent data for this object.
Definition: Decal.cpp:54
CVector3D GetTranslation() const
Definition: Matrix3D.cpp:195
void RecomputeCombinedShaderDefines()
Definition: Material.cpp:70
void RemoveShadows()
Definition: Decal.cpp:111
float m_OffsetZ
Definition: Decal.h:46
virtual void ValidatePosition()
Ensure that both the transformation and the bone matrices are correct for this model and all its prop...
Definition: Decal.cpp:77
T clamp(T value, T min, T max)
Definition: MathUtil.h:32
CModelAbstract * m_Parent
If non-null, points to the model that we are attached to.
virtual void ValidatePosition()=0
Ensure that both the transformation and the bone matrices are correct for this model and all its prop...