/// <summary> /// Clamp the length of a vector. /// </summary> /// <param name="a">Vector to clamp.</param> /// <param name="maxlen">Maximal length.</param> /// <returns>Clamped vector.</returns> public static Vec2 Clamp(Vec2 a, double maxlen) { if (a.Length <= maxlen) return a; else return a.Unit * maxlen; }
/// <summary> /// Floor each component. /// </summary> public static Vec2i Floor(Vec2 v) { return new Vec2i(Floor(v.X), Floor(v.Y)); }
/// <summary> /// Ceil each component. /// </summary> public static Vec2i Ceil(Vec2 v) { return new Vec2i(Ceil(v.X), Ceil(v.Y)); }
/// <summary> /// Multiply two vectors componentwise. /// </summary> /// <param name="a">First vector.</param> /// <param name="b">Second vector.</param> public static Vec2 CompMult(Vec2 a, Vec2 b) { return new Vec2(a.X * b.X, a.Y * b.Y); }
/// <summary> /// Divide one vector by another componentwise. /// </summary> /// <param name="a">First vector.</param> /// <param name="b">Second vector.</param> public static Vec2 CompDiv(Vec2 a, Vec2 b) { return new Vec2(a.X / b.X, a.Y / b.Y); }
/// <summary> /// Rotate a vector 90 degrees counter-clockwise. /// </summary> /// <param name="a">Vector to rotate.</param> public static Vec2 Rotate90(Vec2 a) { return new Vec2(-a.Y, a.X); }
/// <summary> /// Rotate a vector. /// </summary> /// <param name="a">Vector to rotate.</param> /// <param name="angle">Ratation angle.</param> /// <returns>Rotated vector.</returns> public static Vec2 Rotate(Vec2 a, double angle) { double s = Math.Sin(angle); double c = Math.Cos(angle); return new Vec2(a.X * c - a.Y * s, a.X * s + a.Y * c); }
/// <summary> /// Get the skew product of two vectors. /// </summary> /// <param name="a">First vector.</param> /// <param name="b">Second vector.</param> /// <returns></returns> public static double Skew(Vec2 a, Vec2 b) { return a.X * b.Y - a.Y * b.X; }
/// <summary> /// Get the dot product of two vectors. /// </summary> /// <param name="a">First vector.</param> /// <param name="b">Second vector.</param> public static double Dot(Vec2 a, Vec2 b) { return a.X * b.X + a.Y * b.Y; }
public override void MouseMove(Vec2 position) { base.MouseMove(position); if (client.Player != null) client.Player.Get<PositionComponent>().Rotation = (Mouse.Position - new Vec2(App.Width, App.Height) / 2).Arg + camera.Rotation; }
public override void MouseDown(MouseButton button, Vec2 position) { base.MouseDown(button, position); }