I needed a method that took two Vector3f’s and returned a Vector3f that was right between them. I didn’t find one in the Vector3f class so I made one myself. It’s really simple.
[java] public Vector3f middle(Vector3f v1, Vector3f v2){
Vector3f pos = new Vector3f(v1);
pos.addLocal((v2.x-v1.x)/2f,
(v2.y-v1.y)/2f,
(v2.z-v1.z)/2f);
return pos;
}[/java]
Use it as much as you like. Can be made static if you want.
Why is there no method like this in the Vector3f class? Perhaps I didn’t find it.
Example:
[java] Vector3f v1 = new Vector3f(2, 2, 2);
Vector3f v2 = new Vector3f(4, 4, 4);
Vector3f m = middle(v1, v2);
System.out.println(m);[/java]
Prints (3.0, 3.0, 3.0).
FastMath.interpolate()
normen said:
FastMath.interpolate()
Those methods seems to be unnecessarily advanced for what I'm doing. I'll keep using my method :)
No, its very efficient and in contrast to your method it doesnt create a new vector.