Cafu Engine
MapElementT Class Referenceabstract

This is the base class for all elements ("objects") that can exist in a map. More...

#include "MapElement.hpp"

Inheritance diagram for MapElementT:

Public Member Functions

 MapElementT ()
 The default constructor. More...
 
 MapElementT (const MapElementT &Elem)
 The copy constructor for copying a map element. More...
 
virtual ~MapElementT ()
 The virtual destructor. More...
 
virtual void Load_cmap (TextParserT &TP, MapDocumentT &MapDoc, bool IgnoreGroups)
 
virtual void Save_cmap (std::ostream &OutFile, unsigned long ElemNr, const MapDocumentT &MapDoc) const
 
MapEditor::CompMapEntityTGetParent () const
 Returns the entity that this element is a part of, or NULL if the element has no parent entity. More...
 
void SetParent (MapEditor::CompMapEntityT *Ent)
 Sets the parent entity that is element is a part of. More...
 
bool IsSelected () const
 Returns whether this element is currently selected in the map document. More...
 
void SetSelected (bool Selected=true)
 Sets the selection state of this element. More...
 
virtual bool IsTranslucent () const
 Returns whether this map element is (entirely or partially) translucent. More...
 
virtual wxColour GetColor (bool ConsiderGroup=true) const =0
 This method returns the "inherent" color of this map element. More...
 
virtual wxString GetDescription () const
 
GroupTGetGroup () const
 Returns NULL when this map element is in no group, or the pionter to the group it is a member of otherwise. More...
 
void SetGroup (GroupT *Group)
 Sets the group this element is a member of (use NULL for "no group"). More...
 
bool IsVisible () const
 Returns whether this map element is currently visible (in the 2D, 3D and other views). More...
 
bool CanSelect () const
 Returns whether this map element can currently be selected (in the 2D, 3D and other views). More...
 
void GetToggleEffects (ArrayT< MapElementT * > &RemoveFromSel, ArrayT< MapElementT * > &AddToSel, bool AutoGroupEntities)
 Computes how the selection must be changed in order to toggle the given element when the element's entity and group memberships are taken into account. More...
 
virtual void AdvanceTime (float t)
 This is periodically called in order to have the element advance its internal clock by t seconds. More...
 
virtual void Render2D (Renderer2DT &Renderer) const
 
virtual void Render3D (Renderer3DT &Renderer) const
 
virtual BoundingBox3fT GetBB () const =0
 Returns the spatial bounding-box of this map element. More...
 
virtual bool TraceRay (const Vector3fT &RayOrigin, const Vector3fT &RayDir, float &Fraction, unsigned long &FaceNr) const
 Traces a ray against this map element, and returns whether it was hit. More...
 
virtual bool TracePixel (const wxPoint &Pixel, int Radius, const ViewWindow2DT &ViewWin) const
 This method determines if this map element is intersected/affected by the specified disc in ViewWin. More...
 
virtual TrafoMementoTGetTrafoState () const
 Returns a memento that encapsulates the transform-related state of this element. More...
 
virtual void RestoreTrafoState (const TrafoMementoT *TM)
 Restores the transform-related state of this element from the given memento. More...
 
virtual void TrafoMove (const Vector3fT &Delta, bool LockTexCoords)
 Translates this element by the given vector (in world-space). More...
 
virtual void TrafoRotate (const Vector3fT &RefPoint, const cf::math::AnglesfT &Angles, bool LockTexCoords)
 Rotates this element about the given reference point (in world-space). More...
 
virtual void TrafoScale (const Vector3fT &RefPoint, const Vector3fT &Scale, bool LockTexCoords)
 Scales this element about the given reference point (in world-space). More...
 
virtual void TrafoMirror (unsigned int NormalAxis, float Dist, bool LockTexCoords)
 Mirrors this element along the given mirror plane (in world-space). More...
 
virtual void Transform (const Matrix4x4fT &Matrix, bool LockTexCoords)
 Why does this method not replace all the other Trafo*() methods? This method is the most generic, allowing transformations that e.g. More...
 
unsigned int GetFrameCount () const
 
void SetFrameCount (unsigned int FrameCount)
 
virtual const
cf::TypeSys::TypeInfoT
GetType () const
 

Static Public Member Functions

static void * CreateInstance (const cf::TypeSys::CreateParamsT &Params)
 

Static Public Attributes

static const cf::TypeSys::TypeInfoT TypeInfo
 

Protected Attributes

MapEditor::CompMapEntityTm_Parent
 The entity that this element is a part of. More...
 
bool m_IsSelected
 Is this element currently selected in the map document? More...
 
GroupTm_Group
 The group this element is in, NULL if in no group. More...
 
unsigned int m_FrameCount
 The number of the frame in which this element was last rendered in a 3D view, used in order to avoid processing/rendering it twice. More...
 

Detailed Description

This is the base class for all elements ("objects") that can exist in a map.

Generally, elements can exist stand-alone, without being assigned to a parent entity; they are intended to be fully functional even without a parent entity. Examples include newly created elements, elements in the clipboard, temporary copies (e.g. for preview rendering in Selection tool), and elements inside commands (e.g. state before or after a transform). For stand-alone elements, GetParent() returns NULL.

