Jump to content

SpiderPig

Members
  • Posts

    2,306
  • Joined

  • Last visited

Everything posted by SpiderPig

  1. I thought it might. Worth the check though. I'll do the former!
  2. Would something like this be possible? Or is there too much going on behind the scene? Entity::SetWorld(my_2nd_world)
  3. Just wondering if you've had a chance to look at this yet? None of my projects work at the moment.
  4. Thankyou the example now works. However there is a new issue - it appears if you set a collider to nullptr when the mass is zero the program will crash. Comment out this line and it will crash. // box->SetMass(1.0f);
  5. 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; }
  6. 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.
  7. Now that this works - should it be that physics bodies in two separate worlds can still collide? Or is it up to the user to disable those collisions themselves?
  8. Gravity is cool I wonder if the jitter of the boxes is because the sphere is too small for there to be a flat enough face to rest on.
  9. Yes that should work well. I disable world gravity and use AddForce() in a loop elsewhere for now, it works but overwriting the default world gravity would be much cleaner.
  10. I got this to work. I'm pleased with the result. I also (finally) got a custom player controller working with different gravity directions. https://youtu.be/XUKbSHf3e6k
  11. The code below gives 3 different error messages (if you press ignore each time). Here's the first one; 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; }
  12. Debug and Release are working okay for me. Did you try a clean install?
  13. 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);
  14. Can a raw pointer be cast to a shared_ptr? There was just a few things I wanted to create inside component and had to pass the owner entity. I'm sure I'll find another way though so it's no problem.
  15. 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();
  16. I'd like to be able to get the current max force and max torque of a joint.
  17. 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; }
  18. That argument seems commented out at the moment.
  19. On second thought I think it'll introduce too many complications.
  20. 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.
  21. 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.
  22. I think it'll also be needed for moving and turning entities...
  23. Yeah I just noticed things were colliding above my offset collider. Would be nice to see it.
×
×
  • Create New...