Jump to content

SpiderPig

Members
  • Posts

    2,399
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. Not a big deal but here it is anyway.  Tap the W key quickly and you will see that the shadow lags and creates a dark spot briefly on the cylinder.

    JointShadowDelay.gif.d4dc23634fc76571532263451b844bf7.gif

    #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 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 m = CreateCylinder(world, 0.5f, 1.8f);
        m->SetMass(1.0f);
        m->SetPosition(0, 2, 0);
    
        camera->SetParent(m);
    
        auto joint = CreateKinematicJoint(0.0f, 2.0f, 0.0f, m);
        joint->SetMaxForce(FLT_MAX);
    
        while (true)
        {
            while (PeekEvent()) {
                ui->ProcessEvent(WaitEvent());
            }
    
            auto pos = m->GetPosition(true);
            auto rot = m->GetRotation();
            label->SetText("Position : " + String(pos.x) + ", " + String(pos.y) + ", " + String(pos.z) + "\n" +
                "Rotation : " + String(rot.x) + ", " + String(rot.y) + ", " + String(rot.z));
    
            auto target_pos = pos;
            if (window->KeyDown(KEY_W)) { target_pos.z += 1.0f; }
            if (window->KeyDown(KEY_S)) { target_pos.z -= 1.0f; }
    
            joint->SetPose(target_pos, Vec3(0,0,0));
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  2. I think Leadwerks had this... can we get this for Ultra too?

    CreateVectorJoint()

    Would also need to change its pin as well... something Leadwerks didn't allow from memory.

    vector->SetPin(0, 1, 0)

     

  3. In Leadwerks I used to be able to make a player controller and turn off gravity for that entity and just use AddForce() for my own gravity system.  I didn't see a problem with doing it this way for rigid bodies, but I never did think it was a good idea for the character controller.  Doesn't seem to work in Ultra anyway and in all fairness that's okay because I am going to have to make my own controller I think.

    I'm going to post a few attempts here and see if I can't finally get this to work the way I want!

    This used to work in Leadwerks:

    #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 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 m = CreateCylinder(world, 0.5f, 1.8f);
        m->SetPhysicsMode(PHYSICS_PLAYER);
        m->SetPosition(0, 5, 0);
        m->SetMass(1.0f);
        m->SetGravityMode(false);
    
    
        while (true)
        {
            m->AddForce(0.0f, -9.8f, 0.0f);
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  4. I've only had this happen when using a custom widget.  If you hide the parent of the custom widget before at least one loop it will crash.

    #include "Engine.h"
    
    using namespace UltraEngine;
    
    //Declare new style constants
    enum CustomWidgetStyle
    {
        CUSTOMWIDGET_DEFAULT = 0
    };
    
    //Declare new widget class
    class CustomWidget : public Widget
    {
        bool hover;
    
    protected:
    
        virtual bool Initialize(const WString& text, const int x, const int y, const int width, const int height, shared_ptr<Widget> parent, const int style)
        {
            return Widget::Initialize(text, x, y, width, height, parent, style);
        }
    
        //Called when the mouse moves if this widget has the focus
        virtual void MouseMove(const int x, const int y) {}
    
        //Called when the mouse cursor enters the widget bounds
        virtual void MouseEnter(const int x, const int y)
        {
            hover = true;
            Redraw();
        }
    
        //Called when the mouse cursor leaves the widget bounds
        virtual void MouseLeave(const int x, const int y)
        {
            hover = false;
            Redraw();
        }
    
        //Called when the mouse button is pressed
        virtual void MouseDown(const MouseButton button, const int x, const int y)
        {
            if (button == MOUSE_LEFT) EmitEvent(EVENT_WIDGETACTION, Self());
        }
    
        //Called when the mouse button is released
        virtual void MouseUp(const MouseButton button, const int x, const int y) {}
    
        //Called when another widget becomes selected
        virtual void LoseFocus() {}
    
        //Called when mouse double-click occurs
        virtual void DoubleClick(const MouseButton button, const int x, const int y) {}
    
        //Called when mouse triple-click occurs
        virtual void TripleClick(const MouseButton button, const int x, const int y) {}
    
        //Called when widget is selected
        virtual void GainFocus() {}
    
        //Called when key is pressed
        virtual void KeyDown(const KeyCode key) {}
    
        //Called when key is released
        virtual void KeyUp(const KeyCode key) {}
    
        //Called for each keydown event
        virtual void KeyChar(const int keychar) {}
    
        //Called when mouse wheel turns and mouse is hovered over this widget
        virtual void MouseWheel(const int delta, const int x, const int y) {}
    
        //Called each time the widget is redrawn
        virtual void Draw(const int x, const int y, const int width, const int height)
        {
            blocks.clear();
    
            AddBlock("Text", iVec2(0), this->size, Vec4(1), TEXT_CENTER | TEXT_MIDDLE);
        }
    public:
    
        //Constructor
        CustomWidget() : hover(false)
        {}
    
        friend shared_ptr<Widget> CreateCustomWidget(const WString&, const int, const int, const int, const int, shared_ptr<Widget>, const CustomWidgetStyle);
    };
    
    //Create function
    shared_ptr<Widget> CreateCustomWidget(const WString& text, const int x, const int y, const int width, const int height, shared_ptr<Widget> parent, const CustomWidgetStyle style)
    {
        auto widget = std::make_shared<CustomWidget>();
        widget->Initialize(text, x, y, width, height, parent, style);
        return widget;
    }
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        auto camera = CreateCamera(world);
        camera->Move(0, 0, -3);
        camera->SetClearColor(1, 0, 0);
    
        auto box = CreateBox(world);
    
        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);
    
        //Create widget
        auto panel = CreatePanel(10, 10, 100, 100, ui->root);
        auto widget = CreateCustomWidget("Custom", 20, 20, 50, 30, panel, CUSTOMWIDGET_DEFAULT);
    
        while (true)
        {
            panel->SetHidden(true);//Causes crash
            while (PeekEvent()) {
                auto ev = WaitEvent();
                ui->ProcessEvent(ev);
            }
           // panel->SetHidden(true);//No crash here
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  5. I believe it is just like calling Abs() for each of the  x, y & z components of the vector.  Saves time writing it out all the time.

    Vec3 Abs(Vec3 value) {
    	value.x = Abs(value.x);
    	value.y = Abs(value.y);
    	value.z = Abs(value.z);
    
    	return value;
    }

     

  6. The bounds are returning 0 size for some objects I'm loading.  I think its when there are two or more entities in the file.  Here cube1 shows the correct bounds size but cube2 (has two cubes in it) returns 0.

    #include "Engine.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 font = LoadFont("Fonts/arial.ttf");
        auto ui = CreateInterface(world, font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0, 0, 0, 0);
    
        auto ui_cam = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_cam->SetPosition(framebuffer->size.x / 2, framebuffer->size.y / 2, 0);
        ui_cam->SetRenderLayers(2);
        ui_cam->SetClearMode(CLEAR_DEPTH);
    
        auto label = CreateLabel("", 10, 10, 200, 30, ui->root);
    
        auto cube1 = LoadModel(world, "Cube.gltf");
        auto cube2 = LoadModel(world, "Cube2.gltf");
        auto b1 = cube1->GetBounds();
        auto b2 = cube2->GetBounds();
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            label->SetText("Size1 : " + String(b1.size.x) + ", " + String(b1.size.y) + ", " + String(b1.size.z) + "\n"
                "Size2 : " + String(b2.size.x) + ", " + String(b2.size.y) + ", " + String(b2.size.z));
    
            world->Update();
            world->Render(framebuffer, false);
        }
        return 0;
    }

     

    Cubes.zip

  7. I'm going to be using a lot of low poly assets (flat shading and plain colours - only a diffuse texture which sets the colour per triangle) and I'm not sure if the PBR lighting should be used still or if I should use the classic shading?

  8. I wonder if we could get the current update frequency of the world?  I could probably store a variable for this somewhere myself actually but just wondering.

    float convertRPM(float rpm) {
    	auto frequency = (world->update_frequency * 60.0f) / rpm;
    
    	return 360.0f / frequency;
    }

     

  9. Is there a need for something like this in Ultra or is the game loop frequency manged by the engine as indicated by world::Update()'s frequency parameter?

    uint64_t time_span = 1000;//ms
    uint64_t time_interval = 100;//ms
    uint64_t start_time = Millisecs();
    float range = 90.0f;
    float inc = range / (float)(time_span / time_interval);
    
    //loop
    
    auto result = 0.0f;
    uint64_t current_time = Millisecs();
    if (current_time >= start_time + time_interval) {
    	start_time = current_time;
    
    	result += inc;//Should be approx 90.0f after a second
    }

     

  10. I don't think there is as Josh has said that the depth value can change overtime.  You can read the depth value of a widget with Widget::z but this is a temporary member so I wouldn't rely on it.

  11. Thanks its all working now.

    26 minutes ago, Josh said:

    BTW, it seems a lot of your colliders consist of 1-2 triangles. This is probably very inefficient and it would be better if they were in bigger pieces, but that should still not cause a crash like you were experiencing.

    They do and I was actually wondering if it would be better to make less colliders with more triangles each so I will do this.

  12. Okay thanks.  I need to read that book too.  I don't know enough about them.  

    3 hours ago, Josh said:

    Each entity stores its rotation in both Euler and quaternion form, and these are kept in sync whenever rotation changes. The Turn method uses quaternions to accurately turn the entity, and then fills in the entity's Euler rotation value by converting it from the resulting quaternion.

     I want to rotate an object back and forth on the x axis between 0 and 90 degrees.  I thought GetRotation() should return Euler angles?

  13. Getting the rotation of an object doesn't seem to go past 90 degrees on any one axis.  E.g. I turn the box along the x axis but it only just gets to 90 degrees then starts counting down again and the y and z axis flip to 180 at around 45 degrees as it counts down on the x.  This probably has something to do with quaternions but I do not know for sure.

    RotationError.thumb.png.cbb35237e07f574d5d007da33c2acfa9.png

    #include "Engine.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 font = LoadFont("Fonts/arial.ttf");
        auto ui = CreateInterface(world, font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0, 0, 0, 0);
    
        auto ui_cam = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_cam->SetPosition(framebuffer->size.x / 2, framebuffer->size.y / 2, 0);
        ui_cam->SetRenderLayers(2);
        ui_cam->SetClearMode(CLEAR_DEPTH);
    
        auto label = CreateLabel("", 10, 10, 200, 30, ui->root);
    
        auto box = CreateBox(world);
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            box->Turn(0.25f, 0.0f, 0.0f);
    
            auto local = box->GetRotation();
            auto global = box->GetRotation(true);
            label->SetText("Local : " + String(local.x) + ", " + String(local.y) + ", " + String(local.z) + "\n"
                "Global : " + String(global.x) + ", " + String(global.y) + ", " + String(global.z));
    
            world->Update();
            world->Render(framebuffer, false);
        }
        return 0;
    }

     

  14. Thanks that worked.  You are correct.  Although it gives me an idea on what's going on it doesn't help me much.  But it is cool to see it break to the physics code and at least tell me something.  Your welcome to remote debug if you wish.

    NewtonCrash2.thumb.png.f115d73cfb928f762571e289c5d539b7.png

×
×
  • Create New...