Usually though, elements are kept by an entity. The entity that an element is a part of can be learned with the GetParent() method.

Constructor & Destructor Documentation

MapElementT::MapElementT ( )

The default constructor.

MapElementT::MapElementT ( const MapElementT Elem)

The copy constructor for copying a map element.

Parameters
ElemThe element to copy-construct this element from.

Contrary to Elem, the new MapElementT instance is:

  • never selected (no matter if Elem was selected),
  • not in a group (and thus visible). It is up to the caller to assign selection state and group membership if desired. The new element is always constructed with a deep-copy (that is, the children of Elem are copied recursively).
MapElementT::~MapElementT ( )
virtual

The virtual destructor.

Member Function Documentation

virtual void MapElementT::AdvanceTime ( float  t)
inlinevirtual

This is periodically called in order to have the element advance its internal clock by t seconds.

The typical use case is with elements that represent models for updating the current frame in their animation sequence.

bool MapElementT::CanSelect ( ) const

Returns whether this map element can currently be selected (in the 2D, 3D and other views).

Note that as with IsVisible(), the "can select" status is independent of that of the parent entity.

virtual BoundingBox3fT MapElementT::GetBB ( ) const
pure virtual

Returns the spatial bounding-box of this map element.

Implemented in MapBezierPatchT, MapTerrainT, MapBrushT, MapModelT, MapPlantT, and MapEntRepresT.

virtual wxColour MapElementT::GetColor ( bool  ConsiderGroup = true) const
pure virtual

This method returns the "inherent" color of this map element.

The returned color should be used for rendering the map element whenever no better (e.g. texture-mapped) alternative is available.

