Java 类org.lwjgl.util.vector.Matrix4f 实例源码

项目:OpenGL-Bullet-engine    文件:EntityPlayer.java   
@Override
public void update(){
    updatePrevs();
    pos.y(65);
    if(model.isLoaded()&&!model.getFrustrumShape().withTransform(scale, rot).isVisibleAt(pos, Game.get().renderer.frustrum)){
        Vec3f vec=new Vec3f(0, -((FrustrumCube)model.getFrustrumShape()).getSizeY()*scale.y()*1.4F, 0);
        rot.rotate(vec);

        vec.add(Game.get().renderer.getCamera().pos).sub(pos).normalize().directionToEuler();
        Matrix4f mat=new Matrix4f();
        MatrixUtil.rotateX(mat, vec.x());
        MatrixUtil.rotateY(mat, vec.y());
        Quat4.interpolate(rot, rot, new Quat4().fromMatrix(mat), 0.2F);
    }
    //      rot.set(Game.get().renderer.getCamera().activeRotQuat);
    //this.pos.add(RandUtil.RF(0.1), RandUtil.RF(0.1), RandUtil.RF(0.1));
}
项目:OpenGL-Bullet-engine    文件:Quat4.java   
public Matrix4f toRotationMatrix(Matrix4f dest){
    final float xy=x*y,xz=x*z,xw=x*w,yz=y*z,yw=y*w,zw=z*w,xSquared=x*x,ySquared=y*y,zSquared=z*z;
    dest.m00=1-2*(ySquared+zSquared);
    dest.m01=2*(xy-zw);
    dest.m02=2*(xz+yw);
    dest.m03=0;

    dest.m10=2*(xy+zw);
    dest.m11=1-2*(xSquared+zSquared);
    dest.m12=2*(yz-xw);
    dest.m13=0;

    dest.m20=2*(xz-yw);
    dest.m21=2*(yz+xw);
    dest.m22=1-2*(xSquared+ySquared);
    dest.m23=0;

    dest.m30=0;
    dest.m31=0;
    dest.m32=0;
    dest.m33=1;
    return dest;
}
项目:OpenGL-Bullet-engine    文件:MatrixUtil.java   
public static boolean equals(Matrix4f mat1, Matrix4f mat2){
    if(mat1==null?mat2==null:mat1==mat2) return true;
    return mat1.m00==mat2.m00&&
            mat1.m01==mat2.m01&&
            mat1.m02==mat2.m02&&
            mat1.m03==mat2.m03&&

            mat1.m10==mat2.m10&&
            mat1.m11==mat2.m11&&
            mat1.m12==mat2.m12&&
            mat1.m13==mat2.m13&&

            mat1.m20==mat2.m20&&
            mat1.m21==mat2.m21&&
            mat1.m22==mat2.m22&&
            mat1.m23==mat2.m23&&

            mat1.m30==mat2.m30&&
            mat1.m31==mat2.m31&&
            mat1.m32==mat2.m32&&
            mat1.m33==mat2.m33;
}
项目:open-world    文件:Camera.java   
/**
    * Creates a camera with the specified projection matrix
    * @param projection
    */
   public Camera(Matrix4f projection) {
this.projection = projection;

// Set the view to a default identity matrix
view = new Matrix4f();

// Set the position to origin
position = new Vector3f();
// Set the orientation to standard
orientation = new Quaternion();

// Create the default local axes (right handed)
up = new Vector3f(AXIS_Y);
forward = new Vector3f(AXIS_Z).negate(null);
right = new Vector3f(AXIS_X);
   }
