Esempio n. 1
0
        public Kart(ThingBlock block, ThingDefinition def)
            : base(block, def)
        {
            DefaultMaxSpeed = MaxSpeed = def.GetFloatProperty("maxspeed", 180f);
            MaxReverseSpeed = def.GetFloatProperty("maxreversespeed", 4f);

            MaxSpeedSquared = MaxSpeed * MaxSpeed;
            MaxReverseSpeedSquared = MaxReverseSpeed * MaxReverseSpeed;

            IsInAir = false;

            FrontDriftAngle = new Degree(def.GetFloatProperty("FrontDriftAngle", 46)).ValueRadians;
            BackDriftAngle = new Degree(def.GetFloatProperty("BackDriftAngle", 55)).ValueRadians;
            DriftTransitionAngle = new Degree(def.GetFloatProperty("DriftTransitionAngle", 40));
        }
Esempio n. 2
0
        /// <summary>
        /// Set up all of the stuff needed before we create our body
        /// </summary>
        private void SetUpBodyInfo(ThingDefinition def)
        {
            // set up our collision shapes
            CollisionShape shape = LKernel.GetG<CollisionShapeManager>().CreateAndRegisterShape(this, def);

            // get the physics type and set up the mass of the body
            ThingEnum physicsType = def.GetEnumProperty("physics", null);
            float mass = physicsType.HasFlag(ThingEnum.Static) ? 0 : def.GetFloatProperty("mass", 1);

            // create our construction info thingy
            Vector3 inertia;
            shape.CalculateLocalInertia(mass, out inertia);

            // if it's static and doesn't have a sound, we don't need a mogre motion state because we'll be disposing of the root node afterwards
            if (def.GetBoolProperty("Static", false) && SoundComponents == null)
                MotionState = new DefaultMotionState();
            else
                MotionState = InitializationMotionState;

            Info = new RigidBodyConstructionInfo(mass, MotionState, shape, inertia);

            // physics material stuff from a .physmat file
            string physmat = def.GetStringProperty("PhysicsMaterial", "Default");
            LKernel.GetG<PhysicsMaterialFactory>().ApplyMaterial(Info, physmat);

            // we can override some of them in the .thing file
            if (def.FloatTokens.ContainsKey("bounciness"))
                Info.Restitution = def.GetFloatProperty("bounciness", PhysicsMaterial.DEFAULT_BOUNCINESS);
            if (def.FloatTokens.ContainsKey("friction"))
                Info.Friction = def.GetFloatProperty("friction", PhysicsMaterial.DEFAULT_FRICTION);
            if (def.FloatTokens.ContainsKey("angulardamping"))
                Info.AngularDamping = def.GetFloatProperty("angulardamping", PhysicsMaterial.DEFAULT_ANGULAR_DAMPING);
            if (def.FloatTokens.ContainsKey("lineardamping"))
                Info.LinearDamping = def.GetFloatProperty("lineardamping", PhysicsMaterial.DEFAULT_LINEAR_DAMPING);

            // choose which group to use for a default
            ThingEnum defaultGroup;
            if (physicsType.HasFlag(ThingEnum.Dynamic))
                defaultGroup = ThingEnum.Default;
            else if (physicsType.HasFlag(ThingEnum.Static))
                defaultGroup = ThingEnum.Environment;
            else // kinematic
                defaultGroup = ThingEnum.Default;

            // collision group
            ThingEnum collisionGroup = def.GetEnumProperty("CollisionGroup", defaultGroup);
            PonykartCollisionGroups pcg;
            if (!Enum.TryParse<PonykartCollisionGroups>(collisionGroup + String.Empty, true, out pcg))
                throw new FormatException("Invalid collision group!");
            CollisionGroup = pcg;

            // collides-with group
            ThingEnum collidesWith = def.GetEnumProperty("CollidesWith", defaultGroup);
            PonykartCollidesWithGroups pcwg;
            if (!Enum.TryParse<PonykartCollidesWithGroups>(collidesWith + String.Empty, true, out pcwg))
                throw new FormatException("Invalid collides-with group!");
            CollidesWith = pcwg;

            // update the transforms
            Matrix4 transform = new Matrix4();
            transform.MakeTransform(SpawnPosition, SpawnScale, SpawnOrientation);
            Info.StartWorldTransform = transform;
            MotionState.WorldTransform = transform;
        }