Jump to content

EirikNesje

Developers
  • Posts

    4
  • Joined

  • Last visited

Everything posted by EirikNesje

  1. Hi Had the same issue. After Instaling the Windows 10 SDK it started to work for me. BR Eirik
  2. Hi Did some more testing and now it is working as I wanted. Had to use : auto pick = world->Pick(sphere->GetPosition(), Vec3(sphere->GetPosition().x, lowest, sphere->GetPosition().z), 0.0f, true); It was the radius parameter I got wrong. Set it to expected max value but it looks like it works with 0.0f. Instead of using the pick.entity.Position it worked perfect using the pick.position (which looks to be the location of the casted ray entering the entity found. The whole test program looks like this : #include <string> #include "UltraEngine.h" #include "ComponentSystem.h" using namespace UltraEngine; #define SPHERE_SIZE 0.5f #define SPHERE_MOVE_FORCE 10.0f #define SPHERE_JUMP_FORCE 500.0f 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(); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 7, 2); // Load map auto scene = LoadScene(world, "Maps/new.map"); //Create sphere auto sphere = CreateSphere(world, SPHERE_SIZE); sphere->SetColor(1, 0, 0); sphere->SetPosition(2, 10, 2); sphere->SetMass(1); // Get z-position to put camera on and minimal y value of scene float closest = 999.0f; float lowest = -999.0f; for (auto current : scene->entities) { auto aabb = current->GetBounds(); if (aabb.min.z < closest) closest = aabb.min.z; if (aabb.min.y < lowest) lowest = aabb.min.z; } float distanceToEntity = 0.0f; //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { // check if sphere is in the air bool airborne = false; auto pick = world->Pick(sphere->GetPosition(), Vec3(sphere->GetPosition().x, lowest, sphere->GetPosition().z), 0.0f, true); if (pick.success) { distanceToEntity = sphere->GetPosition().y - pick.position.y; } if (distanceToEntity > (SPHERE_SIZE + 0.1f)) { airborne = true; } // Adding torque can be done while in the air causing a spin effect on contact :-) // Add torque to the Z-axis (moving along the x-axis) if (window->KeyDown(KEY_A)) { sphere->AddTorque(Vec3(0.0f, 0.0f, SPHERE_MOVE_FORCE)); } if (window->KeyDown(KEY_D)) { sphere->AddTorque(Vec3(0.0f, 0.0f, -SPHERE_MOVE_FORCE)); } // Add torque to the X-axis (moving along the z-axis) if (window->KeyDown(KEY_S)) { sphere->AddTorque(Vec3(-SPHERE_MOVE_FORCE, 0.0f, 0.0f)); } if (window->KeyDown(KEY_W)) { sphere->AddTorque(Vec3(SPHERE_MOVE_FORCE, 0.0f, 0.0f)); } if (!airborne) { if (window->KeyHit(KEY_SPACE)) { sphere->AddForce(Vec3(0.0f, SPHERE_JUMP_FORCE, 0.0f)); } } world->Update(); camera->SetPosition(sphere->GetPosition().x, 7.0f, closest); camera->Point(sphere); world->Render(framebuffer); } return 0; } Using a map (new.map) that looks like this: Rolling up the ramp had some issues when using the entity's position. Using the PickInfo's position worked well. BR Eirik
  3. Thanks for the information. Will do some more testing and update with result. Currently using the PickInfo.success to test for hit but will change to calculate the distance using the positions as You mentions. If still problem I will drop some code in this thread. BR Eirik
  4. Hi I would like to get the distance from an entity to a scene/map loaded. Intend to use the position of the entity and do a call to a vector on the same x and z values but lower to get the height above the map. Have tested with requesting the first entity but it is always in a distance of -1 (have set the start vector below the mesh to avoid getting the entity I'm using as a start vector for the ray cast). Are there any examples on using a list of entities hit by the ray cast or will not the ray cast register the scene as a hit (not an entity) ? Have also used player physics and it worked well and GetAirborne did much of the same as I want to achieve but not using PHYSICS_PLAYER. (just as an entity with mass). BR Eirik
×
×
  • Create New...