Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - W4ffleKing

Pages: [1]
1
General / Re: Another problem with SFML and Box2d! :)
« on: August 28, 2012, 09:38:33 pm »
Oh my... While stripping out the irrelevant stuff to post my code, I noticed I had missed a few uncasted integers. Apologies for the confusion, all is fine now :) Thank you FRex for your help and patience :D

2
General / Re: Another problem with SFML and Box2d! :)
« on: August 28, 2012, 07:52:14 pm »
Thanks for the suggestion, I tried it but the problem still exists. I attached an image of the problem, thanks again. :D

[attachment deleted by admin]

3
General / Another problem with SFML and Box2d! :)
« on: August 28, 2012, 04:34:15 am »
I know there are already many posts for similar issues, but I've read all of them and am somehow still struggling to get SFML shapes to align to Box2d bodies. The SFML shapes seem to be larger than the Box2d bodies and are offset. It'll probably be something simple, but I've checked over and over again and can't see the problem...

To create an 'object', I give SetAsBox() half of width/height, convert angles between radians and degrees, setOrigin() to half of width/height and divide by my scale (30) where necessary. In my main loop I setPosition() to the body's position * 30, and setRotation() to the body's angle * (180 / b2_pi).

My code is pretty disorganised at the moment, so here are the important bits...

Creating body and shape:

//phys body
        b2BodyDef tbodyDef;
        tbodyDef.type = b2_dynamicBody;
        tbodyDef.position.Set(500 / 30, 500 / 30);
        tbodyDef.angle = 0;
        tbody = world->CreateBody(&tbodyDef);
        b2PolygonShape tdynamicBox;
        tdynamicBox.SetAsBox(75 / 2 / 30, 75 / 2 / 30);
        b2FixtureDef tfixtureDef;
        tfixtureDef.shape = &tdynamicBox;
        tfixtureDef.density = 1.0f;
        tfixtureDef.friction = 0.3f;
        tbody->CreateFixture(&tfixtureDef);

        //sfml
        tbox = new sf::RectangleShape;
        tbox->setSize(sf::Vector2f(75, 75));
        tbox->setFillColor(sf::Color(163, 36, 18, 100));
        tbox->setOrigin(75 / 2, 75 / 2);
        tbox->setRotation(0);

In main loop:

b2Vec2 position2 = tbody->GetPosition();
        float32 angle2 = tbody->GetAngle();
        tbox->setPosition((position2.x * 30), (position2.y * 30));
        tbox->setRotation(angle2 * (180 / b2_pi));
        mainWindow->draw(*tbox);

After many hours of confusion and frustration, I give up and hope someone can help me out. Apologies if I missed anything important and for my poor explanation, thanks in advance! :D

Pages: [1]
anything