示例#1
0
        void InitInstanceData(CollisionObject colObj, CollisionShape shape, ref Matrix transform)
        {
            if (shape.ShapeType == BroadphaseNativeType.CompoundShape)
            {
                foreach (CompoundShapeChild child in (shape as CompoundShape).ChildList)
                {
                    Matrix childTransform = child.Transform * transform;
                    InitInstanceData(colObj, child.ChildShape, ref childTransform);
                }
            }
            else if (shape.ShapeType == BroadphaseNativeType.SoftBodyShape)
            {
                ShapeData shapeData = InitShapeData(shape);
                UpdateSoftBody(colObj as SoftBody, shapeData);

                shapeData.InstanceDataList.Add(new InstanceData()
                {
                    WorldTransform = transform,
                    Color          = softBodyColor
                });
            }
            else
            {
                InitShapeData(shape).InstanceDataList.Add(new InstanceData()
                {
                    WorldTransform = transform,
                    Color          = "Ground".Equals(colObj.UserObject) ? groundColor :
                                     colObj.ActivationState == ActivationState.ActiveTag ? activeColor : passiveColor
                });
            }
        }
示例#2
0
        void InitInstanceData(CollisionObject colObj, CollisionShape shape, ref BulletSharp.Matrix transform)
        {
            switch (shape.ShapeType)
            {
            case BroadphaseNativeType.CompoundShape:
                foreach (CompoundShapeChild child in (shape as CompoundShape).ChildList)
                {
                    BulletSharp.Matrix childTransform = child.Transform * transform;
                    InitInstanceData(colObj, child.ChildShape, ref childTransform);
                }
                break;

            case BroadphaseNativeType.SoftBodyShape:
                ShapeData shapeData = InitShapeData(shape);
                UpdateSoftBody(colObj as SoftBody, shapeData);

                shapeData.InstanceDataList.Add(new InstanceData()
                {
                    WorldTransform = MathHelper.Convert(ref transform),
                    Color          = softBodyColor
                });
                break;

            default:
                InitShapeData(shape).InstanceDataList.Add(new InstanceData()
                {
                    WorldTransform = MathHelper.Convert(ref transform),
                    Color          = "Ground".Equals(colObj.UserObject) ? groundColor :
                                     colObj.ActivationState == ActivationState.ActiveTag ? activeColor : passiveColor
                });
                break;
            }
        }
示例#3
0
 void InitRigidBodyInstance(CollisionObject colObj, CollisionShape shape, ref Matrix transform)
 {
     if (shape.ShapeType == BroadphaseNativeType.CompoundShape)
     {
         foreach (var child in (shape as CompoundShape).ChildList)
         {
             Matrix childTransform = child.Transform * transform;
             InitRigidBodyInstance(colObj, child.ChildShape, ref childTransform);
         }
     }
     else
     {
         var  shapeData = InitShapeData(shape);
         uint color     = "Ground".Equals(colObj.UserObject) ? groundColor :
                          colObj.ActivationState == ActivationState.ActiveTag ? activeColor : passiveColor;
         shapeData.Instances.Add(ref transform, color);
     }
 }
示例#4
0
	BulletSharp.RigidBody createRigidBody (BulletSharp.CollisionShape shape, UnityEngine.Transform transform, float mass)
	{
		Matrix4x4 unityMatrix = Matrix4x4.TRS (transform.position, transform.rotation, UnityEngine.Vector3.one);
		BulletSharp.Matrix bulletMatrix = new BulletSharp.Matrix (
			unityMatrix.m00, unityMatrix.m10, unityMatrix.m20, unityMatrix.m30, 
			unityMatrix.m01, unityMatrix.m11, unityMatrix.m21, unityMatrix.m31, 
			unityMatrix.m02, unityMatrix.m12, unityMatrix.m22, unityMatrix.m32, 
			unityMatrix.m03, unityMatrix.m13, unityMatrix.m23, unityMatrix.m33);
		
		BulletSharp.MotionState motionState = new BulletSharp.DefaultMotionState (bulletMatrix);
		BulletSharp.Vector3 inertia = new BulletSharp.Vector3 (0f, 0f, 0f);
		if (!Mathf.Approximately (mass, 0f)) {
			shape.CalculateLocalInertia (mass, out inertia);
		}
		BulletSharp.RigidBodyConstructionInfo myRigidBodyCI = new BulletSharp.RigidBodyConstructionInfo (mass, motionState, shape, inertia);
		BulletSharp.RigidBody myRigidBody = new BulletSharp.RigidBody (myRigidBodyCI);
		myRigidBodyCI.Dispose ();
		return myRigidBody;
	}
示例#5
0
        RigidBody bulletCreateRigidBody(float mass, BulletSharp.Matrix startTransform, CollisionShape shape)
        {
            bool isDynamic = (mass != 0.0f);

            Vector3 localInertia = Vector3.Zero;

            if (isDynamic)
            {
                shape.CalculateLocalInertia(mass, out localInertia);
            }

            DefaultMotionState motionState = new DefaultMotionState(startTransform);

            RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, motionState, shape, localInertia);
            RigidBody body = new RigidBody(rbInfo);

            bulletWorld.AddRigidBody(body);

            return(body);
        }
示例#6
0
 void InitRigidBodyInstance(CollisionObject colObj, CollisionShape shape, ref BulletSharp.Matrix transform)
 {
     if (shape.ShapeType == BroadphaseNativeType.CompoundShape)
     {
         foreach (CompoundShapeChild child in (shape as CompoundShape).ChildList)
         {
             BulletSharp.Matrix childTransform = child.Transform * transform;
             InitRigidBodyInstance(colObj, child.ChildShape, ref childTransform);
         }
     }
     else
     {
         InitShapeData(shape).Instances.Add(new InstanceData()
         {
             WorldTransform = MathHelper.Convert(ref transform),
             Color          = "Ground".Equals(colObj.UserObject) ? groundColor :
                              colObj.ActivationState == ActivationState.ActiveTag ? activeColor : passiveColor
         });
     }
 }
        public void Evaluate(int SpreadMax)
        {
            if (this.FBodies.PluginIO.IsConnected)
            {
                this.FTransform.SliceCount = this.FBodies.SliceCount;
                var outputBuffer = this.FTransform.Stream.Buffer;

                if (this.FUseMotionState[0])
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        RigidBody body = this.FBodies[i];

                        BulletSharp.Matrix m = body.WorldTransform;

                        outputBuffer[i] = *((SlimDX.Matrix *) & m);
                    }
                }
                else
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        RigidBody body = this.FBodies[i];

                        BulletSharp.Matrix m = body.MotionState.WorldTransform;

                        outputBuffer[i] = *((SlimDX.Matrix *) & m);
                    }
                }

                this.FTransform.Flush(true);
            }
            else
            {
                this.FTransform.SliceCount = 0;
            }
        }
示例#8
0
        void InitInstanceData(CollisionObject colObj, CollisionShape shape, ref Matrix transform)
        {
            if (shape.ShapeType == BroadphaseNativeType.CompoundShape)
            {
                foreach (CompoundShapeChild child in (shape as CompoundShape).ChildList)
                {
                    Matrix childTransform = child.Transform * transform;
                    InitInstanceData(colObj, child.ChildShape, ref childTransform);
                }
            }
            else if (shape.ShapeType == BroadphaseNativeType.SoftBodyShape)
            {
                ShapeData shapeData = InitShapeData(shape);
                UpdateSoftBody(colObj as SoftBody, shapeData);

                shapeData.InstanceDataList.Add(new InstanceData()
                {
                    WorldTransform = transform,
                    Color = softBodyColor
                });
            }
            else
            {
                InitShapeData(shape).InstanceDataList.Add(new InstanceData()
                {
                    WorldTransform = transform,
                    Color = "Ground".Equals(colObj.UserObject) ? groundColor :
                        colObj.ActivationState == ActivationState.ActiveTag ? activeColor : passiveColor
                });
            }
        }
示例#9
0
 void InitRigidBodyInstance(CollisionObject colObj, CollisionShape shape, ref Matrix transform)
 {
     if (shape.ShapeType == BroadphaseNativeType.CompoundShape)
     {
         foreach (var child in (shape as CompoundShape).ChildList)
         {
             Matrix childTransform = child.Transform * transform;
             InitRigidBodyInstance(colObj, child.ChildShape, ref childTransform);
         }
     }
     else
     {
         var shapeData = InitShapeData(shape);
         shapeData.Instances.Add(new InstanceData()
         {
             WorldTransform = transform,
             Color = "Ground".Equals(colObj.UserObject) ? groundColor :
                 colObj.ActivationState == ActivationState.ActiveTag ? activeColor : passiveColor
         });
     }
 }