Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::SoundEntity Class Reference

An invisilbe Entity that plays a positional sound and removes itself from the Scene when the sound ends. More...

Inherits G3D::Entity.

Public Member Functions

const shared_ptr< AudioChannel > & audioChannel () const
 
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 CoordinateFrameframe () 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 override
 Note that Scene::intersect will not invoke this method unless the intersectMarkers argument to that method is true. More...
 
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 Stringname () 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) override
 Updates the AudioChannel::set3DAttributes. More...
 
bool physicalSimulation () const
 
virtual shared_ptr< SoundEntityplaySound (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 CoordinateFramepreviousFrame () 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...
 
const shared_ptr< Sound > & sound () const
 
virtual Any toAny (const bool forceAll=false) const override
 Converts the current Entity to an Any. More...
 
virtual shared_ptr< Tracktrack () const
 
virtual void visualize (RenderDevice *rd, bool isSelected, const class SceneVisualizationSettings &s, const shared_ptr< GFont > &font, const shared_ptr< Camera > &camera) override
 Called by Scene::visualize every frame. More...
 

Static Public Member Functions

static shared_ptr< SoundEntitycreate (const shared_ptr< Sound > &sound, float initialVolume=1.0f, const String &name="")
 Defaults to shouldBeSaved = false, canChange = true. More...
 
static shared_ptr< Entitycreate (const String &name, Scene *scene, AnyTableReader &propertyTable, const ModelTable &modelTable=ModelTable(), const Scene::LoadOptions &options=Scene::LoadOptions())
 For data-driven creation. More...
 

Protected Member Functions

 SoundEntity ()
 
void init (const shared_ptr< Sound > &sound, float initialVolume=1.0f)
 
void init (AnyTableReader &propertyTable)
 
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

shared_ptr< AudioChannelm_audioChannel
 
bool m_canCauseCollisions = false
 
bool m_canChange
 If true, the canChange() method returns true. More...
 
CoordinateFrame m_frame
 Current position. More...
 
bool m_hadFirstSimulation = false
 Playing is triggered only on the first onSimulation, so that the position and velocity are correct. 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< Boxm_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...
 
Scenem_scene
 
bool m_shouldBeSaved
 True if this Entity should be saved when the scene is converted to Any for saving/serialization.
More...
 
shared_ptr< Soundm_sound
 Used when serializing. More...
 
Any m_sourceAny
 The Any from which this was originally constructed. More...
 
shared_ptr< Trackm_track
 Basic simulation behavior for the Entity. More...
 

Detailed Description

An invisilbe Entity that plays a positional sound and removes itself from the Scene when the sound ends.

Typically attached to another Entity via an Entity::EntityTrack.

See also
MarkerEntity

Constructor & Destructor Documentation

◆ SoundEntity()

G3D::SoundEntity::SoundEntity ( )
protected

Member Function Documentation

◆ audioChannel()

const shared_ptr<AudioChannel>& G3D::SoundEntity::audioChannel ( ) const
inline

◆ canCauseCollisions()

bool G3D::Entity::canCauseCollisions ( ) const
inlineinherited

◆ canChange()

bool G3D::Entity::canChange ( ) const
inlineinherited

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.

◆ create() [1/2]

static shared_ptr<SoundEntity> G3D::SoundEntity::create ( const shared_ptr< Sound > &  sound,
float  initialVolume = 1.0f,
const String name = "" 
)
static

Defaults to shouldBeSaved = false, canChange = true.

Parameters
nameIf empty, a unique name is automatically generated.
See also
Entity::playSound

◆ create() [2/2]

static shared_ptr<Entity> G3D::SoundEntity::create ( const String name,
Scene scene,
AnyTableReader propertyTable,
const ModelTable modelTable = ModelTable(),
const Scene::LoadOptions options = Scene::LoadOptions() 
)
static

For data-driven creation.

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ frame()

const CoordinateFrame& G3D::Entity::frame ( ) const
inlineinherited

Current position, i.e., as of last onSimulation call.

◆ getLastBounds() [1/3]

virtual void G3D::Entity::getLastBounds ( class AABox box) const
virtualinherited

Return a world-space axis-aligned bounding box as of the last call to onPose().

◆ getLastBounds() [2/3]

virtual void G3D::Entity::getLastBounds ( class Sphere sphere) const
virtualinherited

Return a world-space bounding sphere as of the last call to onPose().

◆ getLastBounds() [3/3]

virtual void G3D::Entity::getLastBounds ( class Box box) const
virtualinherited

Return a world-space bounding box as of the last call to onPose().

This is always at least as tight as the AABox bounds and often tighter.

◆ init() [1/4]

void G3D::SoundEntity::init ( const shared_ptr< Sound > &  sound,
float  initialVolume = 1.0f 
)
protected

◆ init() [2/4]

void G3D::SoundEntity::init ( AnyTableReader propertyTable)
protected

◆ init() [3/4]

void G3D::Entity::init ( const String name,
Scene scene,
AnyTableReader propertyTable 
)
protectedinherited

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.

Parameters
nameThe name of this Entity, e.g., "Player 1"
propertyTableThe 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>
}
  • The pose field is optional. The Entity base class reads this field. Other subclasses read their own fields.
  • The original caller (typically, a Scene subclass createEntity or Entity subclass create method) should invoke AnyTableReader::verifyDone to ensure that all of the fields specified were read by some subclass along the inheritance chain.
  • See VisibleEntity::init for an example of using this method. This method is separate from the constructor solely because it will throw an exception on a parse error, which is dangerous to do during a constructor because the destructor will not run.
