Rev 782 | Rev 811 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 782 | chris | 1 | using System; |
| 2 | using System.Collections.Generic; |
||
| 3 | using System.Linq; |
||
| 4 | using System.Text; |
||
| 5 | using System.Threading.Tasks; |
||
| 6 | |||
| 7 | namespace BauzoidNET.math |
||
| 8 | { |
||
| 787 | chris | 9 | public class Vector4 |
| 782 | chris | 10 | { |
| 11 | public float x; |
||
| 12 | public float y; |
||
| 13 | public float z; |
||
| 14 | public float w; |
||
| 15 | |||
| 16 | public Vector4() |
||
| 17 | { |
||
| 18 | } |
||
| 19 | |||
| 20 | public Vector4(float _x, float _y, float _z, float _w) |
||
| 21 | { |
||
| 22 | x = _x; |
||
| 23 | y = _y; |
||
| 24 | z = _z; |
||
| 25 | w = _w; |
||
| 26 | } |
||
| 27 | |||
| 28 | public void normalize() |
||
| 29 | { |
||
| 30 | float len = length(); |
||
| 31 | if (len != 0.0f) |
||
| 32 | { |
||
| 33 | x /= len; |
||
| 34 | y /= len; |
||
| 35 | z /= len; |
||
| 36 | w /= len; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | public float length() |
||
| 41 | { |
||
| 42 | float squared = squaredLength(); |
||
| 43 | return (float)Math.Sqrt(squared); |
||
| 44 | } |
||
| 45 | |||
| 46 | public void setLength(float newLength) |
||
| 47 | { |
||
| 48 | normalize(); |
||
| 49 | x *= newLength; |
||
| 50 | y *= newLength; |
||
| 51 | z *= newLength; |
||
| 52 | w *= newLength; |
||
| 53 | } |
||
| 54 | |||
| 55 | public bool isZero() |
||
| 56 | { |
||
| 57 | return ((x == 0.0f) && (y == 0.0f) && (z == 0.0f) && (w == 0.0f)); |
||
| 58 | } |
||
| 59 | |||
| 60 | public float squaredLength() |
||
| 61 | { |
||
| 62 | return (x * x + y * y + z * z * w * w); |
||
| 63 | } |
||
| 64 | |||
| 65 | public void addVector(Vector4 v) |
||
| 66 | { |
||
| 67 | x += v.x; |
||
| 68 | y += v.y; |
||
| 69 | z += v.z; |
||
| 70 | w += v.w; |
||
| 71 | } |
||
| 72 | |||
| 73 | public void subtractVector(Vector4 v) |
||
| 74 | { |
||
| 75 | x -= v.x; |
||
| 76 | y -= v.y; |
||
| 77 | z -= v.z; |
||
| 78 | w -= v.w; |
||
| 79 | } |
||
| 80 | |||
| 81 | public float dotProduct(Vector4 v) |
||
| 82 | { |
||
| 83 | return dotProduct(this, v); |
||
| 84 | } |
||
| 85 | |||
| 86 | static public float dotProduct(Vector4 a, Vector4 b) |
||
| 87 | { |
||
| 88 | return (a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w); |
||
| 89 | } |
||
| 90 | |||
| 91 | static public float distance(Vector4 a, Vector4 b) |
||
| 92 | { |
||
| 93 | Vector4 c = new Vector4(b.x - a.x, b.y - a.y, b.z - a.z, b.w - a.w); |
||
| 94 | return c.length(); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** Return a copy of this Vector4. */ |
||
| 98 | public Vector4 copy() |
||
| 99 | { |
||
| 100 | return new Vector4(x, y, z, w); |
||
| 101 | } |
||
| 102 | |||
| 103 | } |
||
| 104 | } |