コード例 #1
0
        /// <summary>
        /// Sets the frames.
        /// </summary>
        /// <param name="frameA">The frame a.</param>
        /// <param name="frameB">The frame b.</param>
        public void SetFrames(float4x4 frameA, float4x4 frameB)
        {
            var o = (SliderConstraintImp)_sci.UserObject;

            o._sci.SetFrames(Translator.Float4X4ToBtMatrix(frameA), Translator.Float4X4ToBtMatrix(frameB));
        }
コード例 #2
0
 /// <summary>
 /// Calculates the transforms.
 /// </summary>
 /// <param name="transA">The trans a.</param>
 /// <param name="transB">The trans b.</param>
 public void CalculateTransforms(float4x4 transA, float4x4 transB)
 {
     _sci.CalculateTransforms(Translator.Float4X4ToBtMatrix(transA), Translator.Float4X4ToBtMatrix(transB));
 }
コード例 #3
0
        /// <summary>
        /// Adds the point.
        /// </summary>
        /// <param name="point">The point.</param>
        public void AddPoint(float3 point)
        {
            var btPoint = Translator.Float3ToBtVector3(point);

            BtConvexHullShape.AddPoint(btPoint, true);
        }
コード例 #4
0
        /// <summary>
        /// Gets the scaled point.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public float3 GetScaledPoint(int index)
        {
            var retval = Translator.BtVector3ToFloat3(BtConvexHullShape.GetScaledPoint(index));

            return(retval);
        }
コード例 #5
0
        /// <summary>
        /// Gets the hinge angle.
        /// </summary>
        /// <param name="transA">The trans a.</param>
        /// <param name="transB">The trans b.</param>
        /// <returns></returns>
        public float GetHingeAngle(float4x4 transA, float4x4 transB)
        {
            var retval = _hci.GetHingeAngle(Translator.Float4X4ToBtMatrix(transA), Translator.Float4X4ToBtMatrix(transB));

            return(retval);
        }
コード例 #6
0
        /// <summary>
        /// Sets the motor target.
        /// </summary>
        /// <param name="qAinB">The q ain b.</param>
        /// <param name="dt">The dt.</param>
        public void SetMotorTarget(Quaternion qAinB, float dt)
        {
            var o = (HingeConstraintImp)_hci.UserObject;

            o._hci.SetMotorTarget(Translator.QuaternionToBtQuaternion(qAinB), dt);
        }
コード例 #7
0
 /// <summary>
 /// Sets the frames.
 /// </summary>
 /// <param name="frameA">The frame a.</param>
 /// <param name="frameB">The frame b.</param>
 public void SetFrames(float4x4 frameA, float4x4 frameB)
 {
     _g6dofci.SetFrames(Translator.Float4X4ToBtMatrix(frameA), Translator.Float4X4ToBtMatrix(frameB));
 }
コード例 #8
0
        /// <summary>
        /// Sets the axis.
        /// </summary>
        /// <param name="axisInA">The axis in a.</param>
        public void SetAxis(float3 axisInA)
        {
            var o = (HingeConstraintImp)_hci.UserObject;

            _hci.SetAxis(Translator.Float3ToBtVector3(axisInA));
        }
コード例 #9
0
        /// <summary>
        /// Gets the axis.
        /// </summary>
        /// <param name="axisIndex">Index of the axis.</param>
        /// <returns></returns>
        public float3 GetAxis(int axisIndex)
        {
            var retval = Translator.BtVector3ToFloat3(_g6dofci.GetAxis(axisIndex));

            return(retval);
        }
コード例 #10
0
 /// <summary>
 /// Sets the axis.
 /// </summary>
 /// <param name="axis1">The axis1.</param>
 /// <param name="axis2">The axis2.</param>
 public void SetAxis(float3 axis1, float3 axis2)
 {
     _g6dofci.SetAxis(Translator.Float3ToBtVector3(axis1), Translator.Float3ToBtVector3(axis2));
 }
