Not sure if its a bug or feature
Using AWPConvexHullShape and noticed no matter what model I used it always has an extra height from the ground of 4 units.
See the red sphere
http://www.shrewballooba.co.uk/convex/
Im sure I read somewhere that bullet uses 4 units as a distance between objects and the ground.
But why does it only show with convex hull?
package
{
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.debug.AwayStats;
import away3d.library.AssetLibrary;
import away3d.lights.DirectionalLight;
import away3d.events.LoaderEvent;
import away3d.materials.ColorMaterial;
import away3d.primitives.Plane;
import away3d.primitives.Sphere;
import awayphysics.collision.shapes.AWPCompoundShape;
import awayphysics.collision.shapes.AWPConvexHullShape;
import awayphysics.collision.shapes.AWPSphereShape;
import awayphysics.collision.shapes.AWPStaticPlaneShape;
import awayphysics.dynamics.AWPDynamicsWorld;
import awayphysics.dynamics.AWPRigidBody;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
import flash.geom.Matrix3D;
import flash.geom.Vector3D;
import flash.display.Sprite;
import flash.events.Event;
import uk.co.shrewballooba.away4.camera.HoverDragController;
// [SWF(width="800", height="450", frameRate="60", backgroundColor="#000000")]
public class AWPConvexHullShapeTest extends Sprite
{
private var timeStep : Number = 1.0 / 60;
private var view : View3D;
private var camController:HoverDragController;
private var physicsWorld:AWPDynamicsWorld;
private var scene:Scene3D;
private var light:DirectionalLight;
public function AWPConvexHullShapeTest()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
view = new View3D();
view.antiAlias = 8;
view.backgroundColor = 0xfcfcfc
view.camera.z = -2000;
view.camera.lens.far = 8000;
addChild(view);
scene = view.scene;
camController = new HoverDragController(view.camera, stage);
camController.radius = 200;
physicsWorld = AWPDynamicsWorld.getInstance();
physicsWorld.initWithDbvtBroadphase();
addChild(new AwayStats(view));
light = new DirectionalLight();
scene.addChild(light);
initObjects();
}
private function initObjects():void
{
var material:ColorMaterial = new ColorMaterial(0x252525);
material.bothSides = true;
material.lights = [light];
var ground : Plane = new Plane(material, 50000, 50000);
scene.addChild(ground);
var groundShape : AWPStaticPlaneShape = new AWPStaticPlaneShape(new Vector3D(0, 0, -1));
var groundRigidbody : AWPRigidBody = new AWPRigidBody(groundShape, ground, 0);
physicsWorld.addRigidBody(groundRigidbody);
// set ground rotation
var rot : Matrix3D = new Matrix3D();
rot.appendRotation(90, new Vector3D(1, 0, 0));
groundRigidbody.rotation = rot;
groundRigidbody.friction = 0.03
//AWPConvexHullShape center sphere with issue
var redmat:ColorMaterial = new ColorMaterial(0xff4a2f);
redmat.lights = [light];
var s:Sphere = new Sphere(redmat, 25);
scene.addChild(s);
// s.geometry.scale(new Vector3D(1, 0.25, 1));
var sShape:AWPConvexHullShape = new AWPConvexHullShape(s);
var sRb:AWPRigidBody = new AWPRigidBody(sShape, s, 1);
physicsWorld.addRigidBody(sRb);
//Just checking sphere shape doesnt do same
var greenmat:ColorMaterial = new ColorMaterial(0x3dff2f);
greenmat.lights = [light];
var s2:Sphere = new Sphere(greenmat, 25);
scene.addChild(s2);
var sShape2:AWPSphereShape = new AWPSphereShape(25);
var sRb2:AWPRigidBody = new AWPRigidBody(sShape2, s2, 1);
sRb2.position = new Vector3D(80, 50, 0);
physicsWorld.addRigidBody(sRb2);
//Using compound shape to fix AWPConvexHullShape issue
var bluemat:ColorMaterial = new ColorMaterial(0x3d4aff);
bluemat.lights = [light];
var s3:Sphere = new Sphere(bluemat, 25);
// s3.geometry.scale(new Vector3D(1, 0.25, 1));
scene.addChild(s3);
var compoundShape:AWPCompoundShape = new AWPCompoundShape();
var sShape3:AWPConvexHullShape = new AWPConvexHullShape(s3);
compoundShape.addChildShape(sShape3, new Vector3D(0, 4, 0), new Matrix3D());
var sRb3:AWPRigidBody = new AWPRigidBody(compoundShape, s3, 1);
sRb3.position = new Vector3D(-80, 50, 0);
physicsWorld.addRigidBody(sRb3);
this.addEventListener(Event.ENTER_FRAME, handleEnterFrame);
}
private function handleEnterFrame(e : Event) : void
{
physicsWorld.step(timeStep);
view.render();
}
}
}
ps I used sphere is just for quick demo any model does the same thing.