Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Decal.h
Go to the documentation of this file.
1/* Copyright (C) 2023 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#ifndef INCLUDED_DECAL
19#define INCLUDED_DECAL
20
21#include "graphics/Material.h"
23
24class CTerrain;
25
26/**
27 * Terrain decal definition.
28 * Decals are rectangular textures that are projected vertically downwards
29 * onto the terrain.
30 */
31struct SDecal
32{
33 SDecal(const CMaterial& material, float sizeX, float sizeZ, float angle,
34 float offsetX, float offsetZ, bool floating)
35 : m_Material(material), m_SizeX(sizeX), m_SizeZ(sizeZ), m_Angle(angle),
36 m_OffsetX(offsetX), m_OffsetZ(offsetZ), m_Floating(floating)
37 {
38 }
39
41 float m_SizeX;
42 float m_SizeZ;
43 float m_Angle;
44 float m_OffsetX;
45 float m_OffsetZ;
47};
48
50{
51public:
52 CModelDecal(CTerrain* terrain, const SDecal& decal)
53 : m_Terrain(terrain), m_Decal(decal)
54 {
55 ENSURE(terrain != NULL);
56 }
57
58 /// Dynamic cast
60 {
61 return this;
62 }
63
64 std::unique_ptr<CModelAbstract> Clone() const override;
65
66 void SetTerrainDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) override;
67
68 void CalcBounds() override;
69 void ValidatePosition() override;
70 void InvalidatePosition() override;
71 void SetTransform(const CMatrix3D& transform) override;
72
73 // remove shadow receiving
74 void RemoveShadows();
75
76 /**
77 * Compute the terrain vertex indexes that bound the decal's
78 * projection onto the terrain.
79 * The returned indexes are clamped to the terrain size.
80 */
81 void CalcVertexExtents(ssize_t& i0, ssize_t& j0, ssize_t& i1, ssize_t& j1);
82
85};
86
87#endif // INCLUDED_DECAL
Definition: Material.h:29
Definition: Matrix3D.h:34
Abstract base class for graphical objects that are used by units, or as props attached to other CMode...
Definition: ModelAbstract.h:50
Definition: Decal.h:50
void InvalidatePosition() override
Mark this model's position and bone matrices, and all props' positions as invalid.
Definition: Decal.cpp:72
CModelDecal * ToCModelDecal() override
Dynamic cast.
Definition: Decal.h:59
void CalcVertexExtents(ssize_t &i0, ssize_t &j0, ssize_t &i1, ssize_t &j1)
Compute the terrain vertex indexes that bound the decal's projection onto the terrain.
Definition: Decal.cpp:31
void RemoveShadows()
Definition: Decal.cpp:111
std::unique_ptr< CModelAbstract > Clone() const override
Definition: Decal.cpp:26
void CalcBounds() override
(Re)calculates and stores any bounds or bound-dependent data for this object.
Definition: Decal.cpp:54
CModelDecal(CTerrain *terrain, const SDecal &decal)
Definition: Decal.h:52
CTerrain * m_Terrain
Definition: Decal.h:83
void ValidatePosition() override
Ensure that both the transformation and the bone matrices are correct for this model and all its prop...
Definition: Decal.cpp:77
SDecal m_Decal
Definition: Decal.h:84
void SetTerrainDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) override
Called when terrain has changed in the given inclusive bounds.
Definition: Decal.cpp:61
void SetTransform(const CMatrix3D &transform) override
Definition: Decal.cpp:99
Definition: Terrain.h:52
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:277
Terrain decal definition.
Definition: Decal.h:32
float m_Angle
Definition: Decal.h:43
float m_SizeX
Definition: Decal.h:41
float m_OffsetX
Definition: Decal.h:44
SDecal(const CMaterial &material, float sizeX, float sizeZ, float angle, float offsetX, float offsetZ, bool floating)
Definition: Decal.h:33
bool m_Floating
Definition: Decal.h:46
CMaterial m_Material
Definition: Decal.h:40
float m_SizeZ
Definition: Decal.h:42
float m_OffsetZ
Definition: Decal.h:45
intptr_t ssize_t
Definition: wposix_types.h:82