コード例 #11
0
 /// <summary>
 /// Calculates the angle info2.
 /// </summary>
 /// <param name="transA">The trans a.</param>
 /// <param name="transB">The trans b.</param>
 /// <param name="invInertiaWorldA">The inv inertia world a.</param>
 /// <param name="invInertiaWorldB">The inv inertia world b.</param>
 public void CalcAngleInfo2(float4x4 transA, float4x4 transB, float4x4 invInertiaWorldA, float4x4 invInertiaWorldB)
 {
     _cti.CalcAngleInfo2(Translator.Float4X4ToBtMatrix(transA), Translator.Float4X4ToBtMatrix(transB), Translator.Float4X4ToBtMatrix(invInertiaWorldA), Translator.Float4X4ToBtMatrix(invInertiaWorldB));
 }
コード例 #12
0
 /// <summary>
 /// Sets the motor target in constraint space.
 /// </summary>
 /// <param name="q">The q.</param>
 public void SetMotorTargetInConstraintSpace(Quaternion q)
 {
     _cti.SetMotorTargetInConstraintSpace(Translator.QuaternionToBtQuaternion(q));
 }
コード例 #13
0
 /// <summary>
 /// Sets the motor target.
 /// </summary>
 /// <param name="q">The q.</param>
 public void SetMotorTarget(Quaternion q)
 {
     _cti.SetMotorTarget(Translator.QuaternionToBtQuaternion(q));
 }
コード例 #14
0
        /// <summary>
        /// Gets the point for angle.
        /// </summary>
        /// <param name="fAngleInRadius">The f angle in radius.</param>
        /// <param name="fLength">Length of the f.</param>
        /// <returns></returns>
        public float3 GetPointForAngle(float fAngleInRadius, float fLength)
        {
            var retval = Translator.BtVector3ToFloat3(_cti.GetPointForAngle(fAngleInRadius, fLength));

            return(retval);
        }
