当前位置: 首页>>代码示例>>Java>>正文


Java Vector3f.normalize方法代码示例

本文整理汇总了Java中org.joml.Vector3f.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.normalize方法的具体用法?Java Vector3f.normalize怎么用?Java Vector3f.normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.joml.Vector3f的用法示例。


在下文中一共展示了Vector3f.normalize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: subdivide

import org.joml.Vector3f; //导入方法依赖的package包/类
/**
 * Subdivides each of the icospheres triangles into 4 
 * smaller triangles.
 * 
 * @param iterations - Number of subdivisions.
 */
public void subdivide(int iterations) {
	ArrayList<Vector3f> vertices = new ArrayList<>();
	Map<Long, Integer> middlePointIndexCache = new HashMap<Long, Integer>();
	
	for (int i = 0; i < sphere_positions.length; i+=3) {
		vertices.add(new Vector3f(sphere_positions[i], sphere_positions[i + 1], sphere_positions[i + 2]));
	}
	for (Vector3f vec : vertices) {
		vec.normalize();
	}
	
	for (int i = 0; i < iterations; i++) {
		ArrayList<Vector3i> indices = new ArrayList<>();
		for (int j = 0; j < sphere_indices.length; j+=3) {
			indices.add(new Vector3i(sphere_indices[j], sphere_indices[j + 1], sphere_indices[j + 2]));
		}
		
		ArrayList<Vector3i> indices2 = new ArrayList<>();
		for(Vector3i tri : indices) {
			int a = midPoint(tri.x, tri.y, vertices, middlePointIndexCache);
			int b = midPoint(tri.y, tri.z, vertices, middlePointIndexCache);
			int c = midPoint(tri.z, tri.x, vertices, middlePointIndexCache);
			
			Vector3i x0 = new Vector3i(tri.x, a, c);
			Vector3i x1 = new Vector3i(tri.y, b, a);
			Vector3i x2 = new Vector3i(tri.z, c, b);
			Vector3i x3 = new Vector3i(a, b, c);
			
			indices2.add(x0);
			indices2.add(x1);
			indices2.add(x2);
			indices2.add(x3);
		}
		
		sphere_indices = new int[indices2.size()*3];
		for (int j = 0, k = 0; j < sphere_indices.length; j+=3, k++) {
			sphere_indices[j] = indices2.get(k).x;
			sphere_indices[j + 1] = indices2.get(k).y;
			sphere_indices[j + 2] = indices2.get(k).z;
		}
		
		sphere_positions = new float[vertices.size()*3];
		for (int j = 0, k = 0; j < sphere_positions.length; j+=3, k++) {
			sphere_positions[j] = vertices.get(k).x;
			sphere_positions[j + 1] = vertices.get(k).y;
			sphere_positions[j + 2] = vertices.get(k).z;
		}
	}
}
 
开发者ID:brokenprogrammer,项目名称:Mass,代码行数:56,代码来源:Sphere.java

示例2: update

import org.joml.Vector3f; //导入方法依赖的package包/类
@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);
    }

    // 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 = -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));

    // 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;
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:49,代码来源:DummyGame.java

示例3: calcNormals

