org.joml.Vector2f Java Examples

The following examples show how to use org.joml.Vector2f. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static void processFaceVertex(IdxGroup indices, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Integer> indicesList,
        float[] texCoordArr, float[] normArr) {

    // Set index for vertex coordinates
    int posIndex = indices.idxPos;
    indicesList.add(posIndex);

    // Reorder texture coordinates
    if (indices.idxTextCoord >= 0) {
        Vector2f textCoord = textCoordList.get(indices.idxTextCoord);
        texCoordArr[posIndex * 2] = textCoord.x;
        texCoordArr[posIndex * 2 + 1] = 1 - textCoord.y;
    }
    if (indices.idxVecNormal >= 0) {
        // Reorder vectornormals
        Vector3f vecNorm = normList.get(indices.idxVecNormal);
        normArr[posIndex * 3] = vecNorm.x;
        normArr[posIndex * 3 + 1] = vecNorm.y;
        normArr[posIndex * 3 + 2] = vecNorm.z;
    }
}
 
Example #2
Source File: BestCandidateSampling.java    From JOML with MIT License 6 votes vote down vote up
float nearest(float x, float y, float lowerBound, float upperBound) {
    float ub = upperBound;
    if (x < minX - upperBound || x > minX + hs * 2 + upperBound || y < minY - upperBound 
            || y > minY + hs * 2 + upperBound)
        return ub;
    if (children != null) {
        for (int i = quadrant(x, y), c = 0; c < 4; i = (i + 1) & 3, c++) {
            float n1 = children[i].nearest(x, y, lowerBound, ub);
            ub = Math.min(n1, ub);
            if (ub <= lowerBound)
                return lowerBound;
        }
        return ub;
    }
    float ub2 = ub * ub;
    float lb2 = lowerBound * lowerBound;
    for (int i = 0; objects != null && i < objects.size(); i++) {
        Vector2f o = (Vector2f) objects.get(i);
        float d = o.distanceSquared(x, y);
        if (d <= lb2)
            return lowerBound;
        if (d < ub2)
            ub2 = d;
    }
    return (float) Math.sqrt(ub2);
}
 
Example #3
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static void processFaceVertex(IdxGroup indices, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Integer> indicesList,
        float[] texCoordArr, float[] normArr) {

    // Set index for vertex coordinates
    int posIndex = indices.idxPos;
    indicesList.add(posIndex);

    // Reorder texture coordinates
    if (indices.idxTextCoord >= 0) {
        Vector2f textCoord = textCoordList.get(indices.idxTextCoord);
        texCoordArr[posIndex * 2] = textCoord.x;
        texCoordArr[posIndex * 2 + 1] = 1 - textCoord.y;
    }
    if (indices.idxVecNormal >= 0) {
        // Reorder vectornormals
        Vector3f vecNorm = normList.get(indices.idxVecNormal);
        normArr[posIndex * 3] = vecNorm.x;
        normArr[posIndex * 3 + 1] = vecNorm.y;
        normArr[posIndex * 3 + 2] = vecNorm.z;
    }
}
 
