Jump to content

SpiderPig

Members
  • Posts

    2,347
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. I'm getting a popup error when writing the pixels of a non-square pixmap.  This program crashes when x = 8 and y = 0.  I assume its just testing the x value against the y size.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1440, 900, displays[0]);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        auto camera = CreateCamera(world);
        camera->Move(0, 2, -3);
        camera->SetClearColor(1, 0, 0);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 35);
    
        auto floor = CreateBox(world, 100.0f, 0.5f, 100.0f);
    
        auto default_font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, default_font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        auto pixmap = CreatePixmap(16, 8);
        for (int y = 0; y < 8; y++) {
            for (int x = 0; x < 16; x++) {
                pixmap->WritePixel(x, y, 0);
            }
        }
    
        while (window->KeyHit(KEY_ESCAPE) == false && window->Closed() == false)
        {
            while (PeekEvent()) {
                ui->ProcessEvent(WaitEvent());
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    • Confused 1
  2. A panel with a pixmap does not change colour or alpha.  I've tried WIDGETCOLOR_BACKGROUND and WIDGETCOLOR_FORGROUND.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1440, 900, displays[0]);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        auto camera = CreateCamera(world);
        camera->Move(0, 2, -3);
        camera->SetClearColor(1, 0, 0);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 35);
    
        auto floor = CreateBox(world, 100.0f, 0.5f, 100.0f);
    
        auto default_font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, default_font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        auto panel = CreatePanel(0, 0, 512, 512, ui->root);
        panel->SetPixmap(LoadPixmap("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/dirt01.dds"));
        panel->SetColor(1.0f, 0.0f, 1.0f, 0.5f);
    
        while (window->KeyHit(KEY_ESCAPE) == false && window->Closed() == false)
        {
            while (PeekEvent()) {
                ui->ProcessEvent(WaitEvent());
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  3. I checked it here as well.  It's the actors collision method that is not being called.  Josh are you able to take a look at this soon? 🙃

    #ifdef DOUBLE_FLOAT
    void Actor::Collision(std::shared_ptr<Entity> collidedentity, const dVec3& position, const dVec3& normal, const dFloat speed, std::shared_ptr<Material> collidedmaterial)
    #else
    void Actor::Collision(std::shared_ptr<Entity> collidedentity, const Vec3& position, const Vec3& normal, const dFloat speed, std::shared_ptr<Material> collidedmaterial)
    #endif
    {
    	ActorBase::Start();
    	auto actorbase = collidedentity->actor.lock();
    	std::shared_ptr<Actor> actor;
    	if (actorbase) actor = actorbase->As<Actor>();
    	if (actor == NULL) actor = CreateActor(collidedentity);
    	if (this->m_cameracontrols) this->m_cameracontrols->Collide(actor,position,normal,speed);
    	if (this->m_collisioncallback) this->m_collisioncallback->Collide(actor,position,normal,speed);
    	if (this->m_mover) this->m_mover->Collide(actor,position,normal,speed);
    }

     

  4. I just updated the download.  It has a prefab and a map.  There is still a few issues with it (cloud colour at night is red and there are no stars).  Have a play with it and see what you can do.  Hopefully shadmar makes a return one day to fix things up a bit.

  5. Certain vectors cause the entity to scale rapidly down to zero on a few axis.  Below is one example.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1440, 900, displays[0]);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        auto camera = CreateCamera(world);
        camera->Move(0, 1, -3);
        camera->SetClearColor(1, 0, 0);
    
        auto default_font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, default_font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        auto label = CreateLabel("", 10, 10, 500, 200, ui->root);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 35);
    
        auto box = CreateBox(world);
        Vec3 up = Vec3(1.0f, 1.0f, 1.0f).Normalize();
    
        while (window->KeyHit(KEY_ESCAPE) == false && window->Closed() == false)
        {
            box->AlignToVector(up, 1, 1.0f, 1.0f);
    
            auto scale = box->GetScale();
            label->SetText("Scale : " + String(scale.x) + ", " + String(scale.y) + ", " + String(scale.z));
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    • Confused 1
  6. A small example.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1440, 900, displays[0]);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        auto camera = CreateCamera(world);
        camera->Move(0, 26, -3);
        camera->SetClearColor(1, 0, 0);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 35);
    
        auto sphere = CreateSphere(world, 25.0f);
    
        auto box = CreateBox(world);
        box->SetMass(1.0f);
        box->SetPosition(-0.5f, 26.0f, 0.0f, true);
    
        while (window->KeyHit(KEY_ESCAPE) == false && window->Closed() == false)
        {
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  7. So it appears that just a sphere collider will create the above issues.  Using a sphere mesh collider works best.  There is no gap between the surface(other than the obvious gap as the surface curves) and the jitter is gone completely.

    auto sphere = CreateSphere(world, 25.0f);
    auto collider = CreateMeshCollider(sphere->lods[0]->meshes[0]);
    sphere->SetCollider(collider);

    @Josh does all this sound like a bug to you or is it just the way of sphere collisions?

  8. Also it seems with sphere colliders the cubes are not actually colliding with the surface.  For primitive shapes, such as cubes and spheres, is newton actually using the mesh to test collision?  Or is it calculating the surface of the sphere with it's position and radius?  That might explain why there is a gap.

    PhysicsOffset.thumb.png.19cd8d4961bb48cffd4bd9b6834b2b12.png

  9. What could cause this?   Could it be because the surface is a collidable sphere and it is curved too much for it to come to complete rest as a flat surface does?  They are just cubes that fall onto a large sphere, nothing special.  After a minute or two it stops in most cases.

    PhysicsJitter.gif.e16da254f7a0120311b043f805f496f0.gif

  10. The cube randomly bounces about but the collide member is only set to true for the first collision.  After that it fails to work.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1440, 900, displays[0]);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        auto camera = CreateCamera(world);
        camera->Move(0, 2, -3);
        camera->SetClearColor(1, 0, 0);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 35);
    
        auto floor = CreateBox(world, 100.0f, 0.5f, 100.0f);
    
        auto default_font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, default_font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        auto label = CreateLabel("", 10, 10, 500, 200, ui->root);
    
        auto box = CreateBox(world);
        box->SetMass(1.0f);
    
        auto actor = CreateActor(box);
        auto c = actor->AddComponent<CollisionCallback>();
    
        box->SetPosition(0.0f, 5.0f, 0.0f);
    
        auto last_time = Millisecs();
        while (window->KeyHit(KEY_ESCAPE) == false && window->Closed() == false)
        {
            auto time = Millisecs();
    
            while (PeekEvent()) {
                ui->ProcessEvent(WaitEvent());
            }
    
    
            WString text = "Position : " + String(c->collided ? "True" : "False");
            label->SetText(text);
    
            if (time > last_time + 2500) {
                c->collided = false;
                box->AddForce(0.0f, 300.0f, 0.0f);
                last_time = time;
            }
            
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

    Component:

    #pragma once
    #include "UltraEngine.h"
    #include "../ComponentSystem.h"
    
    
    class CollisionCallback : public Component {
    private:
    public:
        bool collided = false, is_updating = false;
        int collision_count = 0;
    
        virtual void Update() {
            is_updating = true;
        }
    
        virtual void Collide(shared_ptr<Actor> collidedactor, const Vec3& position, const Vec3& normal, const dFloat speed) {
            collided = true;
            collision_count++;
        }
    };

     

  11. It works flawlessly if I delete the actor and component and then remake them.  So I'd say the above post shows a bug in the Collide method.

    void EnableRidgedBody(bool state) {
            if (state == true) {
                is_rigid_body = true;
                is_airborne = true;
    
                auto collider = CreateCylinderCollider(0.5f, 1.8f);
    
                if (rigid_body == nullptr) {
                    rigid_body = CreatePivot(world);
                    rigid_body->SetShadows(true);
                    rigid_body->SetCollider(collider);
                    rigid_body->SetCollisionType(COLLISION_PLAYER);
                    rigid_body->SetMass(1.0f);
    
                }
                    
                actor = CreateActor(rigid_body);
                callback = actor->AddComponent<CollisionCallback>();
                model->SetParent(rigid_body);
            }
            else {
                is_rigid_body = false;
                is_airborne = false;
    
                model->SetParent(nullptr);
                model->SetRotation(0.0f, 0.0f, 0.0f);
    
                callback = nullptr;
                actor = nullptr;
            }
        }

     

  12. The idea here is to switch between a rigid body when physics is needed and a kinematic joint when control is needed.  This might end up working but right now the Collide method in the CallbackCollision component is not being called a second time round...

    If you wait for the player to fall, is_rigid_body will set to False, then hit space to jump, the player will jump and fall again but this time will not trigger the collide method.  The component is still attached and is still calling the update method.  A bug perhaps or bad coding by me?

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    
    class Player {
    public:
        shared_ptr<World> world = nullptr;
        shared_ptr<Model> model = nullptr;
        shared_ptr<Entity> rigid_body, controller_body;
        shared_ptr<Actor> actor = nullptr;
        shared_ptr<CollisionCallback> callback = nullptr;
        shared_ptr<Joint> joint = nullptr;
    
        bool is_controlable = false;
        bool is_rigid_body = false;
        bool is_airborne = false;
    
        Player(shared_ptr<World> world) {
            this->world = world;
    
            model = CreateCylinder(world, 0.5f, 1.8f);
            model->SetCollider(nullptr);
            model->SetColor(1, 0, 0);
    
            EnableRidgedBody(true);
        }
    
        ~Player() {}
    
        void SetPosition(float x, float y, float z) {
            if (is_rigid_body) {
                rigid_body->SetPosition(x, y, z);
            }
        }
    
        void EnableRidgedBody(bool state) {
            if (state == true) {
                is_rigid_body = true;
                is_airborne = true;
    
                auto collider = CreateCylinderCollider(0.5f, 1.8f);
    
                if (rigid_body == nullptr) {
                    rigid_body = CreatePivot(world);
                    rigid_body->SetShadows(true);
                    rigid_body->SetCollider(collider);
                    rigid_body->SetCollisionType(COLLISION_PLAYER);
                    rigid_body->SetMass(1.0f);
    
                    actor = CreateActor(rigid_body);
                    callback = actor->AddComponent<CollisionCallback>();
                }
    
                model->SetParent(rigid_body);
            }
            else {
                is_rigid_body = false;
                is_airborne = false;
    
                model->SetParent(nullptr);
                model->SetRotation(0.0f, 0.0f, 0.0f);
    
               // callback = nullptr;
               // actor = nullptr;
                //rigid_body = nullptr;
            }
        }
    
        void EnableController(bool state) {
            if (state == true) {
                is_controlable = true;
    
                if (joint == nullptr) {
                    auto pos = model->GetPosition(true);
                    auto col = CreateCylinderCollider(0.5f, 1.8f);
    
                    controller_body = CreatePivot(world);
                    controller_body->SetShadows(true);
                    controller_body->SetCollider(col);
                    controller_body->SetCollisionType(COLLISION_NONE);
                    controller_body->SetMass(1.0f);
                    controller_body->SetPosition(pos, true);
    
                    joint = CreateKinematicJoint(pos, controller_body);
                }
    
                model->SetParent(controller_body);
            }
            else {
               // joint = nullptr;
               // controller_body = nullptr;
                is_controlable = false;
            }
        }
    
        void SetInput(float move, float angle) {
    
        }
    
        void Update() {
            if (is_airborne == true && callback->collided == true) {
                auto vel = rigid_body->GetVelocity(true);
                auto speed_sqr = (vel.x * vel.x) + (vel.y * vel.y) + (vel.z * vel.z);
                
                if (speed_sqr < FLT_EPSILON) {
                    callback->collided = false;
    
                    EnableRidgedBody(false);
                    EnableController(true);
                }
            }
            
            if (is_controlable == true) {
                auto target_position = model->GetPosition(true);
                auto angle = 0.0f;
                auto up = Vec3(0.0f, 1.0f, 0.0f);
    
                auto window = ActiveWindow();
                if (window != nullptr) {
                    if (window->KeyDown(KEY_UP)) {}
                    if (window->KeyHit(KEY_SPACE)) {
                        EnableController(false);
                        EnableRidgedBody(true);
                        rigid_body->AddForce(up * 250.0f);
                    }
                    else {
                        joint->SetPose(target_position, Vec3(0.0f));
                    }
                }
            }
        }
    };
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1440, 900, displays[0]);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        auto camera = CreateCamera(world);
        camera->Move(0, 2, -3);
        camera->SetClearColor(1, 0, 0);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 35);
    
        auto floor = CreateBox(world, 100.0f, 0.5f, 100.0f);
    
        auto default_font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, default_font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        auto label = CreateLabel("", 10, 10, 500, 200, ui->root);
    
        auto player = make_shared<Player>(world);
        player->SetPosition(0, 5, 0);
    
        while (window->KeyHit(KEY_ESCAPE) == false && window->Closed() == false)
        {
            while (PeekEvent()) {
                ui->ProcessEvent(WaitEvent());
            }
    
            player->Update();
            auto pos = player->model->GetPosition(true);
            auto rot = player->model->GetRotation();
    
            WString text = "Position : " + String(pos.x) + ", " + String(pos.y) + ", " + String(pos.z) + "\n" +
                "Rotation : " + String(rot.x) + ", " + String(rot.y) + ", " + String(rot.z) + "\n" +
                "Rigid Body : " + String(player->is_rigid_body == true ? "True" : "False") + "\n" +
                "Collide : " + String(player->callback->collided == true ? "True" : "False") + "\n" +
                "Collision Count : " + String(player->callback->collision_count) + "\n" +
                "Still Updating : " + String(player->callback->is_updating == true ? "True" : "False");
            label->SetText(text);
            player->callback->is_updating = false;
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

    Component:

    #pragma once
    #include "UltraEngine.h"
    #include "../ComponentSystem.h"
    
    
    class CollisionCallback : public Component {
    private:
    public:
        bool collided = false, is_updating = false;
        int collision_count = 0;
    
        virtual void Update() {
            is_updating = true;
        }
    
        virtual void Collide(shared_ptr<Actor> collidedactor, const Vec3& position, const Vec3& normal, const dFloat speed) {
            collided = true;
            collision_count++;
        }
    };

     

  13. I think I may have addressed this before but can't remember... an entity will not cast a shadow if it has a pivot as a parent.

    #include "UltraEngine.h"
    using namespace UltraEngine;
    
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]);
        auto world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.0f, 0.0f, 1.0f);
        camera->SetFov(70);
        camera->SetRange(0.01f, 1000.0f);
        camera->SetPosition(0, 1, -3);
    
        auto light = CreateDirectionalLight(world);
        light->SetColor(5.0f);
        light->SetRotation(35, 45, 0);
    
        auto floor = CreateBox(world, 100.0f, 0.1f, 100.0f);
    
        auto pivot = CreatePivot(world);
    
        auto box = CreateBox(world);
        box->SetParent(pivot);
        pivot->SetPosition(0.0f, 2.0f, 0.0f);
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
    
            world->Update();
            world->Render(framebuffer, false);
        }
        return 0;
    }

     

  14. Alternatively if we had access to the newton world and entities bodies we could probably use newton commands ourselves.

    float pin[3] = {0, 1, 0};
    auto joint = NewtonConstraintCreateUpVector(world->GetPhysicsWorld(), pin, entity->GetBody())

     

×
×
  • Create New...