Author Topic: Problem with BOX2d code for Ground Body  (Read 2352 times)

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Problem with BOX2d code for Ground Body
« on: November 14, 2012, 02:38:46 pm »
Dear all,
For this line:groundBody->CreateFixture(&groundBox);
Apparently:
error C2664: 'b2Fixture *b2Body::CreateFixture(const b2FixtureDef *)' : cannot convert parameter 1 from 'b2PolygonShape *' to 'const b2FixtureDef *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


Finally, i am getting quite a lot of warnings: conversion from 'const float' to 'int', possible loss of data. is this a major problem?

Thank you for your help

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: Problem with BOX2d code for Ground Body
« Reply #1 on: November 14, 2012, 02:39:36 pm »
Maybe it might help you to answer the question if I post the whole block of code

Code: [Select]
//b2Vec2 Gravity(0, -9.8); //normal earth gravity, 9.8 m/s/s straight down!
Gravity.Set(0.0f, EARTH_GRAVITY);               // Set default gravity vector:
const bool AllowSleep = true;
world = new b2World(Gravity, AllowSleep);


b2BodyDef groundBodyDef; //initialise ground body
groundBodyDef.position.Set(0.0f, 240*SCALE);

//set ground position in container at (0,240) initially
b2Body* groundBody = world->CreateBody(&groundBodyDef); //create a ground polygon
b2PolygonShape groundBox;

groundBox.SetAsBox(240*SCALE, 60*SCALE);
//groundBox.SetAsBox(36.0f, 3.0f); //form ground polygon into a box shape. Centre box on origin of the parent body
//SetAsBox(1,2): 1 = half width
//2 = half height
//half width=240; half height=60

groundBody->CreateFixture(&groundBox); //creating a shape fixture for the ground body



//b2BodyDef rectangle;
//rectangle.type = b2_dynamicBody; //this will be a dynamic body
//rectangle.position.Set(spriteX*SCALE, spriteY*SCALE);
////rectangle.position.Set(0.0f, 20.0f); //set the starting position
////220, 180
//rectangle.angle = 0; //set the starting angle




//Creating dynamic bodies
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody; //by default == static, make them dynamic
bodyDef.position.Set(spriteX*SCALE, spriteY*SCALE);
//(220,180)
b2Body* body = world->CreateBody(&bodyDef);

//creating and attaching a polygon shape using a fixture definition
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(1.0f, 1.50f);
//sprite pixel width = 40
//sprite pixel height = 60

b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f; //set density
fixtureDef.friction = 0.3f; //set friction
body->CreateFixture(&fixtureDef);

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: Problem with BOX2d code for Ground Body
« Reply #2 on: November 14, 2012, 02:46:46 pm »
Maybe it might help you to answer the question if I post the whole block of code

Code: [Select]
//b2Vec2 Gravity(0, -9.8); //normal earth gravity, 9.8 m/s/s straight down!
Gravity.Set(0.0f, EARTH_GRAVITY);               // Set default gravity vector:
const bool AllowSleep = true;
world = new b2World(Gravity, AllowSleep);


b2BodyDef groundBodyDef; //initialise ground body
groundBodyDef.position.Set(0.0f, 240*SCALE);

//set ground position in container at (0,240) initially
b2Body* groundBody = world->CreateBody(&groundBodyDef); //create a ground polygon
b2PolygonShape groundBox;

groundBox.SetAsBox(240*SCALE, 60*SCALE);
//groundBox.SetAsBox(36.0f, 3.0f); //form ground polygon into a box shape. Centre box on origin of the parent body
//SetAsBox(1,2): 1 = half width
//2 = half height
//half width=240; half height=60

groundBody->CreateFixture(&groundBox); //creating a shape fixture for the ground body



//b2BodyDef rectangle;
//rectangle.type = b2_dynamicBody; //this will be a dynamic body
//rectangle.position.Set(spriteX*SCALE, spriteY*SCALE);
////rectangle.position.Set(0.0f, 20.0f); //set the starting position
////220, 180
//rectangle.angle = 0; //set the starting angle




//Creating dynamic bodies
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody; //by default == static, make them dynamic
bodyDef.position.Set(spriteX*SCALE, spriteY*SCALE);
//(220,180)
b2Body* body = world->CreateBody(&bodyDef);

//creating and attaching a polygon shape using a fixture definition
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(1.0f, 1.50f);
//sprite pixel width = 40
//sprite pixel height = 60

b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f; //set density
fixtureDef.friction = 0.3f; //set friction
body->CreateFixture(&fixtureDef);


Sorry, problem has just been solved.