Blame |
Last modification |
View Log
| RSS feed
package com.gebauz.bauzoid.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 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 boolean 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
);
}
}