当前位置: 首页>>代码示例>>C#>>正文


C# UnityEngine.ToBullet方法代码示例

本文整理汇总了C#中UnityEngine.ToBullet方法的典型用法代码示例。如果您正苦于以下问题:C# UnityEngine.ToBullet方法的具体用法?C# UnityEngine.ToBullet怎么用?C# UnityEngine.ToBullet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine的用法示例。


在下文中一共展示了UnityEngine.ToBullet方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddTorque

 public void AddTorque(UnityEngine.Vector3 torque)
 {
     if (isInWorld) {
         m_Brigidbody.ApplyTorque(torque.ToBullet());
     }
 }
开发者ID:RatherGood1,项目名称:BulletSharpUnity3d,代码行数:6,代码来源:BRigidBody.cs

示例2: AddForce

 public void AddForce(UnityEngine.Vector3 force)
 {
     if (isInWorld) {
         m_Brigidbody.ApplyCentralForce(force.ToBullet());
     }
 }
开发者ID:RatherGood1,项目名称:BulletSharpUnity3d,代码行数:6,代码来源:BRigidBody.cs

示例3: AddForceAtPosition

 public void AddForceAtPosition(UnityEngine.Vector3 force, UnityEngine.Vector3 relativePostion)
 {
     if (isInWorld) {
         m_Brigidbody.ApplyForce(force.ToBullet(), relativePostion.ToBullet());
     }
 }
开发者ID:RatherGood1,项目名称:BulletSharpUnity3d,代码行数:6,代码来源:BRigidBody.cs

示例4: CreateFrame

 public bool CreateFrame(UnityEngine.Vector3 forward, UnityEngine.Vector3 up, UnityEngine.Vector3 constraintPoint, ref BulletSharp.Math.Matrix m, ref string errorMsg)
 {
     BulletSharp.Math.Vector4 x;
     BulletSharp.Math.Vector4 y;
     BulletSharp.Math.Vector4 z;
     if (forward == Vector3.zero)
     {
         errorMsg = "forward vector must not be zero";
         return false;
     }
     forward.Normalize();
     if (up == Vector3.zero)
     {
         errorMsg = "up vector must not be zero";
         return false;
     }
     Vector3 right = Vector3.Cross(forward, up);
     if (right == Vector3.zero)
     {
         errorMsg = "forward and up vector must not be colinear";
         return false;
     }
     up = Vector3.Cross(right, forward);
     right.Normalize();
     up.Normalize();
     x.X = forward.x; x.Y = forward.y; x.Z = forward.z; x.W = 0f;
     y.X = up.x; y.Y = up.y; y.Z = up.z; y.W = 0f;
     z.X = right.x; z.Y = right.y; z.Z = right.z; z.W = 0f;
     m.Row1 = x;
     m.Row2 = y;
     m.Row3 = z;
     m.Origin = constraintPoint.ToBullet();
     return true;
 }
开发者ID:Cyberbanan,项目名称:BulletSharpUnity3d,代码行数:34,代码来源:BTypedConstraint.cs

示例5: AddTorqueImpulse

 public void AddTorqueImpulse(UnityEngine.Vector3 impulseTorque)
 {
     if (isInWorld)
     {
         m_rigidBody.ApplyTorqueImpulse(impulseTorque.ToBullet());
     }
 }
开发者ID:Cyberbanan,项目名称:BulletSharpUnity3d,代码行数:7,代码来源:BRigidBody.cs

示例6: AddImpulseAtPosition

 public void AddImpulseAtPosition(UnityEngine.Vector3 impulse, UnityEngine.Vector3 relativePostion)
 {
     if (isInWorld)
     {
         m_rigidBody.ApplyImpulse(impulse.ToBullet(), relativePostion.ToBullet());
     }
 }
开发者ID:Cyberbanan,项目名称:BulletSharpUnity3d,代码行数:7,代码来源:BRigidBody.cs

示例7: AddImpulse

 public void AddImpulse(UnityEngine.Vector3 impulse)
 {
     if (isInWorld)
     {
         m_rigidBody.ApplyCentralImpulse(impulse.ToBullet());
     }
 }
开发者ID:Cyberbanan,项目名称:BulletSharpUnity3d,代码行数:7,代码来源:BRigidBody.cs

