githubEdit

Segment

Introduction

A segment is a object defined by two Pointsarrow-up-right. It is not a PositionedObjectarrow-up-right and its points are absolute, which differentiates it from the Linearrow-up-right class.

Segment Intersection

The following code creates two Linesarrow-up-right. One line rotates automatically while the other is controlled by input from the Keyboardarrow-up-right. The two Linesarrow-up-right call the AsSegment method to create Segments that represent the calling Linesarrow-up-right. The segment can then be used to find the point of collision between the two Linesarrow-up-right. If the resulting intersection point has valid coordinates then a collision has occurred. A red ball Spritearrow-up-right marks the intersection point between the two Linesarrow-up-right.

Add the following using statements:

using FlatRedBall.Math.Geometry;
using FlatRedBall.Input;

Add the following at class scope:

Line firstLine;
Line secondLine;
Sprite sprite;

Add the following in Initialize after initializing FlatRedBall:

firstLine = ShapeManager.AddLine();
firstLine.RelativePoint1 = new Point3D(-5, 0);
firstLine.RelativePoint2 = new Point3D(5, 0);
firstLine.RotationZVelocity = 1;

secondLine = ShapeManager.AddLine();
secondLine.RelativePoint1 = new Point3D(-3, 0);
secondLine.RelativePoint2 = new Point3D(3, 0);

sprite = SpriteManager.AddSprite("redball.bmp");
sprite.ScaleX = sprite.ScaleY = .5f;

Add the following in Update:

Intersection.png

Segment Members

Did this article leave any questions unanswered? Post any question in our forumsarrow-up-right for a rapid response.

Last updated

Was this helpful?