Example #4
Source File: PoissonSampling.java    From JOML with MIT License 6 votes vote down vote up
private boolean searchNeighbors(float px, float py) {
    int row = (int) ((py + diskRadius) / cellSize);
    int col = (int) ((px + diskRadius) / cellSize);
    if (grid[row * numCells + col] != null)
        return true;
    int minX = Math.max(0, col - 1);
    int minY = Math.max(0, row - 1);
    int maxX = Math.min(col + 1, numCells - 1);
    int maxY = Math.min(row + 1, numCells - 1);
    for (int y = minY; y <= maxY; y++) {
        for (int x = minX; x <= maxX; x++) {
            Vector2f v = grid[y * numCells + x];
            if (v != null) {
                float dx = v.x - px;
                float dy = v.y - py;
                if (dx * dx + dy * dy < minDistSquared) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #5
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static void processFaceVertex(IdxGroup indices, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Integer> indicesList,
        float[] texCoordArr, float[] normArr) {

    // Set index for vertex coordinates
    int posIndex = indices.idxPos;
    indicesList.add(posIndex);

    // Reorder texture coordinates
    if (indices.idxTextCoord >= 0) {
        Vector2f textCoord = textCoordList.get(indices.idxTextCoord);
        texCoordArr[posIndex * 2] = textCoord.x;
        texCoordArr[posIndex * 2 + 1] = 1 - textCoord.y;
    }
    if (indices.idxVecNormal >= 0) {
        // Reorder vectornormals
        Vector3f vecNorm = normList.get(indices.idxVecNormal);
        normArr[posIndex * 3] = vecNorm.x;
        normArr[posIndex * 3 + 1] = vecNorm.y;
        normArr[posIndex * 3 + 2] = vecNorm.z;
    }
}
 
Example #6
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static void processFaceVertex(IdxGroup indices, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Integer> indicesList,
        float[] texCoordArr, float[] normArr) {

    // Set index for vertex coordinates
    int posIndex = indices.idxPos;
    indicesList.add(posIndex);

    // Reorder texture coordinates
    if (indices.idxTextCoord >= 0) {
        Vector2f textCoord = textCoordList.get(indices.idxTextCoord);
        texCoordArr[posIndex * 2] = textCoord.x;
        texCoordArr[posIndex * 2 + 1] = 1 - textCoord.y;
    }
    if (indices.idxVecNormal >= 0) {
        // Reorder vectornormals
        Vector3f vecNorm = normList.get(indices.idxVecNormal);
        normArr[posIndex * 3] = vecNorm.x;
        normArr[posIndex * 3 + 1] = vecNorm.y;
        normArr[posIndex * 3 + 2] = vecNorm.z;
    }
}
 
Example #7
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static void processFaceVertex(IdxGroup indices, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Integer> indicesList,
        float[] texCoordArr, float[] normArr) {

    // Set index for vertex coordinates
    int posIndex = indices.idxPos;
    indicesList.add(posIndex);

    // Reorder texture coordinates
    if (indices.idxTextCoord >= 0) {
        Vector2f textCoord = textCoordList.get(indices.idxTextCoord);
        texCoordArr[posIndex * 2] = textCoord.x;
        texCoordArr[posIndex * 2 + 1] = 1 - textCoord.y;
    }
    if (indices.idxVecNormal >= 0) {
        // Reorder vectornormals
        Vector3f vecNorm = normList.get(indices.idxVecNormal);
        normArr[posIndex * 3] = vecNorm.x;
        normArr[posIndex * 3 + 1] = vecNorm.y;
        normArr[posIndex * 3 + 2] = vecNorm.z;
    }
}
 
Example #8
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static void processFaceVertex(IdxGroup indices, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Integer> indicesList,
        float[] texCoordArr, float[] normArr) {

    // Set index for vertex coordinates
    int posIndex = indices.idxPos;
    indicesList.add(posIndex);

    // Reorder texture coordinates
    if (indices.idxTextCoord >= 0) {
        Vector2f textCoord = textCoordList.get(indices.idxTextCoord);
        texCoordArr[posIndex * 2] = textCoord.x;
        texCoordArr[posIndex * 2 + 1] = 1 - textCoord.y;
    }
    if (indices.idxVecNormal >= 0) {
        // Reorder vectornormals
        Vector3f vecNorm = normList.get(indices.idxVecNormal);
        normArr[posIndex * 3] = vecNorm.x;
        normArr[posIndex * 3 + 1] = vecNorm.y;
        normArr[posIndex * 3 + 2] = vecNorm.z;
    }
}
 
Example #9
Source File: AABB.java    From LWJGL-3-Tutorial with MIT License 6 votes vote down vote up
public void correctPosition(AABB box2, Collision data) {
	Vector2f correctionDistance = box2.center.sub(center, new Vector2f());
	if (data.distance.x > data.distance.y) {
		if (correctionDistance.x > 0) {
			center.add(data.distance.x, 0);
		}
		else {
			center.add(-data.distance.x, 0);
		}
	}
	else {
		if (correctionDistance.y > 0) {
			center.add(0, data.distance.y);
		}
		else {
			center.add(0, -data.distance.y);
		}
	}
}
 
Example #10
Source File: AABB.java    From LWJGL-3-Tutorial with MIT License 5 votes vote down vote up
public Collision getCollision(Vector2f point) {
	Vector2f distance = point.sub(center);
	distance.x = Math.abs(distance.x);
	distance.y = Math.abs(distance.y);
	
	distance.sub(half_extent);
	
	return new Collision(distance, distance.x < 0 && distance.y < 0);
}
 
Example #11
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Face> facesList) {

    List<Integer> indices = new ArrayList<>();
    // Create position array in the order it has been declared
    float[] posArr = new float[posList.size() * 3];
    int i = 0;
    for (Vector3f pos : posList) {
        posArr[i * 3] = pos.x;
        posArr[i * 3 + 1] = pos.y;
        posArr[i * 3 + 2] = pos.z;
        i++;
    }
    float[] textCoordArr = new float[posList.size() * 2];
    float[] normArr = new float[posList.size() * 3];

    for (Face face : facesList) {
        IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
        for (IdxGroup indValue : faceVertexIndices) {
            processFaceVertex(indValue, textCoordList, normList,
                    indices, textCoordArr, normArr);
        }
    }
    int[] indicesArr = Utils.listIntToArray(indices);
    Mesh mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
    return mesh;
}
 
Example #12
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Face> facesList, int instances) {

    List<Integer> indices = new ArrayList<>();
    // Create position array in the order it has been declared
    float[] posArr = new float[posList.size() * 3];
    int i = 0;
    for (Vector3f pos : posList) {
        posArr[i * 3] = pos.x;
        posArr[i * 3 + 1] = pos.y;
        posArr[i * 3 + 2] = pos.z;
        i++;
    }
    float[] textCoordArr = new float[posList.size() * 2];
    float[] normArr = new float[posList.size() * 3];

    for (Face face : facesList) {
        IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
        for (IdxGroup indValue : faceVertexIndices) {
            processFaceVertex(indValue, textCoordList, normList,
                    indices, textCoordArr, normArr);
        }
    }
    int[] indicesArr = Utils.listIntToArray(indices);
    Mesh mesh;
    if (instances > 1) {
        mesh = new InstancedMesh(posArr, textCoordArr, normArr, indicesArr, instances);
    } else {
        mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
    }
    return mesh;
}
 
Example #13
Source File: DummyGame.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
@Override
public void update(float interval, MouseInput mouseInput) {
    // Update camera based on mouse            
    if (mouseInput.isRightButtonPressed()) {
        Vector2f rotVec = mouseInput.getDisplVec();
        camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0);
    }

    // Update camera position
    Vector3f prevPos = new Vector3f(camera.getPosition());
    camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP);
    // Check if there has been a collision. If true, set the y position to
    // the maximum height
    float height = terrain != null ? terrain.getHeight(camera.getPosition()) : -Float.MAX_VALUE;
    if (camera.getPosition().y <= height) {
        camera.setPosition(prevPos.x, prevPos.y, prevPos.z);
    }

    lightAngle += angleInc;
    if (lightAngle < 0) {
        lightAngle = 0;
    } else if (lightAngle > 180) {
        lightAngle = 180;
    }
    float zValue = (float) Math.cos(Math.toRadians(lightAngle));
    float yValue = (float) Math.sin(Math.toRadians(lightAngle));
    Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection();
    lightDirection.x = 0;
    lightDirection.y = yValue;
    lightDirection.z = zValue;
    lightDirection.normalize();
}
 
