use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class AABB method intersectRectangle.
public boolean intersectRectangle(Vector3f from, Vector3f direction) {
Vector3f dirfrac = new Vector3f();
dirfrac.x = 1.0f / direction.x;
dirfrac.y = 1.0f / direction.y;
dirfrac.z = 1.0f / direction.z;
float t1 = (min.x - from.x) * dirfrac.x;
float t2 = (max.x - from.x) * dirfrac.x;
float t3 = (min.y - from.y) * dirfrac.y;
float t4 = (max.y - from.y) * dirfrac.y;
float t5 = (min.z - from.z) * dirfrac.z;
float t6 = (max.z - from.z) * dirfrac.z;
float tmin = Math.max(Math.max(Math.min(t1, t2), Math.min(t3, t4)), Math.min(t5, t6));
float tmax = Math.min(Math.min(Math.max(t1, t2), Math.max(t3, t4)), Math.max(t5, t6));
if (tmax < 0) {
return false;
}
if (tmin > tmax) {
return false;
}
return true;
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class AABB method getExtents.
/**
* @return The distance from the center to the max node
*/
public Vector3f getExtents() {
Vector3f dimensions = new Vector3f(max);
dimensions.sub(min);
dimensions.scale(HALVING_FACTOR);
return dimensions;
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class Region3i method createFromCenterExtents.
/**
* Create a region with center point and x,y,z coordinate extents size
* @param center the center point of region
* @param extents the extents size of each side of region
* @return a new region base on the center point and extents size
*/
public static Region3i createFromCenterExtents(BaseVector3f center, BaseVector3f extents) {
Vector3f min = new Vector3f(center.x() - extents.x(), center.y() - extents.y(), center.z() - extents.z());
Vector3f max = new Vector3f(center.x() + extents.x(), center.y() + extents.y(), center.z() + extents.z());
max.x = max.x - Math.ulp(max.x);
max.y = max.y - Math.ulp(max.y);
max.z = max.z - Math.ulp(max.z);
return createFromMinMax(new Vector3i(min), new Vector3i(max));
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class Region3i method center.
/**
* @return The position at the center of the region
*/
public Vector3f center() {
Vector3f result = min.toVector3f();
Vector3f halfSize = size.toVector3f();
halfSize.scale(0.5f);
result.add(halfSize);
return result;
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class AABBRenderer method renderSolid.
public void renderSolid() {
CoreRegistry.get(ShaderManager.class).enableDefault();
glPushMatrix();
Vector3f cameraPosition = CoreRegistry.get(LocalPlayer.class).getViewPosition();
glTranslated(aabb.getCenter().x - cameraPosition.x, -cameraPosition.y, aabb.getCenter().z - cameraPosition.z);
renderSolidLocally();
glPopMatrix();
}
Aggregations