项目:OpenGL-Animation    文件:AnimationLoader.java   
private void processTransforms(String jointName, String[] rawData, KeyFrameData[] keyFrames, boolean root){
    FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
    float[] matrixData = new float[16];
    for(int i=0;i<keyFrames.length;i++){
        for(int j=0;j<16;j++){
            matrixData[j] = Float.parseFloat(rawData[i*16 + j]);
        }
        buffer.clear();
        buffer.put(matrixData);
        buffer.flip();
        Matrix4f transform = new Matrix4f();
        transform.load(buffer);
        transform.transpose();
        if(root){
            //because up axis in Blender is different to up axis in game
            Matrix4f.mul(CORRECTION, transform, transform);
        }
        keyFrames[i].addJointTransform(new JointTransformData(jointName, transform));
    }
}
项目:bia-engine    文件:Maths.java   
public static Matrix4f createTransformationMatrix(final Vector3f translation, final float rx, final float ry, final float rz, final float scale) {
    final Matrix4f matrix = new Matrix4f();
    matrix.setIdentity();
    Matrix4f.translate(translation, matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1, 0, 0), matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0, 1, 0), matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0, 0, 1), matrix, matrix);
    Matrix4f.scale(new Vector3f(scale, scale, scale), matrix, matrix);
    return matrix;
}
项目:Terrain    文件:Maths.java   
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale) {
    Matrix4f matrix = new Matrix4f();
    matrix.setIdentity();
    Matrix4f.translate(translation, matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1, 0, 0), matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0, 1, 0), matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0, 0, 1), matrix, matrix);
    Matrix4f.scale(new Vector3f(scale, scale, scale), matrix, matrix);
    return matrix;
}
项目:MRCEngine    文件:Maths.java   
public static Matrix4f createViewMatrix(Camera camera) {
    Matrix4f viewMatrix = new Matrix4f();
    viewMatrix.setIdentity();
    Matrix4f.rotate((float) Math.toRadians(camera.getPitch()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate((float) Math.toRadians(camera.getYaw()), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
    Vector3f cameraPos = camera.getPosition();
    Vector3f negativeCameraPos = new Vector3f(-cameraPos.x, -cameraPos.y, -cameraPos.z);
    Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
    return viewMatrix;
}
项目:MRCEngine    文件:MasterRenderer.java   
private void createProjectionMatrix() {
    float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
    float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))) * aspectRatio);
    float x_scale = y_scale / aspectRatio;
    float frustum_lenght = FAR_PLANE - NEAR_PLANE;

    projectionMatrix = new Matrix4f();
    projectionMatrix.m00 = x_scale;
    projectionMatrix.m11 = y_scale;
    projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_lenght);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_lenght);
    projectionMatrix.m33 = 0;
}
项目:MRCEngine    文件:EntityRenderer.java   
public EntityRenderer(StaticShader shader, Matrix4f projectionMatrix) {
    this.shader = shader;
    shader.start();
    shader.loadAmbientalLight(0.5f);
    shader.loadProjectionMatrix(projectionMatrix);
    shader.stop();
}
项目:MRCEngine    文件:TerrainRenderer.java   
public TerrainRenderer(TerrainShader shader, Matrix4f projectionMatrix) {
    this.shader = shader;
    shader.start();
    shader.loadAmbientalLight(0.6f);
    shader.loadProjectionMatrix(projectionMatrix);
    shader.connectTextureUnits();
    shader.stop();
}
项目:OpenGL-Bullet-engine    文件:Chunk.java   
@Override
public Matrix4f getTransform(){

    TRANSFORM.setIdentity();
    POS.set(spacePos);
    TRANSFORM.translate(POS);
    return TRANSFORM;
}
项目:Elgin-Plant-Game    文件:Maths.java   
/**
 * Creates view matrix based off camera for rendering
 * @param camera - camera to base view matrix
 * @return - New view matrix
 */
public static Matrix4f createViewMatrix(Camera camera) {
    Matrix4f viewMatrix = new Matrix4f();
    viewMatrix.setIdentity();
    Matrix4f.rotate((float) Math.toRadians(camera.getPitch()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate((float) Math.toRadians(camera.getYaw()), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
    Vector3f cameraPos = camera.getPosition();
    Vector3f negativeCameraPos = new Vector3f(-cameraPos.x, -cameraPos.y, -cameraPos.z);
    Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
    return viewMatrix;
}
项目:OpenGL-Animation    文件:Camera.java   
private static Matrix4f createProjectionMatrix() {
    Matrix4f projectionMatrix = new Matrix4f();
    float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
    float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))));
    float x_scale = y_scale / aspectRatio;
    float frustum_length = FAR_PLANE - NEAR_PLANE;

    projectionMatrix.m00 = x_scale;
    projectionMatrix.m11 = y_scale;
    projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);
    projectionMatrix.m33 = 0;
    return projectionMatrix;
}
项目:OpenGL-Bullet-engine    文件:Quaternion.java   
/**
 * Converts the quaternion to a 4x4 matrix representing the exact same
 * rotation as this quaternion. (The rotation is only contained in the
 * top-left 3x3 part, but a 4x4 matrix is returned here for convenience
 * seeing as it will be multiplied with other 4x4 matrices).
 * 
 * More detailed explanation here:
 * http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/
 * 
 * @return The rotation matrix which represents the exact same rotation as
 *         this quaternion.
 */
