Jump to content

Joint MaxForce() Not Resetting


SpiderPig
 Share

Go to solution Solved by Josh,

Recommended Posts

Using a kinematic joint, if max force is initially 0 I can set it to a higher value at any point in the program by pressing the space bar.  How ever if I set maxtorque initially as well, it seems maxforce can't be set to anything other than it's initial value.

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    auto framebuffer = CreateFramebuffer(window);
    auto world = CreateWorld();

    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 0, -5);

    auto light = CreateBoxLight(world);
    light->SetRotation(35, 35, 0);
    light->SetRange(-20, 20);

    auto box = CreateBox(world);
    box->SetMass(1);
    box->SetColor(0, 1, 0);

    auto floor = CreateBox(world, 10, .1, 10);
    floor->SetPosition(0, -2, 0);

    auto joint = CreateKinematicJoint(box->position, box);
    joint->SetMaxForce(0.0f);
    joint->SetMaxTorque(100.0f);//Force won't set to 100 at press of spacebar if this line is used

    //Main loop
    float a = 0, y = 0;
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->KeyHit(KEY_SPACE)) { joint->SetMaxForce(100); }//won't set if SetMaxTorque has been used

        if (window->KeyDown(KEY_RIGHT)) a -= 2;
        if (window->KeyDown(KEY_LEFT)) a += 2;
        if (window->KeyDown(KEY_UP)) y += 0.1;
        if (window->KeyDown(KEY_DOWN)) y -= 0.1;

        joint->SetPose(Vec3(0, y, 0), Vec3(0, 0, a));

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

  • Josh locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...