|
|
@@ -27,11 +27,10 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|
|
#pragma once
|
|
|
|
|
|
#include "Types.h"
|
|
|
-#include "IdArray.h"
|
|
|
+#include "MathTypes.h"
|
|
|
#include "PhysicsTypes.h"
|
|
|
-#include "Vector3.h"
|
|
|
-#include "Matrix4x4.h"
|
|
|
-#include "Quaternion.h"
|
|
|
+#include "IdArray.h"
|
|
|
+#include "WorldTypes.h"
|
|
|
|
|
|
#include "PxPhysics.h"
|
|
|
#include "PxScene.h"
|
|
|
@@ -39,10 +38,6 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|
|
#include "PxCooking.h"
|
|
|
|
|
|
using physx::PxRigidActor;
|
|
|
-using physx::PxMaterial;
|
|
|
-using physx::PxScene;
|
|
|
-using physx::PxPhysics;
|
|
|
-using physx::PxCooking;
|
|
|
|
|
|
namespace crown
|
|
|
{
|
|
|
@@ -56,132 +51,131 @@ struct Matrix4x4;
|
|
|
struct Unit;
|
|
|
class SceneGraph;
|
|
|
|
|
|
+/// Represents a rigid body.
|
|
|
///
|
|
|
/// @ingroup Physics
|
|
|
struct Actor
|
|
|
{
|
|
|
- /// Constructor
|
|
|
- Actor(const PhysicsResource* res, const PhysicsConfigResource* config, uint32_t index, PxPhysics* physics, PxCooking* cooking,
|
|
|
- PxScene* scene, SceneGraph& sg, int32_t node, Unit* unit, const Vector3& pos, const Quaternion& rot);
|
|
|
- /// Destructor
|
|
|
- ~Actor();
|
|
|
+ Actor(PhysicsWorld& pw, const PhysicsResource* res, uint32_t actor_idx, SceneGraph& sg, int32_t node, UnitId unit_id);
|
|
|
+ ~Actor();
|
|
|
|
|
|
/// Makes the actor subject to gravity
|
|
|
- void enable_gravity();
|
|
|
+ void enable_gravity();
|
|
|
|
|
|
/// Makes the actor unsubject to gravity
|
|
|
- void disable_gravity();
|
|
|
+ void disable_gravity();
|
|
|
|
|
|
- void enable_collision();
|
|
|
- void disable_collision();
|
|
|
+ void enable_collision();
|
|
|
+ void disable_collision();
|
|
|
|
|
|
/// Makes the actor kinematic (keyframed)
|
|
|
/// @note
|
|
|
/// Works only for dynamic actors
|
|
|
- void set_kinematic();
|
|
|
+ void set_kinematic();
|
|
|
|
|
|
/// Makes the actor dynamic
|
|
|
/// @note
|
|
|
/// Works only for kinematic actors
|
|
|
- void clear_kinematic();
|
|
|
+ void clear_kinematic();
|
|
|
|
|
|
/// Moves the actor to @a pos
|
|
|
/// @note
|
|
|
/// Works only for kinematic actors
|
|
|
- void move(const Vector3& pos);
|
|
|
+ void move(const Vector3& pos);
|
|
|
|
|
|
/// Returns whether the actor is static (i.e. immovable).
|
|
|
- bool is_static() const;
|
|
|
+ bool is_static() const;
|
|
|
|
|
|
/// Returns whether the actor is dynamic (i.e. driven dy physics).
|
|
|
- bool is_dynamic() const;
|
|
|
+ bool is_dynamic() const;
|
|
|
|
|
|
/// Returns whether the actor is kinematic (i.e. driven by the user).
|
|
|
- bool is_kinematic() const;
|
|
|
+ bool is_kinematic() const;
|
|
|
|
|
|
/// Returns the rate at which rigid bodies dissipate linear momentum
|
|
|
- float linear_damping() const;
|
|
|
+ float linear_damping() const;
|
|
|
|
|
|
/// Sets the rate at which rigid bodies dissipate linear momentum
|
|
|
- void set_linear_damping(float rate);
|
|
|
+ void set_linear_damping(float rate);
|
|
|
|
|
|
/// Returns the rate at which rigid bodies dissipate angular momentum
|
|
|
- float angular_damping() const;
|
|
|
+ float angular_damping() const;
|
|
|
|
|
|
/// Sets the rate at which rigid bodies dissipate angular momentum
|
|
|
- void set_angular_damping(float rate);
|
|
|
-
|
|
|
+ void set_angular_damping(float rate);
|
|
|
+
|
|
|
/// Returns linear velocity of the actor
|
|
|
/// @note
|
|
|
/// If actor is sleeping, linear velocity must be 0
|
|
|
- Vector3 linear_velocity() const;
|
|
|
+ Vector3 linear_velocity() const;
|
|
|
|
|
|
/// Sets linear velocity of the actor
|
|
|
/// @note
|
|
|
/// If actor is sleeping, this will wake it up
|
|
|
- void set_linear_velocity(const Vector3& vel);
|
|
|
+ void set_linear_velocity(const Vector3& vel);
|
|
|
|
|
|
/// Returns angular velocity of the actor
|
|
|
/// @note
|
|
|
/// If actor is sleeping, angular velocity must be 0
|
|
|
- Vector3 angular_velocity() const;
|
|
|
+ Vector3 angular_velocity() const;
|
|
|
|
|
|
/// Sets angular velocity of the actor
|
|
|
/// @note
|
|
|
/// If actor is sleeping, this will wake it up
|
|
|
- void set_angular_velocity(const Vector3& vel);
|
|
|
+ void set_angular_velocity(const Vector3& vel);
|
|
|
|
|
|
/// Applies a force (or impulse) defined in the global coordinate frame, acting at a particular point in global coordinates, to the actor.
|
|
|
/// @note
|
|
|
/// If the force does not act along the center of mass of the actor, this will also add the corresponding torque.
|
|
|
/// Because forces are reset at the end of every timestep, you can maintain a total external force on an object by calling this once every frame.
|
|
|
- void add_impulse(const Vector3& impulse);
|
|
|
+ void add_impulse(const Vector3& impulse);
|
|
|
|
|
|
/// Applies a force (or impulse) defined in the global coordinate frame, acting at a particular point in local coordinates, to the actor.
|
|
|
/// @note
|
|
|
/// If the force does not act along the center of mass of the actor, this will also add the corresponding torque.
|
|
|
/// Because forces are reset at the end of every timestep, you can maintain a total external force on an object by calling this once every frame.
|
|
|
- void add_impulse_at(const Vector3& impulse, const Vector3& pos);
|
|
|
+ void add_impulse_at(const Vector3& impulse, const Vector3& pos);
|
|
|
|
|
|
/// Applies a force, evaluated by actor's @a mass and @a velocity that will be achieved, to the actor
|
|
|
- void push(const Vector3& vel, const float mass);
|
|
|
+ void push(const Vector3& vel, const float mass);
|
|
|
|
|
|
/// Returns true if tha actor is sleeping, false otherwise
|
|
|
- bool is_sleeping();
|
|
|
+ bool is_sleeping();
|
|
|
|
|
|
/// Forces the actor to wake up
|
|
|
- void wake_up();
|
|
|
+ void wake_up();
|
|
|
|
|
|
/// Returns actor's name
|
|
|
- StringId32 name();
|
|
|
+ StringId32 name();
|
|
|
|
|
|
- /// Returns the unit that owns this actor
|
|
|
- Unit* unit();
|
|
|
+ /// Returns the unit that owns the actor.
|
|
|
+ Unit* unit();
|
|
|
+
|
|
|
+ const PhysicsResource* resource() const { return m_resource; }
|
|
|
|
|
|
private:
|
|
|
|
|
|
- void update(const Matrix4x4& pose);
|
|
|
- void create_shapes(const PhysicsResource* res, const PhysicsConfigResource* config, PxPhysics* physics, PxCooking* cooking);
|
|
|
- Matrix4x4 get_kinematic_pose() const;
|
|
|
+ void create_objects();
|
|
|
+ void destroy_objects();
|
|
|
+
|
|
|
+ void update(const Matrix4x4& pose);
|
|
|
+ Matrix4x4 get_kinematic_pose() const;
|
|
|
|
|
|
public:
|
|
|
|
|
|
- const PhysicsResource* m_resource;
|
|
|
- const PhysicsConfigResource* m_config;
|
|
|
- uint32_t m_index;
|
|
|
+ PhysicsWorld& m_world;
|
|
|
+ const PhysicsResource* m_resource;
|
|
|
+ uint32_t m_index;
|
|
|
+ PxRigidActor* m_actor;
|
|
|
|
|
|
- Unit* m_unit;
|
|
|
+ SceneGraph& m_scene_graph;
|
|
|
+ int32_t m_node;
|
|
|
|
|
|
- PxScene* m_scene;
|
|
|
- SceneGraph& m_scene_graph;
|
|
|
- int32_t m_node;
|
|
|
- PxRigidActor* m_actor;
|
|
|
- uint32_t m_group;
|
|
|
- uint32_t m_mask;
|
|
|
+ UnitId m_unit;
|
|
|
|
|
|
private:
|
|
|
|
|
|
friend class PhysicsWorld;
|
|
|
};
|
|
|
|
|
|
-} // namespace crown
|
|
|
+} // namespace crown
|