public Matrix4f toRotationMatrix(){
    Matrix4f matrix=new Matrix4f();
    final float xy=x*y;
    final float xz=x*z;
    final float xw=x*w;
    final float yz=y*z;
    final float yw=y*w;
    final float zw=z*w;
    final float xSquared=x*x;
    final float ySquared=y*y;
    final float zSquared=z*z;
    matrix.m00=1-2*(ySquared+zSquared);
    matrix.m01=2*(xy-zw);
    matrix.m02=2*(xz+yw);
    matrix.m03=0;
    matrix.m10=2*(xy+zw);
    matrix.m11=1-2*(xSquared+zSquared);
    matrix.m12=2*(yz-xw);
    matrix.m13=0;
    matrix.m20=2*(xz-yw);
    matrix.m21=2*(yz+xw);
    matrix.m22=1-2*(xSquared+ySquared);
    matrix.m23=0;
    matrix.m30=0;
    matrix.m31=0;
    matrix.m32=0;
    matrix.m33=1;
    return matrix;
}
项目:OpenGL-Bullet-engine    文件:Quaternion.java   
/**
 * Extracts the rotation part of a transformation matrix and converts it to
 * a quaternion using the magic of maths.
 * 
 * More detailed explanation here:
 * http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
 * 
 * @param matrix
 *            - the transformation matrix containing the rotation which this
 *            quaternion shall represent.
 */
public static Quaternion fromMatrix(Matrix4f matrix){
    float w,x,y,z;
    float diagonal=matrix.m00+matrix.m11+matrix.m22;
    if(diagonal>0){
        float w4=(float)(Math.sqrt(diagonal+1f)*2f);
        w=w4/4f;
        x=(matrix.m21-matrix.m12)/w4;
        y=(matrix.m02-matrix.m20)/w4;
        z=(matrix.m10-matrix.m01)/w4;
    }else if(matrix.m00>matrix.m11&&matrix.m00>matrix.m22){
        float x4=(float)(Math.sqrt(1f+matrix.m00-matrix.m11-matrix.m22)*2f);
        w=(matrix.m21-matrix.m12)/x4;
        x=x4/4f;
        y=(matrix.m01+matrix.m10)/x4;
        z=(matrix.m02+matrix.m20)/x4;
    }else if(matrix.m11>matrix.m22){
        float y4=(float)(Math.sqrt(1f+matrix.m11-matrix.m00-matrix.m22)*2f);
        w=(matrix.m02-matrix.m20)/y4;
        x=(matrix.m01+matrix.m10)/y4;
        y=y4/4f;
        z=(matrix.m12+matrix.m21)/y4;
    }else{
        float z4=(float)(Math.sqrt(1f+matrix.m22-matrix.m00-matrix.m11)*2f);
        w=(matrix.m10-matrix.m01)/z4;
        x=(matrix.m02+matrix.m20)/z4;
        y=(matrix.m12+matrix.m21)/z4;
        z=z4/4f;
    }
    return new Quaternion(x, y, z, w);
}
项目:Backmemed    文件:ShaderGroup.java   
private void resetProjectionMatrix()
{
    this.projectionMatrix = new Matrix4f();
    this.projectionMatrix.setIdentity();
    this.projectionMatrix.m00 = 2.0F / (float)this.mainFramebuffer.framebufferTextureWidth;
    this.projectionMatrix.m11 = 2.0F / (float)(-this.mainFramebuffer.framebufferTextureHeight);
    this.projectionMatrix.m22 = -0.0020001999F;
    this.projectionMatrix.m33 = 1.0F;
    this.projectionMatrix.m03 = -1.0F;
    this.projectionMatrix.m13 = 1.0F;
    this.projectionMatrix.m23 = -1.0001999F;
}
项目:OpenGL-Animation    文件:Quaternion.java   
/**
 * Extracts the rotation part of a transformation matrix and converts it to
 * a quaternion using the magic of maths.
 * 
 * More detailed explanation here:
 * http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
 * 
 * @param matrix
 *            - the transformation matrix containing the rotation which this
 *            quaternion shall represent.
 */
