public static BaseComponent LoadFromDefinition(ContentManager content, string definitionPath, BaseEntity parent) { TerrainComponentDefinition compDef = content.Load <TerrainComponentDefinition>(definitionPath); TerrainComponent newComponent = new TerrainComponent(parent, compDef); return(newComponent); }
/// <summary> /// Creates a child <see cref="QuadTree"/> section. /// </summary> /// <param name="SourceTerrain">Parent <see cref="Terrain"/> section</param> /// <param name="verticesLength"></param> /// <param name="offsetX"></param> /// <param name="offsetY"></param> public QuadTree(QSGame game, TerrainComponent sourceTerrain, int verticesLength, int offsetX, int offsetZ) { this.Game = game; this.terrain = sourceTerrain; if (boundingBoxMaterial == null) { boundingBoxMaterial = game.Content.Load <Material>("Material/Terrain"); } this.offsetX = offsetX; this.offsetZ = offsetZ; // This truncation requires all heightmap images to be // a power of two in height and width this.width = ((int)Math.Sqrt(verticesLength) / 2) + 1; SetupBoundingBox(); // If this tree is the smallest allowable size, set it as a leaf // so that it will not continue branching smaller. int widthMinusOne = this.width - 1; if ((widthMinusOne * widthMinusOne) <= this.terrain.MinLeafSize) { this.isLeaf = true; CreateBoundingBoxMesh(); } if (this.isLeaf) { SetupTerrainVertices(); this.leafPatch = new TerrainPatch(this.Game, this.terrain, this); } else { BranchOff(); } }
/// <summary> /// Creates a root <see cref="QuadTree"/> node. This should only be called from the /// parent Terrain section. /// </summary> /// <param name="game">QSGame reference</param> /// <param name="terrain">Parent terrain section</param> /// <param name="verticesLength">Length of vertices in this QuadTree</param> public QuadTree(QSGame game, TerrainComponent terrain, int verticesLength) { this.Game = game; this.terrain = terrain; if (boundingBoxMaterial == null) { boundingBoxMaterial = game.Content.Load <Material>("Material/WireFrame"); } // This truncation requires all heightmap images to be // a power of two in height and width this.width = (int)Math.Sqrt(verticesLength); this.rootWidth = width; // Vertices are only used for setting up the dimensions of // the bounding box. The vertices used in rendering are // located in the terrain class. SetupBoundingBox(); // If this tree is the smallest allowable size, set it as a leaf // so that it will not continue branching smaller. if (verticesLength <= this.terrain.MinLeafSize) { this.isLeaf = true; CreateBoundingBoxMesh(); } if (this.isLeaf) { SetupTerrainVertices(); this.leafPatch = new TerrainPatch(this.Game, this.terrain, this); } else { BranchOffRoot(); } }
public TerrainPhysicsComponent(BaseEntity parent, TerrainPhysicsComponentDefinition compDef) : base(parent) { TerrainComponent terrainComp = this.parentEntity.GetComponentByType(ComponentType.TerrainComponent) as TerrainComponent; if (null == terrainComp) { throw new Exception("Terrain Components must be added to an entity prior to TerrainPhysicsComponent. Make sure in the EntityDefinition XML file that TerrainComponent comes first."); } this.collisionGroupType = CollisionGroups.Terrain; this.shapeType = ShapeType.Heightfield; var getPhysSceneMsg = ObjectPool.Aquire <MsgGetPhysicsScene>(); getPhysSceneMsg.UniqueTarget = this.parentEntity.UniqueID; this.parentEntity.Game.SendInterfaceMessage(getPhysSceneMsg, InterfaceType.Physics); IPhysicsScene physScene = getPhysSceneMsg.PhysicsScene; if (physScene != null) { CreateHeightfieldActor(physScene, terrainComp.heightData, terrainComp.ScaleFactor); if (this.actor != null) { var addToSceneMsg = ObjectPool.Aquire <MsgAddEntityToPhysicsScene>(); addToSceneMsg.Actor = this.actor; addToSceneMsg.EntityID = this.parentEntity.UniqueID; this.parentEntity.Game.SendInterfaceMessage(addToSceneMsg, InterfaceType.Physics); var setCollGroup = ObjectPool.Aquire <MsgSetActorToCollisionGroup>(); setCollGroup.Actor = this.actor; setCollGroup.GroupType = this.collisionGroupType; this.parentEntity.Game.SendInterfaceMessage(setCollGroup, InterfaceType.Physics); } } }