Search in sources :

Example 36 with Vector3f

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;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Example 37 with Vector3f

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;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Example 38 with Vector3f

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));
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BaseVector3f(org.terasology.math.geom.BaseVector3f) BaseVector3i(org.terasology.math.geom.BaseVector3i) Vector3i(org.terasology.math.geom.Vector3i)

Example 39 with Vector3f

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;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BaseVector3f(org.terasology.math.geom.BaseVector3f)

Example 40 with Vector3f

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();
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) Vector3f(org.terasology.math.geom.Vector3f)

Aggregations

Vector3f (org.terasology.math.geom.Vector3f)194 LocationComponent (org.terasology.logic.location.LocationComponent)45 EntityRef (org.terasology.entitySystem.entity.EntityRef)44 Quat4f (org.terasology.math.geom.Quat4f)33 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)26 Vector3i (org.terasology.math.geom.Vector3i)21 Test (org.junit.Test)20 ClientComponent (org.terasology.network.ClientComponent)15 Command (org.terasology.logic.console.commandSystem.annotations.Command)14 Matrix4f (org.terasology.math.geom.Matrix4f)13 BaseVector3f (org.terasology.math.geom.BaseVector3f)9 Block (org.terasology.world.block.Block)9 Vector2f (org.terasology.math.geom.Vector2f)8 HitResult (org.terasology.physics.HitResult)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 IOException (java.io.IOException)6 FloatBuffer (java.nio.FloatBuffer)6 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 AABB (org.terasology.math.AABB)5 ChunkMesh (org.terasology.rendering.primitives.ChunkMesh)5