public static Quaternion fromMatrix(Matrix4f matrix) {
    float w, x, y, z;
    float diagonal = matrix.m00 + matrix.m11 + matrix.m22;
    if (diagonal > 0) {
        float w4 = (float) (Math.sqrt(diagonal + 1f) * 2f);
        w = w4 / 4f;
        x = (matrix.m21 - matrix.m12) / w4;
        y = (matrix.m02 - matrix.m20) / w4;
        z = (matrix.m10 - matrix.m01) / w4;
    } else if ((matrix.m00 > matrix.m11) && (matrix.m00 > matrix.m22)) {
        float x4 = (float) (Math.sqrt(1f + matrix.m00 - matrix.m11 - matrix.m22) * 2f);
        w = (matrix.m21 - matrix.m12) / x4;
        x = x4 / 4f;
        y = (matrix.m01 + matrix.m10) / x4;
        z = (matrix.m02 + matrix.m20) / x4;
    } else if (matrix.m11 > matrix.m22) {
        float y4 = (float) (Math.sqrt(1f + matrix.m11 - matrix.m00 - matrix.m22) * 2f);
        w = (matrix.m02 - matrix.m20) / y4;
        x = (matrix.m01 + matrix.m10) / y4;
        y = y4 / 4f;
        z = (matrix.m12 + matrix.m21) / y4;
    } else {
        float z4 = (float) (Math.sqrt(1f + matrix.m22 - matrix.m00 - matrix.m11) * 2f);
        w = (matrix.m10 - matrix.m01) / z4;
        x = (matrix.m02 + matrix.m20) / z4;
        y = (matrix.m12 + matrix.m21) / z4;
        z = z4 / 4f;
    }
    return new Quaternion(x, y, z, w);
}
项目:OpenGL-Bullet-engine    文件:SkyboxShader.java   
@Override
public void uploadProjectionAndViewMat(Matrix4f project, Matrix4f view){
    if(viewMat==null) return;
    viewCopy.load(view);
    viewCopy.m30=0;
    viewCopy.m31=0;
    viewCopy.m32=0;
    viewMat.upload(viewCopy);
    projectionMat.upload(project);
}
项目:OpenGL-Bullet-engine    文件:UniformMat4.java   
public void upload(Matrix4f mat){
    shader.bindingProttect();

    if(MatrixUtil.equals(mat, prev)) return;
    prev.load(mat);

    mat.store(BUFF);
    BUFF.flip();
    glUniformMatrix4(id(), false, BUFF);
    checkError();
}
项目:OpenGL-Bullet-engine    文件:ShaderRenderer.java   
protected Matrix4f getView(){
    Renderer r=getRenderer();
    if(r!=null) return r.getView();
    NULL_VIEW.setIdentity();

    return NULL_VIEW;
}
项目:OcclusionQueries    文件:SunRenderer.java   
private void prepare(Sun sun, ICamera camera) {
    OpenGlUtils.antialias(false);
    GL11.glDepthMask(false);
    OpenGlUtils.enableAlphaBlending();
    shader.start();
    Matrix4f mvpMat = calculateMvpMatrix(sun, camera);
    shader.mvpMatrix.loadMatrix(mvpMat);
    quad.bind(0);
    sun.getTexture().bindToUnit(0);
}
项目:OpenGL-Bullet-engine    文件:Camera.java   
public void createProjection(Matrix4f dest){
    //      float fov=this.fov/zoom;
    //
    //      if(lastRenderFow==fov){
    //          injectProjection(dest);
    //          return;
    //      }
    //      lastRenderFow=fov;
    calcProjection();
    injectProjection(dest);
}
项目:OcclusionQueries    文件:Camera.java   
private static Matrix4f createProjectionMatrix(){
    Matrix4f projectionMatrix = new Matrix4f();
    float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
    float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))));
    float x_scale = y_scale / aspectRatio;
    float frustum_length = FAR_PLANE - NEAR_PLANE;

    projectionMatrix.m00 = x_scale;
    projectionMatrix.m11 = y_scale;
    projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);
    projectionMatrix.m33 = 0;
    return projectionMatrix;
}
项目:Elgin-Plant-Game    文件:MasterRenderer.java   
/**
 * Creates matrix for perspective + camera
 */
