Slider

static Joint* Slider(float posx, float posy, float posz, float pinx, float piny, float pinz, Entity* child, Entity* parent=NULL)

Syntax

Parameters

Returns

Returns a new joint.

Example

#include "Leadwerks.h"

using namespace Leadwerks;

float jointpos = 1;
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);
parent->SetRotation(0, 0, 15);

Entity* child = Model::Box();
child->SetColor(1.0, 0.0, 0.0);
child->SetShape(Shape::Box());
child->SetMass(1);
child->SetGravityMode(true);
child->SetRotation(0, 0, 15);
child->Move(2, 0, 0);

joint = Joint::Slider(0, 0, 0, Math::Cos(15.0), Math::Sin(15.0), 0, child, parent);
joint->EnableLimits();
joint->SetLimits(-5, 1);
joint->EnableMotor();

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

if (window->KeyDown(Key::Up)) jointpos += 0.1;
if (window->KeyDown(Key::Down)) jointpos -= 0.1;

joint->SetAngle(jointpos);
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 position: " + String(jointpos), 0, 0);
context->DrawText("Current position: " + String(joint->GetAngle()), 0, 20);
context->DrawText("Motor enabled: " + String(joint->MotorEnabled()), 0, 40);
context->SetBlendMode(Blend::Solid);

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