Game Development Community

Box2d/Chipmunk/etc physics?

by Tyler Slabinski · in iTorque 2D · 05/08/2011 (6:40 pm) · 12 replies

EDIT: Okay, I found out how to make collisions act as rigid bodies, and I was able to mimic what I needed for the basics.

However, I was hoping for more 'advanced' functionality. Does anyone know if there is a resource explaining how to integrate a 3rd party physics library? Like Box2D or Chipmunk physics?

#1
05/08/2011 (10:17 pm)
@Tyler - There is a resource for Torque 2D on Windows (link), but not iTorque 2D.
#2
05/09/2011 (2:34 pm)
Here is the Box2D integration for iTorque2D: http://code.google.com/p/tgb-box2d-integration/

There is a link to a pdf on that page that explains some of the steps necessary. Unfortunately, the document/code base has not been updated along with Torque so some changes will not match up directly, but with some work it is do-able. Saved us weeks of work.

I would recommend ignoring Michael's advice to change the TickShift to 4 instead of 5, as iTorque2D may hit the performance ceiling a bit too quickly at 60fps.


Good Luck!
#3
05/09/2011 (2:38 pm)
Sorry, need to correct my post. I guess Perry and I are talking about the same thing. The resource works for iTorque2D, even if it wasn't created with it in mind. You can get it working on a Mac by importing the Box2d library into your xCode project. That is the only thing I can think of that he doesn't address on the Mac.

#4
05/09/2011 (2:50 pm)
It's pretty straight forward, likewise consider not changing the tick-shift if the simulation is smooth enough.
#5
05/09/2011 (6:01 pm)
"Straightforward" to some people is certainly not straightforward to me.

I'm not very good at using Xcode, and I have no knowledge of the collision system Torque uses. I'll be trying to figure this out as best as I can, but if anyone has any more experience with this, please share. I'll be posting the steps I've taken so far while I do this (just because I know I'll be making some sort of mistake).

EDIT: Okay, so far I was able to make the necessary changes to remove the memory manager. However, I would like some help on this next step:

Quote:Now add the Box2D Visual Studio project to the TGB Solution. To do this right-click on the Solution in the Solution Explorer in Visual Studio and select "Add -> Existing Project...". Browse to the directory "engine/lib/Box2D/Build/VC8" and there select "Box2D.vcproj" (do not confuse with Box2D.sln). Next open the Properties of the project TGBGame.
- Select Configuration Properties/C/C++/General in the tree-view to the left. In the Additional Include Directories property add the directory ../../lib/Box2D/Include.
- Select Configuration Properties/Linker/General and add the directory ../../lib/Box2D/Library to the Additional Library Directories property.
- Select Configuration Properties/Linker/Input and add box2d.lib to the Additional Dependencies property.7
At last close the Properties dialog and right-click on the TGBGame project again and select Project Dependencies. In the Dependencies tab activate check-box of the Box2D entry. Click OK.

Unfortunately, I have no idea how I would go about doing that in Xcode. Is there someone who knows what I would need to do?
#6
05/09/2011 (8:36 pm)
Give this a try (note, i wrote this before XCode 4 and things might be slightly different now):
- Load your project in XCode
- Right Click on the left panel under Groups & Files, select 'Add' and then 'Existing Files'.
- Add the T2D/Box2D 'ref' files that are provided in the source code Micheal provides.
- Download Box2D ver: 2.0.1
- Right Click on the left panel under Groups & Files, select 'Add' and then 'Existing Files'.
- Add the 'Source' and 'Library' folders from your Box2D download.

You will need to do this for the TGB and also for your project.
#7
05/10/2011 (4:57 pm)
Okay, that is working, so I have all that done, however I am guessing I didn't do the first step correctly.

I make the necessary changes to the Torque Memory Manage (which I am guessing I had to make it to macCarbMemory.cc). However, I couldn't figure out what the preprocessor directive went, so I just put it in the project settings at "Preprocessor Macros":

img3.imageshack.us/img3/1439/preprocessorscreenie.png
Am I completely doing this wrong? This is what I have in my .cc file:

//-----------------------------------------------------------------------------
// Torque Game Engine 
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#include "platform/platform.h"
#include <stdlib.h>
#include <string.h>

//--------------------------------------
#if defined(new) && !defined(TORQUE_DISABLE_MEMORY_MANAGER)
#undef new
#endif

#ifndef TORQUE_DISABLE_MEMORY_MANAGER
void* FN_CDECL operator new(dsize_t, void* ptr)
{
	return (ptr);
}
#endif

...
#8
06/28/2011 (4:32 pm)
I got lost, I would appreciate clarification

a) iTorque2D (for iphone) comes with box2D integrated? or do we have to do it ourselves?

b) if I buy iTorque2D today, whose current version is 1.4. When version 1.5 arrives, would I have the upgrade for free? or should I have to pay something? In that case.. when 1.5 is expected?

Thanks for any answer on this
#9
06/28/2011 (7:54 pm)
Box2D is currently not integrated, but I do believe it is on the staffs agenda to do so. Doing so would certainly boost the engines prestige.

And no. Once you sign up, updates are free.
#10
06/29/2011 (6:59 am)
@Rennie - We have put up many free updates...it doesn't mean they will always be free.
#11
06/29/2011 (7:52 am)
oh. My mistake. It is just that all of mine, in two years have been. My apologies. Any foreseeable paid updates and why? as in what will we be getting with them. Also, box2D, will it be a reality in the foreseeable future? any other cool stuff?


Thanks.
#12
10/06/2011 (10:50 am)
Hi, sorry to bring this subject back again. I did the Box2D integration with TGB with no issues; and looks great. BUT no luck with iT2D 1.5.
Is weird, because the compilation doesn't have errors; but when I tried to run the game:
• Bad screen update. Looks like there is no "clear screen" after the sprite movement. So, all objects leave a trail
• Cannot grab the object with the proper behavior ("Box2dMouseJointObjectBehavior.cs")

What could be the problem? I'm not good with C++ (yet) so the only way that I have is to wait that someone fix this, :). So, does anybody know if there is a solution to this? (TGB and iTorque2D 1.5 with Box2D integration).

THANKS!!