-
Notifications
You must be signed in to change notification settings - Fork 0
physics::rigidbody
Paweł Waligóra edited this page May 4, 2024
·
12 revisions
signature: physics::rigidbody
files: rigidbody.h, rigidbody.cpp
namespace physics {
class rigidbody {
public:
bool dynamic = true;
glm::vec3 position = glm::vec3(0.0f);
glm::quat rotation = glm::quat(glm::vec3(0, 0, 0));
float mass = 10.0f; // [kg]
float moment_of_inertia = 10.0f; // [kg*m^2]
glm::vec3 velocity = glm::vec3(0.0f); // [m/s]
glm::quat angular_speed = glm::quat(glm::vec3(0, 0, 0));
glm::vec3 force = glm::vec3(0.0f); // [N]
glm::vec3 torque = glm::vec3(0.0f);
void update();
};
}
Called exactly once per frame in every frame by physics system.
Just declare member of type phyics::rigidbody
in your script. You can read and write to it's position, rotation, velocity, angular velocity, force and torque by accessing rigidbody members directly. Rigidbodies update automatically - no additional work needed.
In order for rigidbody to collide with other rigidbodies you will need to add a physics::collider as well.
#include "rigidbody.h"
#include "physics.h" // physics::gravity
// (btw. physics.h includes rigidbody.h, so first line not necessary)
namespace game {
class my_script {
private:
physics::rigidbody rb;
public:
void start() override;
void update() override;
};
}
game::my_script::start() {
rb.mass = 20.0f; // kg
rb.force = physics::gravity * rb.mass;
}
game::my_script::update() {
printf("%f, %f, %f\n", rb.position.x, rb.position.y, rb.position.z);
}
- engine
- scripts_system
- scene_loader
- time_system
-
input_system
- input_system::key_held
- input_system::key_events
- input_system::subscribe() (deprecated)
- input_system::axis_state()
- input_system::key_bind
- input_system::axis
- input_system::double_axis
- input_system::triple_axis
- input_system::axis2
- input_system::double_axis2
- input_system::triple_axis2
- input_system::axis-choice
- renderer
- physics
- ui_system
- game