Example #14
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Face> facesList) {

    List<Integer> indices = new ArrayList<>();
    // Create position array in the order it has been declared
    float[] posArr = new float[posList.size() * 3];
    int i = 0;
    for (Vector3f pos : posList) {
        posArr[i * 3] = pos.x;
        posArr[i * 3 + 1] = pos.y;
        posArr[i * 3 + 2] = pos.z;
        i++;
    }
    float[] textCoordArr = new float[posList.size() * 2];
    float[] normArr = new float[posList.size() * 3];

    for (Face face : facesList) {
        IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
        for (IdxGroup indValue : faceVertexIndices) {
            processFaceVertex(indValue, textCoordList, normList,
                    indices, textCoordArr, normArr);
        }
    }
    int[] indicesArr = new int[indices.size()];
    indicesArr = indices.stream().mapToInt((Integer v) -> v).toArray();
    Mesh mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
    return mesh;
}
 
Example #15
Source File: DummyGame.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
@Override
public void update(float interval, MouseInput mouseInput) {
    // Update camera position
    camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP);

    // Update camera based on mouse            
    if (mouseInput.isRightButtonPressed()) {
        Vector2f rotVec = mouseInput.getDisplVec();
        camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0);
    }
}
 
Example #16
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Face> facesList, int instances) {

    List<Integer> indices = new ArrayList<>();
    // Create position array in the order it has been declared
    float[] posArr = new float[posList.size() * 3];
    int i = 0;
    for (Vector3f pos : posList) {
        posArr[i * 3] = pos.x;
        posArr[i * 3 + 1] = pos.y;
        posArr[i * 3 + 2] = pos.z;
        i++;
    }
    float[] textCoordArr = new float[posList.size() * 2];
    float[] normArr = new float[posList.size() * 3];

    for (Face face : facesList) {
        IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
        for (IdxGroup indValue : faceVertexIndices) {
            processFaceVertex(indValue, textCoordList, normList,
                    indices, textCoordArr, normArr);
        }
    }
    int[] indicesArr = Utils.listIntToArray(indices);
    Mesh mesh;
    if (instances > 1) {
        mesh = new InstancedMesh(posArr, textCoordArr, normArr, indicesArr, instances);
    } else {
        mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
    }
    return mesh;
}
 
