Fx2D
A C++20 2D rigid-body physics engine
Loading...
Searching...
No Matches
FxScene Class Reference

Owns a simulated world and advances it with step(). More...

#include <Scene.h>

+ Collaboration diagram for FxScene:

Public Member Functions

 FxScene (FxVec2ui SceneSize)
 
 ~FxScene ()=default
 
void reset ()
 
void capture_initial_state ()
 
void step (double step_dt)
 
double time_elapsed () const
 
void set_substeps (const size_t &substeps)
 
void set_velocity_passes (size_t passes)
 
void set_gravity (const FxVec2f &o_gravity)
 
void set_step_callback (const std::function< void(FxScene &, double dt)> &callback)
 
void set_reset_callback (const std::function< void(FxScene &)> &callback)
 
void set_fillColor (const FxVec4ui8 &color)
 
void set_fillTexture (const std::string &filePath)
 
bool add_entity (const std::shared_ptr< FxEntity > &entity)
 
bool delete_entity (const std::string &name)
 
std::shared_ptr< FxEntity > get_entity (const std::string &name) const
 
bool add_constraint (const std::shared_ptr< FxConstraint > &constraint)
 
bool delete_constraint (const std::string &name)
 
std::shared_ptr< FxConstraint > get_constraint (const std::string &name) const
 
bool add_joint (const std::shared_ptr< FxJoint > &joint)
 
bool delete_joint (const std::string &name)
 
std::shared_ptr< FxJoint > get_joint (const std::string &name) const
 
const FxInput & input () const
 
FxInput & input ()
 
FxMouseJoint & mouse_joint ()
 
const FxMouseJoint & mouse_joint () const
 
void enable_mouse_drag (bool enable)
 
bool mouse_drag_enabled () const
 
const std::vector< FxContact > & contacts () const
 
const std::vector< FxContactEvent > & begin_contact_events () const
 
const std::vector< FxContactEvent > & end_contact_events () const
 
bool raycast (const FxVec2f &origin, const FxVec2f &direction, float max_distance, FxRayHit &out_hit) const
 
void raycast_all (const FxVec2f &origin, const FxVec2f &direction, float max_distance, std::vector< FxRayHit > &out_hits) const
 
void overlap_shape (const FxShape &shape, const FxVec3f &pose, std::vector< std::shared_ptr< FxEntity > > &out) const
 
void overlap_circle (const FxVec2f &centre, float radius, std::vector< std::shared_ptr< FxEntity > > &out) const
 
void overlap_box (const FxVec2f &centre, const FxVec2f &extents, std::vector< std::shared_ptr< FxEntity > > &out) const
 
void overlap_point (const FxVec2f &point, std::vector< std::shared_ptr< FxEntity > > &out) const
 
std::shared_ptr< FxEntity > entity_at_point (const FxVec2f &point) const
 
size_t entity_count () const
 
size_t constraint_count () const
 
size_t joint_count () const
 
bool entity_exists (const std::string &name) const
 
bool constraint_exists (const std::string &name) const
 
bool joint_exists (const std::string &name) const
 
std::shared_ptr< FxEntityGroup > create_group (const std::string &name, bool self_collide=false)
 
bool add_to_group (const std::shared_ptr< FxEntityGroup > &group, const std::shared_ptr< FxEntity > &entity)
 
std::shared_ptr< FxEntityGroup > get_group (const std::string &name) const
 
bool delete_group (const std::string &name)
 
size_t group_count () const
 
std::string unique_entity_name (const std::string &base) const
 
void enable_collision (const std::string &entity1_name, const std::string &entity2_name)
 
void disable_collision (const std::string &entity1_name, const std::string &entity2_name)
 
template<typename ExecPolicy , typename Func >
void for_each_entity (ExecPolicy &&policy, Func &&func)
 
template<typename ExecPolicy , typename Func >
void transform_entities (ExecPolicy &&policy, Func &&func, std::vector< std::invoke_result_t< Func, std::shared_ptr< FxEntity > > > &results)
 

Public Attributes

const FxVec2ui size
 
FxVec4ui8 fillColor {230, 230, 230, 255}
 
std::string fillTexturePath = ""
 
FxVec2f gravity {0.0f, -9.81f}
 

Protected Member Functions

void drive_mouse_joint ()
 

Protected Attributes

FxEntityRegistry m_entities
 
FxNamedRegistry< FxConstraint > m_constraints
 
FxNamedRegistry< FxEntityGroup > m_groups
 
FxNamedRegistry< FxJoint > m_joints
 
FxMouseJoint m_mouse_joint
 
