Author Topic: Box2D and iPhone?  (Read 1891 times)

Offline AlienMenace

  • Mr. Polyvector
  • ***
  • Posts: 149
    • View Profile
Box2D and iPhone?
« on: 2011-Feb-24 »
Hello,

Searched the forums and read some posts about Box2D and iPhone but still don't understand how to get this working. Does anybody have a working version of Box2D for iPhone they could post and perhaps quick sample program?

Thank you.
AM
Apps published: 3

Offline msx

  • Prof. Inline
  • *****
  • Posts: 773
    • View Profile
Re: Box2D and iPhone?
« Reply #1 on: 2011-Feb-24 »
There are samples in GLBasic. Just look.  :good:

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Box2D and iPhone?
« Reply #2 on: 2011-Feb-24 »
You have to compile the Box2D project with GLBasic for iPhone, but before doing that, in the Project/Options menu select "iPhone" from the box and type:
Code: GLBasic [Select]
-O2
 
in the box that says: "cmp". This diables the full optimization and bypasses the iPhone compiler bug.

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1542
    • View Profile
Re: Box2D and iPhone?
« Reply #3 on: 2011-Feb-24 »
Other than that, there is no other difference in the Windows version compile. Cool eh?  :-[

Offline AlienMenace

  • Mr. Polyvector
  • ***
  • Posts: 149
    • View Profile
Re: Box2D and iPhone?
« Reply #4 on: 2011-Feb-25 »
Thanks for the replies.  I did find out that -o2 is not the same as -O2. :)

Does work on this continue? I noticed several things seem to be missing like prismatic & pulley joints, motors, and callbacks.  I wish I had the C background to do this, I'd really love to see a complete implementation of Box2D for GLB.

If anybody wants to finish this, I'd be willing to convert some of my Box2D demos from Darkbasic.
« Last Edit: 2011-Feb-25 by AlienMenace »
Apps published: 3

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Box2D and iPhone?
« Reply #5 on: 2011-Feb-25 »
Cool. - Post the request in the Box2D thread.
http://www.glbasic.com/forum/index.php?topic=3561.0

Offline AlienMenace

  • Mr. Polyvector
  • ***
  • Posts: 149
    • View Profile
Re: Box2D and iPhone?
« Reply #6 on: 2011-Apr-29 »
I swear that this language will be the death of me.  :rant:

Okay, my latest frustation involves trying to use box2d. Last night I was able to put together a small demo and it was working great. Today, I load up that same exact demo and lo and behold, it now wants to have errors.

Console output:

Code: GLBasic [Select]
Wordcount:102 commands
compiling:
C:\Users\AM\AppData\Local\Temp\glbasic\gpc_temp1.cpp: In function `DGInt __GLBASIC__::b_CreatePoly(DGInt, DGInt, DGInt, DGInt, DGInt, DGInt, DGInt, __GLBASIC__::DGIntArray&)':
C:\Users\AM\AppData\Local\Temp\glbasic\gpc_temp1.cpp:550: error: no match for call to `(__GLBASIC__::DGIntArray) (int&, int)'
C:/Coding/GLBasic/Compiler/platform/Include/glb.h:402: note: candidates are: DGInt& __GLBASIC__::DGIntArray::operator()(int)
C:/Coding/GLBasic/Compiler/platform/Include/glb.h:442: note:                 __GLBASIC__::DGIntArray& __GLBASIC__::DGIntArray::operator()()
C:\Users\AM\AppData\Local\Temp\glbasic\gpc_temp1.cpp:550: error: no match for call to `(__GLBASIC__::DGIntArray) (int&, int)'
C:/Coding/GLBasic/Compiler/platform/Include/glb.h:402: note: candidates are: DGInt& __GLBASIC__::DGIntArray::operator()(int)
C:/Coding/GLBasic/Compiler/platform/Include/glb.h:442: note:                 __GLBASIC__::DGIntArray& __GLBASIC__::DGIntArray::operator()()
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.6 sec. Time: 20:13
Build: 0 succeeded.
*** 1 FAILED ***
 

and here is the code that it seems to be referring to...

Code: GLBasic [Select]
//! Create a polygonal shaped object. The pts[] is a 2D array
//! that has the polygon points. The last point must not equal the first point.
//! pts[] must be clockwise points.
FUNCTION b_CreatePoly: mass, friction, restitution, lineardamp, angulardamp, x, y, pts[]
        INLINE
        b2BodyDef def;
        def.position.Set(x,y);
        def.linearDamping = lineardamp;
        def.angularDamping = angulardamp;
        b2Body* pBody = bWorld->CreateBody( &def );
        b2PolygonDef poly;
                poly.vertexCount = LEN(pts);
                for(int i=0; i<LEN(pts); ++i)
                {
                        poly.vertices[i] = b2Vec2(pts(i,0), pts(i,1));
                }
                if(mass>0.0) poly.density = mass;
                poly.friction = friction;
                poly.restitution = restitution;
                pBody->CreateShape( &poly);
                if(mass>0.0) pBody->SetMassFromShapes();
        return b_NewObject(pBody, bBody);
        ENDINLINE
ENDFUNCTION
 

If I remove this section from the included file, the program runs. Let me stress that it worked fine with this code last night.
WTH?
Apps published: 3

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Box2D and iPhone?
« Reply #7 on: 2011-Apr-29 »
somewhere in your code write:
LOCAL a[]
DIM a[0][0]

-> This tells GLBasic that you are using arrays with at least 2 dimensions. If you only have 1D arrays, GLBasic uses a bit faster access functions. And the pre-compiler ignores INLINE code.

That should be done in the library (Box2D) you are using.