Example #17
Source File: DummyGame.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
@Override
public void update(float interval, MouseInput mouseInput, Window window) {
    if (mouseInput.isRightButtonPressed()) {
        // Update camera based on mouse            
        Vector2f rotVec = mouseInput.getDisplVec();
        camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0);
        sceneChanged = true;
    }

    // Update camera position
    camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP);

    lightAngle += angleInc;
    if (lightAngle < 0) {
        lightAngle = 0;
    } else if (lightAngle > 180) {
        lightAngle = 180;
    }
    float zValue = (float) Math.cos(Math.toRadians(lightAngle));
    float yValue = (float) Math.sin(Math.toRadians(lightAngle));
    Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection();
    lightDirection.x = 0;
    lightDirection.y = yValue;
    lightDirection.z = zValue;
    lightDirection.normalize();

    // Update view matrix
    camera.updateViewMatrix();
}
 
Example #18
Source File: DummyGame.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
@Override
public void update(float interval, MouseInput mouseInput, Window window) {
    if (mouseInput.isRightButtonPressed()) {
        // Update camera based on mouse            
        Vector2f rotVec = mouseInput.getDisplVec();
        camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0);
        sceneChanged = true;
    }

    // Update camera position
    camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP);

    lightAngle += angleInc;
    if (lightAngle < 0) {
        lightAngle = 0;
    } else if (lightAngle > 180) {
        lightAngle = 180;
    }
    float zValue = (float) Math.cos(Math.toRadians(lightAngle));
    float yValue = (float) Math.sin(Math.toRadians(lightAngle));
    Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection();
    lightDirection.x = 0;
    lightDirection.y = yValue;
    lightDirection.z = zValue;
    lightDirection.normalize();

    particleEmitter.update((long) (interval * 1000));

    // Update view matrix
    camera.updateViewMatrix();

    // Update sound listener position;
    soundMgr.updateListenerPosition(camera);

    boolean aux = mouseInput.isLeftButtonPressed();
    if (aux && !this.leftButtonPressed && this.selectDetector.selectGameItem(gameItems, window, mouseInput.getCurrentPos(), camera)) {
        this.hud.incCounter();
    }
    this.leftButtonPressed = aux;
}
 
Example #19
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Face> facesList) {

    List<Integer> indices = new ArrayList<>();
    // Create position array in the order it has been declared
    float[] posArr = new float[posList.size() * 3];
    int i = 0;
    for (Vector3f pos : posList) {
        posArr[i * 3] = pos.x;
        posArr[i * 3 + 1] = pos.y;
        posArr[i * 3 + 2] = pos.z;
        i++;
    }
    float[] textCoordArr = new float[posList.size() * 2];
    float[] normArr = new float[posList.size() * 3];

    for (Face face : facesList) {
        IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
        for (IdxGroup indValue : faceVertexIndices) {
            processFaceVertex(indValue, textCoordList, normList,
                    indices, textCoordArr, normArr);
        }
    }
    int[] indicesArr = new int[indices.size()];
    indicesArr = indices.stream().mapToInt((Integer v) -> v).toArray();
    Mesh mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
    return mesh;
}
 
