Author Topic: Box2d - 2D physics  (Read 16945 times)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 2288
  • Integrated Brain
    • View Profile
Re: Box2d - 2D physics
« Reply #120 on: 2011-May-09 »
Hi friends, I´ve got a question about the polygon creator command.

Well I try to make shapes whit more of 7 index on the first dimension of the array, but the code crashes.

It´s limited this command to 7 index (1st Index), or perhaps I made some wrong.

Kinds Regards,
Iván J.


Offline neseir

  • Mc. Print
  • *
  • Posts: 21
    • View Profile
Re: Box2d - 2D physics
« Reply #121 on: 2011-May-09 »
Hi

There are a limitation in the Box2D code that limits the number of polygonvertices to 8. It is located in the b2settings.h file (line 75 : const int32 b2_maxPolygonVertices = 8;)

Regards
Eirik
« Last Edit: 2011-May-09 by neseir »

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 2288
  • Integrated Brain
    • View Profile
Re: Box2d - 2D physics
« Reply #122 on: 2011-May-11 »
HI neseir, lot of thanks I go to see this.
Thanks  :nw:

Iván J.

Offline quangdx

  • Mr. Polyvector
  • ***
  • Posts: 172
  • work hard / play hard
    • View Profile
    • Asobitech
Re: Box2d - 2D physics
« Reply #123 on: 2011-Jul-24 »
Is there a command to destroy/remove objects after they've been created?
Also there doesn't seem to be any commands to manually set the x and y position of an object that has already been created.
Any help here would be great.
« Last Edit: 2011-Jul-24 by quangdx »
Asobitech 1UP Game series,
52 games in 1 year, a new game every Sunday.
http://www.asobitech.com

Offline backslider

  • Prof. Inline
  • *****
  • Posts: 856
    • View Profile
Re: Box2d - 2D physics
« Reply #124 on: 2011-Jul-25 »
Hi there,

you should download the library from page 6 in this thread.

The direct link is: http://www.glbasic.com/forum/index.php?action=dlattach;topic=3561.0;attach=2262

Then you can use some "new" functions:

edited functions:
 - b_CreateCircle (extended parameters)
 - b_CreateBox    (extended parameters)
 - b_CreatePoly   (extended parameters)

new functions:
 - b_DestroyJoint% (function has now code to destroy joints)
 - b_destroyBody    (delete bodys that you don´t need)

cheers
visit our alpha gameplay demo of "Fränk'n'Hänk": http://www.devandart.com/games/fnh/index.html

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *****
  • Posts: 10292
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Box2d - 2D physics
« Reply #125 on: 2011-Jul-25 »
wouldn't it be better to put the extended parameters into a seperate function and update "any" shape after creation?

Offline quangdx

  • Mr. Polyvector
  • ***
  • Posts: 172
  • work hard / play hard
    • View Profile
    • Asobitech
Re: Box2d - 2D physics
« Reply #126 on: 2011-Jul-27 »
Hi there,

you should download the library from page 6 in this thread.

The direct link is: http://www.glbasic.com/forum/index.php?action=dlattach;topic=3561.0;attach=2262

Then you can use some "new" functions:

edited functions:
 - b_CreateCircle (extended parameters)
 - b_CreateBox    (extended parameters)
 - b_CreatePoly   (extended parameters)

new functions:
 - b_DestroyJoint% (function has now code to destroy joints)
 - b_destroyBody    (delete bodys that you don´t need)

cheers

Many thanks dude,
So for me to manually change the location of an Object at a later point,
I have to destroy the body then recreate it in the new location?
Would be a lot easy to just update the X pos and Y pos.
Asobitech 1UP Game series,
52 games in 1 year, a new game every Sunday.
http://www.asobitech.com

Offline backslider

  • Prof. Inline
  • *****
  • Posts: 856
    • View Profile
Re: Box2d - 2D physics
« Reply #127 on: 2011-Jul-28 »
Ah, sorry.

To move an object, you have to add the following function to your box2d library
Code: GLBasic [Select]
FUNCTION b_BodySetXForm: body%, x, y, angle // add this function to the wrapper
        INLINE
                b2Vec2 pos = bBody(body)->GetPosition();
                pos.x=x;
                pos.y=y;
                bBody(body)->SetXForm(b2Vec2(x,y), angle);
        ENDINLINE
ENDFUNCTION
 

Somebody should update the library with all functions in this thread and put it into the first post. :)
visit our alpha gameplay demo of "Fränk'n'Hänk": http://www.devandart.com/games/fnh/index.html

Offline bigsofty

  • Prof. Inline
  • *****
  • Posts: 1991
    • View Profile
Re: Box2d - 2D physics
« Reply #128 on: 2011-Jul-28 »
I started to add some features a while back but later programers would alter a copy of the original source and erase my changes in the process. It was like running up a sandy hill... this lib desperately needs an SVN IMHO.  :S
“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline backslider

  • Prof. Inline
  • *****
  • Posts: 856
    • View Profile
Re: Box2d - 2D physics
« Reply #129 on: 2011-Jul-28 »
*sign*
visit our alpha gameplay demo of "Fränk'n'Hänk": http://www.devandart.com/games/fnh/index.html

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *****
  • Posts: 10292
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Box2d - 2D physics
« Reply #130 on: 2011-Jul-28 »
I implemented all changes (except the parameter on creation extension - I''d like to see that in a seperate function) and updated post #1.

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: Box2d - 2D physics
« Reply #131 on: 2011-Jul-28 »
Out of interest I've read box2d is compatible with iOS with a small change to compiler parameters, but what about Android and WebOS?

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline backslider

  • Prof. Inline
  • *****
  • Posts: 856
    • View Profile
Re: Box2d - 2D physics
« Reply #132 on: 2011-Jul-28 »
With webOS the box2d-wrapper worked fine for me!
On Android I don´t know, but why not. :)
visit our alpha gameplay demo of "Fränk'n'Hänk": http://www.devandart.com/games/fnh/index.html

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: Box2d - 2D physics
« Reply #133 on: 2011-Jul-28 »
That's interesting to know. Thanks for that!

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *****
  • Posts: 10292
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Box2d - 2D physics
« Reply #134 on: 2011-Jul-28 »
the iOS compiler is broken. The others are pretty up to date so no problems I hope.