1
\$\begingroup\$

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);
\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you very much. That helped a lot. I'm really bad at trigonometry. I need to get a trigonometry book. Thanks again ^_^ \$\endgroup\$
    – user50637
    Aug 16 '14 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy