Rev 811 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BauzoidNET
.math
{
public class Vector4
{
public float x
;
public float y
;
public float z
;
public float w
;
public Vector4
()
{
}
public Vector4
(float _x,
float _y,
float _z,
float _w
)
{
set
(_x, _y, _z, _w
);
}
public void set
(float _x,
float _y,
float _z,
float _w
)
{
x
= _x
;
y
= _y
;
z
= _z
;
w
= _w
;
}
public void setFrom
(Vector4 other
)
{
x
= other
.x;
y
= other
.y;
z
= other
.z;
w
= other
.w;
}
public void normalize
()
{
float len
= length
();
if (len
!= 0
.0f
)
{
x
/= len
;
y
/= len
;
z
/= len
;
w
/= len
;
}
}
public float length
()
{
float squared
= squaredLength
();
return (float)Math
.Sqrt(squared
);
}
public void setLength
(float newLength
)
{
normalize
();
x
*= newLength
;
y
*= newLength
;
z
*= newLength
;
w
*= newLength
;
}
public bool isZero
()
{
return ((x
== 0
.0f
) && (y
== 0
.0f
) && (z
== 0
.0f
) && (w
== 0
.0f
));
}
public float squaredLength
()
{
return (x
* x
+ y
* y
+ z
* z
* w
* w
);
}
public void addVector
(Vector4 v
)
{
x
+= v
.x;
y
+= v
.y;
z
+= v
.z;
w
+= v
.w;
}
public void subtractVector
(Vector4 v
)
{
x
-= v
.x;
y
-= v
.y;
z
-= v
.z;
w
-= v
.w;
}
public float dotProduct
(Vector4 v
)
{
return dotProduct
(this, v
);
}
static public float dotProduct
(Vector4 a, Vector4 b
)
{
return (a
.x * b
.x + a
.y * b
.y + a
.z * b
.z + a
.w * b
.w);
}
static public float distance
(Vector4 a, Vector4 b
)
{
Vector4 c
= new Vector4
(b
.x - a
.x, b
.y - a
.y, b
.z - a
.z, b
.w - a
.w);
return c
.length();
}
/** Return a copy of this Vector4. */
public Vector4 copy
()
{
return new Vector4
(x, y, z, w
);
}
/// <summary>
/// Return the largest component of the Vector3.
/// </summary>
public float max
()
{
return Math
.Max(x, Math
.Max(y, Math
.Max(z, w
)));
}
/// <summary>
/// Return the smallest component of the Vector3.
/// </summary>
public float min
()
{
return Math
.Min(x, Math
.Min(y, Math
.Min(z, w
)));
}
}
}