sceneMay be nullptr so long as no entity() controller is used

◆ init() [4/4]

void G3D::Entity::init ( const String name,
Scene scene,
const CFrame frame,
const shared_ptr< Track > &  controller,
bool  canChange,
bool  shouldBeSaved 
)
protectedinherited

◆ intersect()

virtual bool G3D::SoundEntity::intersect ( const Ray R,
float &  maxDistance,
Model::HitInfo info = Model::HitInfo::ignore 
) const
overridevirtual

Note that Scene::intersect will not invoke this method unless the intersectMarkers argument to that method is true.

Reimplemented from G3D::Entity.

◆ intersectBounds()

virtual bool G3D::Entity::intersectBounds ( const Ray R,
float &  maxDistance,
Model::HitInfo info = Model::HitInfo::ignore 
) const
virtualinherited

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.

◆ lastBoxBoundArray()

virtual const Array<Box>& G3D::Entity::lastBoxBoundArray ( ) const
inlinevirtualinherited

Return a world-space bounding box array for all surfaces produced by this Entity as of the last call to onPose().

◆ lastBoxBoundArraysOverlap()

bool G3D::Entity::lastBoxBoundArraysOverlap ( const shared_ptr< Entity > &  other) const
inherited

Returns true if the world space bounds of these two entities overlap.

See also
lastBoxBoundArray

◆ lastChangeTime()

RealTime G3D::Entity::lastChangeTime ( ) const
inlineinherited

Wall-clock time at which this entity changed in some way, e.g., that might require recomputing a spatial data structure.

◆ makeGUI()

virtual void G3D::Entity::makeGUI ( class GuiPane pane,
class GApp app 
)
virtualinherited

Create a user interface for controlling the properties of this Entity.

Called by SceneEditorWindow on selection.

Parameters
appMay be nullptr.

Reimplemented in G3D::Light, G3D::Camera, and G3D::VisibleEntity.

◆ markChanged()

void G3D::Entity::markChanged ( )
inlineinherited

Sets the lastChangeTime() to the current System::time()

◆ mass()

float G3D::Entity::mass ( ) const
inlineinherited

◆ name()

const String& G3D::Entity::name ( ) const
inlineinherited

Referenced by G3D::Light::spotTarget().

◆ onPose()

virtual void G3D::Entity::onPose ( Array< shared_ptr< class Surface > > &  surfaceArray)
virtualinherited

Pose as of the last simulation time.

Reimplemented in G3D::Light, G3D::Camera, G3D::ParticleSystem, and G3D::VisibleEntity.

◆ onSimulation()

virtual void G3D::SoundEntity::onSimulation ( SimTime  absoluteTime,
SimTime  deltaTime 
)
overridevirtual

Updates the AudioChannel::set3DAttributes.

Reimplemented from G3D::Entity.

◆ physicalSimulation()

bool G3D::Entity::physicalSimulation ( ) const
inlineinherited

◆ playSound()

virtual shared_ptr<SoundEntity> G3D::Entity::playSound ( const shared_ptr< Sound > &  sound,
const CFrame childFrame = CFrame(),
bool  attach = true 
)
virtualinherited

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.

◆ previousFrame()

const CoordinateFrame& G3D::Entity::previousFrame ( ) const
inlineinherited

◆ setCanCauseCollisions()

virtual void G3D::Entity::setCanCauseCollisions ( bool  c)
inlinevirtualinherited

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.

◆ setFrame()

virtual void G3D::Entity::setFrame ( const CFrame f,
bool  updatePreviousFrame = true 
)
virtualinherited

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.

◆ setFrameSpline()

virtual void G3D::Entity::setFrameSpline ( const PhysicsFrameSpline spline)
virtualinherited

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.

See also
setTrack

Used by SceneEditorWindow

◆ setMass()

virtual void G3D::Entity::setMass ( float  m)
inlinevirtualinherited

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).

◆ setPhysicalSimulation()

virtual void G3D::Entity::setPhysicalSimulation ( bool  s)
inlinevirtualinherited

If true, this object should receive physical simulation for its motion.

If true, canMove must also be true and there must be no Track on this Entity.

◆ setPreviousFrame()

virtual void G3D::Entity::setPreviousFrame ( const CFrame f)
inlinevirtualinherited

Explicitly override the previous frame value used for computing motion vectors.

This is very rarely needed because simulation automatically updates this value.

◆ setShouldBeSaved()

void G3D::Entity::setShouldBeSaved ( bool  b)
inlineinherited

◆ setTrack()

