SetMass
Sets an entity's mass.
Syntax
- void SetMass(const float mass)
- void SetMass(const float mass, const float cx, const float cy, const float cz, const float ixx, const float iyy, const float izz)
Parameters
- mass: the mass to set. When an entity is created, its mass is 0.0.
- cx: center of mass x position.
- cy: center of mass y position.
- cz: center of mass z position.
- ixx: center of mass x position.
- iyy: center of mass y position.
- izz: center of mass z position.
Remarks
Entities with zero mass will still collide with other objects, but will be unmovable and unresponsive to physical forces.
If the mass matrix is not specified then the center of mass and moment of inertia will be automatically calculated. The second function overload can be used to specify the mass matrix for fine control of the object's behavior.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Entity* entity = NULL;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->SetRotation(35, 0, 0);
camera->Move(0, 0, -6);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
//Create the ground
Model* ground = Model::Box(10, 1, 10);
ground->SetPosition(0, 0, -0.5);
ground->SetColor(0.0, 1.0, 0.0);
//Create a shape
Shape* shape = Shape::Box(0, 0, 0, 0, 0, 0, 10, 1, 10);
ground->SetShape(shape);
shape->Release();
//Create a model
entity = Model::Box();
entity->SetColor(0.0, 0.0, 1.0);
entity->SetPosition(0, 3, 0);
entity->SetMass(1);
//Create a shape
shape = Shape::Box();
entity->SetShape(shape);
shape->Release();
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Time::Update();
world->Update();
world->Render();
context->SetBlendMode(Blend::Alpha);
context->DrawText("Mass: " + String(entity->GetMass()), 2, 2);
context->Sync();
}
return 0;
}