Wasabi
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
WObject Class Reference

#include <WObject.hpp>

Inheritance diagram for WObject:
WOrientation WFileAsset WMaterialsStore WBase

Public Member Functions

virtual std::string GetTypeName () const override
 
virtual void SetID (uint32_t newID) override
 
virtual void SetName (std::string newName) override
 
 WObject (Wasabi *const app, uint32_t ID=0)
 
 WObject (Wasabi *const app, class WEffect *fx, uint32_t bindingSet, uint32_t ID=0)
 
bool WillRender (class WRenderTarget *rt)
 
void Render (class WRenderTarget *rt, class WMaterial *material, bool updateInstances=true)
 
WError SetGeometry (class WGeometry *geometry)
 
WError SetAnimation (class WAnimation *animation)
 
class WGeometryGetGeometry () const
 
class WAnimationGetAnimation () const
 
WError InitInstancing (uint32_t maxInstances)
 
void DestroyInstancingResources ()
 
WInstanceCreateInstance ()
 
WInstanceGetInstance (uint32_t index) const
 
void DeleteInstance (WInstance *instance)
 
void DeleteInstance (uint32_t index)
 
uint32_t GetInstancesCount () const
 
void Show ()
 
void Hide ()
 
bool Hidden () const
 
void EnableFrustumCulling ()
 
void DisableFrustumCulling ()
 
bool InCameraView (class WCamera *cam)
 
void Scale (WVector3 scale)
 
WVector3 GetScale () const
 
WMatrix GetWorldMatrix ()
 
bool UpdateLocals ()
 
virtual void OnStateChange (STATE_CHANGE_TYPE type) override
 
virtual bool Valid () const override
 
virtual WError SaveToStream (WFile *file, std::ostream &outputStream) override
 
virtual WError LoadFromStream (WFile *file, std::istream &inputStream, std::vector< void * > &args, std::string nameSuffix) override
 
- Public Member Functions inherited from WOrientation
void SetPosition (float x, float y, float z)
 
void SetPosition (const WVector3 pos)
 
void Point (float x, float y, float z)
 
void Point (WVector3 target)
 
void SetAngle (WQuaternion quat)
 
void SetToRotation (const WOrientation *const device)
 
void SetULRVectors (WVector3 up, WVector3 look, WVector3 right)
 
void SetToTransformation (WMatrix mtx)
 
void Yaw (float angle)
 
void Roll (float angle)
 
void Pitch (float angle)
 
void Move (float units)
 
void Strafe (float units)
 
void Fly (float units)
 
float GetPositionX () const
 
float GetPositionY () const
 
float GetPositionZ () const
 
WVector3 GetPosition () const
 
float GetAngleX () const
 
float GetAngleY () const
 
float GetAngleZ () const
 
WQuaternion GetRotation () const
 
WVector3 GetUVector () const
 
WVector3 GetLVector () const
 
WVector3 GetRVector () const
 
virtual void SetBindingMatrix (WMatrix mtx)
 
void RemoveBinding ()
 
WMatrix GetBindingMatrix () const
 
bool IsBound () const
 
WMatrix ComputeTransformation () const
 
WMatrix ComputeInverseTransformation () const
 
- Public Member Functions inherited from WFileAsset
 WFileAsset (class Wasabi *const app, uint32_t ID=0)
 
virtual WError LoadFromStream (class WFile *file, std::istream &inputStream, vector< void * > &args, std::string nameSuffix)=0
 
- Public Member Functions inherited from WBase
 WBase (class Wasabi *const app, uint32_t ID=0)
 
uint32_t GetID () const
 
std::string GetName () const
 
class WasabiGetAppPtr () const
 
void AddReference ()
 
void RemoveReference ()
 
- Public Member Functions inherited from WMaterialsStore
void AddEffect (class WEffect *effect, uint32_t bindingSet=0)
 
void RemoveEffect (class WEffect *effect)
 
void RemoveEffect (class WMaterial *material)
 
void ClearEffects ()
 
class WMaterialGetMaterial (class WEffect *effect)
 
