forked from Rampastring/Rampastring.XNAUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRMath.cs
42 lines (39 loc) · 1.28 KB
/
RMath.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rampastring.XNAUI
{
/// <summary>
/// Contains static vector math functions.
/// </summary>
public static class RMath
{
/// <summary>
/// Returns the angle / direction of a vector in radians.
/// </summary>
/// <param name="vector">The vector.</param>
public static float AngleFromVector(Vector2 vector)
{
return (float)Math.Atan2(vector.Y, vector.X);
}
/// <summary>
/// Creates and returns a new vector with the given length and angle.
/// </summary>
/// <param name="length">The length of the vector.</param>
/// <param name="angle">The angle of the vector.</param>
public static Vector2 VectorFromLengthAndAngle(float length, float angle)
{
return new Vector2(length * (float)Math.Cos(angle), length * (float)Math.Sin(angle));
}
public static Color MultiplyAlpha(Color color)
{
return new Color((color.A * color.R) / 255,
(color.A * color.G) / 255,
(color.A * color.B) / 255,
color.A);
}
}
}