本文整理汇总了Java中org.lwjgl.util.vector.Vector3f.normalise方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.normalise方法的具体用法?Java Vector3f.normalise怎么用?Java Vector3f.normalise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.lwjgl.util.vector.Vector3f
的用法示例。
在下文中一共展示了Vector3f.normalise方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotationMatrix
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
public static Matrix3f rotationMatrix(float angle, float x, float y, float z)
{
angle *= (float)Math.PI/180f;
Vector3f axis = new Vector3f(x,y,z);
axis.normalise();
float s = (float)Math.sin(angle);
float c = (float)Math.cos(angle);
float oc = 1.0f - c;
Matrix3f mat = new Matrix3f();
mat.m00 = oc * axis.x * axis.x + c;
mat.m01 = oc * axis.x * axis.y - axis.z * s;
mat.m02 = oc * axis.z * axis .x + axis.y * s;
mat.m10 = oc * axis.x * axis.y + axis.z * s;
mat.m11 = oc * axis.y * axis.y + c;
mat.m12 = oc * axis.y * axis.z - axis.x * s;
mat.m20 = oc * axis.z * axis.x - axis.y * s;
mat.m21 = oc * axis.y * axis.z + axis.x * s;
mat.m22 = oc * axis.z * axis.z + c;
return mat;
}
示例2: calculateNormals
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
/**
* Calculates the normals of the mesh using vector cross products
* @param vertices The vertices of the mesh
* @param indices The indices of the mesh
*/
public static void calculateNormals(Vertex[] vertices, int[] indices) {
// Iterate through every face
for(int i = 0; i < indices.length; i+=3) {
// Get the three indices for the triangle face
int i0 = indices[i];
int i1 = indices[i+1];
int i2 = indices[i+2];
// Get the two displacement vectors for the face from the base vertex (arbitrary)
Vector3f v1 = Vector3f.sub(vertices[i1].getPos(), vertices[i0].getPos(), null);
Vector3f v2 = Vector3f.sub(vertices[i2].getPos(), vertices[i0].getPos(), null);
// Calculate the normal using the cross product of the two displacements
Vector3f normal = Vector3f.cross(v1, v2, null);
normal.normalise();
// Set the normal to all the vertices in the face
vertices[i0].setNormal(normal);
vertices[i1].setNormal(normal);
vertices[i2].setNormal(normal);
}
}
示例3: averageNormals
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
/**
* Computes the average of the normals supplied.
* @param normals The normals, located at the same position, that should be averaged
*/
private Vector3f averageNormals(Vector3f[] normals) {
Vector3f sum = new Vector3f();
for(int i = 0; i < normals.length; i++) {
if(normals[i] != null) {
Vector3f.add(sum, normals[i], sum);
}
}
sum.normalise();
return sum;
}
示例4: move
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
/**
* Moves the camera in the specified direction by the specified distance
* @param direction The direction to move in world space
* @param distance The distance to move in world space
*/
public void move(Vector3f direction, float distance) {
// Create a copy of the direction to avoid modifying the original TODO: fix temp
Vector3f deltaMovement = new Vector3f(direction);
// Scale the direction to be the length of the specified distance
deltaMovement.normalise();
deltaMovement.scale(distance);
// Add the movement to the camera's position
Vector3f.add(position, deltaMovement, position);
}
示例5: rotate
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
/**
* Rotates the camera around the specified axis in the counter-clockwise direction
* @param axis The axis to rotate around
* @param v1 The first local camera vector to be updated
* @param v2 The second local camera vector to be updated
* @param angle The amount to rotate around the axis in degrees
*/
private void rotate(Vector3f axis, Vector3f v1, Vector3f v2, float angle) {
Quaternion rotation = QuaternionUtil.createFromAxisAngle(axis, angle, null);
Quaternion.mul(rotation, orientation, orientation);
QuaternionUtil.rotate(v1, rotation, v1);
QuaternionUtil.rotate(v2, rotation, v2);
v1.normalise();
v2.normalise();
}
示例6: calcNormal
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
/**
* Calculates the normal of the triangle made from the 3 vertices. The vertices must be specified in counter-clockwise order.
* @param vertex0
* @param vertex1
* @param vertex2
* @return
*/
public static Vector3f calcNormal(Vector3f vertex0, Vector3f vertex1, Vector3f vertex2) {
Vector3f tangentA = Vector3f.sub(vertex1, vertex0, null);
Vector3f tangentB = Vector3f.sub(vertex2, vertex0, null);
Vector3f normal = Vector3f.cross(tangentA, tangentB, null);
normal.normalise();
return normal;
}
示例7: toWorldCoords
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
private Vector3f toWorldCoords(Vector4f eyeCoords) {
Matrix4f invertedView = Matrix4f.invert(viewMatrix, null);
Vector4f rayWorld = Matrix4f.transform(invertedView, eyeCoords, null);
Vector3f mouseRay = new Vector3f(rayWorld.x, rayWorld.y, rayWorld.z);
mouseRay.normalise();
return mouseRay;
}
示例8: calculateNormal
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
private static Vector3f calculateNormal(int x, int z, float[][] heights) {
float heightL = getHeight(x - 1, z, heights);
float heightR = getHeight(x + 1, z, heights);
float heightD = getHeight(x, z - 1, heights);
float heightU = getHeight(x, z + 1, heights);
Vector3f normal = new Vector3f(heightL - heightR, 2f, heightD - heightU);
normal.normalise();
return normal;
}
示例9: calculateNormal
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
private static Vector3f calculateNormal(int x, int z, float[][] heights) {
float heightL = getHeight(x - 1, z, heights);
float heightR = getHeight(x + 1, z, heights);
float heightD = getHeight(x, z - 1, heights);
float heightU = getHeight(x, z + 1, heights);
Vector3f normal = new Vector3f(heightL - heightR, 2f, heightD - heightU);
normal.normalise();
return normal;
}
示例10: setLightDirection
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
public void setLightDirection(Vector3f direction) {
direction.normalise();
this.lightDirection.set(direction);
}
示例11: calcNormal
import org.lwjgl.util.vector.Vector3f; //导入方法依赖的package包/类
/**
* Calculates the normal of the triangle made from the 3 vertices. The vertices must be specified in counter-clockwise order.
*
* @param vertex0
* @param vertex1
* @param vertex2
* @return
*/
public static Vector3f calcNormal(Vector3f vertex0, Vector3f vertex1, Vector3f vertex2) {
Vector3f tangentA = Vector3f.sub(vertex1, vertex0, null);
Vector3f tangentB = Vector3f.sub(vertex2, vertex0, null);
Vector3f normal = Vector3f.cross(tangentA, tangentB, null);
normal.normalise();
return normal;
}