class WMaterialCollectionGetMaterials ()
 

Static Public Member Functions

static std::string _GetTypeName ()
 
static std::vector< void * > LoadArgs ()
 

Protected Member Functions

virtual void OnMaterialAdded (class WMaterial *newMaterial) override
 
- Protected Member Functions inherited from WMaterialsStore
void _AddMaterial (class WMaterial *material)
 

Friends

class WObjectManager
 

Additional Inherited Members

- Protected Attributes inherited from WBase
class Wasabim_app
 
uint32_t m_ID
 
std::string m_name
 
- Protected Attributes inherited from WMaterialsStore
std::unordered_map< class WEffect *, class WMaterial * > m_materialMap
 
class WMaterialCollectionm_materialsCollection
 

Detailed Description

A WObject provides an easy way to render things in Wasabi. A WObject combines WGeometry and WMaterial to render geometry using the material. Furthermore, WObject provides an interface to manipulate the rendered object's desired position, orientation and scale. A WObject also provides an easy way to apply animations and instancing on rendered geometry.

Member Function Documentation

◆ _GetTypeName()

static std::string WObject::_GetTypeName ( )
static

Returns "Object" string.

Returns
Returns "Object" string

◆ CreateInstance()

WInstance* WObject::CreateInstance ( )

Creates an instance of this object. Instancing has to be initialized prior to calling this function (see InitInstancing()).

Returns
The newly created instance, or nullptr if it cannot be created. An instance creation failure will occur if instancing is not initiated or if the maximum number of instances is reached

◆ DeleteInstance() [1/2]

void WObject::DeleteInstance ( uint32_t  index)

Destroys an instance created for this object. Any pointer to the instance destroyed by this call cannot be used as that memory will be freed.

Parameters
indexIndex of the instance to destroy

◆ DeleteInstance() [2/2]

void WObject::DeleteInstance ( WInstance instance)

Destroys an instance created for this object. The memory of the instance will be freed and The pointer given to the function cannot be used after this call.

Parameters
instanceInstance to destroy

◆ DestroyInstancingResources()

void WObject::DestroyInstancingResources ( )

Cleans up all instancing assets, and disables instancing.

◆ DisableFrustumCulling()

void WObject::DisableFrustumCulling ( )

Disables frustum culling, see EnableFrustumCulling() for more info.

◆ EnableFrustumCulling()

void WObject::EnableFrustumCulling ( )

Enables frustum culling. Frustum culling causes the object to only be rendered if part of its geometry is within the viewing frustum of the camera.

◆ GetAnimation()

class WAnimation* WObject::GetAnimation ( ) const

Retrieves the attached animation.

Returns
Attached animation, nullptr if none exists

◆ GetGeometry()

class WGeometry* WObject::GetGeometry ( ) const

Retrieves the attached geometry.

Returns
Attached geometry, nullptr if none exists

◆ GetInstance()

WInstance* WObject::GetInstance ( uint32_t  index) const

Retrieves an instance of the object at a given index.

Parameters
indexIndex of the instance to retrieve
Returns
Pointer to the instance at the given index, or nullptr if it cannot be found

◆ GetInstancesCount()

uint32_t WObject::GetInstancesCount ( ) const

Retrieves the number of instances for this object that are currently created.

Returns
Number of currently created instances of the object

◆ GetScale()

WVector3 WObject::GetScale ( ) const

Retrieves the scale factors of this object.

Returns
3D vector containing the scale factors

◆ GetTypeName()

virtual std::string WObject::GetTypeName ( ) const
overridevirtual

This function must be implemented by a child class. This is used for debugging, in which a class should return its name.

Returns
The name of the class

Implements WBase.

◆ GetWorldMatrix()

WMatrix WObject::GetWorldMatrix ( )

Retrieves the world matrix computed so far. A call to UpdateLocals() should be made prior to this one to ensure getting the most recent matrix.

Returns
World matrix of this object

◆ Hidden()

bool WObject::Hidden ( ) const

Checks if the object is hidden.

