program works with Box2D Lite, but not Regular Box2D

Hi...I just downloaded Box2D for the first time today..and i can't get this to work right.

I an trying to set this up in a way that I can use it in a top down driving game.

I am having two main problems right now. First, things are not drawing in the right place. I couldn't find a detailed enough specifications about how bodies and fixtures are defined in the documentation. Because of this, I can't really tell if things are moving correctly in my scene.

Also, for some reason, when I set the linear velocity of the player body, it moves really slow until it hits something..then it bounces off at an insane speed..not sure why =/

any help with this would be appreciated.


Code:
#include "main.h"
#include <vector>
using std::vector;

// used to cap the framerate to 30 frames per second
unsigned int lastFlip = 0;

unsigned int FPS = 60;

// 1000 milliseconds divided by the desired frames per second
unsigned int frameTime = 1000 / FPS;

/////////////////// BOX 2D ///////////////////

int iterations = 10;
b2Vec2 gravity(0.0f, 0.0f); // TOP DOWN: no gravity
float maxPlayerSpeed = 50.0f;
float secToTopSpeed = 5.0f;

b2World world(gravity, true);
vector<b2Body*> bodies;
b2Body *player;

//////////////////////////////////////////////

void AddStaticBody(b2Vec2 position, b2Vec2 &width, float friction, float angle)
{
   b2BodyDef bodyDef;
   bodyDef.position.Set(position.x, position.y);
   b2Body *body = world.CreateBody(&bodyDef);
   
   b2PolygonShape box;
   box.SetAsBox(width.x / 2, width.y / 2);
   
   body->CreateFixture(&box, 0.0f);
   
   bodies.push_back(body);
}

void DrawBody(SDL_Surface *dest, b2Body* body)
{
   const b2Transform& transform = body->GetTransform();
   
   for (b2Fixture* f = body->GetFixtureList(); f != NULL; f = f->GetNext())
   {
      b2PolygonShape *box = (b2PolygonShape*)f->GetShape();
      
      b2Vec2 v1 = b2Mul(transform, box->GetVertex(0));
      b2Vec2 v2 = b2Mul(transform, box->GetVertex(1));
      b2Vec2 v3 = b2Mul(transform, box->GetVertex(2));
      b2Vec2 v4 = b2Mul(transform, box->GetVertex(3));

      lineRGBA(dest, (short)v1.x, (short)v1.y, (short)v2.x, (short)v2.y, 255, 0, 0, 255);
      lineRGBA(dest, (short)v2.x, (short)v2.y, (short)v3.x, (short)v3.y, 255, 0, 0, 255);
      lineRGBA(dest, (short)v3.x, (short)v3.y, (short)v4.x, (short)v4.y, 255, 0, 0, 255);
      lineRGBA(dest, (short)v4.x, (short)v4.y, (short)v1.x, (short)v1.y, 255, 0, 0, 255);
   }
}

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
   if(SDL_Init(SDL_INIT_VIDEO) != 0)
   {
      // show a standard windows message box to notify of failure, and end the program
      MessageBox(0, "Failed to Initialize SDL", "Errror", MB_OK | MB_ICONERROR);
      return -1;
   }

   // create an SDL window
   SDL_Surface *screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);
   


   if(screen == NULL)
   {
      MessageBox(0, "Failed to create an SDL window", "Errror", MB_OK | MB_ICONERROR);
      return -1;
   }
   
   SDL_WM_SetCaption("Box2D Demo", NULL);

   ////////////////////////// INIT BOX2D ////////////////////////////

   b2BodyDef playerBodyDef;
   playerBodyDef.type = b2_dynamicBody;
   playerBodyDef.position.Set(200.0f, 200.0f);
   player = world.CreateBody(&playerBodyDef);
   
   b2PolygonShape box;
   box.SetAsBox(25, 50);
   
   b2FixtureDef fixtureDef;
   fixtureDef.shape = &box;
   fixtureDef.density = 0.000001f;
   fixtureDef.friction = 0.2f;
   player->CreateFixture(&fixtureDef);
   player->SetLinearDamping(5.0f);
   player->SetAngularDamping(1.0f);
   //player->SetSleepingAllowed(false);

   // void AddStaticBody(b2Vec2 position, b2Vec2 &width, float friction, float angle)
   AddStaticBody(b2Vec2(400, 100), b2Vec2(100, 75), 0.2f, 0.0f);
   AddStaticBody(b2Vec2(380, 210), b2Vec2(75, 100), 0.2f, 0.0f);
   AddStaticBody(b2Vec2(410, 320), b2Vec2(75, 75), 0.2f, 0.0f);
   AddStaticBody(b2Vec2(460, 430), b2Vec2(100, 100), 0.2f, 0.0f);
   AddStaticBody(b2Vec2(350, 360), b2Vec2(75, 100), 0.2f, 0.0f);
   
   //////////////////////////////////////////////////////////////////

   // set this to true to end the game
   float time = 0.0f;
   lastFlip = SDL_GetTicks();

   b2Vec2 velocity;

   bool gameDone = false;
   while(gameDone == false)
   {
      // if enough time has passed, render the next frame
      if(SDL_GetTicks() - lastFlip >= frameTime)
      {
         // calculate time
         float elapsed = (float)(SDL_GetTicks() - lastFlip) / 1000.0f;
         time += elapsed;
         lastFlip = SDL_GetTicks();

         // move player
         SDL_PumpEvents();
         Uint8 *keys = SDL_GetKeyState(NULL);

         b2Vec2 input(0, 0);

         if(keys[SDLK_LEFT])  input.x -= 1.0f;
         if(keys[SDLK_RIGHT]) input.x += 1.0f;
         if(keys[SDLK_UP])    input.y -= 1.0f;
         if(keys[SDLK_DOWN])  input.y += 1.0f;

         float length = input.Length();
         if(length > 0)
         {
            float force = (maxPlayerSpeed / secToTopSpeed) * elapsed;

            input.Normalize();
            input *= force;
            player->ApplyLinearImpulse(input, player->GetPosition());
         }
         
         // update world
         world.Step(elapsed, 10, 10);

         // clear screen
         SDL_FillRect(screen, 0, 0);
         
         // draw world
         for (b2Body* b = world.GetBodyList(); b; b = b->GetNext())
         {
            DrawBody(screen, b);
         }

         // redraw
         SDL_Flip(screen);


         SDL_Event evt;
         while(SDL_PollEvent(&evt)){
            switch(evt.type){
               case SDL_QUIT:
                  gameDone = true;
                  break;
            }
         }
      }
   }

   SDL_Quit();

   return 0;
}
This is especially strange to me, because the following code works perfectly fine(using Box2D Lite)

