Hinge

This function creates a new hinge joint.

Syntax

Parameters

Example

#include "Leadwerks.h"

using namespace Leadwerks;

float angle = 25;
Joint* joint;

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->Move(0, 0, -4);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);

Entity* parent = Model::Box();
parent->SetColor(0.0, 0.0, 1.0);

Entity* child = Model::Box();
child->SetColor(1.0, 0.0, 0.0);
child->SetShape(Shape::Box());
child->SetMass(1);
child->SetPosition(2, 0, 0);

joint = Joint::Hinge(0, 0, 0, 0, 0, 1, child, parent);
joint->EnableLimits();
joint->SetLimits(-45, 45);
joint->EnableMotor();

while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;

if (window->KeyDown(Key::Up)) angle += 1.0;
if (window->KeyDown(Key::Down)) angle -= 1.0;
joint->SetAngle(angle);
if (window->KeyHit(Key::Space))
{
if (!joint->MotorEnabled())
{
joint->EnableMotor();
}
else
{
joint->DisableMotor();
}
}

Leadwerks::Time::Update();
world->Update();
world->Render();

context->SetBlendMode(Blend::Alpha);
context->DrawText("Target angle: " + String(angle), 0, 0);
context->DrawText("Current angle: " + String(joint->GetAngle()), 0, 20);
context->DrawText("Motor enabled: " + String(joint->MotorEnabled()), 0, 40);
context->SetBlendMode(Blend::Solid);

context->Sync();
}
return 0;
}