Parameters
ConsiderGroupWhether the map elements group color should be taken into account.
Returns
the "inherent" color of this map element. When the map element is in a group and ConsiderGroup is true, the group color is returned. When the map element is an entity, the color of the entity class is returned. Otherwise (the element is a primitive), when the map element is part of an entity, the entity color is returned. Finally (it's a map primitive that is in the world), its native color is returned.

Implemented in MapPrimitiveT, and MapEntRepresT.

GroupT* MapElementT::GetGroup ( ) const
inline

Returns NULL when this map element is in no group, or the pionter to the group it is a member of otherwise.

MapEditor::CompMapEntityT* MapElementT::GetParent ( ) const
inline

Returns the entity that this element is a part of, or NULL if the element has no parent entity.

See the MapElementT class documentation for additional information.

void MapElementT::GetToggleEffects ( ArrayT< MapElementT * > &  RemoveFromSel,
ArrayT< MapElementT * > &  AddToSel,
bool  AutoGroupEntities 
)

Computes how the selection must be changed in order to toggle the given element when the element's entity and group memberships are taken into account.

Unfortunately, the method cannot be const, because this map element is possibly added to one of the given arrays, whose elements are non-const.

virtual TrafoMementoT* MapElementT::GetTrafoState ( ) const
inlinevirtual

Returns a memento that encapsulates the transform-related state of this element.

The method saves all state in the memento that calls to the Trafo*() methods can possibly modify.

Reimplemented in MapBezierPatchT, MapTerrainT, MapBrushT, MapPlantT, MapModelT, and MapEntRepresT.

bool MapElementT::IsSelected ( ) const
inline

Returns whether this element is currently selected in the map document.

virtual bool MapElementT::IsTranslucent ( ) const
inlinevirtual

Returns whether this map element is (entirely or partially) translucent.

Translucent map elements are typically implemented with "alpha blending" and require rendering in back-to-front order.

See Also
EditorMaterialI::IsTranslucent()

Reimplemented in MapBezierPatchT, MapBrushT, MapPlantT, and MapEntRepresT.

bool MapElementT::IsVisible ( ) const

Returns whether this map element is currently visible (in the 2D, 3D and other views).

Note that the visibility does not depend on the visibility of the parent entity – in CaWE, map elements are mostly independent of their parents (and thus entities can also be "half visible" if the user wishes so).

virtual void MapElementT::RestoreTrafoState ( const TrafoMementoT TM)
inlinevirtual

Restores the transform-related state of this element from the given memento.

The method restores all state from the memento that calls to the Trafo*() methods have possibly modified.

Reimplemented in MapBezierPatchT, MapTerrainT, MapBrushT, MapPlantT, MapModelT, and MapEntRepresT.

void MapElementT::SetGroup ( GroupT Group)
inline

Sets the group this element is a member of (use NULL for "no group").

void MapElementT::SetParent ( MapEditor::CompMapEntityT Ent)

Sets the parent entity that is element is a part of.

See the MapElementT class documentation for additional information.

void MapElementT::SetSelected ( bool  Selected = true)
inline

Sets the selection state of this element.

As this should always be in sync with the map document, the map document is the only legitimate caller of this method (but there are some exceptions).

bool MapElementT::TracePixel ( const wxPoint &  Pixel,
int  Radius,
const ViewWindow2DT ViewWin 
) const
virtual

This method determines if this map element is intersected/affected by the specified disc in ViewWin.

The disc for the test is defined by the given center pixel and the given radius. For example, the caller can learn by the result of this method whether the map element should respond to a mouse-click at the same pixel. Therefore, this method can be considered as the 2D analogue of the TraceRay() method.

Reimplemented in MapBezierPatchT, MapTerrainT, MapBrushT, MapModelT, MapPlantT, and MapEntRepresT.

bool MapElementT::TraceRay ( const Vector3fT RayOrigin,
const Vector3fT RayDir,
float &  Fraction,
unsigned long &  FaceNr 
) const
virtual

Traces a ray against this map element, and returns whether it was hit.

The ray for the trace is defined by RayOrigin + RayDir*Fraction, where Fraction is a scalar >= 0. If a hit was detected, the Fraction is returned. Hit brushes return the number of the hit face as well. This method has been implemented mainly for "picking", that is, left-click selection in the 3D views (it makes sure that also objects that "clip nothing" in the engine can be picked), but it can also be used for any other purpose.

Parameters
RayOriginThe point in world space where the ray starts.
RayDirA unit vector in world space that describes the direction the ray extends to.
FractionOn hit, the scalar along RayDir at which the hit occurred is returned here.
FaceNrIf this map element is a brush and it was hit, the number of the hit face is returned here.
Returns
true if the ray hit this map element, false otherwise. Additional hit data (i.e. Fraction and FaceNr) is returned via reference paramaters.

Reimplemented in MapBezierPatchT, MapTerrainT, MapBrushT, and MapEntRepresT.

virtual void MapElementT::TrafoMirror ( unsigned int  NormalAxis,
float  Dist,
bool  LockTexCoords 
)
inlinevirtual

Mirrors this element along the given mirror plane (in world-space).

Parameters
NormalAxisThe number of the axis along which the normal vector of the mirror plane points: 0, 1 or 2 for the x-, y- or z-axis respectively.
DistThe position of the mirror plane along its normal vector, where it intersects the NormalAxis.
LockTexCoordsTransform the texture-space along with the geometry. Note that the mirroring is not necessarily "perfect", because for some elements like models or plants, only their point of origin can be mirrored, but not their mesh.

Reimplemented in MapBezierPatchT, MapTerrainT, MapBrushT, MapPlantT, MapModelT, and MapEntRepresT.

virtual void MapElementT::TrafoMove ( const Vector3fT Delta,
bool  LockTexCoords 
)
inlinevirtual

Translates this element by the given vector (in world-space).

Parameters
DeltaThe offset by which to translate the element.
LockTexCoordsTransform the texture-space along with the geometry.

Reimplemented in MapBezierPatchT, MapTerrainT, MapBrushT, MapPlantT, MapModelT, and MapEntRepresT.

virtual void MapElementT::TrafoRotate ( const Vector3fT RefPoint,
const cf::math::AnglesfT Angles,
bool  LockTexCoords 
)
inlinevirtual

Rotates this element about the given reference point (in world-space).

Parameters
RefPointThe reference point (origin) for the rotation.
AnglesThe rotation angles for the three axes.
LockTexCoordsTransform the texture-space along with the geometry.

Reimplemented in MapBezierPatchT, MapTerrainT, MapBrushT, MapPlantT, MapModelT, and MapEntRepresT.

virtual void MapElementT::TrafoScale ( const Vector3fT RefPoint,
const Vector3fT Scale,
bool  LockTexCoords 
)
inlinevirtual

Scales this element about the given reference point (in world-space).

Parameters
RefPointThe reference point (origin) for the scale.
ScaleThe scale factors for the three axes.
LockTexCoordsTransform the texture-space along with the geometry.
Exceptions
DivisionByZeroE,e.g.when Scale is too small and the element becomes degenerate (e.g. a brush with too small faces).

Reimplemented in MapBezierPatchT, MapTerrainT, MapBrushT, MapPlantT, MapModelT, and MapEntRepresT.

virtual void MapElementT::Transform ( const Matrix4x4fT Matrix,
bool  LockTexCoords 
)
inlinevirtual

Why does this method not replace all the other Trafo*() methods? This method is the most generic, allowing transformations that e.g.

are non-orthogonal (like shears or non-uniform scales). This in turn conflicts with map primitives that can only store and deal with a restricted fixed set of transformations, e.g. an origin, a rotation and a uniform scale. These values cannot properly be re-computed from a general matrix with non-orthogonal basis vectors.

Parameters
MatrixThe matrix that describes the transform to be applied.
LockTexCoordsTransform the texture-space along with the geometry.

Reimplemented in MapBezierPatchT, MapTerrainT, MapBrushT, MapPlantT, MapModelT, and MapEntRepresT.

Member Data Documentation

unsigned int MapElementT::m_FrameCount
protected

The number of the frame in which this element was last rendered in a 3D view, used in order to avoid processing/rendering it twice.

GroupT* MapElementT::m_Group
protected

The group this element is in, NULL if in no group.

bool MapElementT::m_IsSelected
protected

Is this element currently selected in the map document?

MapEditor::CompMapEntityT* MapElementT::m_Parent
protected

The entity that this element is a part of.


The documentation for this class was generated from the following files: