/// <summary> /// Erzeugt ein BauZustand-Objekt mit den aktuellen Daten des Bau. /// </summary> internal AnthillState ErzeugeInfo() { AnthillState zustand = new AnthillState(colonyId, Id); zustand.PositionX = koordinate.X / SimulationEnvironment.PLAYGROUND_UNIT; zustand.PositionY = koordinate.Y / SimulationEnvironment.PLAYGROUND_UNIT; zustand.Radius = koordinate.Radius / SimulationEnvironment.PLAYGROUND_UNIT; return(zustand); }
public AnthillState GenerateState() { AnthillState state = new AnthillState(ColonyId, Id); state.PositionX = PositionX; state.PositionY = PositionY; state.Radius = Radius; return(state); }
protected override void RequestDraw() { MainState _currentState = _state; if (_currentState != null) { Index2 cells = _currentState.Map.GetCellCount(); DrawPlayground(cells, _currentState.Map.Tiles); foreach (var item in _currentState.Items) { if (item is AnthillState) { AnthillState anthillState = item as AnthillState; DrawItem(item.Id, item.Position, anthillState.Radius, null, null, Color.Brown, null, null, null, null, null, null); } if (item is AntState) { AntState antState = item as AntState; // DrawItem(item.Id, item.Position, antState.Radius, Color.Black); } if (item is SugarState) { SugarState sugarState = item as SugarState; // DrawItem(item.Id, item.Position, sugarState.Radius, Color.White); } if (item is AppleState) { AppleState appleState = item as AppleState; // DrawItem(item.Id, item.Position, 5, Color.LightGreen); } if (item is MarkerState) { MarkerState markerState = item as MarkerState; // DrawItem(item.Id, item.Position, 10, Color.Yellow); } if (item is BugState) { // DrawItem(item.Id, item.Position, 10, Color.Blue); } } } }
/// <summary> /// Render Anthill. /// </summary> /// <param name="colony">Colony-ID</param> /// <param name="state"><see cref="AnthillState"/></param> /// <param name="pickray"><see cref="Pickray"/></param> /// <param name="selected">true, if selected</param> /// <returns>distance from viewer to item, if <see cref="Pickray"/> hits</returns> public float RenderAnthill(int colony, AnthillState state, Pickray pickray, bool selected) { Matrix matrix = Matrix.Translation(state.PositionX - playgroundWidth, 0, -state.PositionY + playgroundHeight); renderDevice.Material = (selected ? selectionMaterial : antMaterial[colony]); renderDevice.Transform.World = matrix; antHillMesh.DrawSubset(0); // Check for pickray-collision matrix.M42 = 0.0f; matrix.Invert(); pickray.Origin.TransformCoordinate(matrix); pickray.Direction.TransformNormal(matrix); if (collisionBox.Intersect(pickray.Origin, pickray.Direction)) { return (Vector3.Subtract ( pickray.Origin, new Vector3(state.PositionX - playgroundWidth, 0, -state.PositionY + playgroundHeight)).Length()); } return(0.0f); }
public float DrawAnthill(int colony, AnthillState state, Pickray pickray, bool selected) { Matrix matrix = Matrix.CreateTranslation(state.PositionX - playgroundWidth, 0, -state.PositionY + playgroundHeight); BoundingSphere collisionBox = new BoundingSphere( new Vector3(state.PositionX - playgroundWidth, 0, -state.PositionY + playgroundHeight), state.Radius); // Cone var mesh = anthill.Meshes[0]; foreach (BasicEffect eff in mesh.Effects) { eff.World = matrix; eff.View = camera.ViewMatrix; eff.Projection = camera.ProjectionMatrix; eff.LightingEnabled = true; eff.EmissiveColor = new Vector3(0.1f, 0.05f, 0f); eff.DirectionalLight0.Enabled = true; eff.DirectionalLight0.Direction = LIGHT_0_DIRECTION; eff.DirectionalLight0.DiffuseColor = new Vector3(0.4f, 0.4f, 0.4f); eff.DirectionalLight1.Enabled = true; eff.DirectionalLight1.Direction = LIGHT_1_DIRECTION; eff.DirectionalLight1.DiffuseColor = new Vector3(0.1f, 0.1f, 0.2f); eff.DirectionalLight2.Enabled = true; eff.DirectionalLight2.Direction = LIGHT_2_DIRECTION; eff.DirectionalLight2.DiffuseColor = new Vector3(0.1f, 0.1f, 0.2f); } mesh.Draw(); // Bar mesh = anthill.Meshes[1]; foreach (BasicEffect eff in mesh.Effects) { eff.World = matrix; eff.View = camera.ViewMatrix; eff.Projection = camera.ProjectionMatrix; eff.LightingEnabled = true; eff.EmissiveColor = new Vector3(0.5f, 0.5f, 0.5f); eff.DirectionalLight0.Enabled = true; eff.DirectionalLight0.Direction = LIGHT_0_DIRECTION; eff.DirectionalLight1.Enabled = true; eff.DirectionalLight1.Direction = LIGHT_1_DIRECTION; eff.DirectionalLight2.Enabled = true; eff.DirectionalLight2.Direction = LIGHT_2_DIRECTION; } mesh.Draw(); // Flag mesh = anthill.Meshes[2]; foreach (BasicEffect eff in mesh.Effects) { eff.World = matrix; eff.View = camera.ViewMatrix; eff.Projection = camera.ProjectionMatrix; eff.LightingEnabled = true; eff.EmissiveColor = playerColors[colony - 1]; eff.DirectionalLight0.Enabled = true; eff.DirectionalLight0.Direction = LIGHT_0_DIRECTION; eff.DirectionalLight1.Enabled = true; eff.DirectionalLight1.Direction = LIGHT_1_DIRECTION; eff.DirectionalLight2.Enabled = true; eff.DirectionalLight2.Direction = LIGHT_2_DIRECTION; } mesh.Draw(); // Check for pickray-collision float?distance = collisionBox.Intersects(new Ray(pickray.Origin, pickray.Direction)); if (distance.HasValue) { return(distance.Value); } return(0.0f); }
public Anthill(AnthillState state) : base(state.ColonyId, state.Id) { PositionX = state.PositionX; PositionY = state.PositionY; Radius = state.Radius; }