org.joml.Vector3f Java Examples
The following examples show how to use
org.joml.Vector3f.
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 |
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: OBJLoader.java From lwjglbook with Apache License 2.0 | 6 votes |
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 #3
Source File: OBJLoader.java From lwjglbook with Apache License 2.0 | 6 votes |
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: DummyGame.java From lwjglbook with Apache License 2.0 | 5 votes |
private void setupLights() { SceneLight sceneLight = new SceneLight(); scene.setSceneLight(sceneLight); // Ambient Light sceneLight.setAmbientLight(new Vector3f(0.3f, 0.3f, 0.3f)); sceneLight.setSkyBoxLight(new Vector3f(1.0f, 1.0f, 1.0f)); // Directional Light float lightIntensity = 1.0f; Vector3f lightPosition = new Vector3f(1, 1, 0); sceneLight.setDirectionalLight(new DirectionalLight(new Vector3f(1, 1, 1), lightPosition, lightIntensity)); }
Example #5
Source File: Terrain.java From lwjglbook with Apache License 2.0 | 5 votes |
protected Vector3f[] getTriangle(Vector3f position, Box2D boundingBox, GameItem terrainBlock) { // Get the column and row of the heightmap associated to the current position float cellWidth = boundingBox.width / (float) verticesPerCol; float cellHeight = boundingBox.height / (float) verticesPerRow; int col = (int) ((position.x - boundingBox.x) / cellWidth); int row = (int) ((position.z - boundingBox.y) / cellHeight); Vector3f[] triangle = new Vector3f[3]; triangle[1] = new Vector3f( boundingBox.x + col * cellWidth, getWorldHeight(row + 1, col, terrainBlock), boundingBox.y + (row + 1) * cellHeight); triangle[2] = new Vector3f( boundingBox.x + (col + 1) * cellWidth, getWorldHeight(row, col + 1, terrainBlock), boundingBox.y + row * cellHeight); if (position.z < getDiagonalZCoord(triangle[1].x, triangle[1].z, triangle[2].x, triangle[2].z, position.x)) { triangle[0] = new Vector3f( boundingBox.x + col * cellWidth, getWorldHeight(row, col, terrainBlock), boundingBox.y + row * cellHeight); } else { triangle[0] = new Vector3f( boundingBox.x + (col + 1) * cellWidth, getWorldHeight(row + 2, col + 1, terrainBlock), boundingBox.y + (row + 1) * cellHeight); } return triangle; }
Example #6
Source File: DummyGame.java From lwjglbook with Apache License 2.0 | 5 votes |
@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(); particleEmitter.update((long)(interval * 1000)); }
Example #7
Source File: Transform3DTest.java From WraithEngine with Apache License 2.0 | 5 votes |
@Test public void setPosition_FromFloat() { Transform3D t = new Transform3D(); t.setPosition(0, 1, 2); Vector3f pos = t.getPosition(); Assert.assertEquals(0f, pos.x, 0f); Assert.assertEquals(1f, pos.y, 0f); Assert.assertEquals(2f, pos.z, 0f); }
Example #8
Source File: Matrix4fTest.java From JOML with MIT License | 5 votes |
public static void testPositiveXPerspectiveRotateY() { Vector3f dir = new Vector3f(); Matrix4f m = new Matrix4f() .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f) .rotateY((float) Math.toRadians(90)); m.positiveX(dir); TestUtil.assertVector3fEquals(new Vector3f(0, 0, -1), dir, 1E-7f); }
Example #9
Source File: Terrain.java From lwjglbook with Apache License 2.0 | 5 votes |
/** * Gets the bounding box of a terrain block * * @param terrainBlock A GameItem instance that defines the terrain block * @return The boundingg box of the terrain block */ private Box2D getBoundingBox(GameItem terrainBlock) { float scale = terrainBlock.getScale(); Vector3f position = terrainBlock.getPosition(); float topLeftX = HeightMapMesh.STARTX * scale + position.x; float topLeftZ = HeightMapMesh.STARTZ * scale + position.z; float width = Math.abs(HeightMapMesh.STARTX * 2) * scale; float height = Math.abs(HeightMapMesh.STARTZ * 2) * scale; Box2D boundingBox = new Box2D(topLeftX, topLeftZ, width, height); return boundingBox; }
Example #10
Source File: DummyGame.java From lwjglbook with Apache License 2.0 | 5 votes |
@Override public void init(Window window) throws Exception { renderer.init(window); scene = new Scene(); Mesh[] houseMesh = StaticMeshesLoader.load("models/house/house.obj", "models/house"); GameItem house = new GameItem(houseMesh); Mesh[] terrainMesh = StaticMeshesLoader.load("models/terrain/terrain.obj", "models/terrain"); GameItem terrain = new GameItem(terrainMesh); terrain.setScale(100.0f); scene.setGameItems(new GameItem[]{house, terrain}); // Shadows scene.setRenderShadows(true); // Fog Vector3f fogColour = new Vector3f(0.5f, 0.5f, 0.5f); scene.setFog(new Fog(true, fogColour, 0.02f)); // Setup SkyBox float skyBoxScale = 100.0f; SkyBox skyBox = new SkyBox("models/skybox.obj", new Vector4f(0.65f, 0.65f, 0.65f, 1.0f)); skyBox.setScale(skyBoxScale); scene.setSkyBox(skyBox); // Setup Lights setupLights(); camera.getPosition().x = -17.0f; camera.getPosition().y = 17.0f; camera.getPosition().z = -30.0f; camera.getRotation().x = 20.0f; camera.getRotation().y = 140.f; }
Example #11
Source File: ShadowCascade.java From lwjglbook with Apache License 2.0 | 5 votes |
public ShadowCascade(float zNear, float zFar) { this.zNear = zNear; this.zFar = zFar; this.projViewMatrix = new Matrix4f(); this.orthoProjMatrix = new Matrix4f(); this.centroid = new Vector3f(); this.lightViewMatrix = new Matrix4f(); this.frustumCorners = new Vector3f[FRUSTUM_CORNERS]; for (int i = 0; i < FRUSTUM_CORNERS; i++) { frustumCorners[i] = new Vector3f(); } tmpVec = new Vector4f(); }
Example #12
Source File: DirectionalLight.java From lwjglbook with Apache License 2.0 | 5 votes |
public DirectionalLight(Vector3f color, Vector3f direction, float intensity) { this.orthoCords = new OrthoCoords(); this.shadowPosMult = 1; this.color = color; this.direction = direction; this.intensity = intensity; shadowPosMult = 1; }
Example #13
Source File: SoundManager.java From lwjglbook with Apache License 2.0 | 5 votes |
public void updateListenerPosition(Camera camera) { // Update camera matrix with camera data Transformation.updateGenericViewMatrix(camera.getPosition(), camera.getRotation(), cameraMatrix); listener.setPosition(camera.getPosition()); Vector3f at = new Vector3f(); cameraMatrix.positiveZ(at).negate(); Vector3f up = new Vector3f(); cameraMatrix.positiveY(up); listener.setOrientation(at, up); }
Example #14
Source File: Particle.java From lwjglbook with Apache License 2.0 | 5 votes |
public Particle(Particle baseParticle) { super(baseParticle.getMesh()); Vector3f aux = baseParticle.getPosition(); setPosition(aux.x, aux.y, aux.z); aux = baseParticle.getRotation(); setRotation(aux.x, aux.y, aux.z); setScale(baseParticle.getScale()); this.speed = new Vector3f(baseParticle.speed); this.ttl = baseParticle.geTtl(); this.updateTextureMillis = baseParticle.getUpdateTextureMillis(); this.currentAnimTimeMillis = 0; this.animFrames = baseParticle.getAnimFrames(); }
Example #15
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 5 votes |
public Matrix4f getOrtoProjModelMatrix(GameItem gameItem, Matrix4f orthoMatrix) { Vector3f rotation = gameItem.getRotation(); Matrix4f modelMatrix = new Matrix4f(); modelMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f orthoMatrixCurr = new Matrix4f(orthoMatrix); orthoMatrixCurr.mul(modelMatrix); return orthoMatrixCurr; }
Example #16
Source File: OBJLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
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: PointLight.java From lwjglbook with Apache License 2.0 | 4 votes |
public Vector3f getColor() { return color; }
Example #18
Source File: DirectionalLight.java From lwjglbook with Apache License 2.0 | 4 votes |
public void setColor(Vector3f color) { this.color = color; }
Example #19
Source File: Camera.java From lwjglbook with Apache License 2.0 | 4 votes |
public Camera() { position = new Vector3f(); rotation = new Vector3f(); }
Example #20
Source File: MD5BoundInfo.java From lwjglbook with Apache License 2.0 | 4 votes |
public Vector3f getMinBound() { return minBound; }
Example #21
Source File: PointLight.java From lwjglbook with Apache License 2.0 | 4 votes |
public void setColor(Vector3f color) { this.color = color; }
Example #22
Source File: SoundListener.java From lwjglbook with Apache License 2.0 | 4 votes |
public SoundListener() { this(new Vector3f()); }
Example #23
Source File: Camera.java From lwjglbook with Apache License 2.0 | 4 votes |
public Camera() { position = new Vector3f(); rotation = new Vector3f(); }
Example #24
Source File: SceneLight.java From lwjglbook with Apache License 2.0 | 4 votes |
public void setAmbientLight(Vector3f ambientLight) { this.ambientLight = ambientLight; }
Example #25
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 4 votes |
public Matrix4f updateLightViewMatrix(Vector3f position, Vector3f rotation) { return updateGenericViewMatrix(position, rotation, lightViewMatrix); }
Example #26
Source File: DirectionalLight.java From lwjglbook with Apache License 2.0 | 4 votes |
public DirectionalLight(DirectionalLight light) { this(new Vector3f(light.getColor()), new Vector3f(light.getDirection()), light.getIntensity()); }
Example #27
Source File: Camera.java From lwjglbook with Apache License 2.0 | 4 votes |
public Camera(Vector3f position, Vector3f rotation) { this.position = position; this.rotation = rotation; }
Example #28
Source File: Rotate3f.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public Vector3f createOutput(final Vector3f v, final Quaternionfc q) { return new Vector3f(); }
Example #29
Source File: DirectionalLight.java From lwjglbook with Apache License 2.0 | 4 votes |
public Vector3f getDirection() { return direction; }
Example #30
Source File: OBJLoader.java From lwjglbook with Apache License 2.0 | 4 votes |
public static Mesh loadMesh(String fileName) throws Exception { List<String> lines = Utils.readAllLines(fileName); List<Vector3f> vertices = new ArrayList<>(); List<Vector2f> textures = new ArrayList<>(); List<Vector3f> normals = new ArrayList<>(); List<Face> faces = new ArrayList<>(); for (String line : lines) { String[] tokens = line.split("\\s+"); switch (tokens[0]) { case "v": // Geometric vertex Vector3f vec3f = new Vector3f( Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]), Float.parseFloat(tokens[3])); vertices.add(vec3f); break; case "vt": // Texture coordinate Vector2f vec2f = new Vector2f( Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2])); textures.add(vec2f); break; case "vn": // Vertex normal Vector3f vec3fNorm = new Vector3f( Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]), Float.parseFloat(tokens[3])); normals.add(vec3fNorm); break; case "f": Face face = new Face(tokens[1], tokens[2], tokens[3]); faces.add(face); break; default: // Ignore other lines break; } } return reorderLists(vertices, textures, normals, faces); }