Jump to content

World falling


Guppy
 Share

Recommended Posts

Spent all morning figuring this one out and distilling it to it's very essence;

 

if you do

 

Leadwerks::Window::GetCurrent()->GetMousePosition();

 

inside app::start

 

the world will fall though you - or more specific; CSG boxes wont get drawn and barrels, etc will start falling while the FPS controller just hangs there.

 

 

Reason I'm trying to do the above is to have my gui class as encapsulated and easy to use as possible - so rather than requiring the user to pass a valid window instance it just grabs the current if none are specified.

 

I've several workaround ( like initializing on first draw call, etc ) but I don't understand why it's happing this way, I mean there should be no difference between calling through one pointer or another.

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

  • 4 months later...

I am unable to produce any error with this code:

#include "App.h"

using namespace Leadwerks;

App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}

App::~App() { delete world; delete window; }

Vec3 camerarotation;
bool freelookmode=true;

bool App::Start()
{
   //Initialize Steamworks (optional)
   /*if (!Steamworks::Initialize())
   {
       System::Print("Error: Failed to initialize Steam.");
       return false;
   }*/

   //Create a window
   window = Leadwerks::Window::Create("CPP TEST");

   //Create a context
   context = Context::Create(window);

   //Create a world
   world = World::Create();

   //Create a camera
   camera = Camera::Create();
   camera->Move(0,2,-5);

   //Hide the mouse cursor
   window->HideMouse();

   std::string mapname = System::GetProperty("map","Maps/start.map");
   Map::Load(mapname);

   Leadwerks::Window::GetCurrent()->GetMousePosition();

   //Move the mouse to the center of the screen
   window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2);

   return true;
}

bool App::Loop()
{
   //Close the window to end the program
   if (window->Closed()) return false;

   //Press escape to end freelook mode
   if (window->KeyHit(Key::Escape))
   {
       if (!freelookmode) return false;
       freelookmode=false;
       window->ShowMouse();
   }

   if (freelookmode)
   {
       //Keyboard movement
       float strafe = (window->KeyDown(Key:) - window->KeyDown(Key::A))*Leadwerks::Time::GetSpeed() * 0.05;
       float move = (window->KeyDown(Key::W) - window->KeyDown(Key::S))*Leadwerks::Time::GetSpeed() * 0.05;
       camera->Move(strafe,0,move);

       //Get the mouse movement
       float sx = context->GetWidth()/2;
       float sy = context->GetHeight()/2;
       Vec3 mouseposition = window->GetMousePosition();
       float dx = mouseposition.x - sx;
       float dy = mouseposition.y - sy;

       //Adjust and set the camera rotation
       camerarotation.x += dy / 10.0;
       camerarotation.y += dx / 10.0;
       camera->SetRotation(camerarotation);

       //Move the mouse to the center of the screen
       window->SetMousePosition(sx,sy);
   }

   Leadwerks::Time::Update();
   world->Update();
   world->Render();
   context->Sync(false);

   return true;
}

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...