Box2d - 2D physics

Previous topic - Next topic

Ruidesco

I don't know if it's some strange behaviour on Vista/x64, but I did notice that too.

While coding and testing the SunVox wrapper, it seemed that whenever I opened the project some of the INLINEs (not all of them, just the first four or five INLINEs) had their IFs, RETURNs and such common keywords automatically uppercased. I suspect it had something to do with parsing the code for bad casing on opening a project, since they were always saved with their correct C lower case.

Kitty Hello

It's really bad. I have not found the last occourance, yet.
You can set the "auto-capitalize" option for the Editor to "On Save", that should really prevent it.

AMateus

Hello,

Doing some test with Box2D. Copied the Box2D.gbas, box2d.h and everything in the Source dir from the project in the first page. When compiling give me this error...

Code (glbasic) Select

C:\Users\ANTNIO~1\AppData\Local\Temp\glbasic\gpc_temp1.cpp: In function `DGInt __GLBASIC__::b_CreatePoly(DGInt, DGInt, DGInt, DGInt, DGInt, __GLBASIC__::DGIntArray&)':
C:\Users\ANTNIO~1\AppData\Local\Temp\glbasic\gpc_temp1.cpp:492: error: no match for call to `(__GLBASIC__::DGIntArray) (int&, int)'
D:/Program Files (x86)/GLBasic/Compiler/platform/Include/glb.h:402: note: candidates are: DGInt& __GLBASIC__::DGIntArray::operator()(int)
D:/Program Files (x86)/GLBasic/Compiler/platform/Include/glb.h:442: note:                 __GLBASIC__::DGIntArray& __GLBASIC__::DGIntArray::operator()()
C:\Users\ANTNIO~1\AppData\Local\Temp\glbasic\gpc_temp1.cpp:492: error: no match for call to `(__GLBASIC__::DGIntArray) (int&, int)'
D:/Program Files (x86)/GLBasic/Compiler/platform/Include/glb.h:402: note: candidates are: DGInt& __GLBASIC__::DGIntArray::operator()(int)
D:/Program Files (x86)/GLBasic/Compiler/platform/Include/glb.h:442: note:                 __GLBASIC__::DGIntArray& __GLBASIC__::DGIntArray::operator()()
*** FATAL ERROR - Please post this output in the forum


If I run the project from the first page everything is ok.

Any ideias?

Thanks,
António

AMateus

#153
Also, I'm no even using any command from the wrapper.. I've just add the file for future use  :blink:

I'm also doing some tests on the example and something is terribly wrong... sometimes compiles, sometimes don't. Even if I copy my files to the example project and run it sometimes has erros, sometimes don't.. I'm completly lost here... :|

my code for your review (I have a main file - this on -, the box2d wrapper, and a utils library, nothing more):

Code (glbasic) Select

GLOBAL SysInfo AS tSystemInfo // Current Platform Info
GLOBAL AppInfo AS tApplicationInfo // Application defined Info

GLOBAL sw%, sh% // Screen Resolution
GLOBAL aw%, ah% // Application defined resolution

GLOBAL lGameRunning // Indicates the game is running. If FALSE then go to the menu
GLOBAL iAppState // Indicates in what stage the application is: 1-Intro 2-Menu 3-Game

GLOBAL lDebug // Indicates if the application is in debugmode

GOSUB InitializeApplication

doSleep = TRUE

b_InitWorld(0,0, aw%,ah%,  0.0, 10.0, doSleep)

WHILE lGameRunning=TRUE

b_Update(0.1, 10)

IF lDebug THEN b_WorldDebug()

SHOWSCREEN
WEND

SUB GLB_ON_QUIT:
b_Cleanup()
ENDSUB

SUB InitializeApplication:

ALLOWESCAPE TRUE

SysInfo.GetCurrentResolution(sw%,sh%)
AppInfo.GetAppResolution(aw%,ah%)

lGameRunning = TRUE
iAppState = 1

lDebug=TRUE
ENDSUB

SUB CloseApplication:
ENDSUB


Inside the project dir I copied from the example the source dir, the documentation dir and the Box2D.h file.

Any help?!

Thanks,
AMateus

AMateus

Some more info...

If I use the example with some commented lines (see bellow) I have compile errors:

Code (glbasic) Select

doSleep = TRUE

// Box
DRAWRECT 0,0,32,32,RGB(255,255,255)
GRABSPRITE 0, 0,0,32,32
CLEARSCREEN

DRAWRECT 0,0,320,32,RGB(0,100,255)
GRABSPRITE 1, 0,0,320,32
CLEARSCREEN

b_InitWorld(0,0, 640,480,  0.0, 10.0, doSleep)

//LOCAL box1%, ground%
//box1 = b_CreateBox(1, .2, .5, 301,20,32,32)
//box2 = b_CreateBox(1, 3.2,.5, 347,20,32,32)
//cir1 = b_CreateCircle(1,1,.5, 290,-10,25)
//ground = b_CreateGroundbox(323,300,320,32)
//
//
//DEBUG "box1 "+box1+"\n"
//DEBUG "box2 "+box2+"\n"
//DEBUG "cir1 "+cir1+"\n"
//DEBUG "gnd  "+ground+"\n"
//
//// a triangle
//LOCAL pts[]
//DIM pts[3][2]
// // polygon points (clockwise!!)
// //        x            y
// pts[0][0]=0; pts[0][1]=0
// pts[1][0]=20;pts[1][1]=15
// pts[2][0]=0; pts[2][1]=20
// b_CreatePoly( 1, 2.0, 0.5,  301,60, pts[])
//
//
//
//b_BodySetAngle(box1,47)
//
//b_BodySetAngle(box2,44)

WHILE TRUE
b_Update(0.1, 10)

// ROTOSPRITE 0, b_BodyGetPosX(box1)-16,    b_BodyGetPosY(box1)-16,   b_BodyGetAngle(box1)
// ROTOSPRITE 0, b_BodyGetPosX(box2)-16,    b_BodyGetPosY(box2)-16,   b_BodyGetAngle(box2)
// ROTOSPRITE 1, b_BodyGetPosX(ground)-160, b_BodyGetPosY(ground)-16, b_BodyGetAngle(ground)


b_WorldDebug() // debug a wireframe of what's happening
SHOWSCREEN
WEND




SUB GLB_ON_QUIT:
b_Cleanup()
ENDSUB


Really don't understand why. I only comment the drawing routines...

AMateus

Well, one afternoon to find the solution... nevermind the 3 post above =)

António

Kitty Hello

See update in post #1:
Code (glbasic) Select

// iWhat: 1 - contact, 0 - persistent, -1 - contact released
IF LEN(b_Collisions[]) THEN INC iStep%
FOREACH col IN b_Collisions[]
DEBUG iStep% + "Collision: "+col.iBody1+", "+col.iBody2+" = "+col.iWhat+"\n"
NEXT


Is that of any use?

AMateus

Oh yes IT IS! =)  :nw: :nw: :nw:

Thank you thank you thank you :)

AMateus

Hello,

I'm having problems with destroying a body in the Box2D environment.

Everytime I try to b_DestroyBody(wall) I have the following reaction:

1- I do b_DestroyBody(wall) on contact. The wall only disappears AFTER the next collision with a different object happens

2 - The next collisions (variable) the App crashes.

Please see the attachment. The ball will go right and collide with the right wall. The expected behavior is that the wall should disappear right away, but it only disappears in the next collision. Then when it collides with the left wall the app crashes.

I appreciate if someone could help me.

Thanks,
AMateus


[attachment deleted by admin]

AMateus

Well, following my previous post, I did more tests and it *seems* the problem is in the b_WorldDebug function of the wrapper. I'll have to do more tests (mainly replacing the lines of b_WorldDebug with sprites, cause when I'm prototyping I have only placeholders) to confirm it.

António


AMateus

#160
Ok guys, I can now confirm that b_WorldDebug crashes the application if b_DestroyBody is used.

It's possible that b_WorldDebug tries to use a body already deleted, but I leave that to the C experts out there.

Regards,
António

Kitty Hello

Bugfix in 1st post. (Update your browser's cache).
The pointer was not set to NULL in the body list in b_DestroyBody. So sorry...

AMateus

You're the best :)

Thank you so much Kitty.

António

Smashton

#163
Quote from: Kitty Hello on 2011-Sep-28
It's really bad. I have not found the last occourance, yet.
You can set the "auto-capitalize" option for the Editor to "On Save", that should really prevent it.

How do you do that? How do I set this option in my editor. I can't find it. Also are you going to support Mouse Joint? Thank you for your help.

Kitty Hello

Tools/Options -> Reformat code on compile (or so...) the checkbox.