bool m_mouse_drag = false
 

Detailed Description

Owns a simulated world and advances it with step().

Definition at line 56 of file Scene.h.

Constructor & Destructor Documentation

◆ FxScene()

FxScene::FxScene ( FxVec2ui  SceneSize)
inline

Definition at line 177 of file Scene.h.

◆ ~FxScene()

FxScene::~FxScene ( )
default

Member Function Documentation

◆ add_constraint()

bool FxScene::add_constraint ( const std::shared_ptr< FxConstraint > &  constraint)

◆ add_entity()

bool FxScene::add_entity ( const std::shared_ptr< FxEntity > &  entity)

◆ add_joint()

bool FxScene::add_joint ( const std::shared_ptr< FxJoint > &  joint)

◆ add_to_group()

bool FxScene::add_to_group ( const std::shared_ptr< FxEntityGroup > &  group,
const std::shared_ptr< FxEntity > &  entity 
)

◆ begin_contact_events()

const std::vector< FxContactEvent > & FxScene::begin_contact_events ( ) const
inline

Definition at line 249 of file Scene.h.

◆ capture_initial_state()

void FxScene::capture_initial_state ( )

◆ constraint_count()

size_t FxScene::constraint_count ( ) const
inline

Definition at line 279 of file Scene.h.

◆ constraint_exists()

bool FxScene::constraint_exists ( const std::string &  name) const
inline

Definition at line 284 of file Scene.h.

◆ contacts()

const std::vector< FxContact > & FxScene::contacts ( ) const
inline

Definition at line 247 of file Scene.h.

◆ create_group()

std::shared_ptr< FxEntityGroup > FxScene::create_group ( const std::string &  name,
bool  self_collide = false 
)

◆ delete_constraint()

bool FxScene::delete_constraint ( const std::string &  name)

◆ delete_entity()

bool FxScene::delete_entity ( const std::string &  name)

◆ delete_group()

bool FxScene::delete_group ( const std::string &  name)

◆ delete_joint()

bool FxScene::delete_joint ( const std::string &  name)

◆ disable_collision()

void FxScene::disable_collision ( const std::string &  entity1_name,
const std::string &  entity2_name 
)
inline

Definition at line 313 of file Scene.h.

◆ drive_mouse_joint()

void FxScene::drive_mouse_joint ( )
protected

◆ enable_collision()

void FxScene::enable_collision ( const std::string &  entity1_name,
const std::string &  entity2_name 
)
inline

Definition at line 310 of file Scene.h.

◆ enable_mouse_drag()

void FxScene::enable_mouse_drag ( bool  enable)
inline

Definition at line 242 of file Scene.h.

◆ end_contact_events()

const std::vector< FxContactEvent > & FxScene::end_contact_events ( ) const
inline

Definition at line 251 of file Scene.h.

◆ entity_at_point()

std::shared_ptr< FxEntity > FxScene::entity_at_point ( const FxVec2f &  point) const

◆ entity_count()

size_t FxScene::entity_count ( ) const
inline

Definition at line 278 of file Scene.h.

◆ entity_exists()

bool FxScene::entity_exists ( const std::string &  name) const
inline

Definition at line 281 of file Scene.h.

◆ for_each_entity()

template<typename ExecPolicy , typename Func >
void FxScene::for_each_entity ( ExecPolicy &&  policy,
Func &&  func 
)
inline

Definition at line 319 of file Scene.h.

◆ get_constraint()

std::shared_ptr< FxConstraint > FxScene::get_constraint ( const std::string &  name) const

◆ get_entity()

std::shared_ptr< FxEntity > FxScene::get_entity ( const std::string &  name) const

◆ get_group()

std::shared_ptr< FxEntityGroup > FxScene::get_group ( const std::string &  name) const
inline

Definition at line 298 of file Scene.h.

◆ get_joint()

std::shared_ptr< FxJoint > FxScene::get_joint ( const std::string &  name) const

◆ group_count()

size_t FxScene::group_count ( ) const
inline

Definition at line 303 of file Scene.h.

◆ input() [1/2]

FxInput & FxScene::input ( )
inline

Definition at line 234 of file Scene.h.

◆ input() [2/2]

const FxInput & FxScene::input ( ) const
inline

Definition at line 233 of file Scene.h.

◆ joint_count()

size_t FxScene::joint_count ( ) const
inline

Definition at line 280 of file Scene.h.

◆ joint_exists()

bool FxScene::joint_exists ( const std::string &  name) const
inline

Definition at line 287 of file Scene.h.

◆ mouse_drag_enabled()