コード例 #15
0
        /*private void MyTickCallBack(ManifoldPoint cp, CollisionObjectWrapper colobj0wrap, int partid0, int index0, CollisionObjectWrapper colobj1wrap, int partid1, int index1)
         * {
         *  Debug.WriteLine("MyTickCallBack");
         *  int numManifolds = BtWorld.Dispatcher.NumManifolds;
         *  RigidBodyImp myRb;
         *  //Debug.WriteLine("numManifolds: " + numManifolds);
         *  for (int i = 0; i < numManifolds; i++)
         *  {
         *      PersistentManifold contactManifold = BtWorld.Dispatcher.GetManifoldByIndexInternal(i);
         *      int numContacts = contactManifold.NumContacts;
         *      if (numContacts > 0)
         *      {
         *          CollisionObject obA = (CollisionObject) contactManifold.Body0;
         *          CollisionObject obB = (CollisionObject) contactManifold.Body1;
         *
         *         // Debug.WriteLine(numContacts);
         *          var pnA = obA.UserObject;
         *
         *          for (int j = 0; j < numContacts; j++)
         *          {
         *              ManifoldPoint pt = contactManifold.GetContactPoint(j);
         *
         *          }
         *      }
         *  }
         * }*/


        /// <summary>
        /// Adds the rigid body.
        /// </summary>
        /// <param name="mass">The mass.</param>
        /// <param name="worldTransform">The world transform.</param>
        /// <param name="orientation">The orientation.</param>
        /// <param name="colShape">The col shape.</param>
        /// <returns></returns>
        public IRigidBodyImp AddRigidBody(float mass, float3 worldTransform, float3 orientation, ICollisionShapeImp colShape /*, float3 intertia*/)
        {
            // Use bullet to do what needs to be done:


            var btMatrix = Matrix.RotationX(orientation.x)
                           * Matrix.RotationY(orientation.y)
                           * Matrix.RotationZ(orientation.z)
                           * Matrix.Translation(worldTransform.x, worldTransform.y, worldTransform.z);

            var btMotionState = new DefaultMotionState(btMatrix);


            var shapeType = colShape.GetType().ToString();

            CollisionShape btColShape;

            // var isStatic = false;
            switch (shapeType)
            {
            //Primitives
            case "Fusee.Engine.BoxShapeImp":
                var box = (BoxShapeImp)colShape;
                var btBoxHalfExtents = Translator.Float3ToBtVector3(box.HalfExtents);
                btColShape = new BoxShape(btBoxHalfExtents);
                break;

            case "Fusee.Engine.CapsuleShapeImp":
                var capsule = (CapsuleShapeImp)colShape;
                btColShape = new CapsuleShape(capsule.Radius, capsule.HalfHeight);
                break;

            case "Fusee.Engine.ConeShapeImp":
                var cone = (ConeShapeImp)colShape;
                btColShape = new ConeShape(cone.Radius, cone.Height);
                break;

            case "Fusee.Engine.CylinderShapeImp":
                var cylinider             = (CylinderShapeImp)colShape;
                var btCylinderHalfExtents = Translator.Float3ToBtVector3(cylinider.HalfExtents);
                btColShape = new CylinderShape(btCylinderHalfExtents);
                break;

            case "Fusee.Engine.MultiSphereShapeImp":
                var multiSphere = (MultiSphereShapeImp)colShape;
                var btPositions = new Vector3[multiSphere.SphereCount];
                var btRadi      = new float[multiSphere.SphereCount];
                for (int i = 0; i < multiSphere.SphereCount; i++)
                {
                    var pos = Translator.Float3ToBtVector3(multiSphere.GetSpherePosition(i));
                    btPositions[i] = pos;
                    btRadi[i]      = multiSphere.GetSphereRadius(i);
                }
                btColShape = new MultiSphereShape(btPositions, btRadi);
                break;

            case "Fusee.Engine.SphereShapeImp":
                var sphere   = (SphereShapeImp)colShape;
                var btRadius = sphere.Radius;
                btColShape = new SphereShape(btRadius);
                break;

            //Misc
            case "Fusee.Engine.CompoundShapeImp":
                var compShape = (CompoundShapeImp)colShape;
                btColShape = new CompoundShape(true);
                btColShape = compShape.BtCompoundShape;
                break;

            case "Fusee.Engine.EmptyShapeImp":
                btColShape = new EmptyShape();
                break;

            //Meshes
            case "Fusee.Engine.ConvexHullShapeImp":
                var convHull = (ConvexHullShapeImp)colShape;
                var btPoints = new Vector3[convHull.GetNumPoints()];
                for (int i = 0; i < convHull.GetNumPoints(); i++)
                {
                    var point = convHull.GetScaledPoint(i);
                    btPoints[i] = Translator.Float3ToBtVector3(point);
                }
                btColShape = new ConvexHullShape(btPoints);
                //btColShape.LocalScaling = new Vector3(3,3,3);
                break;

            case "Fusee.Engine.StaticPlaneShapeImp":
                var staticPlane = (StaticPlaneShapeImp)colShape;
                Debug.WriteLine("staticplane: " + staticPlane.Margin);
                var btNormal = Translator.Float3ToBtVector3(staticPlane.PlaneNormal);
                btColShape = new StaticPlaneShape(btNormal, staticPlane.PlaneConstant);
                // isStatic = true;
                //btColShape.Margin = 0.04f;
                //Debug.WriteLine("btColshape" + btColShape.Margin);
                break;

            case "Fusee.Engine.GImpactMeshShapeImp":
                var gImpMesh = (GImpactMeshShapeImp)colShape;
                gImpMesh.BtGImpactMeshShape.UpdateBound();
                var btGimp = new GImpactMeshShape(gImpMesh.BtGImpactMeshShape.MeshInterface);

                btGimp.UpdateBound();
                btColShape = btGimp;

                break;

            //Default
            default:
                Debug.WriteLine("defaultImp");
                btColShape = new EmptyShape();
                break;
            }

            var btLocalInertia = btColShape.CalculateLocalInertia(mass);
            // btLocalInertia *= (10.0f*10);
            RigidBodyConstructionInfo btRbcInfo = new RigidBodyConstructionInfo(mass, btMotionState, btColShape,
                                                                                btLocalInertia);

            var btRigidBody = new RigidBody(btRbcInfo);

            btRigidBody.Restitution    = 0.2f;
            btRigidBody.Friction       = 0.2f;
            btRigidBody.CollisionFlags = CollisionFlags.CustomMaterialCallback;

            BtWorld.AddRigidBody(btRigidBody);
            btRbcInfo.Dispose();
            var retval = new RigidBodyImp();

            retval._rbi            = btRigidBody;
            btRigidBody.UserObject = retval;
            return(retval);
        }