22 lines
804 B
Java
22 lines
804 B
Java
package speiger.src.coreengine.math.vector;
|
|
|
|
import speiger.src.coreengine.math.vector.floats.Vec2f;
|
|
import speiger.src.coreengine.math.vector.floats.Vec3f;
|
|
|
|
public class VectorUtil
|
|
{
|
|
public static float barryCentric(Vec3f p1, Vec3f p2, Vec3f p3, Vec2f pos)
|
|
{
|
|
float det = (p2.getZ() - p3.getZ()) * (p1.getX() - p3.getX()) + (p3.getX() - p2.getX()) * (p1.getZ() - p3.getZ());
|
|
float l1 = ((p2.getZ() - p3.getZ()) * (pos.getX() - p3.getX()) + (p3.getX() - p2.getX()) * (pos.getY() - p3.getZ())) / det;
|
|
float l2 = ((p3.getZ() - p1.getZ()) * (pos.getX() - p3.getX()) + (p1.getX() - p3.getX()) * (pos.getY() - p3.getZ())) / det;
|
|
float l3 = 1.0f - l1 - l2;
|
|
return l1 * p1.getY() + l2 * p2.getY() + l3 * p3.getY();
|
|
}
|
|
|
|
public static float fma(float x, float y, float z)
|
|
{
|
|
return x * y + z;
|
|
}
|
|
}
|