Exemple #1
0
        /// <summary>
        /// Creates a heightfield shape descriptor for the physics system.
        /// </summary>
        /// <param name="heightData">Array of all height values on the heightfield</param>
        /// <param name="scaleFactor">Terrain scale factor. 4x means a spacing of 4 units (along horz plane) between adjacent vertices</param>
        /// <returns>Heightfield shape descriptor.</returns>
        private HeightFieldShapeDesc CreateHeightfieldShape(float[,] heightData, float scaleFactor)
        {
            var heightFieldDesc = new HeightFieldShapeDesc();

            heightFieldDesc.HeightField = heightData;
            heightFieldDesc.SizeX       = heightData.GetLength(0) * scaleFactor;
            heightFieldDesc.SizeZ       = heightData.GetLength(1) * scaleFactor;

            return(heightFieldDesc);
        }
Exemple #2
0
        /// <summary>
        /// Creates an actor using shape info and information from the parent BaseEntity.
        /// </summary>
        /// <param name="PhysicsScene">Reference to the physics scene</param>
        /// <param name="density">Density of physics object</param>
        private void CreateHeightfieldActor(IPhysicsScene PhysicsScene, float[,] heightData, float scaleFactor)
        {
            HeightFieldShapeDesc heightfieldShape = CreateHeightfieldShape(heightData, scaleFactor);

            if (heightfieldShape == null)
            {
                throw new Exception("Shape did not load properly");
            }

            var desc = new ActorDesc();

            desc.Orientation       = parentEntity.Rotation;
            desc.Mass              = 1.0f;
            desc.Dynamic           = false;
            desc.AffectedByGravity = false;
            desc.Position          = parentEntity.Position;
            desc.EntityID          = this.parentEntity.UniqueID;
            desc.Shapes.Add(heightfieldShape);
            desc.Type = ActorType.Terrain;

            actor = PhysicsScene.CreateActor(desc);
        }