virtual void G3D::Entity::setTrack ( const shared_ptr< Track > &  c)
inlinevirtualinherited
See also
Entity::Track

◆ shouldBeSaved()

bool G3D::Entity::shouldBeSaved ( ) const
inlineinherited

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.

◆ sound()

const shared_ptr<Sound>& G3D::SoundEntity::sound ( ) const
inline
See also
audioChannel()

◆ toAny()

virtual Any G3D::SoundEntity::toAny ( const bool  forceAll = false) const
overridevirtual

Converts the current Entity to an Any.

Subclasses should modify at least the name of the Table, which will be "Entity" if not changed.

See also
shouldBeSaved

Reimplemented from G3D::Entity.

◆ track()

virtual shared_ptr<Track> G3D::Entity::track ( ) const
inlinevirtualinherited
See also
Entity::Track

◆ visualize()

virtual void G3D::SoundEntity::visualize ( RenderDevice rd,
bool  isSelected,
const class SceneVisualizationSettings s,
const shared_ptr< GFont > &  font,
const shared_ptr< Camera > &  camera 
)
overridevirtual

Called by Scene::visualize every frame.

During this, Entitys may make rendering calls according to the SceneVisualizationSettings to display control points and other features.

Parameters
isSelectedTrue if this entity is selected by a sceneEditorWindow, which may trigger additional visualization for it.

Reimplemented from G3D::Entity.

Member Data Documentation

◆ m_audioChannel

shared_ptr<AudioChannel> G3D::SoundEntity::m_audioChannel
protected

Referenced by audioChannel().

◆ m_canCauseCollisions

bool G3D::Entity::m_canCauseCollisions = false
protectedinherited

◆ m_canChange

bool G3D::Entity::m_canChange
protectedinherited

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 G3D::Entity::canChange().

◆ m_frame

CoordinateFrame G3D::Entity::m_frame
protectedinherited

Current position.

Do not directly mutate–invoke setFrame() to ensure that times are modified correctly.

Referenced by G3D::Light::distance(), G3D::Entity::frame(), G3D::Light::frame(), and G3D::Light::position().

◆ m_hadFirstSimulation

bool G3D::SoundEntity::m_hadFirstSimulation = false
protected

Playing is triggered only on the first onSimulation, so that the position and velocity are correct.

◆ m_lastAABoxBounds

AABox G3D::Entity::m_lastAABoxBounds
protectedinherited

Bounds at the last pose() call, in world space.

◆ m_lastBoundsTime

RealTime G3D::Entity::m_lastBoundsTime
protectedinherited

Time at which the bounds were computed.

◆ m_lastBoxBoundArray

Array<Box> G3D::Entity::m_lastBoxBoundArray
protectedinherited

Bounds on all of the surfaces from the last pose() call, in world space.

Referenced by G3D::Entity::lastBoxBoundArray().

◆ m_lastBoxBounds

Box G3D::Entity::m_lastBoxBounds
protectedinherited

Bounds at the last pose() call, in world space.

◆ m_lastChangeTime

RealTime G3D::Entity::m_lastChangeTime
protectedinherited

◆ m_lastObjectSpaceAABoxBounds

AABox G3D::Entity::m_lastObjectSpaceAABoxBounds
protectedinherited

Bounds at the last pose() call, in object space.

◆ m_lastSphereBounds

Sphere G3D::Entity::m_lastSphereBounds
protectedinherited

Bounds at the last pose() call, in world space.

◆ m_mass

float G3D::Entity::m_mass = 1
protectedinherited

◆ m_movedSinceLoad

bool G3D::Entity::m_movedSinceLoad
protectedinherited

True if the frame has changed since load.

Used by toAny() to decide if m_sourceAny is out of date.

◆ m_movedSinceSimulation

bool G3D::Entity::m_movedSinceSimulation = false
protectedinherited

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.

◆ m_name

String G3D::Entity::m_name
protectedinherited

Referenced by G3D::Entity::name().

◆ m_physicalSimulation

bool G3D::Entity::m_physicalSimulation = false
protectedinherited

◆ m_previousFrame

CoordinateFrame G3D::Entity::m_previousFrame
protectedinherited

Frame before onSimulation().

Used for tracking poses and for velocity estimation.

Referenced by G3D::Entity::previousFrame(), and G3D::Entity::setPreviousFrame().

◆ m_scene

Scene* G3D::Entity::m_scene
protectedinherited

◆ m_shouldBeSaved

bool G3D::Entity::m_shouldBeSaved
protectedinherited

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 G3D::Entity::setShouldBeSaved(), and G3D::Entity::shouldBeSaved().

◆ m_sound

shared_ptr<Sound> G3D::SoundEntity::m_sound
protected

Used when serializing.

Referenced by sound().

◆ m_sourceAny

Any G3D::Entity::m_sourceAny
protectedinherited

The Any from which this was originally constructed.

◆ m_track

shared_ptr<Track> G3D::Entity::m_track
protectedinherited

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 G3D::Entity::setTrack(), and G3D::Entity::track().


documentation generated on Wed Nov 24 2021 08:02:00 using doxygen 1.8.15