Hi, I'm playing with actionscript3 port of this engine.
At the beginning i wanted to understand what can be done, and how it can be done with box2d.
I created some complex shapes. But there seems to be bug where small poligon shapes tend to pass through other poligon shapes, and even accelerate while doing it. (I created basked - movable, and small boxes seem to pass through baskets skewed sides)
I tried to compare svn versions and see what changes have been done to fix this (or similar) issue in C++ version. But code looks like pretty much different.
Maybe somebody has fixed this issue in AS3 port already, or AS3 port or Box2d Does not support that kind of shapes ?
Attachment:
basket.jpg [ 34.39 KiB | Viewed 331 times ]
Code for this example:
Code:
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
package TestBed{
import Engine.Dynamics.*;
import Engine.Collision.*;
import Engine.Collision.Shapes.*;
import Engine.Dynamics.Joints.*;
import Engine.Dynamics.Contacts.*;
import Engine.Common.*;
import Engine.Common.Math.*;
public class TestExample extends Test{
public function TestExample(){
// Set Text field
Main.m_aboutText.text = "Example";
var ground:b2Body = m_world.m_groundBody;
var bd:b2BodyDef;
var body:b2Body;
var circ:b2CircleDef = new b2CircleDef();
var box:b2BoxDef = new b2BoxDef();
var myBox:b2BoxDef = new b2BoxDef();
var basketBox1:b2BoxDef = new b2BoxDef();
var basketBox2:b2BoxDef = new b2BoxDef();
var basketBox3:b2BoxDef = new b2BoxDef();
var basketBody:b2BodyDef = new b2BodyDef();
var jd:b2RevoluteJointDef
var i:int;
var angle:Number;
var tX:Number;
var tY:Number;
// Create basket
{
basketBox1.extents.Set(40 / m_physScale, 5 / m_physScale);
basketBox1.localPosition.Set(-60/ m_physScale,20 / m_physScale);
basketBox1.localRotation = 45 / 180 * Math.PI;
basketBox1.density = 1;
basketBox1.restitution = 0.5;
basketBox1.friction = 1;
basketBox2.extents.Set(40 / m_physScale, 5 / m_physScale);
basketBox2.localPosition.Set(60/ m_physScale,20 / m_physScale);
basketBox2.localRotation = -45 / 180 * Math.PI;
basketBox2.density = 1;
basketBox2.restitution = 0.5;
basketBox2.friction = 1;
basketBox3.extents.Set(30 / m_physScale, 5 / m_physScale);
basketBox3.localPosition.Set(0/ m_physScale,50 / m_physScale);
basketBox3.density = 1;
basketBox3.restitution = 0.5;
basketBox3.friction = 1;
basketBody.AddShape(basketBox1);
basketBody.AddShape(basketBox2);
basketBody.AddShape(basketBox3);
basketBody.position.Set(260 / m_physScale, 155 / m_physScale);
m_world.CreateBody(basketBody);
}
// Create plane, ball and dominoes
{
// excentic hammer
circ.radius = 10 / m_physScale;
circ.density = 1;
circ.friction = 0.5;
circ.restitution = 0;
bd = new b2BodyDef();
bd.AddShape(circ);
myBox.extents.Set(70 / m_physScale, 3 / m_physScale);
myBox.localPosition.Set(0,50 / m_physScale);
myBox.density = 5;
myBox.localRotation = 0.5 * Math.PI;
bd.AddShape(myBox);
bd.position.Set(160 / m_physScale, 55 / m_physScale);
m_world.CreateBody(bd);
}
// Box, ramp, and circle
{
// Simple Cirlce
circ.radius = 15 / m_physScale;
circ.density = 1;
circ.friction = 0.5;
circ.restitution = 1;
bd = new b2BodyDef();
bd.AddShape(circ);
bd.position.Set(510 / m_physScale, 120 / m_physScale);
m_world.CreateBody(bd);
}
// Stack of small boxes
{
// box
box.extents.Set(7 / m_physScale, 7 / m_physScale);
box.friction = 1;
box.density = 0.5;
bd = new b2BodyDef();
bd.AddShape(box);
for (var x:int = 0; x < 3; x++){
for (var y:int = 0; y < 15; y++){
bd.position.Set((50 + x * 16) / m_physScale, (348 - y * 13.5) / m_physScale);
body = m_world.CreateBody(bd);
body.m_flags |= b2Body.e_sleepFlag;
}
}
}
}
}
}
Thanks