Returns
true if the object is hidden, false otherwise

◆ Hide()

void WObject::Hide ( )

Hides the object, making it unable to render.

◆ InCameraView()

bool WObject::InCameraView ( class WCamera cam)

Checks if the object appears anywhere in the view of the camera

Parameters
camCamera to check against
Returns
true of the object is in the viewing frustum of cam, false otherwise

◆ InitInstancing()

WError WObject::InitInstancing ( uint32_t  maxInstances)

Initiates geometry instancing for this object. When geometry instancing is initiated, and at least one instance is created (via CreateInstance()), the object will be rendered with geometry instancing.

Parameters
maxInstancesMaximum number of instanced allowed to be created
Returns
Error code, see WError.h

◆ LoadArgs()

static std::vector<void*> WObject::LoadArgs ( )
static

Animations can only be saved if they are an instance of WSkeleton

◆ OnStateChange()

virtual void WObject::OnStateChange ( STATE_CHANGE_TYPE  type)
overridevirtual

A callback called by this class when the entity changes its position or orientation.

Parameters
typeOrientation change type

Reimplemented from WOrientation.

◆ Render()

void WObject::Render ( class WRenderTarget rt,
class WMaterial material,
bool  updateInstances = true 
)

Renders this object. An object will only render to the render target if its valid (see Valid()) and not hidden (see Hide()). If frustum culling is enabled (see EnableFrustumCulling()), the object will only render if it is within the viewing frustum of the render target's camera. Before an object binds the provided material (WMaterial::Bind()), it will set the following variables and resources in the material, if they exist:

  • "worldMatrix" (WMatrix) will be set to the world matrix of this object.
  • "isInstanced" (int) will be set to 1 if instancing data is available, 0 otherwise.
  • texture "animationTexture" will be assigned to the animation texture from the attached animation. This will only occur if the object's material is rigged and there is an animation supplied.
  • texture "instancingTexture" will be assigned to the instancing texture created by this object. This will only occur if isInstanced was set to 1.

If the object's instancing is initiated (see InitInstancing()), and there is at least one instance created (see CreateInstance()), the object will be rendered using geometry instancing.

Parameters
rtRender target to render to.
materialMaterial to fill in with object data and bind
updateInstancesWhether or not to update the instances data

◆ Scale()

void WObject::Scale ( WVector3  scale)

Sets the scale of this object.

Parameters
scaleScale factor components

◆ SetAnimation()

WError WObject::SetAnimation ( class WAnimation animation)

Sets the attached animation.

Parameters
animationAnimation to attach, or nullptr to remove the attachment
Returns
Error code, see WError.h

◆ SetGeometry()

WError WObject::SetGeometry ( class WGeometry geometry)

Sets the attached geometry.

Parameters
geometryGeometry to attach, or nullptr to remove the attachment
Returns
Error code, see WError.h

◆ SetID()

virtual void WObject::SetID ( uint32_t  newID)
overridevirtual

Sets the ID of this object and notifies its manager.

Parameters
newIDNew ID

Implements WBase.

◆ SetName()

virtual void WObject::SetName ( std::string  newName)
overridevirtual

Sets the name of this object.

Parameters
nameNew name for the object

Implements WBase.

◆ Show()

void WObject::Show ( )

Shows the object, allowing to render.

◆ UpdateLocals()

bool WObject::UpdateLocals ( )

Updates the locally computed world matrix of this object.

Parameters
offsetAn offset position to apply to the local matrix
Returns
true if changes have occurred since the last update, false otherwise

◆ Valid()

virtual bool WObject::Valid ( ) const
overridevirtual

Checks the validity of this object. An object is valid if it meets all the following conditions:

  • it has a valid geometry and a valid material attached
  • both the input layout (at the 0th index) of the material and the vertex description of the geometry have the same size.
    Returns
    true if the object is valid, false otherwise

Implements WBase.

◆ WillRender()

bool WObject::WillRender ( class WRenderTarget rt)

Checks whether a call to Render() will cause any rendering (draw call) to happen.


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