示例8: SimulateBall

    //IMPORTANT Time.fixedTime must match the timestep being used here.
    public static List<UnityEngine.Vector3> SimulateBall(BRigidBody ballRb, UnityEngine.Vector3 ballThrowForce, int numberOfSimulationSteps, bool reverseOrder)
    {
        var ballPositions = new List<UnityEngine.Vector3>(numberOfSimulationSteps);

        //Create a World
        Debug.Log("Initialize physics");

        CollisionConfiguration CollisionConf;
        CollisionDispatcher Dispatcher;
        BroadphaseInterface Broadphase;
        CollisionWorld cw;
        SequentialImpulseConstraintSolver Solver;
        BulletSharp.SoftBody.SoftBodyWorldInfo softBodyWorldInfo;

        //This should create a copy of the BPhysicsWorld with the same settings
        BPhysicsWorld bw = BPhysicsWorld.Get();
        bw.CreatePhysicsWorld(out cw, out CollisionConf, out Dispatcher, out Broadphase, out Solver, out softBodyWorldInfo);
        World = (DiscreteDynamicsWorld) cw;

        //Copy all existing rigidbodies in scene
        // IMPORTANT rigidbodies must be added to the offline world in the same order that they are in the source world
        // this is because collisions must be resolved in the same order for the sim to be deterministic
        DiscreteDynamicsWorld sourceWorld = (DiscreteDynamicsWorld) bw.world;
        BulletSharp.RigidBody bulletBallRb = null;
        BulletSharp.Math.Matrix mm = BulletSharp.Math.Matrix.Identity;
        for(int i = 0; i < sourceWorld.NumCollisionObjects; i++)
        {
            CollisionObject co = sourceWorld.CollisionObjectArray[i];
            if (co != null && co.UserObject is BRigidBody)
            {
                BRigidBody rb = (BRigidBody) co.UserObject;
                float mass = rb.isDynamic() ? rb.mass : 0f;
                BCollisionShape existingShape = rb.GetComponent<BCollisionShape>();
                CollisionShape shape = null;
                if (existingShape is BSphereShape)
                {
                    shape = ((BSphereShape)existingShape).CopyCollisionShape();
                }
                else if (existingShape is BBoxShape)
                {
                    shape = ((BBoxShape)existingShape).CopyCollisionShape();
                }

                RigidBody bulletRB = null;
                BulletSharp.Math.Vector3 localInertia = new BulletSharp.Math.Vector3();
                rb.CreateOrConfigureRigidBody(ref bulletRB, ref localInertia, shape, null);
                BulletSharp.Math.Vector3 pos = rb.GetCollisionObject().WorldTransform.Origin;
                BulletSharp.Math.Quaternion rot = rb.GetCollisionObject().WorldTransform.GetOrientation();
                BulletSharp.Math.Matrix.AffineTransformation(1f, ref rot, ref pos, out mm);
                bulletRB.WorldTransform = mm;
                World.AddRigidBody(bulletRB, rb.groupsIBelongTo, rb.collisionMask);
                if (rb == ballRb)
                {
                    bulletBallRb = bulletRB;
                    bulletRB.ApplyCentralImpulse(ballThrowForce.ToBullet());
                }
            }
        }

        //Step the simulation numberOfSimulationSteps times
        for (int i = 0; i < numberOfSimulationSteps; i++)
        {
            int numSteps = World.StepSimulation(1f / 60f, 10, 1f / 60f);
            ballPositions.Add(bulletBallRb.WorldTransform.Origin.ToUnity());
        }

        UnityEngine.Debug.Log("ExitPhysics");
        if (World != null)
        {
            //remove/dispose constraints
            int i;
            for (i = World.NumConstraints - 1; i >= 0; i--)
            {
                TypedConstraint constraint = World.GetConstraint(i);
                World.RemoveConstraint(constraint);
                constraint.Dispose();
            }

            //remove the rigidbodies from the dynamics world and delete them
            for (i = World.NumCollisionObjects - 1; i >= 0; i--)
            {
                CollisionObject obj = World.CollisionObjectArray[i];
                RigidBody body = obj as RigidBody;
                if (body != null && body.MotionState != null)
                {
                    body.MotionState.Dispose();
                }
                World.RemoveCollisionObject(obj);
                obj.Dispose();
            }

            World.Dispose();
            Broadphase.Dispose();
            Dispatcher.Dispose();
            CollisionConf.Dispose();
        }

        if (Broadphase != null)
        {
//.........这里部分代码省略.........
开发者ID:Cyberbanan,项目名称:BulletSharpUnity3d,代码行数:101,代码来源:OfflineBallSimulation.cs


注:本文中的UnityEngine.ToBullet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。