Beispiel #1
0
        public Body(World world, Collision collision)
            : base(NativeAPI.CreateBody(world.handle, collision.handle))
        {
            this.World = world;
            this.collision = collision;

            IntPtr ptr = GCHandle.ToIntPtr(GCHandle.Alloc(this));
            NativeAPI.BodySetUserData(handle, ptr);

            NativeAPI.BodySetDestructorCallback(handle, NativeDestructorHandler);
        }
Beispiel #2
0
        internal static Collision FromNewtonCollision(World world, IntPtr newtonCollision)
        {
            NativeAPI.NewtonCollisionInfoRecord info;
            NativeAPI.CollisionGetInfo(newtonCollision, out info);

            Collision collision;

            switch (info.m_collisionType)
            {
                case NativeAPI.SERIALIZE_ID_BOX:
                case NativeAPI.SERIALIZE_ID_CONE:
                case NativeAPI.SERIALIZE_ID_SPHERE:
                case NativeAPI.SERIALIZE_ID_CAPSULE:
                case NativeAPI.SERIALIZE_ID_CYLINDER:
                case NativeAPI.SERIALIZE_ID_COMPOUND:
                case NativeAPI.SERIALIZE_ID_CONVEXHULL:
                case NativeAPI.SERIALIZE_ID_CONVEXMODIFIER:
                case NativeAPI.SERIALIZE_ID_CHAMFERCYLINDER:
                case NativeAPI.SERIALIZE_ID_NULL:
                    collision = new ConvexCollision(world, newtonCollision);
                    break;

                case NativeAPI.SERIALIZE_ID_TREE:
                    collision = new TreeCollision(world, newtonCollision);
                    break;

                case NativeAPI.SERIALIZE_ID_HEIGHFIELD:
                    collision = new Collision(world, newtonCollision);
                    break;

                case NativeAPI.SERIALIZE_ID_SCENE: //TODO
                default:
                    collision = new Collision(world, newtonCollision);
                    break;
            }

            collision.AddReference();
            return collision;
        }