private void createProjectionMatrix() {
    float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
    float y_scale = (float) ((1f / Math.tan(Math.toRadians(Reference.FOV / 2f))) * aspectRatio);
    float x_scale = y_scale / aspectRatio;
    float frustum_length = Reference.FAR_PLANE - Reference.NEAR_PLANE;

    projectionMatrix = new Matrix4f();
    projectionMatrix.m00 = x_scale;
    projectionMatrix.m11 = y_scale;
    projectionMatrix.m22 = -((Reference.FAR_PLANE + Reference.NEAR_PLANE) / frustum_length);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2 * Reference.NEAR_PLANE * Reference.FAR_PLANE) / frustum_length);
    projectionMatrix.m33 = 0;
}
项目:open-world    文件:WaterRegion.java   
/**
    * Creates a water region at the specified x and z coordinates. Scaled to the size of a region.
    * @param x
    * @param z
    */
   public WaterRegion(float x, float z) {
transformation = new Matrix4f().translate(new Vector3f(x, WATER_HEIGHT, z));

if(shader == null) {
    try {
    shader = new WaterShader("water");
    shader.setUniform("reflection_texture", 0);
    shader.setUniform("dudv_texture", 1);
    shader.setUniform("normal_texture", 2);
    } catch (IOException e) {
    e.printStackTrace();
    System.exit(1);
    }
}

if(dudvTexture == null) {
    dudvTexture = new Texture("waterdudv.png");
}

if(normalTexture == null) {
    normalTexture = new Texture("waternormal.png");
}

framebuffer = new FrameBuffer(REFLECTION_WIDTH, REFLECTION_HEIGHT);
framebuffer.attachTexture();
framebuffer.attachDepthBuffer();
framebuffer.verifyIntegrity();
   }
项目:open-world    文件:Region.java   
/**
    * Creates a square region of length size SIZE, and generates tiled terrain.
    * @param x The x offset of the region
    * @param z The z offset of the region
    */
   public Region(float x, float z) {
transformationMatrix = new Matrix4f();
transformationMatrix.translate(new Vector3f(x * SIZE, 0, z * SIZE));

if(grassTexture == null) {
    grassTexture = new Texture("grass.png");
}

createTerrain();
water = new WaterRegion(x * SIZE, z * SIZE);
   }
项目:open-world    文件:Mesh.java   
/**
    * Create a mesh with the specified vertices and indices and whether the normals should be calculated
    * @param vertices
    * @param indices
    * @param calculateNormals
    */
   public Mesh(Vertex[] vertices, int[] indices, boolean calculateNormals) {
modelMatrix = new Matrix4f();

// Automatically calculate normals for the mesh
if(calculateNormals) {
    calculateNormals(vertices, indices);
}

// Create a FloatBuffer to hold Vertex data
FloatBuffer data = BufferUtils.createFloatBuffer(vertices.length * Vertex.SIZE);

for(int i = 0; i < vertices.length; i++) {
    // Store the position
    data.put(vertices[i].getPos().x);
    data.put(vertices[i].getPos().y);
    data.put(vertices[i].getPos().z);
    // Store the texture coordinates
    data.put(vertices[i].getTexCoords().x);
    data.put(vertices[i].getTexCoords().y);
    // Store the normal
    data.put(vertices[i].getNormal().x);
    data.put(vertices[i].getNormal().y);
    data.put(vertices[i].getNormal().z);
    // Store the color
    data.put(vertices[i].getColor().x);
    data.put(vertices[i].getColor().y);
    data.put(vertices[i].getColor().z);
}

// Prepare the buffer for get() operations
data.flip();

// Create the VAO using the vertices and indices
vao = new IndexedVAO(data, indices, Vertex.DIMENSIONS);
   }
