Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to draw multiple primitive lines which start at the center of the screen and end at the edges of the screen, traveling at specific angles:

enter image description here

How can I set the angle for each line?

Here is my code where I draw only one line from the middle of the screen to the top of the screen.

LineVertices = new VertexPositionColor[2];
LineVertices[0].Position = new Vector3(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2, 0);
LineVertices[0].Color = Color.Red;
LineVertices[1].Position = new Vector3(graphics.GraphicsDevice.Viewport.Width / 2, 0, 0);
LineVertices[1].Color = Color.Red;
.
.
.
//Draw call 
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, Line2Vertices, 0, 1);
share|improve this question

1 Answer 1

This is essentially simple trigonometry. Assuming the center of the screen is your origin (i.e. (0, 0)), then it's pretty straightforward:

x = length * sin(angle);
y = length * cos(angle);

Just insert the proper numbers and you end up with your vertex coordinates.

share|improve this answer
    
Thank you very much. That helped a lot. I'm really bad at trigonometry. I need to get a trigonometry book. Thanks again ^_^ –  user50637 Aug 16 at 10:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.