Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 19 Mar 2004
Offline Last Active Aug 03 2012 02:09 PM

Topics I've Started

force required for body to reach certain height

08 September 2009 - 05:56 AM

I'm having trouble with an formula to calculate the force required to push a body up to a certain height. That is, the body should reach a velocity of zero at the specified height. Gravity and air friction act upon the body (though perhaps the latter can be ignored as it is likely to be negligible). I want to use this to make the player jump to climb up on an obstacle. Given are: * vertical distance * body mass * gravity (9.8 m/s) * air friction coefficient The answer is probably very simple, but I don't know where to start.

[GLSL] parallax & offset limiting

13 July 2009 - 04:31 AM

I have functional parallax working but am wondering what the hell I've actually implemented. Is this normal parallax mapping? Or "Parallax mapping with offset limiting"? If the former, how do I turn the below snippet into the "offset limiting" version?
vec3 eye = normalize(eyeToSurfVec);

float pheight = (1.0-texture2D(texture4, uv1).a) * pscale - pbias;
uv1 += (eye.xz * pheight);

(Note: yes, eye.xz, I use this on on a flat floor, everything is in world space.) I've been told I'd want the "offset limiting" variant with "3 steps", to reduce the artifacts which become visible under steep angles. I've never been able to find an actual implementation of this (safe for the sample in the paper), much less in GLSL. Driving me nuts... Mucho thanks!

wxWidgets external mainloop

25 June 2009 - 06:41 AM

I'm trying to implement a build-in text editor into our game engine, but having trouble to integrate it. The editor is build with wxWidgets, but wx documentation on how to implement external main loops is scarce (demo/code samples seem to be non-existent). CEditor is a wrapper class that will implement a simple wx based text editor (CEditApp, derived from wxApp), which sits in it's own independent window. I can already compile it as stand-alone application via IMPLEMENT_APP(CEditApp) without changes, so I know the code is functional (and dare I say, bug-free). Some pseudo-code: (Warning to googlers from the future; the below code will probably not work for you!)
// initialize wx application
bool CEditor::Init(HINSTANCE blah)
 app = new CEditApp;
 wxApp::SetInstance( app );  // supposedly this is not needed, but harmless
 wxEntry(inst,blah);         // <--- crash!
 return true;

// handle all wx application related events
void CEditor::ProcessEvents()
 if (!app) return;
 // process events here:
 // * mouse/keyboard input
 // * redraw window/controls etc.
 // no idea how to do this at all

// unload wx application
void CEditor::Unload()
 if (!app) return;
 //wxApp::CleanUp();           // <--- does not even compile
 delete app;
 app = NULL;

// and this is the 
int WinMain(HINSTANCE inst, blah)
 // init stuff
 Editor.Init( inst );
 // engine main loop
 while (!exit)
  // do lots of stuff
  // etc.  
  // and also handle editor events
 // shutdown
 return 0;
The parts I'm struggling with: 1) Crash when wxEntry is called. I've tried both the cross platform version and the Windows version of this function. In either case, a crash occurs which I can trace to the editor window resize event (::OnResize). But I know the app runs flawlessly stand-alone, so this is probably related to the wxApp initialization (or lack thereof). I also create a window via SDL, GL context and render to it, but I think it should not interfere (I'll test this to be sure). 2) The main loop. wxWidgets prefers you to surrender your own mainloop to the build-in wx mainloop (aka MessageLoop/EventLoop). However, I cannot change my entire engine framework just for this, and also, the engine can be compiled without editor (thus without wxWidgets dependency). Button clicks, dropdown menus, common dialogs, etc. halting the game mainloop is not a problem, and in fact is desirable (I would run the editor in a separate thread if do not I want that). The only documentation I can find about this is to override the internal wx MainLoop, but that's not what I'm looking for. What I need is something like wxApp::ProcessEvents(), that processes all pending window messages, and redraws the window and controls. I guess I will have to manually implement that, but I cannot find exactly what the default wx MainLoop is supposed to call (I guess I will have to dig into the guts of wxWidgets itself). Any pointers? 3) Cleanup. The wxWiki refers to wxApp::CleanUp() but I have no idea in what context it is intended to be used. I cannot produce any code with this line that compiles. Many thanks if you can help me out! :) [Edited by - remdul on June 25, 2009 1:45:05 PM]

main loop trouble

14 January 2009 - 10:44 PM

Hi, I have a problem in my main loop, the the game seems to hang for a second or so after executing a CPU intensive process deep inside the loop. I'll first show the relevant code:
 Console.Print("Main loop...\n");
 unsigned int curtime;
 unsigned int newtime;
 double delta;
 double accum = 0.0;
 curtime = SDL_GetTicks();
  // measure time
  newtime = SDL_GetTicks();
  delta = (double)(newtime-curtime) / 1000;
  curtime = newtime;
  // inner main loop
  if (delta > 0.0) {
   accum += delta;
   while(accum >= TIMESTEP && !System.exit)
    accum -= TIMESTEP;
   System.fps = 1.0 / (float)delta;
  // draw
 Console.Print("Shutting down...\n");

This code is called in the main() function. The outer loop continuously redraws the screen, the inner loop takes care of all game routines and physics. It is done this way to ensure a fixed time step (we don't interpolate between physics updates, but that's something I may change later). Before the game loop (code not shown), the config files are loaded, display surface/ audio is initialized, the GUI is loaded etc. This works fine. Once the main loop is started, the game sits in idle in the game main menu. At some point during the runtime of the game, the user loads a level. This occurs inside the inner loop, System.Input() to be exact, as the action is triggered by a button click. The load-level routine is then started. The 'load level' function does this each time a level resource (e.g. texture or model) has been loaded from file:
 ComputeProgress(); // computes progress, how far the level has been loaded
 System.Input();    // user can cancel process by pressing ESC
 System.Draw();     // redraw screen to show progress bar updates

Once the level is fully loaded, the 'load level' routine is exited, we return to the inner main loop. We expect the loading screen to disappear and the first frame of the 3d world will be drawn. What I then observe is the following: 1) the first frame of the game is drawn instantly when the progress bar hits 100% (so far so good) 2) after the first frame is drawn (System::Draw, called in outer loop) the game 'hangs' for a few seconds (longer load time seems to cause longer hang) 3) after the second frame there seems to be a second shorter hang, but I'm not entirely sure 4) then the game continues to run smoothly from the 3rd frame on, no noticeable hangs During the hangs, the game is responsive to input, this means that System::Input() is being called. That indicates that during the 'hang', the inner main loop is called for large number of iterations, and the screen never gets redrawn until it exits the inner loop. I *think* the hang happens because the timer is thrown off by the very large time difference that occurs inside System::Input (the 'load level' routine typically takes 30 seconds or so before SDL_GetTicks is called again). The second hang, *i guess*, could be triggered by the first 'hang'. For the same reason, long time elapsed since last SDL_GetTicks, though shorter than the first. As you can tell from the source, the timer code is isolated from the rest of the code, so it cannot be influenced outside the main() function. But I can't wrap my head around the problem, I can't seem to reconstruct what exactly happens. Do you have any idea? Thanks. :)

worldspace normalmap - tangent space normalmap

02 October 2008 - 11:27 AM

I'm trying to convert a world space normal map to tangent space normal map, with the help of existing TBN matrix (I cannot change these). How do I do this? Someone suggested to me that all I have to do is rotate the world space normal by the TBN matrix, but it doesn't give correct results... Thanks.