Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ModelAbstract.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 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 "ModelAbstract.h"
21 
22 #include "ps/CLogger.h"
23 
25 {
27  {
29  m_SelectionBoxValid = true;
30  }
31  return m_SelectionBox;
32 }
33 
35 {
37  {
38  // custom shape
40  {
42  {
43  // create object-space bounds according to the information in the descriptor, and transform them to world-space.
44  // the box is centered on the X and Z axes, but extends from 0 to its height on the Y axis.
45  const float width = m_CustomSelectionShape->m_Size0;
46  const float depth = m_CustomSelectionShape->m_Size1;
47  const float height = m_CustomSelectionShape->m_Height;
48 
49  CBoundingBoxAligned bounds;
50  bounds += CVector3D(-width/2.f, 0, -depth/2.f);
51  bounds += CVector3D( width/2.f, height, depth/2.f);
52 
54  }
55  break;
57  {
58  // TODO: unimplemented
60  LOGWARNING(L"[ModelAbstract] TODO: Cylinder selection boxes are not yet implemented. Use BOX or BOUNDS selection shapes instead.");
61  }
62  break;
63  default:
64  {
66  //LOGWARNING(L"[ModelAbstract] Unrecognized selection shape type: %ld", m_CustomSelectionShape->m_Type);
67  debug_warn("[ModelAbstract] Unrecognized selection shape type");
68  }
69  break;
70  }
71  }
72  else
73  {
74  // standard method
75 
76  // Get the object-space bounds that should be used to construct this model (and its children)'s selection box
78  if (objBounds.IsEmpty())
79  {
80  m_SelectionBox.SetEmpty(); // model does not wish to participate in selection
81  return;
82  }
83 
84  // Prevent the bounding box from extending through the terrain; clip the lower plane at Y=0 in object space.
85  if (objBounds[1].Y > 0.f) // should always be the case, unless the models are defined really weirdly
86  objBounds[0].Y = std::max(0.f, objBounds[0].Y);
87 
88  // transform object-space axis-aligned bounds to world-space arbitrary-aligned box
90  }
91 
92 }
void CalcSelectionBox()
The selection shape is determined by a cylinder of custom, user-specified size.
Definition: ModelAbstract.h:52
void Transform(const CMatrix3D &m, CBoundingBoxAligned &result) const
Transforms these bounds according to the specified transformation matrix m, and writes the axis-align...
Definition: Decompose.h:22
float m_Size0
Box width if BOX, or radius if CYLINDER.
Definition: ModelAbstract.h:56
float m_Height
Box height if BOX, cylinder height if CYLINDER.
Definition: ModelAbstract.h:58
float m_Size1
Box depth if BOX, or radius if CYLINDER.
Definition: ModelAbstract.h:57
virtual const CBoundingBoxOriented & GetSelectionBox()
Returns the world-space selection box of this model.
#define LOGWARNING
Definition: CLogger.h:34
CustomSelectionShape * m_CustomSelectionShape
Pointer to a descriptor for a custom-defined selection box shape.
virtual const CBoundingBoxAligned GetObjectSelectionBoundsRec()
Returns the (object-space) bounds that should be used to construct a selection box for this model and...
CBoundingBoxOriented m_SelectionBox
Selection box for this model.
const CMatrix3D & GetTransform() const
#define debug_warn(expr)
display the error dialog with the given text.
Definition: debug.h:324
bool m_SelectionBoxValid
Is the current selection box valid?
The selection shape is determined by an oriented box of custom, user-specified size.
Definition: ModelAbstract.h:50