项目:OcclusionQueries    文件:WaterRenderer.java   
public void render(List<WaterTile> water, ICamera camera, Vector3f lightDir) {
    prepareRender(camera, lightDir);
    for (WaterTile tile : water) {
        Matrix4f modelMatrix = createModelMatrix(tile.getX(), tile.getHeight(), tile.getZ(), WaterTile.TILE_SIZE);
        shader.modelMatrix.loadMatrix(modelMatrix);
        GL11.glDrawElements(GL11.GL_TRIANGLES, quad.getIndexCount(), GL11.GL_UNSIGNED_INT, 0);
    }
    finish();
}
项目:BaseClient    文件:FaceBakery.java   
private void rotateScale(Vector3f position, Vector3f rotationOrigin, Matrix4f rotationMatrix, Vector3f scale)
{
    Vector4f vector4f = new Vector4f(position.x - rotationOrigin.x, position.y - rotationOrigin.y, position.z - rotationOrigin.z, 1.0F);
    Matrix4f.transform(rotationMatrix, vector4f, vector4f);
    vector4f.x *= scale.x;
    vector4f.y *= scale.y;
    vector4f.z *= scale.z;
    position.set(vector4f.x + rotationOrigin.x, vector4f.y + rotationOrigin.y, vector4f.z + rotationOrigin.z);
}
项目:EcoSystem-Official    文件:Maths.java   
public static void updateViewMatrix(Matrix4f viewMatrix, float x, float y, float z, float pitch, float yaw) {
    viewMatrix.setIdentity();
    Matrix4f.rotate((float) Math.toRadians(pitch), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate((float) Math.toRadians(yaw), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
    Vector3f negativeCameraPos = new Vector3f(-x, -y, -z);
    Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
}
项目:Terrain    文件:Maths.java   
public static Matrix4f createViewMatrix(Camera camera) {
    Matrix4f viewMatrix = new Matrix4f();
    viewMatrix.setIdentity();
    Matrix4f.rotate((float) Math.toRadians(camera.getPitch()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate((float) Math.toRadians(camera.getYaw()), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
    Vector3f cameraPos = camera.getPosition();
    Vector3f negativeCameraPos = new Vector3f(-cameraPos.x, -cameraPos.y, -cameraPos.z);
    Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
    return viewMatrix;
}
项目:Terrain    文件:MasterRenderer.java   
private void createProjectionMatrix() {
    float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
    float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))) * aspectRatio);
    float x_scale = y_scale / aspectRatio;
    float frustum_length = FAR_PLANE - NEAR_PLANE;

    projectionMatrix = new Matrix4f();
    projectionMatrix.m00 = x_scale;
    projectionMatrix.m11 = y_scale;
    projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);
    projectionMatrix.m33 = 0;
}
项目:bia-engine    文件:MasterRenderer.java   
private void createProjectionMatrix() {
    float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
    float yScale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))) * aspectRatio);
    float xScale = yScale / aspectRatio;
    float frustumLength = FAR_PLANE - NEAR_PLANE;

    projectionMatrix = new Matrix4f();
    projectionMatrix.m00 = xScale;
    projectionMatrix.m11 = yScale;
    projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustumLength);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustumLength);
    projectionMatrix.m33 = 0;
}
项目:bia-engine    文件:EntityRenderer.java   
private void prepareInstance(final Entity entity) {
    final Matrix4f transformationMatrix = Maths.createTransformationMatrix(
            entity.getPosition(),
            entity.getRotX(),
            entity.getRotY(),
            entity.getRotZ(),
            entity.getScale()
    );
    shader.loadTransformationMatrix(transformationMatrix);
}
项目:OpenGL-Animation    文件:Camera.java   
private void updateViewMatrix() {
    viewMatrix.setIdentity();
    Matrix4f.rotate((float) Math.toRadians(pitch.get()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate((float) Math.toRadians(yaw), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
    Vector3f negativeCameraPos = new Vector3f(-position.x, -position.y, -position.z);
    Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
}
项目:bia-engine    文件:TerrainRenderer.java   
private void loadModelMatrix(final Terrain terrain) {
    final Matrix4f transformationMatrix = Maths.createTransformationMatrix(
            new Vector3f(terrain.getX(), 0, terrain.getZ()),
            0, 0, 0, 1
    );
    shader.loadTransformationMatrix(transformationMatrix);
}
项目:MRCEngine    文件:TerrainShader.java   
public void loadTransformationMatrix(Matrix4f matrix) {
    super.loadMatrix(location_transformationMatrix, matrix);
}
项目:MRCEngine    文件:TerrainShader.java   
public void loadViewMatrix(Camera camera) {
    Matrix4f viewMatrix = Maths.createViewMatrix(camera);
    super.loadMatrix(location_viewMatrix, viewMatrix);
}
项目:Elgin-Plant-Game    文件:UniformMat4.java   
public void loadData(Matrix4f value) {
    value.store(matrixBuffer);
    matrixBuffer.flip();
    GL20.glUniformMatrix4(uniformLocation, false, matrixBuffer);
}