Example #20
Source File: Matrix2fTest.java    From JOML with MIT License 5 votes vote down vote up
public void testRotation() {
    final float angle = (float)Math.PI / 4;
    Matrix2f mat = new Matrix2f().rotation(angle);
    final float coord = 1 / (float) Math.sqrt(2);
    assertTrue("Matrix2f.rotation()",
            new Vector2f(coord, coord).equals(mat.transform(new Vector2f(1, 0)), 0.001f));
}
 
Example #21
Source File: DummyGame.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
@Override
public void update(float interval, MouseInput mouseInput) {
    // Update camera based on mouse            
    if (mouseInput.isRightButtonPressed()) {
        Vector2f rotVec = mouseInput.getDisplVec();
        camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0);
    }

    // Update camera position
    Vector3f prevPos = new Vector3f(camera.getPosition());
    camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP);
    // Check if there has been a collision. If true, set the y position to
    // the maximum height
    float height = terrain != null ? terrain.getHeight(camera.getPosition()) : -Float.MAX_VALUE;
    if (camera.getPosition().y <= height) {
        camera.setPosition(prevPos.x, prevPos.y, prevPos.z);
    }

    lightAngle += angleInc;
    if (lightAngle < 0) {
        lightAngle = 0;
    } else if (lightAngle > 180) {
        lightAngle = 180;
    }
    float zValue = (float) Math.cos(Math.toRadians(lightAngle));
    float yValue = (float) Math.sin(Math.toRadians(lightAngle));
    Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection();
    lightDirection.x = 0;
    lightDirection.y = yValue;
    lightDirection.z = zValue;
    lightDirection.normalize();
}
 
Example #22
Source File: IntersectionfTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testIntersectRaySphere() {
    Vector3f origin = new Vector3f();
    Vector3f dir = new Vector3f(1, 0, 0);
    Vector3f center = new Vector3f(5, 0, 0);
    float radiusSquared = 1.0f;
    Vector2f result = new Vector2f();
    boolean intersect = Intersectionf.intersectRaySphere(origin, dir, center, radiusSquared, result);
    assertTrue(intersect);
    assertEquals(4.0f, result.x, 1E-6f);
    assertEquals(6.0f, result.y, 1E-6f);
}
 
Example #23
Source File: Matrix3x2fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testView() {
    Matrix3x2f m = new Matrix3x2f().view(-4, 0.5f, -2, 3);
    Vector2f v = new Vector2f(-4, -2);
    m.transformPosition(v);
    TestUtil.assertVector2fEquals(new Vector2f(-1, -1), v, 0f);
    v.set(0.5f, 3);
    m.transformPosition(v);
    TestUtil.assertVector2fEquals(new Vector2f(1, 1), v, 0f);
}
 
Example #24
Source File: PoissonSampling.java    From JOML with MIT License 5 votes vote down vote up
private void compute(int k, Callback2d callback) {
    float x, y;
    do {
        x = rnd.nextFloat() * 2.0f - 1.0f;
        y = rnd.nextFloat() * 2.0f - 1.0f;
    } while (x * x + y * y > 1.0f);
    Vector2f initial = new Vector2f(x, y);
    processList.add(initial);
    callback.onNewSample(initial.x, initial.y);
    insert(initial);
    while (!processList.isEmpty()) {
        int i = rnd.nextInt(processList.size());
        Vector2f sample = (Vector2f) processList.get(i);
        boolean found = false;
        search: for (int s = 0; s < k; s++) {
            float angle = rnd.nextFloat() * (float) Math.PI2;
            float radius = minDist * (rnd.nextFloat() + 1.0f);
            x = (float) (radius * Math.sin_roquen_9(angle + Math.PIHalf));
            y = (float) (radius * Math.sin_roquen_9(angle));
            x += sample.x;
            y += sample.y;
            if (x * x + y * y > diskRadiusSquared)
                continue search;
            if (!searchNeighbors(x, y)) {
                found = true;
                callback.onNewSample(x, y);
                Vector2f f = new Vector2f(x, y);
                processList.add(f);
                insert(f);
                break;
            }
        }
        if (!found) {
            processList.remove(i);
        }
    }
}
 
