public void OnRendererRefresh() { // Remove old shadows _shadowHulls.ForEach(sH => LightingComponent.Light.Hulls.Remove(sH)); int polyCount = Polygon.Indices.Length / 3; for (int index = 0; index < polyCount; index++) { List<short> currentIndie = Polygon.Indices.ToList<short>().GetRange(index * 3, 3); List<Vector2> currentVerts = new List<Vector2>(); currentIndie.ForEach(i => currentVerts.Add(Polygon.Vertices[i] + Polygon.WorldPosition)); currentVerts.Reverse(); PolygonHull hull = new PolygonHull(WorldPosition, currentVerts.ToList<Vector2>()); // Hacky fix hull.Hull.Position.Y -= Globals.ScreenHeight; _shadowHulls.Add(hull.Hull); LightingComponent.Light.Hulls.Add(hull.Hull); } }
public override void Update(GameTime gameTime) { effect.Projection = GetProjectionMatrix(); effect.View = GetViewMatrix(); if (!isComplete && (MouseInput.isLeftClicked() || (points.Count > 0 && Vector2.Distance(points[points.Count - 1], MouseInput.Position) > 5))) { points.Add(MouseInput.Position); } if (MouseInput.isRightClicked()) { isComplete = false; points.Clear(); } if (KeyboardInput.isKeyPressed(Keys.Enter)) { isComplete = true; // points.Add(points[0]); Vector2[] sourceVerticies; int[] sourceIndicies; Triangulator.Triangulator.Triangulate(points.ToArray(), Triangulator.WindingOrder.Clockwise, out sourceVerticies, out sourceIndicies); verticies = new VertexPositionColorTexture[sourceVerticies.Length]; for (int index = 0; index < sourceVerticies.Length; index++) { Color mRandomColor = new Color( (Globals.Random.Next(50, 230)), (Globals.Random.Next(50, 230)), (Globals.Random.Next(50, 230))); verticies[index] = new VertexPositionColorTexture(new Vector3(sourceVerticies[index], 0f), Color.White, sourceVerticies[index] / 10); } indices = new short[sourceIndicies.Length]; for (int index = 0; index < sourceIndicies.Length; index++) { indices[index] = (short)sourceIndicies[index]; } //RepairTextureWrapSeam(verticies.ToList<VertexPositionColorTexture>(), indices.ToList<short>()); //sourceVerticies.(points[0]); //sourceVerticies.Reverse(); int numOfPoly = indices.Length / 3; for (int index = 0; index < numOfPoly; index++) { List<short> currentIndie = indices.ToList<short>().GetRange(index * 3, 3); List<Vector2> currentVerts = new List<Vector2>(); currentIndie.ForEach(i => currentVerts.Add(sourceVerticies[i])); //= sourceVerticies.ToList<Vector2>().GetRange(index * 3, 3); currentVerts.Reverse(); hull = new PolygonHull(WorldPosition, currentVerts.ToList<Vector2>()); hull.Hull.Position.Y -= Globals.ScreenHeight; //hull.Hull.Opacity = 0.5f; //hull = new BasicHull(WorldPosition,new Vector2(50, 50)); Scene.ComponentManager.GetComponent<LightingComponent>().Light.Hulls.Add(hull.Hull); //currentVerts.Reverse(); /* * List<Vector2> physicsVerts = new List<Vector2>(); currentVerts.ToList<Vector2>().ForEach(s => physicsVerts.Add(ConvertUnits.ToSimUnits(s))); Body b = BodyFactory.CreatePolygon(PhysicsComponent.World, new FarseerPhysics.Common.Vertices(physicsVerts), 1); */ List<Vector2> physicsVerts = new List<Vector2>(); currentVerts.ToList<Vector2>().ForEach(s => physicsVerts.Add(ConvertUnits.ToSimUnits(s))); Path path = new Path(physicsVerts); path.Closed = true; path.Add(physicsVerts[0]); Body body = BodyFactory.CreateBody(PhysicsComponent.World); body.BodyType = BodyType.Static; PathManager.ConvertPathToPolygon(path, body, 1.0f, currentVerts.Count); } outlineVerticies = new List<VertexPositionColor[]>(); if (points.Count > 3) { for (int i = 0; i < points.Count - 2; i++) { MakeZone(points[i], points[i + 1], points[i + 2]); } MakeZone(points[points.Count - 2], points[points.Count - 1], points[0]); MakeZone(points[points.Count - 1], points[0], points[1]); } } //if (hull != null) hull.setPosition(points[0]); base.Update(gameTime); }