Hey,
I'm trying to setup a square in the middle of the screen that rotates at a consistent rate, and a ball that I can throw at it. I tried doing the same process of shape creation for a ball, but it doesn't seem to like certain values, and crashes at world.createBody.

Also, the cube in the middle seems to constantly increase in its rotational velocity, and I want it to rotate at one steady rate. Here's what I have so far:
(I'm using code from the SVN)
Code:
void Game_Loop (void)
{
Uint8 *keys;
bool done = false;
SDL_Event event;
unsigned long total_update;
// Box2D stuffs
worldAABB.minVertex.Set(0, 0);
worldAABB.maxVertex.Set(640.0f, 480.0f);
b2Vec2 gravity;
gravity.x = 0.0f;
gravity.y = 0.0f;
bool doSleep = true;
b2World world(worldAABB, gravity, doSleep);
// spinning cube in the center
b2PolyDef cs;
cs.type = e_polyShape;
cs.vertexCount = 4;
cs.vertices[0].Set(-100, -100);
cs.vertices[1].Set(100, -100);
cs.vertices[2].Set(100, 100);
cs.vertices[3].Set(-100, 100);
cs.density = 1.0f;
cs.friction = 1.0f;
b2BodyDef cube;
cube.AddShape(&cs);
cube.position.Set(320.0f, 240.0f);
cube.angularVelocity = 100.0f;
b2Body *cubeBody = world.CreateBody(&cube);
cubeBody->SetAngularVelocity(1);
// ************
while(!done) {
// check FPS timer things
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYUP:
break;
case SDL_KEYDOWN: // single key events
ProcessKey(event.key.keysym.sym);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
ProcessClick(event.button);
break;
case SDL_VIDEORESIZE:
screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 32,
SDL_OPENGL|SDL_RESIZABLE);
if (screen) {
ReSizeGLScene(event.resize.w, event.resize.h);
} else {
// boom.
}
break;
case SDL_QUIT:
done = 1;
break;
}
}
modifiers = SDL_GetModState();
keys = SDL_GetKeyState(NULL); // constant key events
sys_counter = SDL_GetTicks();
if (!oldticks)
oldticks = sys_counter - 1000;
total_update = sys_counter - oldticks;
timediff = MIN(total_update, UPDATE_SIZE);
while (total_update > 0)
{
if (!paused)
{
world.Step(timediff/1000.0f, 10);
timecounter += timediff;
}
total_update -= timediff;
timediff = MIN(total_update, UPDATE_SIZE);
}
// DRAW SCENE HERE!
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Setup2D();
glColor4f(1,1,1,1);
// DRAW CUBE
glPushMatrix();
glTranslatef(cube.position.x, cube.position.y, 0);
glRotatef(cubeBody->GetRotation(), 0, 0, 1);
glBegin(GL_LINE_LOOP);
for (int i=0; i < cs.vertexCount; i++)
glVertex2f(cs.vertices[i].x, cs.vertices[i].y);
glEnd();
glPopMatrix();
// ******
// DRAW BALL
/*/ glPushMatrix();
glTranslatef(cube.position.x, cube.position.y, 0);
glBegin(GL_LINE_LOOP);
for (int i=0; i < cs.vertexCount; i++)
glVertex2f(ss.vertices[i].x, ss.vertices[i].y);
glEnd();
glPopMatrix();*/
FinishGL();
SDL_GL_SwapBuffers();
done = terminate ? true : done;
}
}
I've tried a couple of different methods and I have trouble with each. Is this right? How should I continue?
Thanks,
Entar