public static RaySegmentsShape CreateRays(RaySegment[] raySegments) { RaySegmentsShape rayShape = new RaySegmentsShape(raySegments); rayShape.Tag = new RaysSegmentsDrawable(rayShape); return(rayShape); }
void SetShape(RaySegmentsShape shape) { current = new RaySegmentsCollisionInfo[shape.Segments.Length]; next = new RaySegmentsCollisionInfo[shape.Segments.Length]; Init(current); Init(next); }
public RaysSegmentsDrawable(RaySegmentsShape shape) { this.shape = shape; this.array = new Vector2D[shape.Segments.Length * 2]; for (int index = 0; index < shape.Segments.Length; ++index) { RaySegment segment = shape.Segments[index]; Ray ray = segment.RayInstance; array[index * 2] = ray.Origin; array[index * 2 + 1] = ray.Origin + ray.Direction * segment.Length; } }
public RaySegmentsCollisionLogic(Body body) : base(GetLifespan(body)) { this.body = body; RaySegmentsShape shape = body.Shape as RaySegmentsShape; if (shape == null) { throw new ArgumentException("the shape must be a RaySegmentsShape"); } SetShape(shape); body.LifetimeChanged += OnLifetimeChanged; body.ShapeChanged += OnShapeChanged; body.Collided += OnCollided; }
void OnShapeChanged(object sender, EventArgs e) { RaySegmentsShape newShape = body.Shape as RaySegmentsShape; if (newShape == null) { this.Lifetime = new Lifespan(); this.Lifetime.IsExpired = true; ClearEvents(); } else { SetShape(newShape); } }
void DrawInternal() { if (entity.Shape.Tag is Sprite) { Sprite s = (Sprite)entity.Shape.Tag; s.Draw(); if (DrawLinesAndNormalsForSprites) { foreach (Vector2D[] vertexes in s.Polygons) { Gl.glLineWidth(1); Gl.glBegin(Gl.GL_LINES); Vector2D v1 = vertexes[vertexes.Length - 1]; Vector2D v2; for (int index = 0; index < vertexes.Length; ++index, v1 = v2) { v2 = vertexes[index]; Gl.glColor3f(1, 1, 1); Gl.glVertex2f(v1.X, v1.Y); Gl.glColor3f(1, 0, 0); Gl.glVertex2f(v2.X, v2.Y); DrawNormal(ref v1, ref v2); } Gl.glEnd(); } } } else if (entity.Shape is ParticleShape) { Gl.glBegin(Gl.GL_POINTS); Gl.glColor3f(1, 0, 0); //Gl.glColor3d(rand.NextDouble(), rand.NextDouble(), rand.NextDouble()); foreach (Vector2D vector in entity.Shape.Vertexes) { Gl.glVertex2f((Scalar)vector.X, (Scalar)vector.Y); } Gl.glEnd(); } else if (entity.Shape is RaySegmentsShape) { Gl.glLineWidth(1); RaySegmentsShape collection = (RaySegmentsShape)entity.Shape; Gl.glBegin(Gl.GL_LINES); for (int index = 0; index < collection.Segments.Length; ++index) { Gl.glColor3f(1, 0, 1); RaySegment ray = collection.Segments[index]; Gl.glVertex2f(ray.RayInstance.Origin.X, ray.RayInstance.Origin.Y); Scalar length; if (logic.Collisions[index].Distance == -1) { length = ray.Length; } else { length = logic.Collisions[index].Distance; } Vector2D temp = ray.RayInstance.Origin + ray.RayInstance.Direction * length; Gl.glColor3f(1, 1, 1); Gl.glVertex2f(temp.X, temp.Y); } Gl.glEnd(); } else { Gl.glBegin(Gl.GL_POLYGON); bool first = true; bool second = true; foreach (Vector2D vector in entity.Shape.Vertexes) { if (first) { Gl.glColor3f(1, .5f, 0); first = false; } else if (second) { Gl.glColor3f(1, 1, 1); second = false; } Gl.glVertex2f((Scalar)vector.X, (Scalar)vector.Y); } Gl.glEnd(); } }