Support Forum G3D Web Page |
Base class for objects in a G3D::Scene. More...
Inherits G3D::ReferenceCountedObject.
Inherited by G3D::Camera, G3D::MarkerEntity, G3D::Skybox, G3D::SoundEntity, and G3D::VisibleEntity.
Classes | |
class | EntityTrack |
class | SplineTrack |
class | Track |
Base class for Entity animation controllers. More... | |
Public Member Functions | |
bool | canCauseCollisions () const |
bool | canChange () const |
True if this Entity can change (when not Scene::editing(); all objects can change when in editing mode). More... | |
const CoordinateFrame & | frame () const |
Current position, i.e., as of last onSimulation call. More... | |
virtual void | getLastBounds (class AABox &box) const |
Return a world-space axis-aligned bounding box as of the last call to onPose(). More... | |
virtual void | getLastBounds (class Sphere &sphere) const |
Return a world-space bounding sphere as of the last call to onPose(). More... | |
virtual void | getLastBounds (class Box &box) const |
Return a world-space bounding box as of the last call to onPose(). More... | |
virtual bool | intersect (const Ray &R, float &maxDistance, Model::HitInfo &info=Model::HitInfo::ignore) const |
virtual bool | intersectBounds (const Ray &R, float &maxDistance, Model::HitInfo &info=Model::HitInfo::ignore) const |
Returns true if there is conservatively some intersection with the object's bounds closer than maxDistance to the ray origin. More... | |
virtual const Array< Box > & | lastBoxBoundArray () const |
Return a world-space bounding box array for all surfaces produced by this Entity as of the last call to onPose(). More... | |
bool | lastBoxBoundArraysOverlap (const shared_ptr< Entity > &other) const |
Returns true if the world space bounds of these two entities overlap. More... | |
RealTime | lastChangeTime () const |
Wall-clock time at which this entity changed in some way, e.g., that might require recomputing a spatial data structure. More... | |
virtual void | makeGUI (class GuiPane *pane, class GApp *app) |
Create a user interface for controlling the properties of this Entity. More... | |
void | markChanged () |
Sets the lastChangeTime() to the current System::time() More... | |
float | mass () const |
const String & | name () const |
virtual void | onPose (Array< shared_ptr< class Surface > > &surfaceArray) |
Pose as of the last simulation time. More... | |
virtual void | onSimulation (SimTime absoluteTime, SimTime deltaTime) |
Physical simulation callback. More... | |
bool | physicalSimulation () const |
virtual shared_ptr< SoundEntity > | playSound (const shared_ptr< Sound > &sound, const CFrame &childFrame=CFrame(), bool attach=true) |
Creates a new G3D::SoundEntity attached to this Entity at childFrame by an Entity::EntityTrack and returns it. More... | |
const CoordinateFrame & | previousFrame () const |
virtual void | setCanCauseCollisions (bool c) |
If true, causes collisions for other objects during physical simulation. More... | |
virtual void | setFrame (const CFrame &f, bool updatePreviousFrame=true) |
This sets the position of the Entity for the current simulation step. More... | |
virtual void | setFrameSpline (const PhysicsFrameSpline &spline) |
If there is a controller on this object and it is a SplineTrack, mutate it to store this value. More... | |
virtual void | setMass (float m) |
Set to a negative number to tell the physics system to use the absolute value as a density and infer the mass from the mesh on load. More... | |
virtual void | setPhysicalSimulation (bool s) |
If true, this object should receive physical simulation for its motion. More... | |
virtual void | setPreviousFrame (const CFrame &f) |
Explicitly override the previous frame value used for computing motion vectors. More... | |
void | setShouldBeSaved (bool b) |
virtual void | setTrack (const shared_ptr< Track > &c) |
bool | shouldBeSaved () const |
True if this Entity should be saved when the scene is converted to Any for saving/serialization. More... | |
virtual Any | toAny (const bool forceAll=false) const |
Converts the current Entity to an Any. More... | |
virtual shared_ptr< Track > | track () const |
virtual void | visualize (RenderDevice *rd, bool isSelected, const class SceneVisualizationSettings &s, const shared_ptr< GFont > &font, const shared_ptr< Camera > &camera) |
Called by Scene::visualize every frame. More... | |
Protected Member Functions | |
Entity () | |
Construct an entity, m_framSplineChange defaults to false. More... | |
void | init (const String &name, Scene *scene, AnyTableReader &propertyTable) |
The initialization sequence for Entity and its subclasses is different than for typical C++ classes. More... | |
void | init (const String &name, Scene *scene, const CFrame &frame, const shared_ptr< Track > &controller, bool canChange, bool shouldBeSaved) |
Static Protected Member Functions | |
template<class T , class ... ArgTypes> | |
static shared_ptr< T > | createShared (ArgTypes &&... args) |
Like std::make_shared, but works for protected constructors. More... | |
Protected Attributes | |
bool | m_canCauseCollisions = false |
bool | m_canChange |
If true, the canChange() method returns true. More... | |
CoordinateFrame | m_frame |
Current position. More... | |
AABox | m_lastAABoxBounds |
Bounds at the last pose() call, in world space. More... | |
RealTime | m_lastBoundsTime |
Time at which the bounds were computed. More... | |
Array< Box > | m_lastBoxBoundArray |
Bounds on all of the surfaces from the last pose() call, in world space. More... | |
Box | m_lastBoxBounds |
Bounds at the last pose() call, in world space. More... | |
RealTime | m_lastChangeTime |
AABox | m_lastObjectSpaceAABoxBounds |
Bounds at the last pose() call, in object space. More... | |
Sphere | m_lastSphereBounds |
Bounds at the last pose() call, in world space. More... | |
float | m_mass = 1 |
bool | m_movedSinceLoad |
True if the frame has changed since load. More... | |
bool | m_movedSinceSimulation = false |
Has this Entity been explicitly moved by setFrame() since it was last simulated? If so, onSimulation will not update the m_previousFrame because it assumes some external logic is moving the Entity. More... | |
String | m_name |
bool | m_physicalSimulation = false |
CoordinateFrame | m_previousFrame |
Frame before onSimulation(). More... | |
Scene * | m_scene |
bool | m_shouldBeSaved |
True if this Entity should be saved when the scene is converted to Any for saving/serialization. More... | |
Any | m_sourceAny |
The Any from which this was originally constructed. More... | |
shared_ptr< Track > | m_track |
Basic simulation behavior for the Entity. More... | |
Base class for objects in a G3D::Scene.
Entity can be subclassed as long as you override the Scene::createEntity method to understand the new subclass.
To make an object controled by its own logic (instead of moving along a predetermined spline), subclass VisibleEntity and override Entity::onSimulation(). Do not invoke the base class's Entity::onSimulation() in that case.
|
protected |
Construct an entity, m_framSplineChange defaults to false.
|
inline |
|
inline |
True if this Entity can change (when not Scene::editing(); all objects can change when in editing mode).
It is safe to build static data structures over Entitys that cannot change.
|
inlinestaticprotectedinherited |
Like std::make_shared, but works for protected constructors.
Call as createShared<myclass>.
|
inline |
Current position, i.e., as of last onSimulation call.
|
virtual |
Return a world-space axis-aligned bounding box as of the last call to onPose().
|
virtual |
Return a world-space bounding sphere as of the last call to onPose().
|
virtual |
|
protected |
The initialization sequence for Entity and its subclasses is different than for typical C++ classes.
That is because they must avoid throwing exceptions from a constructor when parsing, need to support both AnyTableReader and direct parameter versions, and have to verify that all fields from an AnyTableReader are actually consumed. See samples/entity and G3D::VisibleEntity for examples of how to initialize an Entity subclass.
name | The name of this Entity, e.g., "Player 1" |
propertyTable | The form is given below. It is intended that subclasses replace the table name and add new fields. <some base class name> { model = <modelname>; frame = <initial CFrame or equivalent; overriden if a controller is present> track = <see Entity::Track>; canChange = <boolean> }
|
scene | May be nullptr so long as no entity() controller is used |
|
protected |
|
virtual |
Reimplemented in G3D::VisibleEntity, G3D::MarkerEntity, and G3D::SoundEntity.
|
virtual |
Returns true if there is conservatively some intersection with the object's bounds closer than maxDistance to the ray origin.
If so, updates maxDistance with the intersection distance.
The bounds used may be more accurate than any of the given getLastBounds() results because the method may recurse into individual parts of the scene graph within the Entity.
Reimplemented in G3D::VisibleEntity.
bool G3D::Entity::lastBoxBoundArraysOverlap | ( | const shared_ptr< Entity > & | other | ) | const |
Returns true if the world space bounds of these two entities overlap.
|
inline |
Wall-clock time at which this entity changed in some way, e.g., that might require recomputing a spatial data structure.
Create a user interface for controlling the properties of this Entity.
Called by SceneEditorWindow on selection.
app | May be nullptr. |
Reimplemented in G3D::Light, G3D::Camera, and G3D::VisibleEntity.
|
inline |
Sets the lastChangeTime() to the current System::time()
|
inline |
|
inline |
Referenced by G3D::Light::spotTarget().
Pose as of the last simulation time.
Reimplemented in G3D::Light, G3D::Camera, G3D::ParticleSystem, and G3D::VisibleEntity.
Physical simulation callback.
The default implementation animates the model pose (by calling simulatePose()) and moves the frame() along m_frameSpline.
If setFrame() has been called since the last onSimulation call, then the previous frame is not updated to the current frame by onSimulation because it assumes some external logic is maintaining the Entity's position.
deltaTime | The change in time since the previous call to onSimulation. Two values are special: 0 means that simulation is paused and time should not advance. As much as possible, all state should remain unchanged. For example, anything computed by differentials such as velocity should remain at its current value (rather than becoming infinite!). In particular, this allows freeze-frame rendering of motion blur. The default implementation leaves m_previousFrame and the previous pose unchanged. A value of nan() means that the time has been changed discontinuously, for example, by Scene::setTime. In this case, all state should update to the new absolute time and differentials can be approximated as zero (or whatever other result is reasonable for this Entity). |
Reimplemented in G3D::Light, G3D::Camera, G3D::ParticleSystem, G3D::VisibleEntity, G3D::MarkerEntity, G3D::SoundEntity, and G3D::XRWidget::TrackedEntity.
|
inline |
|
virtual |
Creates a new G3D::SoundEntity attached to this Entity at childFrame by an Entity::EntityTrack and returns it.
The new SoundEntity is automatically added to the Scene and will remain rigidly attached to the Entity.
You do not need to retain the pointer to the created sound for it to remain playing and in the scene. The SoundEntity will automatically remove itself from the Scene when it stops playing.
If attach == false, then the EntityTrack is not created and the sound will remain fixed in space.
|
inline |
|
inlinevirtual |
If true, causes collisions for other objects during physical simulation.
It may not react to those collisions if physicalSimulation is false. Default is true for VisibleEntity and false for other subclasses.
|
virtual |
This sets the position of the Entity for the current simulation step.
If there is a controller set and the base class Entity::onSimulation is invoked, it will override the value assigned here.
|
virtual |
If there is a controller on this object and it is a SplineTrack, mutate it to store this value.
Otherwise, create a new SplineTrack to overwrite the current controller.
Used by SceneEditorWindow
|
inlinevirtual |
Set to a negative number to tell the physics system to use the absolute value as a density and infer the mass from the mesh on load.
Default is -10 (kg/m^3).
|
inlinevirtual |
|
inlinevirtual |
Explicitly override the previous frame value used for computing motion vectors.
This is very rarely needed because simulation automatically updates this value.
|
inline |
|
inlinevirtual |
|
inline |
True if this Entity should be saved when the scene is converted to Any for saving/serialization.
Defaults to true. Set to false for transient objects. For example, a character's spawn point Entity might have shouldBeSaved() = true, while the character itself might have shouldBeSaved() = false. This would allow editing of the scene while the simulation loop is running without having the scene at the end of the editing session reflecting the result of the character moving about.
|
virtual |
Converts the current Entity to an Any.
Subclasses should modify at least the name of the Table, which will be "Entity" if not changed.
Reimplemented in G3D::Light, G3D::ParticleSystem, G3D::VisibleEntity, G3D::Camera, G3D::MarkerEntity, G3D::Skybox, and G3D::SoundEntity.
|
inlinevirtual |
|
virtual |
Called by Scene::visualize every frame.
During this, Entitys may make rendering calls according to the SceneVisualizationSettings to display control points and other features.
isSelected | True if this entity is selected by a sceneEditorWindow, which may trigger additional visualization for it. |
Reimplemented in G3D::MarkerEntity, and G3D::SoundEntity.
|
protected |
Referenced by canCauseCollisions(), and setCanCauseCollisions().
|
protected |
If true, the canChange() method returns true.
Defaults to true.
It is illegal to set m_canChange to false if m_frameSpline has more than one control point because a spline implies animation.
Subclasses should set this to false during initialization if the object will never move so that other classes can precompute data structures that are affected by the Entity.
Referenced by canChange().
|
protected |
Current position.
Do not directly mutate–invoke setFrame() to ensure that times are modified correctly.
Referenced by G3D::Light::distance(), frame(), G3D::Light::frame(), and G3D::Light::position().
|
protected |
Bounds at the last pose() call, in world space.
|
protected |
Time at which the bounds were computed.
Bounds on all of the surfaces from the last pose() call, in world space.
Referenced by lastBoxBoundArray().
|
protected |
Bounds at the last pose() call, in world space.
|
protected |
Referenced by lastChangeTime(), markChanged(), G3D::Light::setEnabled(), and G3D::Light::setShadowsEnabled().
|
protected |
Bounds at the last pose() call, in object space.
|
protected |
Bounds at the last pose() call, in world space.
|
protected |
True if the frame has changed since load.
Used by toAny() to decide if m_sourceAny is out of date.
|
protected |
Has this Entity been explicitly moved by setFrame() since it was last simulated? If so, onSimulation will not update the m_previousFrame because it assumes some external logic is moving the Entity.
|
protected |
Referenced by physicalSimulation(), and setPhysicalSimulation().
|
protected |
Frame before onSimulation().
Used for tracking poses and for velocity estimation.
Referenced by previousFrame(), and setPreviousFrame().
|
protected |
|
protected |
True if this Entity should be saved when the scene is converted to Any for saving/serialization.
Defaults to true. Set to false for transient objects. For example, a character's spawn point Entity might have shouldBeSaved() = true, while the character itself might have shouldBeSaved() = false. This would allow editing of the scene while the simulation loop is running without having the scene at the end of the editing session reflecting the result of the character moving about.
Referenced by setShouldBeSaved(), and shouldBeSaved().
|
protected |
Basic simulation behavior for the Entity.
If nullptr, the Entity is never moved by the base class' onSimulation method. You can subclass Track, but it is usually easier to subclass Entity and override onSimulation directly when creating behaviors more complex than those supported by the default Track language.
Referenced by setTrack(), and track().