import org.joml.Vector3f; //导入方法依赖的package包/类
private float[] calcNormals(float[] posArr, int width, int height) {
    Vector3f v0 = new Vector3f();
    Vector3f v1 = new Vector3f();
    Vector3f v2 = new Vector3f();
    Vector3f v3 = new Vector3f();
    Vector3f v4 = new Vector3f();
    Vector3f v12 = new Vector3f();
    Vector3f v23 = new Vector3f();
    Vector3f v34 = new Vector3f();
    Vector3f v41 = new Vector3f();
    List<Float> normals = new ArrayList<>();
    Vector3f normal = new Vector3f();
    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            if (row > 0 && row < height - 1 && col > 0 && col < width - 1) {
                int i0 = row * width * 3 + col * 3;
                v0.x = posArr[i0];
                v0.y = posArr[i0 + 1];
                v0.z = posArr[i0 + 2];

                int i1 = row * width * 3 + (col - 1) * 3;
                v1.x = posArr[i1];
                v1.y = posArr[i1 + 1];
                v1.z = posArr[i1 + 2];
                v1 = v1.sub(v0);

                int i2 = (row + 1) * width * 3 + col * 3;
                v2.x = posArr[i2];
                v2.y = posArr[i2 + 1];
                v2.z = posArr[i2 + 2];
                v2 = v2.sub(v0);

                int i3 = (row) * width * 3 + (col + 1) * 3;
                v3.x = posArr[i3];
                v3.y = posArr[i3 + 1];
                v3.z = posArr[i3 + 2];
                v3 = v3.sub(v0);

                int i4 = (row - 1) * width * 3 + col * 3;
                v4.x = posArr[i4];
                v4.y = posArr[i4 + 1];
                v4.z = posArr[i4 + 2];
                v4 = v4.sub(v0);

                v1.cross(v2, v12);
                v12.normalize();

                v2.cross(v3, v23);
                v23.normalize();

                v3.cross(v4, v34);
                v34.normalize();

                v4.cross(v1, v41);
                v41.normalize();

                normal = v12.add(v23).add(v34).add(v41);
                normal.normalize();
            } else {
                normal.x = 0;
                normal.y = 1;
                normal.z = 0;
            }
            normal.normalize();
            normals.add(normal.x);
            normals.add(normal.y);
            normals.add(normal.z);
        }
    }
    return Utils.listToArray(normals);
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:72,代码来源:HeightMapMesh.java

示例4: calcNormals

import org.joml.Vector3f; //导入方法依赖的package包/类
private float[] calcNormals(float[] posArr, int width, int height) {
  Vector3f v0 = new Vector3f();
  Vector3f v1 = new Vector3f();
  Vector3f v2 = new Vector3f();
  Vector3f v3 = new Vector3f();
  Vector3f v4 = new Vector3f();
  Vector3f v12 = new Vector3f();
  Vector3f v23 = new Vector3f();
  Vector3f v34 = new Vector3f();
  Vector3f v41 = new Vector3f();
  List<Float> normals = new ArrayList<>();
  Vector3f normal = new Vector3f();
  for (int row = 0; row < height; row++) {
    for (int col = 0; col < width; col++) {
      if (row > 0 && row < height -1 && col > 0 && col < width -1) {
        int i0 = row*width*3 + col*3;
        v0.x = posArr[i0];
        v0.y = posArr[i0 + 1];
        v0.z = posArr[i0 + 2];

        int i1 = row*width*3 + (col-1)*3;
        v1.x = posArr[i1];
        v1.y = posArr[i1 + 1];
        v1.z = posArr[i1 + 2];
        v1 = v1.sub(v0);

        int i2 = (row+1)*width*3 + col*3;
        v2.x = posArr[i2];
        v2.y = posArr[i2 + 1];
        v2.z = posArr[i2 + 2];
        v2 = v2.sub(v0);

        int i3 = (row)*width*3 + (col+1)*3;
        v3.x = posArr[i3];
        v3.y = posArr[i3 + 1];
        v3.z = posArr[i3 + 2];
        v3 = v3.sub(v0);

        int i4 = (row-1)*width*3 + col*3;
        v4.x = posArr[i4];
        v4.y = posArr[i4 + 1];
        v4.z = posArr[i4 + 2];
        v4 = v4.sub(v0);

        v1.cross(v2, v12);
        v12.normalize();

        v2.cross(v3, v23);
        v23.normalize();

        v3.cross(v4, v34);
        v34.normalize();

        v4.cross(v1, v41);
        v41.normalize();

        normal = v12.add(v23).add(v34).add(v41);
        normal.normalize();
      } else {
        normal.x = 0;
        normal.y = 1;
        normal.z = 0;
      }
      normal.normalize();
      normals.add(normal.x);
      normals.add(normal.y);
      normals.add(normal.z);
    }
  }
  return Util.listToArray(normals);
}
 
开发者ID:adamegyed,项目名称:endless-hiker,代码行数:72,代码来源:HeightMapMesh.java


注:本文中的org.joml.Vector3f.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。