Jump to content

SpiderPig

Members
  • Posts

    2,285
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. I want to be able have physics working on various different platforms that each have there own velocity and rotations happening.  (In this example I'm just turning the floor object, so that might be the wrong way to do that.)

    On each platform I'd want to have physics working normally as though each platform is it's own little physics world, oblivious to the fact that it's platform is moving about.  Just like we can walk on Earth and not feel like were hurtling around the sun and around the Earths axis. ;)

     

    I guess this is similar to parenting a player controller to an elevator that moves left and right so the player doesn't slide off the platform as it moves.

    As the GIF shows, simply parenting the box to the floor breaks the physics sim I think.  But the concept is what I'm trying to achieve.

    The same goes for parenting the player controller to the floor.

    It looks like it wants to work the way I intend, it just keeps bouncing back and forth.

    Any one know if this might be possible?

     

    ParentedPhysicsObject.gif.dcf746d27915661e131f0af1f500e64b.gif

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    Vec3 mousepos = Vec3(0.0f);
    float move_adjustment = 0.1f;
    float move_speed = 1.0f;
    float lookspeed = 0.1f;
    float looksmoothing = 0.5f;
    bool enable_camera = true;
    
    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 world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 10, -5);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 45, 0);
    
        auto floor = CreateBox(world, 10.0f, 0.1f, 10.0f);
        floor->SetPosition(0.0f, -3.0f, 0.0f);
        floor->SetMaterial(LoadMaterial("Materials\\Developer\\bluegrid.mat"));
    
        auto box = CreateBox(world);
        box->SetMass(1.0f);
        box->SetPosition(2.0f, 2.0f, 0.0f);
        box->SetParent(floor);
    
        auto player = CreateCylinder(world);
        player->SetPhysicsMode(PHYSICS_PLAYER);
        player->SetPosition(0.0f, 5.0f, 0.0f);
        player->SetMass(1.0f);
    
        auto cam_pivot = CreatePivot(world);
        cam_pivot->SetParent(player);
        cam_pivot->SetPosition(0.0f, 1.8f, 0.0f);
    
        camera->SetParent(cam_pivot);
        camera->SetPosition(0.0f, 0.0f, -3.0f);
        camera->SetDebugPhysicsMode(true);
    
        bool stage = 0;
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_F2) == true) { camera->SetWireframe(!camera->GetWireframe()); }
            if (window->KeyHit(KEY_F3) == true) { camera->SetDebugPhysicsMode(!camera->GetDebugPhysicsMode()); }
            if (window->KeyHit(KEY_F4) == true) { enable_camera = !enable_camera; }
    
            if (enable_camera) {
                auto _displaySize = window->GetSize();
                float cx = Round((float)_displaySize.x / 2.0f);
                float cy = Round((float)_displaySize.y / 2.0f);
    
                auto mpos = Vec3(window->GetMousePosition().x, window->GetMousePosition().y, window->GetMousePosition().z);
                window->SetMousePosition(cx, cy);
                mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
                auto dx = (mpos.x - cx) * lookspeed;
                auto dy = (mpos.y - cy) * lookspeed;
    
    
                auto camrot = cam_pivot->GetRotation();
                camrot.x += dy;
                camrot.y += dx;
                cam_pivot->SetRotation(camrot);
                mousepos = mpos;
            }
    
            floor->Turn(0.0f, 0.1f, 0.0f);
            
            auto y_angle = cam_pivot->GetRotation().y;
            auto move = 0.0f, strafe = 0.0f;
            if (window->KeyDown(KEY_W)) { move = 1.0f; }
            else if (window->KeyDown(KEY_S)) { move = -1.0f; }
            if (window->KeyDown(KEY_A)) { strafe = -1.0f; }
            else if (window->KeyDown(KEY_D)) { strafe = 1.0f; }
            player->SetInput(y_angle, move, strafe);
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  2. Now I think this is a bug...  the cylinder falls and lands half way up.  It moves around fine.  I get it there's an offset of 0.5 but in this case I do not know how to fix it.  Modify the vertices?  Will that update the collider model too?  What shape is the player controller?  Is it not using the collider of the model I set PHYSICS_PLAYER on?

    Seth Meyers Question GIF by Late Night with Seth Meyers

    ControllerHalfWay.thumb.jpg.292d83bb874fe9797dc1daa85db06c51.jpg

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    Vec3 mousepos = Vec3(0.0f);
    float move_adjustment = 0.1f;
    float move_speed = 1.0f;
    float lookspeed = 0.1f;
    float looksmoothing = 0.5f;
    bool enable_camera = true;
    
    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 world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 10, -5);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 45, 0);
    
        auto floor = CreateBox(world, 10.0f, 0.1f, 10.0f);
        floor->SetPosition(0.0f, -3.0f, 0.0f);
        floor->SetMaterial(LoadMaterial("Materials\\Developer\\bluegrid.mat"));
    
        auto box = CreateBox(world);
        box->SetMass(1.0f);
        box->SetPosition(2.0f, 2.0f, 0.0f);
    
        auto player = CreateCylinder(world);
        player->SetPhysicsMode(PHYSICS_PLAYER);
        player->SetPosition(0.0f, 5.0f, 0.0f);
        player->SetMass(10.0f);
    
        auto cam_pivot = CreatePivot(world);
        cam_pivot->SetParent(player);
        cam_pivot->SetPosition(0.0f, 1.8f, 0.0f);
    
        camera->SetParent(cam_pivot);
        camera->SetPosition(0.0f, 0.0f, -3.0f);
        camera->SetDebugPhysicsMode(true);
    
        bool stage = 0;
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_F2) == true) { camera->SetWireframe(!camera->GetWireframe()); }
            if (window->KeyHit(KEY_F3) == true) { camera->SetDebugPhysicsMode(!camera->GetDebugPhysicsMode()); }
            if (window->KeyHit(KEY_F4) == true) { enable_camera = !enable_camera; }
    
            if (enable_camera) {
                auto _displaySize = window->GetSize();
                float cx = Round((float)_displaySize.x / 2.0f);
                float cy = Round((float)_displaySize.y / 2.0f);
    
                auto mpos = Vec3(window->GetMousePosition().x, window->GetMousePosition().y, window->GetMousePosition().z);
                window->SetMousePosition(cx, cy);
                mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
                auto dx = (mpos.x - cx) * lookspeed;
                auto dy = (mpos.y - cy) * lookspeed;
    
    
                auto camrot = cam_pivot->GetRotation();
                camrot.x += dy;
                camrot.y += dx;
                cam_pivot->SetRotation(camrot);
                mousepos = mpos;
            }
    
            auto y_angle = cam_pivot->GetRotation().y;
            auto move = 0.0f, strafe = 0.0f;
            if (window->KeyDown(KEY_W)) { move = 1.0f; }
            else if (window->KeyDown(KEY_S)) { move = -1.0f; }
            if (window->KeyDown(KEY_A)) { strafe = -1.0f; }
            else if (window->KeyDown(KEY_D)) { strafe = 1.0f; }
            player->SetInput(y_angle, move, strafe);
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  3. I'm not sure how to go about this.  I think what I need is one of the transform functions.

    This is a simplified example of my voxel terrain where each box represents a component of the terrain.

    Holding 'space' will replace random boxes.

    While all the boxes in this example exist, in the voxel terrain not all components exist at once, they can be created for the first time when the player edits the terrain, so I can't just grab the existing boxes rotation and use that for the new box.

    I only have the pivots position and rotation to decided what the new boxes position and rotation should be relative to the pivot.

    The position of the new box is okay if I set it's position to be local.  I wonder if the rotation should be the same? <_<

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    Vec3 mousepos = Vec3(0.0f);
    float move_adjustment = 0.1f;
    float move_speed = 1.0f;
    float lookspeed = 0.1f;
    float looksmoothing = 0.5f;
    bool enable_camera = false;
    
    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 world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 10, -5);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 45, 0);
    
        auto floor = CreateBox(world, 100.0f, 0.1f, 100.0f);
        floor->SetPosition(0.0f, -3.0f, 0.0f);
    
        const int grid_size = 3;
        const int total_cubes = grid_size * grid_size * grid_size;
        shared_ptr<Entity> rubix_cube[total_cubes];
    
        auto material = CreateMaterial();
        material->SetShaderFamily(LoadShaderFamily("Shaders\\Unlit.fam"));
    
        auto pivot = CreatePivot(world);
        pivot->SetShadows(true);
    
        int id = 0;
        for (int z = 0; z < grid_size; z++) {
            for (int y = 0; y < grid_size; y++) {
                for (int x = 0; x < grid_size; x++) {
                    rubix_cube[id] = CreateBox(world);
                    rubix_cube[id]->SetColor(Random(), Random(), Random());
                    rubix_cube[id]->SetParent(pivot);
                    rubix_cube[id]->SetPosition(x - 1, y - 1, z - 1);
    
                    id++;
                }
            }
        }
    
        //Main loop
        bool stage = 0;
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_F2) == true) { camera->SetWireframe(!camera->GetWireframe()); }
            if (window->KeyHit(KEY_F3) == true) { camera->SetDebugPhysicsMode(!camera->GetDebugPhysicsMode()); }
            if (window->KeyHit(KEY_F4) == true) { enable_camera = !enable_camera; }
    
            //Rotate the pivot
            auto pos = pivot->GetPosition(true);
            pivot->Turn(0.025f, 0.025f, 0.025f);
            switch (stage) {
            case 0:
                if (pos.x < 5.0f) { pivot->Move(0.01f, 0.0f, 0.0f); }
                else { stage = 1; }
                break;
            case 1:
                if (pos.x > 0.0f) { pivot->Move(-0.01f, 0.0f, 0.0f); }
                else { stage = 0; }
                break;
            }
    
            //Randomly Replace a Box
            if (window->KeyDown(KEY_SPACE) == true) {
    
                auto x = Floor(Random(2.5f));
                auto y = Floor(Random(2.5f));
                auto z = Floor(Random(2.5f));
    
                id = (z * (grid_size * grid_size)) + (y * grid_size) + x;
    
                rubix_cube[id]->SetParent(nullptr);//Should this be needed?
                rubix_cube[id] = CreateBox(world);
                rubix_cube[id]->SetColor(Random(), Random(), Random());
                rubix_cube[id]->SetParent(pivot);
                rubix_cube[id]->SetPosition(x - 1, y - 1, z - 1);
    
                //How to transform to keep the rotation and position.
                //Can't use current rotation and position of box
                //In my game there is not allways a model present at that location
    
                //Nope
                //auto new_r = TransformRotation(Vec3(0.0f) , Mat4(), pivot->GetMatrix());
                //rubix_cube[id]->SetRotation(new_r);
            }
    
            if (enable_camera) {
                auto _displaySize = window->GetSize();
                float cx = Round((float)_displaySize.x / 2.0f);
                float cy = Round((float)_displaySize.y / 2.0f);
    
                auto mpos = Vec3(window->GetMousePosition().x, window->GetMousePosition().y, window->GetMousePosition().z);
                window->SetMousePosition(cx, cy);
                mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
                auto dx = (mpos.x - cx) * lookspeed;
                auto dy = (mpos.y - cy) * lookspeed;
    
    
                auto camrot = camera->GetRotation();
                camrot.x += dy;
                camrot.y += dx;
                camera->SetRotation(camrot);
                mousepos = mpos;
    
                auto speed = 0.1f;
                if (window->KeyDown(KEY_SHIFT) == true) { speed = speed * 10.0f; }
                if (window->KeyDown(KEY_W) == true) { camera->Move(0, 0, speed); }
                else if (window->KeyDown(KEY_S) == true) { camera->Move(0, 0, -speed); }
                if (window->KeyDown(KEY_A) == true) { camera->Move(-speed, 0, 0); }
                else if (window->KeyDown(KEY_D) == true) { camera->Move(speed, 0, 0); }
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  4. That actually gives me an idea.  I suppose I could create a series of low resolution shadow maps and use a shader to blend between them depending on the light direction.  Or even a compute shader to calculate the shadow map on the fly.  🤔

  5. The terrain does have shadows now but what I really want to do is have terrain shadows far into the distance.  Ideally the whole terrain casts shadows at least onto itself at a low resolution if required.  Is this something that can be done with shaders and an extra camera?

  6. Okay I got it working.  The physics mode should be set AFTER setting the desired position.  Is this correct or is it a bug?

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    Vec3 mousepos = Vec3(0.0f);
    float move_adjustment = 0.1f;
    float move_speed = 1.0f;
    float lookspeed = 0.1f;
    float looksmoothing = 0.5f;
    bool enable_camera = false;
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    
        //Create a world
        auto world = CreateWorld();
        world->SetGravity(0.0f, -0.1f, 0.0f);
    
        //Create a framebuffer
        auto framebuffer = CreateFramebuffer(window);
    
        //Create a camera
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 10, -5);
    
        //Create a light
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 45, 0);
        light->SetRange(-10, 10);
    
        auto floor = CreateBox(world, 100.0f, 1, 100.0f);
    
        auto thing = CreateCylinder(world);
        thing->SetColor(1, 0, 0);
        thing->SetPosition(-2.0f, 10.0f, 0.0f);
    
    
        auto controller = CreatePivot(world);
        controller->SetCollisionType(COLLISION_PLAYER);
      	//controller->SetPhysicsMode(PHYSICS_PLAYER);
    
        auto player = CreateCylinder(world);
        player->SetParent(controller);
        player->SetPosition(0, 0.0, 0);
        player->SetColor(0, 1, 0);
        player->SetCollider(nullptr);
    
        controller->SetPosition(2.0f, 10.0f, 0.0f);
        controller->SetMass(1.0f);
        //camera->SetParent(controller);
    
        controller->SetPhysicsMode(PHYSICS_PLAYER);
        
    
        //Reads as the set position above, but appears to start at a lower position.  Gravity has been slowed to better see it at startup.
        auto c_pos = controller->GetPosition(true);
        auto p_pos = player->GetPosition(true);
        auto l_pos = player->GetPosition();
        Print("Controller Position : " + String(c_pos.x) + ", " + String(c_pos.y) + ", " + String(c_pos.z));
        Print("Player Global Position : " + String(p_pos.x) + ", " + String(p_pos.y) + ", " + String(p_pos.z));
        Print("Player Local Position : " + String(l_pos.x) + ", " + String(l_pos.y) + ", " + String(l_pos.z));
    
       /* bool started = false;
        int it = 0;
        while (started == false) {
            world->Render(framebuffer);
            while (PeekEvent()) {
                auto event = WaitEvent();
                if (event.id == EVENT_STARTRENDERER) {
                    started = true;
                    break;
                }
                it++;
            }
            it++;
        }*/
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
    
            if (window->KeyHit(KEY_F2) == true) { camera->SetWireframe(!camera->GetWireframe()); }
            if (window->KeyHit(KEY_F3) == true) { camera->SetDebugPhysicsMode(!camera->GetDebugPhysicsMode()); }
            if (window->KeyHit(KEY_F4) == true) { enable_camera = !enable_camera; }
            if (window->KeyHit(KEY_F5) == true) {
                auto c_pos = controller->GetPosition(true);
                auto p_pos = player->GetPosition(true);
    
                Print("Controller Position : " + String(c_pos.x) + ", " + String(c_pos.y) + ", " + String(c_pos.z));
                Print("Player Position : " + String(p_pos.x) + ", " + String(p_pos.y) + ", " + String(p_pos.z));
            }
    
            if (enable_camera) {
                auto _displaySize = window->GetSize();
                float cx = Round((float)_displaySize.x / 2.0f);
                float cy = Round((float)_displaySize.y / 2.0f);
    
                auto mpos = Vec3(window->GetMousePosition().x, window->GetMousePosition().y, window->GetMousePosition().z);
                window->SetMousePosition(cx, cy);
                mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
                auto dx = (mpos.x - cx) * lookspeed;
                auto dy = (mpos.y - cy) * lookspeed;
    
    
                auto camrot = camera->GetRotation();
                camrot.x += dy;
                camrot.y += dx;
                camera->SetRotation(camrot);
                mousepos = mpos;
    
                auto speed = 0.1f;
                if (window->KeyDown(KEY_SHIFT) == true) { speed = speed * 10.0f; }
                if (window->KeyDown(KEY_W) == true) { camera->Move(0, 0, speed); }
                else if (window->KeyDown(KEY_S) == true) { camera->Move(0, 0, -speed); }
                if (window->KeyDown(KEY_A) == true) { camera->Move(-speed, 0, 0); }
                else if (window->KeyDown(KEY_D) == true) { camera->Move(speed, 0, 0); }
            }
    
            //if (window->KeyDown(KEY_SPACE)) {
                world->Update();
            //}
            world->Render(framebuffer);
        }
        return 0;
    }

     

  7. Yes that made a difference.  I removed the pre-loop check and put the world update into a key hit check.

    if (window->KeyHit(KEY_SPACE)) {
        world->Update();
    }
    world->Render(framebuffer);

    Upon loading it is slightly offset up, I believe that's the 0.5 offset.

    Offset_001.thumb.jpg.4c1a3e6798edf49ad3cd4b5e085b11bd.jpg

    After two key hits the cylinder snaps instantly to the lower position.

    Offset_002.thumb.jpg.6cd328b3b26d4969fd91a78a9edf9bfe.jpg

  8. I added this before the main loop and it didn't help.  I get about 4k iterations before the loop finishes.

    //WHAT FOR THE RENDERER TO START BEFORE STARTING THE GAME
    bool started = false;
    int it = 0;
    while (started == false) {
        world->Render(framebuffer);
        while (PeekEvent()) {
            auto event = WaitEvent();
            if (event.id == EVENT_STARTRENDERER) {
                started = true;
                break;
            }
            it++;
        }
        it++;
    }
    
    //Main loop
    ...

     

  9. Ah that makes sense.  It didn't solve it though.

    In your example if you raise the cameras height to 8 you'll be able to see the green player cylinder still starts a few units below the other cylinder even though the console output says there now only 0.5 units apart.

  10. I was seeing issues with setting my player controllers position in game so I tried replicating it the best I could here.  With the setup below, setting the mass causes the height to be offset and the player no longer falls.  I thought I was creating the pivot at a different location from the cylinder but if you hit F5 it shows they are at the same location.  I tried giving the pivot it's own collider, but that did nothing.  I assume PHYSICS_PLAYER has it's own collider anyway.  I also tried removing the floor plane.

    EDIT : I solved why it wasn't falling.   Stupid me didn't disable the collider on the 'player' model. ;)

    There is still the issue of starting with an offset though.  This is what I was seeing in my larger project.  The position reads as 10 units high however it starts lower than that.  In game I've had to add an arbitrary offset to the players height but that won't do forever.

    ControllerOffset_001.thumb.jpg.e20440c3d81655ba4a0f572e1c052f51.jpg

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    Vec3 mousepos = Vec3(0.0f);
    float move_adjustment = 0.1f;
    float move_speed = 1.0f;
    float lookspeed = 0.1f;
    float looksmoothing = 0.5f;
    bool enable_camera = false;
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    
        //Create a world
        auto world = CreateWorld();
        world->SetGravity(0.0f, -0.1f, 0.0f);
    
        //Create a framebuffer
        auto framebuffer = CreateFramebuffer(window);
    
        //Create a camera
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 9, -5);
    
        //Create a light
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 45, 0);
        light->SetRange(-10, 10);
    
        auto floor = CreatePlane(world, 100.0f, 100.0f);
    
        auto thing = CreateCylinder(world);
        thing->SetColor(1, 0, 0);
        thing->SetPosition(-2.0f, 10.0f, 0.0f);
    
    
        auto controller = CreatePivot(world);
        controller->SetPhysicsMode(PHYSICS_PLAYER);
        controller->SetCollisionType(COLLISION_PLAYER);
    
        auto player = CreateCylinder(world);
        player->SetParent(controller);
        player->SetColor(0, 1, 0);
        player->SetCollider(nullptr);
    
        controller->SetPosition(2.0f, 10.0f, 0.0f);
        controller->SetMass(1.0f);
        camera->SetParent(controller);
    
      	//Reads as the set position above, but appears to start at a lower position.  Gravity has been slowed to better see it at startup.
        auto c_pos = controller->GetPosition(true);
        auto p_pos = player->GetPosition(true);
        Print("Controller Position : " + String(c_pos.x) + ", " + String(c_pos.y) + ", " + String(c_pos.z));
        Print("Player Position : " + String(p_pos.x) + ", " + String(p_pos.y) + ", " + String(p_pos.z));
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_F2) == true) { camera->SetWireframe(!camera->GetWireframe()); }
            if (window->KeyHit(KEY_F3) == true) { camera->SetDebugPhysicsMode(!camera->GetDebugPhysicsMode()); }
            if (window->KeyHit(KEY_F4) == true) { enable_camera = !enable_camera; }
            if (window->KeyHit(KEY_F5) == true) {
                auto c_pos = controller->GetPosition(true);
                auto p_pos = player->GetPosition(true);
    
                Print("Controller Position : " + String(c_pos.x) + ", " + String(c_pos.y) + ", " + String(c_pos.z));
                Print("Player Position : " + String(p_pos.x) + ", " + String(p_pos.y) + ", " + String(p_pos.z));
            }
    
            if (enable_camera) {
                auto _displaySize = window->GetSize();
                float cx = Round((float)_displaySize.x / 2.0f);
                float cy = Round((float)_displaySize.y / 2.0f);
    
                auto mpos = Vec3(window->GetMousePosition().x, window->GetMousePosition().y, window->GetMousePosition().z);
                window->SetMousePosition(cx, cy);
                mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
                auto dx = (mpos.x - cx) * lookspeed;
                auto dy = (mpos.y - cy) * lookspeed;
    
    
                auto camrot = camera->GetRotation();
                camrot.x += dy;
                camrot.y += dx;
                camera->SetRotation(camrot);
                mousepos = mpos;
    
                auto speed = 0.1f;
                if (window->KeyDown(KEY_SHIFT) == true) { speed = speed * 10.0f; }
                if (window->KeyDown(KEY_W) == true) { camera->Move(0, 0, speed); }
                else if (window->KeyDown(KEY_S) == true) { camera->Move(0, 0, -speed); }
                if (window->KeyDown(KEY_A) == true) { camera->Move(-speed, 0, 0); }
                else if (window->KeyDown(KEY_D) == true) { camera->Move(speed, 0, 0); }
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  11. Got some weird results with this.  It's using the default shaders for the material so I understand that the result is supposed to be red as there's only data in the red channel of the image.  However only a few small areas appear to have a gradient between red and black pixels and the rest is just solid black or solid red.  Unsure if an appropriate shader needs to be made to sample this or if the texture is not being created correctly.

    Saved result of the pixmap shown is Visual Studio:

    VS_Image.jpg.ce6271888c2b0b547525ab11e25dd224.jpg

    Result with bluegrid.dds:

    BlueGrid_Works.thumb.jpg.c29c7cd486b35d0392c733c1ceaaff70.jpg

    Result with R16 texture:

    Result.thumb.jpg.7903d7a926a13bd60e6fc092749d2d73.jpg

    The texture is spread across a grid, so each pixel should be a metre apart and there should be interpolation between each pixel shouldn't there?  I'm seeing some pixels that worked and others that have rounded edges where I think they should be blending.

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    Vec3 mousepos = Vec3(0.0f);
    float move_adjustment = 0.1f;
    float move_speed = 1.0f;
    float lookspeed = 0.1f;
    float looksmoothing = 0.5f;
    
    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 world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 10, 0);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 0);
    
        auto box = CreateBox(world);
        box->SetPosition(10.0f, 2049.0f, 10.0f);
    
        int size = 256;
        unsigned short* buffer = new unsigned short[size * size];
        for (int y = 0; y < size; y++) {
            for (int x = 0; x < size; x++) {
                buffer[(y * size) + x] = (unsigned short)Random(USHRT_MAX);
            }
        }
    
        auto data = CreateBuffer(size * size * 2);
        data->Poke(0, (const char*)buffer, size * size * 2);
    
        auto map = CreatePixmap(size, size, TEXTURE_R16, data);
        map->Save("Test.dds");
    
        vector<shared_ptr<Pixmap>> mipchain;
        mipchain.push_back(map);
        auto texture = CreateTexture(TEXTURE_2D, size, size, map->format, mipchain);
        auto mat = CreateMaterial();
        mat->SetTexture(texture, TEXTURE_DIFFUSE);
        //mat->SetTexture(LoadTexture("Materials\\Developer\\bluegrid.dds"), TEXTURE_DIFFUSE);//Works
    
        delete[] buffer;
    
        auto custom_model = CreateModel(world);
        auto mesh = custom_model->AddMesh();
    
        int index = 0;
        for (int z = 0; z < size; z++) {
            for (int x = 0; x < size; x++) {
                mesh->AddVertex(x, 0.0f, z, 0.0f, 1.0f, 0.0f, (float)x / (float)size, (float)z / (float)size);
    
                if (x != 0 && x != size - 1 && z != 0 && z != size - 1) {
                    mesh->AddPrimitive(index, index - size - 1, index - 1);
                    mesh->AddPrimitive(index, index - size, index - size - 1);
                }
                index++;
            }
        }
        custom_model->UpdateBounds();
        custom_model->SetMaterial(mat);
    
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_F2) == true) { camera->SetWireframe(!camera->GetWireframe()); }
    
            auto _displaySize = window->GetSize();
            float cx = Round((float)_displaySize.x / 2.0f);
            float cy = Round((float)_displaySize.y / 2.0f);
    
            auto mpos = Vec3(window->GetMousePosition().x, window->GetMousePosition().y, window->GetMousePosition().z);
            window->SetMousePosition(cx, cy);
            mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
            auto dx = (mpos.x - cx) * lookspeed;
            auto dy = (mpos.y - cy) * lookspeed;
    
    
            auto camrot = camera->GetRotation();
            camrot.x += dy;
            camrot.y += dx;
            camera->SetRotation(camrot);
            mousepos = mpos;
    
            auto speed = 0.1f;
            if (window->KeyDown(KEY_SHIFT) == true) { speed = speed * 10.0f; }
            if (window->KeyDown(KEY_W) == true) { camera->Move(0, 0, speed); }
            else if (window->KeyDown(KEY_S) == true) { camera->Move(0, 0, -speed); }
            if (window->KeyDown(KEY_A) == true) { camera->Move(-speed, 0, 0); }
            else if (window->KeyDown(KEY_D) == true) { camera->Move(speed, 0, 0); }
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

×
×
  • Create New...