Jump to content

Slider joints and local rotation


AggrorJorn
 Share

Recommended Posts

I have slider joints successfully working but I am left with a problem. Right now my object can move beautifully across the x axis. But now lets say that both the parent (a pivot) and the child (a box) are rotated 30 degrees. The code for the joint is this:

slidingDoorJoint = Joint::Slider(0,0,0, 1,0,0, slidingDoor,slidingDoorPivot

But what if I my object is rotated 30 degrees? I tried setting the rotation of the joint itself but that doesn't work.

 

try it yourself:

 

#include "App.h"
using namespace Leadwerks;App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}
App::~App() { delete world; delete window; }//sliding Door
Pivot* slidingDoorPivot;
Model* slidingDoor;
Joint* slidingDoorJoint;
bool App::Start()
{
   //Create a window
   window = Window::Create("_12_Joints");//Create a context
   context = Context::Create(window);

   //Create a world
   world = World::Create();//Create a camera
   camera = Camera::Create();
   camera->Move(0, 1, -4);
   camera->SetRotation(0,0,0);
   Light* light = DirectionalLight::Create();
   light->SetRotation(45,45,0);

   //Sliding door
   Shape* slideDoorShape = Shape::Box(0,0,0 ,0,0,0, 2,4,0.2);
   slidingDoorPivot = Pivot::Create();
   slidingDoorPivot->SetPosition(-2,0,0);
   slidingDoorPivot->SetRotation(0,30,0);

   slidingDoor = Model::Box(2,4,0.2);
   slidingDoor->SetShape(slideDoorShape);
   slidingDoor->SetMass(1);
   slidingDoor->SetPosition(-2,0,0);
   slidingDoor->SetRotation(0,30,0);
   slidingDoorJoint = Joint::Slider(0,0,0, 1,0,0, slidingDoor,slidingDoorPivot,-2, 2);
   slideDoorShape->Release();return true;
}
bool App::Loop()
{
   //Close the window to end the program
   if (window->Closed()) return false;

   float sliderForce = window->KeyDown(Key::E) - window->KeyDown(Key::Q);
   slidingDoor->AddForce(sliderForce* Time::GetSpeed() * 2,0,0);

   Time::Update();
   world->Update();
   world->Render();
   context->Sync(false);return true;
}

Link to comment
Share on other sites

Oh, I've been using newton for too long, I'm so used to using the custom 6DOF joint that I totally forget that the normal joints need parents.

 

But in Newton 2 (I know Newton 3 is out, but I'm still using 2), even if you do create a joint with a parent, you can call NewtonBodySetMatrixRecursive (which sounds like the SetMatrix function in Leadwerks with the recursive flag set to true) on the 'parent', and it will move all children too, and rotates all the joint pins on the parent to match.

 

I don't know if Leadwerks allows this or not, or if you have to call EntityParent first - or whatever that function is called in the new version, so that the door is parented to the pivot.

 

But in my mind though, I'm still sure that moving and rotating only the pivot (the parent), after they have been joined together is the way you're supposed to do it. That's certainly how you do it in Newton 2.

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

  • 2 weeks later...

I don't know what else to try here. I made a lot of different combinations but it just doesn't work

 

 

 slidingDoorJoint->SetRotation(0,30,0);
 slidingDoorPivot->SetRotation(0,30,0);
 slidingDoorJoint->SetRotation(0,30,0, 1);
 slidingDoorPivot->SetRotation(0,30,0, 0);
 slidingDoorJoint->SetRotation(0,30,0, 0);
 slidingDoorPivot->SetRotation(0,30,0, 1);
 slidingDoor->SetRotation(0,30,0, 1);
 slidingDoor->SetRotation(0,30,0, 0);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   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.

 Share

×
×
  • Create New...