/// <summary>
        /// 剛体を生成する
        /// </summary>
        /// <param name="rigidBodyData_s">剛体データ</param>
        private void CreateRigid(List <RigidBodyData> rigidBodyData_s)
        {
            foreach (var r in rigidBodyData_s)
            {
                var tempRigidBodyData = new TempRigidBodyData(r);
                var init_matrix       = tempRigidBodyData.init_matrix;
                tempRigidBodyData_s.Add(tempRigidBodyData);
                BulletSharp.RigidBody rigidBody = null;
                CollisionShape        collisionShape;
                switch (r.Shape)
                {
                case RigidBodyShape.Sphere:     // 球体
                    collisionShape = new SphereShape(r.Size.X);
                    break;

                case RigidBodyShape.Box:            // ボックス
                    collisionShape = new BoxShape(r.Size.X, r.Size.Y, r.Size.Z);
                    break;

                case RigidBodyShape.Capsule:        // カプセル
                    collisionShape = new CapsuleShape(r.Size.X, r.Size.Y);
                    break;

                default:        //  例外処理
                    throw new System.Exception("Invalid rigid body data");
                }
                var rigidProperty = new RigidProperty(r.Mass, r.Repulsion, r.Friction, r.MoveAttenuation, r.RotationAttenuation);
                var superProperty = new SuperProperty(r.PhysicsCalcType == PhysicsCalcType.Static, (CollisionFilterGroups)(1 << r.RigidBodyGroup), (CollisionFilterGroups)r.UnCollisionGroupFlag);
                rigidBody = bulletManager.CreateRigidBody(collisionShape, init_matrix, rigidProperty, superProperty);
                rigidBodies.Add(rigidBody);
            }
        }
        /// <summary>
        /// To create a rigid
        /// </summary>
        /// <param name="rigidBodyData">Rigid data</param>
        private void CreateRigid(List <RigidBodyData> rigidBodyData)
        {
            foreach (var r in rigidBodyData)
            {
                var tempRigidBodyData = new TempRigidBodyData(r);
                //Debug.WriteLine("名字: {0}, 质量: {1}, 排斥力: {2}, 摩擦: {3}, 移动衰减: {4}, 旋转衰减: {5}",
                //    r.RigidBodyName, r.Mass, r.Repulsion, r.Friction, r.MoveAttenuation, r.Rotation);
                var init_matrix = tempRigidBodyData.init_matrix;
                this.tempRigidBodyData.Add(tempRigidBodyData);
                RigidBody      rigidBody = null;
                CollisionShape collisionShape;
                switch (r.Shape)
                {
                case RigidBodyShape.Sphere:     // 球体
                    collisionShape = new SphereShape(r.Size.X);
                    break;

                case RigidBodyShape.Box:            // box
                    collisionShape = new BoxShape(r.Size.X, r.Size.Y, r.Size.Z);
                    break;

                case RigidBodyShape.Capsule:        // capsule
                    collisionShape = new CapsuleShape(r.Size.X, r.Size.Y);
                    break;

                default:        //  Exception handling
                    throw new System.Exception("Invalid rigid body data");
                }
                //质量, 排斥力, 摩擦, 移动衰减, 旋转衰减
                var rigidProperty = new RigidProperty(r.Mass, r.Repulsion, r.Friction, r.MoveAttenuation, r.RotationAttenuation);
                var superProperty = new SuperProperty(r.PhysicsCalcType == PhysicsCalcType.Static, (CollisionFilterGroups)(1 << r.RigidBodyGroup), (CollisionFilterGroups)r.UnCollisionGroupFlag);
                rigidBody = this.bulletManager.CreateRigidBody(collisionShape, init_matrix, rigidProperty, superProperty);
                this.rigidBodies.Add(rigidBody);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 剛体を作る
        /// </summary>
        /// <param name="collisionShape">剛体の形</param>
        /// <param name="world">剛体のワールド変換行列</param>
        /// <param name="rigidProperty">剛体の物性</param>
        /// <param name="superProperty">物理演算を超越した特性</param>
        /// <returns></returns>
        public RigidBody CreateRigidBody(CollisionShape collisionShape, Matrix world, RigidProperty rigidProperty, SuperProperty superProperty)
        {
            var mass = superProperty.kinematic ? 0 : rigidProperty.mass;

            collisionShapes.Add(collisionShape);
            Vector3 localInertia = new Vector3(0, 0, 0);

            if (mass != 0)
            {
                collisionShape.CalculateLocalInertia(mass, out localInertia);
            }
            DefaultMotionState        motionState = new DefaultMotionState(world);
            RigidBodyConstructionInfo rbInfo      = new RigidBodyConstructionInfo(mass, motionState, collisionShape, localInertia);
            RigidBody body = new RigidBody(rbInfo);

            body.Restitution = rigidProperty.restitution;
            body.Friction    = rigidProperty.friction;
            body.SetDamping(rigidProperty.linear_damp, rigidProperty.angular_damp);
            float linearDamp  = body.LinearDamping;
            float angularDamp = body.AngularDamping;

            if (superProperty.kinematic)
            {
                body.CollisionFlags = body.CollisionFlags | CollisionFlags.KinematicObject;
            }
            body.ActivationState = ActivationState.DisableDeactivation;
            dynamicsWorld.AddRigidBody(body, superProperty.group, superProperty.mask);
            return(body);
        }
Beispiel #4
0
 /// <summary>
 /// 剛体を作る
 /// </summary>
 /// <param name="collisionShape">剛体の形</param>
 /// <param name="world">剛体のワールド変換行列</param>
 /// <param name="rigidProperty">剛体の物性</param>
 /// <param name="superProperty">物理演算を超越した特性</param>
 /// <returns>剛体</returns>
 public RigidBody CreateRigidBody(CollisionShape collisionShape, Matrix world, RigidProperty rigidProperty, SuperProperty superProperty)
 {
     return(rigidBodyFactory.CreateRigidBody(collisionShape, world, rigidProperty, superProperty));
 }