Jump to content
  • 1
Lethal Raptor Games

Moveing a Sliders parent

Question

#include "App.h"

using namespace Leadwerks;

App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}

App::~App() { delete world; delete window; }

float jointpos = 1;
bool wireframe = false;
Joint* joint;
Entity* parent;

bool App::Start()
{
	window = Leadwerks::Window::Create();
	context = Context::Create(window);
	world = World::Create();
	camera = Camera::Create();
	camera->Move(0, 0, -4);
	Light* light = DirectionalLight::Create();
	light->SetRotation(35, 35, 0);

	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->SetFriction(0, 0);
	child->SetGravityMode(true);

	joint = Joint::Slider(0, 0, 0, 0, 1, 0, child, parent);
	joint->EnableLimits();
	joint->SetLimits(-3, 1);

	Model* mdl = Model::Box();
	mdl->SetScale(10, 0.1, 10);
	mdl->SetPosition(0, -2, 0);

	Shape* shp = Shape::Box();
	mdl->SetShape(shp);

	return true;
}

bool App::Loop()
{
	if (window->Closed() || window->KeyDown(Key::Escape)) return false;
	if (window->KeyHit(Key::F3) == true) { camera->GetDebugPhysicsMode() == true ? camera->SetDebugPhysicsMode(false) : camera->SetDebugPhysicsMode(true); }
	if (window->KeyHit(Key::F4) == true) { camera->GetDebugEntityBoxesMode() == true ? camera->SetDebugEntityBoxesMode(false) : camera->SetDebugEntityBoxesMode(true); }
	if (window->KeyHit(Key::F2) == true)
	{
		if (wireframe == true)
		{
			camera->SetDrawMode(0);
			wireframe = false;
		}
		else
		{
			camera->SetDrawMode(2);
			wireframe = true;
		}
	}

	if (window->KeyDown(Key::Up)) { parent->Move(0, 0, 0.1); }
	if (window->KeyDown(Key::Down)) { parent->Move(0, 0, -0.1); }
	if (window->KeyDown(Key::Left)) { parent->Move(-0.1, 0, 0); }
	if (window->KeyDown(Key::Right)) { parent->Move(0.1, 0, 0); }

	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 true;
}

Using the arrows keys to move the sliders parent around you can see that the child takes time to realign itself.  Is it possible to stop this delay?

Share this post


Link to post

5 answers to this question

Recommended Posts

  • 1

Do I get the trophy marked? I answered the question! 😋

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...