Jump to content

SpiderPig

Members
  • Posts

    2,423
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. Not sure if this is a bug or not a good way to use the physics engine ;)

    The box will still collide with the floor if you store it's collider elsewhere and set the boxes collider to nullptr.  Are colliders unique to the object they are applied too?

    #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();
        world->SetGravity(0.0f, -2.0f, 0.0f);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetPosition(0, 0, -8);
        camera->SetDebugPhysicsMode(true);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 0);
    
        auto box = CreateBox(world);
        box->SetMass(1.0f);
        box->SetColor(0, 1, 0);
    
        auto store = box->GetCollider();
        box->SetCollider(nullptr);//Will still collide...
    
        auto floor = CreateBox(world, 10, .1, 10);
        floor->SetPosition(0, -2, 0);
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  2. Never mind.  Physics objects in two separate worlds don't collide at all.  It turns out that the code I was using to transfer a collider from an entity to a pivot was flawed.

    auto box = CreateBox(worldA);
    
    //Transfer Collider to 2nd world
    auto pivot = CreatePivot(worldB);
    pivot->SetCollider(box->GetCollider());
    
    box->SetCollider(nullptr);

    It seems that if I set an entities collider to another object and then remove that collider from the original entity, although the collider is no longer visible when debugging physics, that box still collides.  :huh:

  3. The code below gives 3 different error messages (if you press ignore each time).  Here's the first one;

    KinematicJointError_001.jpg.2a4fc9a3c81a1be8691b50936f1a3523.jpg

    Only get the errors in debug mode.  In release mode the object is shot away at speed.

    #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, -8);
        camera->SetDebugPhysicsMode(true);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 0);
    
        auto box = CreateCylinder(world, 0.5f, 1.8f);
        box->SetMass(1.0f);
        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(100);
        joint->SetMaxTorque(100);
    
        auto pivot = CreatePivot(nullptr);
        
        float a = 0, y = 0;
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            pivot->AlignToVector(Vec3(0, 0, -1));
            auto quat = pivot->GetQuaternion();
    
            joint->SetPose(Vec3(0, y, 0),  quat);
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  4. Currently I'm doing this;

    if (pivot == nullptr) { pivot = CreatePivot(nullptr); }
    pivot->AlignToVector(vector, 1);
    
    joint->SetPose(pos, pivot->GetQuaternion());

    But I'm wondering if it makes more sense to be able to do this instead;

    auto quat = Quat();
    quat.AlignToVector(vector);
    
    OR
    
    auto rot = Vec3();
    rot.AlignToVector(vector);

     

  5. Is there a reason the only accessible reference to a components entity is a raw pointer?

    		std::weak_ptr<Entity> entityptr;  //<-- not accessable?
    		std::map<WString, std::vector<Connection> > connections;
    		friend CComponent;
    
    	protected:
    		virtual void ReceiveSignal(shared_ptr<Component> sender, const WString& input, std::vector<std::any> arguments);
    		Entity* entity;//<-- Use this one?
    		virtual void Start();
    		virtual void Update();

     

  6. 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;
    }

     

  7. This is what I'm doing to transform the objects.

    void UpdatePhysics(shared_ptr<Entity> source, shared_ptr<Entity> target, shared_ptr<Entity> platform = nullptr) {
        auto pos = source->GetPosition();
        auto rot = source->GetRotation();
    
        if (platform != nullptr) {
            auto matrix = platform->GetMatrix();
            matrix = matrix.Inverse();
            matrix.t = Vec4(0, 0, 0, 1);
    
            pos = TransformPoint(pos, Mat4(), matrix);
            rot = TransformRotation(rot, Mat4(), matrix);
        }
    
        target->SetPosition(pos);
        target->SetRotation(rot);
    }

    This may yet not work for all cases, but I wonder if a simple callback system between the physics thread and the rendered world could do this?  Basically it would mean we could offset the rendered object away from it's collider.  Just thinking out loud. :)

  8. Got it working with the player controller.  I'm going to expand on this and make a complex level with a lot going on to see if it holds up.  You can see in the animation that the physics objects don't rotate and none of the rendered objects have colliders.  It's just a matter of getting the physics matrix's and transforming them based on what platform is moving.

    ParentedPhysicsObject_003.gif.1f40aa464c6d8112dce93aaedd50917c.gif

×
×
  • Create New...