Hello Box2D Community!
I just started using Box2D and realy like the simplicity. Today I started implementing the Hello World with SFML. When I ran it (not finished yet) I got a crap-load of errors 😮 :
This is very weird because I didn't have any problems running the standard helloworld.cpp.
This is my code so far:
//INCLUDES
#include <SFML/Graphics.hpp>
#include "Box2D.h"
int main()
{
//INIT SFML
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Physics Game");
//INIT PHYSICS
//create gravity
b2Vec2 gravity(0.0f, -9.81f);
//stop inactive bodies
bool doSleep = true;
//create world
b2World world(gravity, doSleep);
//PHYSICS
//create groundbody definition
b2BodyDef groundBodyDef;
//give th definition a position
groundBodyDef.position.Set(0.0f, -10.0f);
//create ground body on position
b2Body* groundBody = world.CreateBody(&groundBodyDef);
//create a box in our body
b2PolygonShape groundBox;
groundBox.SetAsBox(50.0f, 10.0f);
groundBody->CreateFixture(&groundBox);
//Create the cuwl box in this game! :D
//Define
b2BodyDef bodyDef;
//make it a dynamic
bodyDef.type = b2_dynamicBody;
//set position
bodyDef.position.Set(0.0f, 4.0f);
//put the body in our world
b2Body* body = world.CreateBody(&bodyDef);
//make the shape
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(1.0f, 1.0f);
//give the box properties!
//define
b2FixtureDef fixtureDef;
//the shape
fixtureDef.shape = &dynamicBox;
//density
fixtureDef.density = 1.0f;
//friction
fixtureDef.friction = 0.3f;
//create the fixture
body->CreateFixture(&fixtureDef);
//make a 60Hz timestep
float32 timeStep = 1.0f / 60.0f;
//velocity and position iterations
int32 velocityIterations = 10;
int32 positionIterations = 10;
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
//Take a step
world.Step(timeStep, velocityIterations, positionIterations);
//clear the forces applied
world.ClearForces();
//get the position
b2Vec2 position = body->GetPosition();
//get the angle
float32 angle = body->GetAngle();
// Clear the screen (fill it with black color)
App.Clear();
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
It isn't finished yet!
I think it is a one thing fix because I didn't get the erorrs in the .cpp file.
I hope someone can help me out here! 🙂
-Yuri
I just started using Box2D and realy like the simplicity. Today I started implementing the Hello World with SFML. When I ran it (not finished yet) I got a crap-load of errors 😮 :
Code:
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(20) : error C2661: 'b2World::b2World' : no overloaded function takes 2 arguments
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(31) : error C2512: 'b2PolygonShape' : no appropriate default constructor available
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(32) : error C2039: 'SetAsBox' : is not a member of 'b2PolygonShape'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\collision\shapes\b2polygonshape.h(55) : see declaration of 'b2PolygonShape'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(33) : error C2039: 'CreateFixture' : is not a member of 'b2Body'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\dynamics\b2body.h(99) : see declaration of 'b2Body'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(40) : error C2039: 'type' : is not a member of 'b2BodyDef'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\dynamics\b2body.h(37) : see declaration of 'b2BodyDef'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(40) : error C2065: 'b2_dynamicBody' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(47) : error C2512: 'b2PolygonShape' : no appropriate default constructor available
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(48) : error C2039: 'SetAsBox' : is not a member of 'b2PolygonShape'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\collision\shapes\b2polygonshape.h(55) : see declaration of 'b2PolygonShape'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(52) : error C2065: 'b2FixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(52) : error C2146: syntax error : missing ';' before identifier 'fixtureDef'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(52) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(54) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(54) : error C2228: left of '.shape' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(56) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(56) : error C2228: left of '.density' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(58) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(58) : error C2228: left of '.friction' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(61) : error C2039: 'CreateFixture' : is not a member of 'b2Body'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\dynamics\b2body.h(99) : see declaration of 'b2Body'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(61) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(85) : error C2660: 'b2World::Step' : function does not take 3 arguments
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(87) : error C2039: 'ClearForces' : is not a member of 'b2World'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\dynamics\b2world.h(52) : see declaration of 'b2World'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(31) : error C2512: 'b2PolygonShape' : no appropriate default constructor available
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(32) : error C2039: 'SetAsBox' : is not a member of 'b2PolygonShape'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\collision\shapes\b2polygonshape.h(55) : see declaration of 'b2PolygonShape'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(33) : error C2039: 'CreateFixture' : is not a member of 'b2Body'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\dynamics\b2body.h(99) : see declaration of 'b2Body'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(40) : error C2039: 'type' : is not a member of 'b2BodyDef'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\dynamics\b2body.h(37) : see declaration of 'b2BodyDef'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(40) : error C2065: 'b2_dynamicBody' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(47) : error C2512: 'b2PolygonShape' : no appropriate default constructor available
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(48) : error C2039: 'SetAsBox' : is not a member of 'b2PolygonShape'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\collision\shapes\b2polygonshape.h(55) : see declaration of 'b2PolygonShape'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(52) : error C2065: 'b2FixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(52) : error C2146: syntax error : missing ';' before identifier 'fixtureDef'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(52) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(54) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(54) : error C2228: left of '.shape' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(56) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(56) : error C2228: left of '.density' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(58) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(58) : error C2228: left of '.friction' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(61) : error C2039: 'CreateFixture' : is not a member of 'b2Body'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\dynamics\b2body.h(99) : see declaration of 'b2Body'
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(61) : error C2065: 'fixtureDef' : undeclared identifier
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(85) : error C2660: 'b2World::Step' : function does not take 3 arguments
1>c:\users\yuri\documents\visual studio 2008\projects\box2d-first\box2d-first\main.cpp(87) : error C2039: 'ClearForces' : is not a member of 'b2World'
1> c:\users\yuri\documents\visual studio 2008\box2d\source\dynamics\b2world.h(52) : see declaration of 'b2World'
This is very weird because I didn't have any problems running the standard helloworld.cpp.
This is my code so far:
Code:
//INCLUDES
#include <SFML/Graphics.hpp>
#include "Box2D.h"
int main()
{
//INIT SFML
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Physics Game");
//INIT PHYSICS
//create gravity
b2Vec2 gravity(0.0f, -9.81f);
//stop inactive bodies
bool doSleep = true;
//create world
b2World world(gravity, doSleep);
//PHYSICS
//create groundbody definition
b2BodyDef groundBodyDef;
//give th definition a position
groundBodyDef.position.Set(0.0f, -10.0f);
//create ground body on position
b2Body* groundBody = world.CreateBody(&groundBodyDef);
//create a box in our body
b2PolygonShape groundBox;
groundBox.SetAsBox(50.0f, 10.0f);
groundBody->CreateFixture(&groundBox);
//Create the cuwl box in this game! :D
//Define
b2BodyDef bodyDef;
//make it a dynamic
bodyDef.type = b2_dynamicBody;
//set position
bodyDef.position.Set(0.0f, 4.0f);
//put the body in our world
b2Body* body = world.CreateBody(&bodyDef);
//make the shape
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(1.0f, 1.0f);
//give the box properties!
//define
b2FixtureDef fixtureDef;
//the shape
fixtureDef.shape = &dynamicBox;
//density
fixtureDef.density = 1.0f;
//friction
fixtureDef.friction = 0.3f;
//create the fixture
body->CreateFixture(&fixtureDef);
//make a 60Hz timestep
float32 timeStep = 1.0f / 60.0f;
//velocity and position iterations
int32 velocityIterations = 10;
int32 positionIterations = 10;
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
//Take a step
world.Step(timeStep, velocityIterations, positionIterations);
//clear the forces applied
world.ClearForces();
//get the position
b2Vec2 position = body->GetPosition();
//get the angle
float32 angle = body->GetAngle();
// Clear the screen (fill it with black color)
App.Clear();
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
It isn't finished yet!
I think it is a one thing fix because I didn't get the erorrs in the .cpp file.
I hope someone can help me out here! 🙂
-Yuri