Hi,
Basically my app works like this:
Timer every 33 miliseconds -> Re-render
I want this to become
Timer -> Calculate physics -> Re-render
My rendering system looks like this:
main.cpp:
The "render" function is in a seperate source file render.cpp:
Now, I've added a new file called physics.cpp. However, I already run into problems when creating the world. This is how it looks now:
This however poses the problem that the world stops existing after the initialize function is done. I don't see a way to globally define world, so that it actually keeps existing.
How would I do that? Or should I implent the physics in a whole other way anyway?
Basically my app works like this:
Timer every 33 miliseconds -> Re-render
I want this to become
Timer -> Calculate physics -> Re-render
My rendering system looks like this:
main.cpp:
Code:
case WM_PAINT:
render(hwnd);
break;
case WM_TIMER:
//Force Windows to redraw the window
InvalidateRect(hwnd, NULL, TRUE);
break;
render(hwnd);
break;
case WM_TIMER:
//Force Windows to redraw the window
InvalidateRect(hwnd, NULL, TRUE);
break;
The "render" function is in a seperate source file render.cpp:
Code:
int render(HWND hwnd)
{
//Variables
PAINTSTRUCT psInfo;
//Prepare painting
HDC hdc = BeginPaint(hwnd, &psInfo);
//Create surfaces
if (doneloading == false)
{
bmBackground = CreateCompatibleDC(hdc);
hbmOld = (HBITMAP)CreateCompatibleBitmap(hdc, 1000, 700);
SelectObject ( bmBackground, hbmOld );
doneloading = true;
}
//Draw background
RECT rcBackground;
rcBackground.left = 0;
rcBackground.top = 0;
rcBackground.right = 1000;
rcBackground.bottom = 700;
FillRect(bmBackground, &rcBackground, CreateSolidBrush(RGB(255, 255, 255)));
//Draw physical objects
//Flip buffers
BitBlt(hdc, 0, 0, 1000, 700, bmBackground, 0, 0, SRCCOPY);
//Stop painting
EndPaint(hwnd, &psInfo);
return 1;
}
{
//Variables
PAINTSTRUCT psInfo;
//Prepare painting
HDC hdc = BeginPaint(hwnd, &psInfo);
//Create surfaces
if (doneloading == false)
{
bmBackground = CreateCompatibleDC(hdc);
hbmOld = (HBITMAP)CreateCompatibleBitmap(hdc, 1000, 700);
SelectObject ( bmBackground, hbmOld );
doneloading = true;
}
//Draw background
RECT rcBackground;
rcBackground.left = 0;
rcBackground.top = 0;
rcBackground.right = 1000;
rcBackground.bottom = 700;
FillRect(bmBackground, &rcBackground, CreateSolidBrush(RGB(255, 255, 255)));
//Draw physical objects
//Flip buffers
BitBlt(hdc, 0, 0, 1000, 700, bmBackground, 0, 0, SRCCOPY);
//Stop painting
EndPaint(hwnd, &psInfo);
return 1;
}
Now, I've added a new file called physics.cpp. However, I already run into problems when creating the world. This is how it looks now:
Code:
//Box2D Physics engine
#include "Box2D.h"
//Variables
b2AABB worldAABB;
void pInitialize()
{
//Create world
worldAABB.lowerBound.Set(-500.0f, -350.0f);
worldAABB.upperBound.Set(500.0f, 350.0f);
b2Vec2 gravity(0.0f, -10.0f);
bool doSleep = true;
b2World world(worldAABB, gravity, doSleep);
}
void pStep()
{
}
#include "Box2D.h"
//Variables
b2AABB worldAABB;
void pInitialize()
{
//Create world
worldAABB.lowerBound.Set(-500.0f, -350.0f);
worldAABB.upperBound.Set(500.0f, 350.0f);
b2Vec2 gravity(0.0f, -10.0f);
bool doSleep = true;
b2World world(worldAABB, gravity, doSleep);
}
void pStep()
{
}
This however poses the problem that the world stops existing after the initialize function is done. I don't see a way to globally define world, so that it actually keeps existing.
How would I do that? Or should I implent the physics in a whole other way anyway?