public void UpdateInstances(GraphicsDevice g, Predicate <BoundingBox> fVisible) { visible = new List <VisibleBuilding>(); if (fTeamIndex == eTeamIndex) { // Always Show Friendly Buildings for (int i = 0; i < fTeam.Buildings.Count; i++) { if (fTeam.Buildings[i].Data != Data) { continue; } if (fVisible(fTeam.Buildings[i].BBox)) { VisibleBuilding vb = new VisibleBuilding(); vb.Position = fTeam.Buildings[i].WorldPosition; vb.View = fTeam.Buildings[i].ViewDirection; vb.BuildAmount = 1 - (float)fTeam.Buildings[i].BuildAmountLeft / (float)fTeam.Buildings[i].Data.BuildAmount; if (vb.BuildAmount < 0.5) { visible.Add(vb); } else { visible.Add(vb); } } } } else { for (int i = 0; i < fTeam.ViewedEnemyBuildings.Count; i++) { ViewedBuilding bv = fTeam.ViewedEnemyBuildings[i]; if (bv.Team != eTeamIndex || bv.Type != bType) { continue; } BoundingBox bb = new BoundingBox( Data.BBox.Min + bv.WorldPosition, Data.BBox.Max + bv.WorldPosition ); if (fVisible(bb)) { VisibleBuilding vb = new VisibleBuilding(); vb.Position = bv.WorldPosition; vb.View = bv.ViewDirection; vb.BuildAmount = bv.BuildAmount; visible.Add(vb); } } } for (int i = 0; i < VisibleInstanceCount; i++) { instVerts[i].World = Matrix.CreateRotationY( (float)Math.Atan2(-visible[i].View.Y, visible[i].View.X) ) * Matrix.CreateTranslation(visible[i].Position) ; instVerts[i].AnimationFrame = visible[i].BuildAmount; } if (rebuildDVB) { dvbInstances = new DynamicVertexBuffer(g, VertexRTSAnimInst.Declaration, instVerts.Length, BufferUsage.WriteOnly); dvbInstances.ContentLost += (s, a) => { rebuildDVB = true; }; } dvbInstances.SetData(instVerts); }
public void UpdateInstances(GraphicsDevice g, Predicate<BoundingBox> fVisible) { visible = new List<VisibleBuilding>(); if(fTeamIndex == eTeamIndex) { // Always Show Friendly Buildings for(int i = 0; i < fTeam.Buildings.Count; i++) { if(fTeam.Buildings[i].Data != Data) continue; if(fVisible(fTeam.Buildings[i].BBox)) { VisibleBuilding vb = new VisibleBuilding(); vb.Position = fTeam.Buildings[i].WorldPosition; vb.View = fTeam.Buildings[i].ViewDirection; vb.BuildAmount = 1 - (float)fTeam.Buildings[i].BuildAmountLeft / (float)fTeam.Buildings[i].Data.BuildAmount; if(vb.BuildAmount < 0.5) { visible.Add(vb); } else { visible.Add(vb); } } } } else { for(int i = 0; i < fTeam.ViewedEnemyBuildings.Count; i++) { ViewedBuilding bv = fTeam.ViewedEnemyBuildings[i]; if(bv.Team != eTeamIndex || bv.Type != bType) continue; BoundingBox bb = new BoundingBox( Data.BBox.Min + bv.WorldPosition, Data.BBox.Max + bv.WorldPosition ); if(fVisible(bb)) { VisibleBuilding vb = new VisibleBuilding(); vb.Position = bv.WorldPosition; vb.View = bv.ViewDirection; vb.BuildAmount = bv.BuildAmount; visible.Add(vb); } } } for(int i = 0; i < VisibleInstanceCount; i++) { instVerts[i].World = Matrix.CreateRotationY( (float)Math.Atan2(-visible[i].View.Y, visible[i].View.X) ) * Matrix.CreateTranslation(visible[i].Position) ; instVerts[i].AnimationFrame = visible[i].BuildAmount; } if(rebuildDVB) { dvbInstances = new DynamicVertexBuffer(g, VertexRTSAnimInst.Declaration, instVerts.Length, BufferUsage.WriteOnly); dvbInstances.ContentLost += (s, a) => { rebuildDVB = true; }; } dvbInstances.SetData(instVerts); }