Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/Decal.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 10 Lines | |||||
#include "Decal.h" | #include "Decal.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
CModelAbstract* CModelDecal::Clone() const | CModelAbstract* CModelDecal::Clone() const | ||||
{ | { | ||||
CModelDecal* clone = new CModelDecal(m_Terrain, m_Decal); | CModelDecal* clone = new CModelDecal(m_Terrain, m_Decal); | ||||
CModelAbstract::Clone(*clone); | |||||
return clone; | return clone; | ||||
} | } | ||||
void CModelDecal::CalcVertexExtents(ssize_t& i0, ssize_t& j0, ssize_t& i1, ssize_t& j1) | void CModelDecal::CalcVertexExtents(ssize_t& i0, ssize_t& j0, ssize_t& i1, ssize_t& j1) | ||||
{ | { | ||||
CVector3D corner0(m_Decal.m_OffsetX + m_Decal.m_SizeX/2, 0, m_Decal.m_OffsetZ + m_Decal.m_SizeZ/2); | CVector3D corner0(m_Decal.m_OffsetX + m_Decal.m_SizeX/2, 0, m_Decal.m_OffsetZ + m_Decal.m_SizeZ/2); | ||||
CVector3D corner1(m_Decal.m_OffsetX + m_Decal.m_SizeX/2, 0, m_Decal.m_OffsetZ - m_Decal.m_SizeZ/2); | CVector3D corner1(m_Decal.m_OffsetX + m_Decal.m_SizeX/2, 0, m_Decal.m_OffsetZ - m_Decal.m_SizeZ/2); | ||||
CVector3D corner2(m_Decal.m_OffsetX - m_Decal.m_SizeX/2, 0, m_Decal.m_OffsetZ - m_Decal.m_SizeZ/2); | CVector3D corner2(m_Decal.m_OffsetX - m_Decal.m_SizeX/2, 0, m_Decal.m_OffsetZ - m_Decal.m_SizeZ/2); | ||||
Show All 28 Lines | void CModelDecal::SetTerrainDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) | ||||
ssize_t bi0, bj0, bi1, bj1; | ssize_t bi0, bj0, bi1, bj1; | ||||
CalcVertexExtents(bi0, bj0, bi1, bj1); | CalcVertexExtents(bi0, bj0, bi1, bj1); | ||||
if (bi1 < i0 || bi0 > i1 || bj1 < j0 || bj0 > j1) | if (bi1 < i0 || bi0 > i1 || bj1 < j0 || bj0 > j1) | ||||
return; | return; | ||||
SetDirty(RENDERDATA_UPDATE_VERTICES); | SetDirty(RENDERDATA_UPDATE_VERTICES); | ||||
} | } | ||||
void CModelDecal::InvalidatePosition() | |||||
{ | |||||
m_PositionValid = false; | |||||
} | |||||
void CModelDecal::ValidatePosition() | |||||
{ | |||||
if (m_PositionValid) | |||||
{ | |||||
ENSURE(!m_Parent || m_Parent->m_PositionValid); | |||||
return; | |||||
} | |||||
if (m_Parent && !m_Parent->m_PositionValid) | |||||
{ | |||||
// Make sure we don't base our calculations on | |||||
// a parent animation state that is out of date. | |||||
m_Parent->ValidatePosition(); | |||||
// Parent will recursively call our validation. | |||||
ENSURE(m_PositionValid); | |||||
return; | |||||
} | |||||
m_PositionValid = true; | |||||
} | |||||
void CModelDecal::SetTransform(const CMatrix3D& transform) | void CModelDecal::SetTransform(const CMatrix3D& transform) | ||||
{ | { | ||||
// Since decals are assumed to be horizontal and projected downwards | // Since decals are assumed to be horizontal and projected downwards | ||||
// onto the terrain, use just the Y-axis rotation and the translation | // onto the terrain, use just the Y-axis rotation and the translation | ||||
CMatrix3D newTransform; | CMatrix3D newTransform; | ||||
newTransform.SetYRotation(transform.GetYRotation() + m_Decal.m_Angle); | newTransform.SetYRotation(transform.GetYRotation() + m_Decal.m_Angle); | ||||
newTransform.Translate(transform.GetTranslation()); | newTransform.Translate(transform.GetTranslation()); | ||||
CRenderableObject::SetTransform(newTransform); | CRenderableObject::SetTransform(newTransform); | ||||
InvalidatePosition(); | InvalidatePositionRec(); | ||||
} | } | ||||
void CModelDecal::RemoveShadows() | void CModelDecal::RemoveShadows() | ||||
{ | { | ||||
m_Decal.m_Material.AddShaderDefine(str_DISABLE_RECEIVE_SHADOWS, str_1); | m_Decal.m_Material.AddShaderDefine(str_DISABLE_RECEIVE_SHADOWS, str_1); | ||||
m_Decal.m_Material.RecomputeCombinedShaderDefines(); | m_Decal.m_Material.RecomputeCombinedShaderDefines(); | ||||
} | } |
Wildfire Games · Phabricator