Rev 32 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.framework.util;
public class Vector2
{
public float x
;
public float y
;
public Vector2
()
{
}
public Vector2
(float _x,
float _y
)
{
x = _x
;
y = _y
;
}
public void normalize
()
{
float len = length
();
if (len
!= 0.0f
)
{
x /= len
;
y /= len
;
}
}
public float length
()
{
float squared = squaredLength
();
return (float)Math.
sqrt(squared
);
}
public void setLength
(float newLength
)
{
normalize
();
x
*= newLength
;
y
*= newLength
;
}
public boolean isZero
()
{
return ((x == 0.0f
) && (y == 0.0f
));
}
public float squaredLength
()
{
return (x
*x + y
*y
);
}
public void addVector
(Vector2 v
)
{
x += v.
x;
y += v.
y;
}
public void subtractVector
(Vector2 v
)
{
x -= v.
x;
y -= v.
y;
}
public float dotProduct
(Vector2 v
)
{
return dotProduct
(this, v
);
}
static public float dotProduct
(Vector2 a, Vector2 b
)
{
return (a.
x*b.
x + a.
y*b.
y);
}
static public float distance
(Vector2 a, Vector2 b
)
{
Vector2 c =
new Vector2
(b.
x - a.
x, b.
y - a.
y);
return c.
length();
}
}