Example #25
Source File: IntersectionfTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testLineSegmentAar() {
    Vector2f p = new Vector2f();
    assertEquals(Intersectionf.ONE_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, 0, 1, 0, 0.5f, -1, 1.5f, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0.5f, 0.5f), p, 1E-6f);
    assertEquals(Intersectionf.ONE_INTERSECTION, Intersectionf.intersectLineSegmentAar(1, 0, 0, 0, 0.5f, -1, 1.5f, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0.5f, 0.5f), p, 1E-6f);
    assertEquals(Intersectionf.INSIDE, Intersectionf.intersectLineSegmentAar(0, 0, 1, 0, -0.5f, -1, 1.5f, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(-0.5f, 1.5f), p, 1E-6f);
    assertEquals(Intersectionf.INSIDE, Intersectionf.intersectLineSegmentAar(1, 0, 0, 0, -0.5f, -1, 1.5f, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(-0.5f, 1.5f), p, 1E-6f);
    assertEquals(Intersectionf.OUTSIDE, Intersectionf.intersectLineSegmentAar(0, 0, 1, 0, 1.5f, -1, 2.5f, 1, p));
    assertEquals(Intersectionf.OUTSIDE, Intersectionf.intersectLineSegmentAar(1, 0, 0, 0, 1.5f, -1, 2.5f, 1, p));
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, 0, 1, 0, 0.5f, -1, 0.75f, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0.5f, 0.75f), p, 1E-6f);
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(1, 0, 0, 0, 0.5f, -1, 0.75f, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0.25f, 0.5f), p, 1E-6f);
    assertEquals(Intersectionf.ONE_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, 0, 1, 0, 1, -1, 2, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(1, 1), p, 1E-6f);
    assertEquals(Intersectionf.ONE_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, 0, -1, 0, -2, -1, -1, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(1, 1), p, 1E-6f);
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, 0, 1, 0, 0.5f, -1, 1, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0.5f, 1), p, 1E-6f);
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, 0, 0, 1, -0.5f, 0, 0, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0, 1), p, 1E-6f);
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, 0, 1, 0, 0, 0, 1, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0, 1), p, 1E-6f);
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(1, 0, 0, 0, 0, 0, 1, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0, 1), p, 1E-6f);
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, 1, 0, 0, 0, 0, 1, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0, 1), p, 1E-6f);
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, 0, 0, 1, 0, 0, 1, 1, p));
    TestUtil.assertVector2fEquals(new Vector2f(0, 1), p, 1E-6f);
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, -1, 0, 0, -1, -1, 0, 0, p));
    TestUtil.assertVector2fEquals(new Vector2f(0, 1), p, 1E-6f);
    assertEquals(Intersectionf.TWO_INTERSECTION, Intersectionf.intersectLineSegmentAar(0, -1, 0, 1, -1, -1, 0, 0, p));
    TestUtil.assertVector2fEquals(new Vector2f(0, 0.5f), p, 1E-6f);
}
 
Example #26
Source File: OBJLoader.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
        List<Vector3f> normList, List<Face> facesList) {

    List<Integer> indices = new ArrayList<>();
    // Create position array in the order it has been declared
    float[] posArr = new float[posList.size() * 3];
    int i = 0;
    for (Vector3f pos : posList) {
        posArr[i * 3] = pos.x;
        posArr[i * 3 + 1] = pos.y;
        posArr[i * 3 + 2] = pos.z;
        i++;
    }
    float[] textCoordArr = new float[posList.size() * 2];
    float[] normArr = new float[posList.size() * 3];

    for (Face face : facesList) {
        IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
        for (IdxGroup indValue : faceVertexIndices) {
            processFaceVertex(indValue, textCoordList, normList,
                    indices, textCoordArr, normArr);
        }
    }
    int[] indicesArr = new int[indices.size()];
    indicesArr = indices.stream().mapToInt((Integer v) -> v).toArray();
    Mesh mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
    return mesh;
}
 
Example #27
Source File: CameraBoxSelectionDetector.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public CameraBoxSelectionDetector() {
    dir = new Vector3f();
    min = new Vector3f();
    max = new Vector3f();
    nearFar = new Vector2f();
}
 
Example #28
Source File: MouseInput.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Vector2f getDisplVec() {
    return displVec;
}
 
Example #29
Source File: MouseInput.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public MouseInput() {
    previousPos = new Vector2d(-1, -1);
    currentPos = new Vector2d(0, 0);
    displVec = new Vector2f();
}
 
Example #30
Source File: MD5Mesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Vector2f getTextCoords() {
    return textCoords;
}