but the full version gives me all kinds of wierd results
Code:
#include "main.h"
#include <vector>

using std::vector;

// used to cap the framerate to 30 frames per second
unsigned int lastFlip = 0;

unsigned int FPS = 60;

// 1000 milliseconds divided by the desired frames per second
unsigned int frameTime = 1000 / FPS;

/////////////////// BOX 2D ///////////////////

int iterations = 10;
Vec2 gravity(0.0f, 0.0f); // TOP DOWN: no gravity
float maxPlayerSpeed = 50.0f;
float secToTopSpeed = 2.0f;

World world(gravity, 10);
vector<Body*> bodies;
Body *player;

//////////////////////////////////////////////

void AddStaticBody(Vec2 position, Vec2 &width, float friction, float angle)
{
   Body *b = new Body;

   b->position = position;
   b->width = width;
   b->friction = friction;
   b->mass = 0.0;
   b->rotation = 0;
   
   world.Add(b);
}

void DrawBody(SDL_Surface *dest, Body* body)
{
   Mat22 R(body->rotation);
   Vec2 c = body->position;
   Vec2 w = 0.5f * body->width;

   Vec2 v1 = c + R * Vec2(-w.x, -w.y);
   Vec2 v2 = c + R * Vec2( w.x, -w.y);
   Vec2 v3 = c + R * Vec2( w.x,  w.y);
   Vec2 v4 = c + R * Vec2(-w.x,  w.y);

   lineRGBA(dest, (short)v1.x, (short)v1.y, (short)v2.x, (short)v2.y, 255, 0, 0, 255);
   lineRGBA(dest, (short)v2.x, (short)v2.y, (short)v3.x, (short)v3.y, 255, 0, 0, 255);
   lineRGBA(dest, (short)v3.x, (short)v3.y, (short)v4.x, (short)v4.y, 255, 0, 0, 255);
   lineRGBA(dest, (short)v4.x, (short)v4.y, (short)v1.x, (short)v1.y, 255, 0, 0, 255);
}

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
   if(SDL_Init(SDL_INIT_VIDEO) != 0)
   {
      // show a standard windows message box to notify of failure, and end the program
      MessageBox(0, "Failed to Initialize SDL", "Errror", MB_OK | MB_ICONERROR);
      return -1;
   }

   // create an SDL window
   SDL_Surface *screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);
   


   if(screen == NULL)
   {
      MessageBox(0, "Failed to create an SDL window", "Errror", MB_OK | MB_ICONERROR);
      return -1;
   }
   
   SDL_WM_SetCaption("Box2D Demo", NULL);

   ////////////////////////// INIT BOX2D ////////////////////////////

   Body *player = new Body;

   player->Set(Vec2(25, 50), 0.001f);
   player->position = Vec2(200, 200);
