Jump to content

SpiderPig

Members
  • Posts

    2,285
  • Joined

  • Last visited

Everything posted by SpiderPig

  1. 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; }
  2. I don't think so. The position readout seems to be accurate but the fact that it jumps down like that as soon as it starts updating shouldn't happen I think. It should start falling slowly from the higher position.
  3. 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. After two key hits the cylinder snaps instantly to the lower position.
  4. 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 ...
  5. Is it possible for me to start physics when I want to rather than it being automatic? I could load all aspects of the game and then after a few frames are rendered start the physics thread.
  6. 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.
  7. I agree, I have run into to similar situations with my voxel terrain. The mesh class is fast but it can be faster as you say.
  8. There's also this addon for blender. Haven't tried it myself yet but it looks pretty good. https://blendermarket.com/products/ravage?ref=2
  9. 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. #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; }
  10. Just tested an .r16 map too. It seems some of the values are being clamped. auto buffer = LoadBuffer("Terrain.r16"); auto map = CreatePixmap(256, 256, TEXTURE_R16, buffer); map->Save("Test.dds"); Terrain.zip
  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: Result with bluegrid.dds: Result with R16 texture: 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; }
  12. Yes it saves now, thanks. Thanks @klepto2 I think VK_FORMAT_R16_UINT does what I want it too.
  13. Might be related to the problem. I've never seen the shadow polygons get that high.
  14. SpiderPig

    small_optimization

    Wow impressive stats! Good job.
  15. SpiderPig

    small_optimization

    Sounds pretty flexable. Will it have cumulonimbus?
  16. SpiderPig

    small_optimization

    Now that's cool. So you can use masks to change the shape?
  17. SpiderPig

    small_optimization

    Looks great, good stuff. Optimizing projects is the fun part.
  18. Posted a bug report for the saving issue. https://www.ultraengine.com/community/topic/62096-cant-save-r16-pixmap-as-dds/
  19. I'm not sure if I'm actually setting the buffer correctly, but the problem here is it fails to save as a DDS image. #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 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 = 1024; 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"); delete[] buffer; while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } Output: Saving texture "Test.dds" Error: Unsupported pixel format 76 can't be saved to DDS. Error: Failed to save texture "Test.dds".
  20. Also I couldn't save a pixmap with R16 format as DDS. I saw you had it working here though, is this no longer supported?
  21. Oh cool, thanks. And that'll still between 0 and 1 yeah?
  22. Can I still sample a half float texture like this? vec4 color = texture(texture2DSampler[textureID], texcoords.xy); Or is there a different function for this? I don't know what the value of the vec4 would actually be...
×
×
  • Create New...