Sign in to follow this  

dark gdk and box2d rotation not working right

Recommended Posts

my code:


#include "DarkGDK.h"
#include "Box2D/Box2D.h"
#include <time.h>

float face1X,face1Y, face2X,face2Y,a;

bool Click = false;

    char SCREEN_VALUE[50] = "";

void DarkGDK ( void )


    dbSyncOn   ( );
    dbSyncRate ( 60 );

    b2Vec2 gravity(0.0f,50.0f);
    bool doSleep = false;
    b2World world(gravity);
    b2BodyDef groundBodyDef;
    b2Body* groundBody = world.CreateBody(&groundBodyDef);
    b2PolygonShape groundBox;
    groundBox.SetAsBox(600.0f, 10.0f);
    groundBody->CreateFixture(&groundBox, 0.0f);

    b2BodyDef myBodyDef;
    myBodyDef.type = b2_dynamicBody;//this will be a dynamic body
  myBodyDef.position.Set(200, 20); //set the starting position
  myBodyDef.angle = 0; //set the starting angle

  b2Body* dynamicBody = world.CreateBody(&myBodyDef);
  b2PolygonShape boxShape;
  b2FixtureDef boxFixtureDef;
  boxFixtureDef.shape = &boxShape;
  boxFixtureDef.density = 10;
  boxFixtureDef.friction = 1.3;

    // next

            b2BodyDef bodyDef1;
    bodyDef1.type = b2_dynamicBody;
    bodyDef1.position.Set(260.0f, 100.0f);
    b2Body* body1 = world.CreateBody(&bodyDef1);

    b2PolygonShape dynamicBox1;
    dynamicBox1.SetAsBox(50.0f, 50.0f);

    b2FixtureDef fixtureDef1;
    fixtureDef1.shape = &dynamicBox1;
    fixtureDef1.density = 10;
    fixtureDef1.friction = 1.3f;


    float32 timeStep = 1.0f / 60.0f;
    int32 velocityIterations = 6;
    int32 positionIterations = 2;


    dbLoadImage ("file\\back.png",1);
    dbLoadImage ("file\\1.png",2);


    while ( LoopGDK ( ) )

    world.Step(timeStep, velocityIterations, positionIterations);
    b2Vec2 position = dynamicBody->GetPosition();
    float32 angle = dynamicBody->GetAngle();

    b2Vec2 position1 = body1->GetPosition();
    float32 angle1 = body1->GetAngle();

    face1X = position.x;
    face1Y = position.y;
    face2X = position1.x;
    face2Y = position1.y;

            strcpy(SCREEN_VALUE," debug: ");
        dbText(dbScreenWidth()-705,10,SCREEN_VALUE );



        position1.x = dbMouseX();
        position1.y = dbMouseY();

            Click = true;

            Click = true;

            if( dbMouseClick() != 1 && Click )
                Click = false;




sry for mess in code... but as long as i can read it it's ok...

i create 2 body one on other and
slightly to left that it rotate but object only slide from object and not rotating... and if i change angle 45 degrees and when object hit ground it's still stand on edge 45 degrees rotated

Any ideas?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this