//   player->width = Vec2(25, 50);
   player->friction = 0.2f;
   //player->mass = 0.001;
   
   player->rotation = 0;
   
   world.Add(player);
   bodies.push_back(player);

   // void AddStaticBody(b2Vec2 position, b2Vec2 &width, float friction, float angle)
   AddStaticBody(Vec2(400, 100), Vec2(100, 75), 0.2f, 81.0f);
   AddStaticBody(Vec2(380, 210), Vec2(75, 100), 0.2f, 45.0f);
   AddStaticBody(Vec2(410, 320), Vec2(75, 75), 0.2f, 15.0f);
   AddStaticBody(Vec2(460, 430), Vec2(100, 100), 0.2f, 5.0f);
   AddStaticBody(Vec2(350, 540), Vec2(75, 100), 0.2f, 64.0f);
   
   //////////////////////////////////////////////////////////////////

   // set this to true to end the game
   float time = 0.0f;
   lastFlip = SDL_GetTicks();

   //b2Vec2 velocity;

   bool gameDone = false;
   while(gameDone == false)
   {
      // if enough time has passed, render the next frame
      if(SDL_GetTicks() - lastFlip >= frameTime)
      {
         // calculate time
         float elapsed = (float)(SDL_GetTicks() - lastFlip) / 1000.0f;
         time += elapsed;
         lastFlip = SDL_GetTicks();

         // move player
         SDL_PumpEvents();
         Uint8 *keys = SDL_GetKeyState(NULL);

         Vec2 input(0, 0);

         if(keys[SDLK_LEFT])  input.x -= 1.0f;
         if(keys[SDLK_RIGHT]) input.x += 1.0f;
         if(keys[SDLK_UP])    input.y -= 1.0f;
         if(keys[SDLK_DOWN])  input.y += 1.0f;

         float length = input.Length();
         if(length > 0)
         {
            // add user input to player
            float force = (maxPlayerSpeed / secToTopSpeed) * elapsed;
            input.x /= length;
            input.y /= length;
            input *= force;
            
            player->AddForce(input);
         }
         else
         {
            // decay linear velocity
            float decay = (maxPlayerSpeed / secToTopSpeed) * elapsed;
            float velLen = player->velocity.Length();
            if(velLen >= decay)
            {
               input = player->velocity;
               input.x /= velLen;
               input.y /= velLen;
               input *= -decay;
               player->velocity = player->velocity + input;
            }
            else
            {
               player->velocity = Vec2(0, 0);
            }
         }
         
         //decay angular velocity
         float angularDecay = k_pi / 4 * elapsed;
         if(player->angularVelocity >= angularDecay)
         {
            player->angularVelocity -= angularDecay;
         }
         else
         {
            player->angularVelocity = 0;
         }

         // update world
         world.Step(elapsed);

         // clear screen
         SDL_FillRect(screen, 0, 0);
         
         // draw player
         DrawBody(screen, player);

         // draw world
         for(Uint16 i = 0; i < bodies.size(); i++)
         {
            DrawBody(screen, bodies[i]);
         }


         // redraw
         SDL_Flip(screen);


         SDL_Event evt;
         while(SDL_PollEvent(&evt)){
            switch(evt.type){
               case SDL_QUIT:
                  gameDone = true;
                  break;
            }
         }
      }
   }

   for(Uint16 i = 0; i < world.bodies.size(); i++)
   {
      delete world.bodies[i];
   }

   SDL_Quit();

   return 0;
}
Got it!
the code in the original post has been updated to the working version.

Original thread: https://box2d.org/forum/viewtopic.php?t=6877