Ejemplo n.º 1
0
        /// <summary>
        /// reading rigidbodies data
        /// </summary>
        void ReadRigit(Reader reader)
        {
            int readCount = reader.ReadInt32();

            rigitBodies = new RigidContainer[readCount];
            RigidContainer rigit;

            for (int i = 0; i < readCount; i++)
            {
                rigit           = new RigidContainer();
                rigit.Name      = reader.readString();
                rigit.NameEng   = reader.readString();
                rigit.BoneIndex = reader.readVal(header.GetBoneIndexSize);
                //shift for 16 bytes to prevent interfer with other physical instances
                rigit.GroupId           = (byte)(16 + reader.ReadByte());
                rigit.NonCollisionGroup = (int)reader.ReadUInt16() << 16;
                rigit.PrimitiveType     = (PhysPrimitiveType)reader.ReadByte();
                rigit.Size            = reader.readVector3() * multipler;
                rigit.Position        = reader.readVector3() * multipler;
                rigit.Rotation        = reader.readVector3();
                rigit.Mass            = reader.ReadSingle();
                rigit.MassAttenuation = reader.ReadSingle();
                rigit.RotationDamping = reader.ReadSingle();
                rigit.Restitution     = reader.ReadSingle();
                rigit.Friction        = reader.ReadSingle();
                rigit.Phys            = (PhysType)reader.ReadByte();

                rigitBodies[i] = rigit;
            }
        }
Ejemplo n.º 2
0
        void ReadRigit(Reader reader)
        {
            var bodyCount = reader.ReadInt32();

            rigitBodies = new RigidContainer[bodyCount];
            for (int i = 0; i < bodyCount; i++)
            {
                var rigit = new RigidContainer();
                rigit.Name              = reader.readStringLength(20);
                rigit.BoneIndex         = reader.ReadInt16();
                rigit.GroupId           = (byte)(16 + reader.ReadByte());
                rigit.NonCollisionGroup = (int)reader.ReadUInt16() << 16;
                rigit.PrimitiveType     = (PhysPrimitiveType)reader.ReadByte();
                rigit.Size              = reader.readVector3() * multipler;
                rigit.Position          = reader.readVector3() * multipler;
                rigit.Rotation          = reader.readVector3();
                rigit.Mass              = reader.ReadSingle();
                rigit.MassAttenuation   = reader.ReadSingle();
                rigit.RotationDamping   = reader.ReadSingle();
                rigit.Restitution       = reader.ReadSingle();
                rigit.Friction          = reader.ReadSingle();
                rigit.Phys              = (PhysType)reader.ReadByte();

                //convert coordinates from rigit2bone to rigit2world
                if (rigit.BoneIndex > -1)
                {
                    rigit.Position += bones[rigit.BoneIndex].Position;
                }

                rigitBodies[i] = rigit;
            }
        }
Ejemplo n.º 3
0
        public RigidBodyBone(RigidContainer rcon)
        {
            bodyContainer = rcon;
            CollisionShape shape = null;

            switch (rcon.PrimitiveType)
            {
            case PhysPrimitiveType.Box:
                shape = new BoxShape(rcon.Size.Convert());
                break;

            case PhysPrimitiveType.Capsule:
                shape = new CapsuleShape(rcon.Size.X, rcon.Size.Y);
                break;

            case PhysPrimitiveType.Sphere:
                shape = new SphereShape(rcon.Size.X);
                break;
            }
            if (rcon.Phys == PhysType.FollowBone)
            {
                rcon.Mass = 0;
            }

            bool isDynamic = (rcon.Mass != 0.0f);

            Vector3 inertia = Vector3.Zero;

            if (isDynamic)
            {
                shape.CalculateLocalInertia(rcon.Mass, out inertia);
            }
            startTransform = Matrix.RotationYawPitchRoll(rcon.Rotation.Y, rcon.Rotation.X, rcon.Rotation.Z) * Matrix.Translation(rcon.Position.Convert());

            //Convert left to right coordinates
            var reverce = Matrix.Scaling(new Vector3(1, 1, -1));

            startTransform = reverce * startTransform * reverce;

            rbInfo = new RigidBodyConstructionInfo(rcon.Mass, new DefaultMotionState(startTransform), shape, inertia);
            Body   = new RigidBody(rbInfo);
            Body.ActivationState = ActivationState.DisableDeactivation;
            Body.Friction        = rcon.Friction;
            Body.SetDamping(rcon.MassAttenuation, rcon.RotationDamping);
            Body.Restitution = rcon.Restitution;
            if (rcon.Phys == PhysType.FollowBone)
            {
                //Body.SetCustomDebugColor(new Vector3(0, 1, 0));
                Body.CollisionFlags = Body.CollisionFlags | CollisionFlags.KinematicObject;
            }

            /*
             * else if (rcon.Phys == PhysType.Gravity)
             *  Body.SetCustomDebugColor(new Vector3(1, 0, 0));
             * else if (rcon.Phys == PhysType.GravityBone)
             *  Body.SetCustomDebugColor(new Vector3(0, 0, 1));
             */
            //Disabled debug color cause its freeze engine on 3rd model load
        }