bool FxScene::mouse_drag_enabled ( ) const
inline

Definition at line 243 of file Scene.h.

◆ mouse_joint() [1/2]

FxMouseJoint & FxScene::mouse_joint ( )
inline

Definition at line 240 of file Scene.h.

◆ mouse_joint() [2/2]

const FxMouseJoint & FxScene::mouse_joint ( ) const
inline

Definition at line 241 of file Scene.h.

◆ overlap_box()

void FxScene::overlap_box ( const FxVec2f &  centre,
const FxVec2f &  extents,
std::vector< std::shared_ptr< FxEntity > > &  out 
) const

◆ overlap_circle()

void FxScene::overlap_circle ( const FxVec2f &  centre,
float  radius,
std::vector< std::shared_ptr< FxEntity > > &  out 
) const

◆ overlap_point()

void FxScene::overlap_point ( const FxVec2f &  point,
std::vector< std::shared_ptr< FxEntity > > &  out 
) const

◆ overlap_shape()

void FxScene::overlap_shape ( const FxShape &  shape,
const FxVec3f &  pose,
std::vector< std::shared_ptr< FxEntity > > &  out 
) const

◆ raycast()

bool FxScene::raycast ( const FxVec2f &  origin,
const FxVec2f &  direction,
float  max_distance,
FxRayHit &  out_hit 
) const

◆ raycast_all()

void FxScene::raycast_all ( const FxVec2f &  origin,
const FxVec2f &  direction,
float  max_distance,
std::vector< FxRayHit > &  out_hits 
) const

◆ reset()

void FxScene::reset ( )

◆ set_fillColor()

void FxScene::set_fillColor ( const FxVec4ui8 &  color)
inline

Definition at line 204 of file Scene.h.

◆ set_fillTexture()

void FxScene::set_fillTexture ( const std::string &  filePath)
inline

Definition at line 208 of file Scene.h.

◆ set_gravity()

void FxScene::set_gravity ( const FxVec2f &  o_gravity)
inline

Definition at line 193 of file Scene.h.

◆ set_reset_callback()

void FxScene::set_reset_callback ( const std::function< void(FxScene &)> &  callback)
inline

Definition at line 200 of file Scene.h.

◆ set_step_callback()

void FxScene::set_step_callback ( const std::function< void(FxScene &, double dt)> &  callback)
inline

Definition at line 195 of file Scene.h.

◆ set_substeps()

void FxScene::set_substeps ( const size_t &  substeps)
inline

Definition at line 190 of file Scene.h.

◆ set_velocity_passes()

void FxScene::set_velocity_passes ( size_t  passes)
inline

Definition at line 192 of file Scene.h.

◆ step()

void FxScene::step ( double  step_dt)

◆ time_elapsed()

double FxScene::time_elapsed ( ) const
inline

Definition at line 189 of file Scene.h.

◆ transform_entities()

template<typename ExecPolicy , typename Func >
void FxScene::transform_entities ( ExecPolicy &&  policy,
Func &&  func,
std::vector< std::invoke_result_t< Func, std::shared_ptr< FxEntity > > > &  results 
)
inline

Definition at line 325 of file Scene.h.

◆ unique_entity_name()

std::string FxScene::unique_entity_name ( const std::string &  base) const
inline

Definition at line 305 of file Scene.h.

Member Data Documentation

◆ fillColor

FxVec4ui8 FxScene::fillColor {230, 230, 230, 255}

Definition at line 171 of file Scene.h.

◆ fillTexturePath

std::string FxScene::fillTexturePath = ""

Definition at line 172 of file Scene.h.

◆ gravity

FxVec2f FxScene::gravity {0.0f, -9.81f}

Definition at line 174 of file Scene.h.

◆ m_constraints

FxNamedRegistry<FxConstraint> FxScene::m_constraints
protected

Definition at line 159 of file Scene.h.

◆ m_entities

FxEntityRegistry FxScene::m_entities
protected

Definition at line 158 of file Scene.h.

◆ m_groups

FxNamedRegistry<FxEntityGroup> FxScene::m_groups
protected

Definition at line 160 of file Scene.h.

◆ m_joints

FxNamedRegistry<FxJoint> FxScene::m_joints
protected

Definition at line 161 of file Scene.h.

◆ m_mouse_drag

bool FxScene::m_mouse_drag = false
protected

Definition at line 163 of file Scene.h.

◆ m_mouse_joint

FxMouseJoint FxScene::m_mouse_joint
protected

Definition at line 162 of file Scene.h.

◆ size

const FxVec2ui FxScene::size

Definition at line 169 of file Scene.h.


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