public EntityRenderer(StaticShader Shader, Matrix4f projectionMatrix)
 {
     this.shader = Shader;
     shader.start();
     shader.loadProjectionMatrix(projectionMatrix);
     shader.stop();
 }
 public TerrainRenderer(TerrainShader shader, Matrix4f projectionMAtrix)
 {
     this.shader = shader;
     this.shader.start();
     shader.loadProjectionMatrix(projectionMAtrix);
     this.shader.stop();
 }
        public static void rotate(float angle, Vertex3f axis, Matrix4f src, ref Matrix4f dest)
        {
            Matrix4f rotationMatrix = new Matrix4f();

            rotationMatrix.SetIdentity();
            float[] matbuffer = rotationMatrix.Buffer;
            if (axis.x != 0)
            {
                matbuffer[5]  = (float)Math.Cos(angle);
                matbuffer[6]  = (float)-Math.Sin(angle);
                matbuffer[9]  = (float)Math.Sin(angle);
                matbuffer[10] = (float)Math.Cos(angle);
            }
            else if (axis.y != 0)
            {
                matbuffer[0]  = (float)Math.Cos(angle);
                matbuffer[2]  = (float)Math.Sin(angle);
                matbuffer[8]  = (float)-Math.Sin(angle);
                matbuffer[10] = (float)Math.Cos(angle);
            }
            else if (axis.z != 0)
            {
                matbuffer[0] = (float)Math.Cos(angle);
                matbuffer[1] = (float)-Math.Sin(angle);
                matbuffer[4] = (float)Math.Sin(angle);
                matbuffer[5] = (float)Math.Cos(angle);
            }

            // apply rotation to src matrix
            Matrix tempmat = (Matrix) new Matrix(matbuffer, 4, 4).Multiply(src);

            // set dest matrix to the rotated matrix
            dest = new Matrix4f(tempmat.Buffer);
        }
        public static void scale(Vertex3f vector, Matrix4f src, ref Matrix4f dest)
        {
            Matrix4f scalerMatrix = new Matrix4f();

            scalerMatrix.SetIdentity();
            float[] matbuffer = scalerMatrix.Buffer;
            matbuffer[0]  = vector.x;
            matbuffer[5]  = vector.y;
            matbuffer[10] = vector.z;
            Matrix tempmat = (Matrix) new Matrix(matbuffer, 4, 4).Multiply(src);

            dest = new Matrix4f(tempmat.Buffer);
        }
        public static void translate(Vertex3f translation, Matrix4f src, out Matrix4f des)
        {
            Matrix4f translationMatrix = new Matrix4f();

            translationMatrix.SetIdentity();
            float[] matbuffer = translationMatrix.Buffer;
            matbuffer[12] = translation.x;
            matbuffer[13] = translation.y;
            matbuffer[14] = translation.z;
            Matrix tempmat = (Matrix) new Matrix(matbuffer, 4, 4).Multiply(src);

            des = new Matrix4f(tempmat.Buffer);
        }
Beispiel #6
0
        private void createProjectionMatrix()
        {
            float aspectRatio    = (float)window.windowWidth / window.windowHeight;
            float y_scale        = 1f / (float)Math.Tan(math.toRadians(FOV / 2f));
            float x_scale        = y_scale / aspectRatio;
            float frustum_length = FAR_PLANE - NEAR_PLANE;

            Console.WriteLine(window.windowWidth);
            Console.WriteLine(window.windowHeight);

            float[] matbuffer = projectionMatrix.Buffer;


            matbuffer[0]  = x_scale;
            matbuffer[5]  = y_scale;
            matbuffer[10] = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
            matbuffer[11] = -1;
            matbuffer[14] = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);
            matbuffer[15] = 0;

            this.projectionMatrix = new Matrix4f(matbuffer);
        }
 protected void loadMatrix(int location, Matrix4f matrix)
 {
     Gl.UniformMatrix4(location, false, matrix.Buffer);
 }
        public void loadViewMatrix(Camera camera)
        {
            Matrix4f viewMatrix = Maths.createViewMatrix(camera);

            base.loadMatrix(location_viewMatrix, viewMatrix);
        }
 public void loadProjectionMatrix(Matrix4f projection)
 {
     base.loadMatrix(location_projectionMatrix, projection);
 }
 public void loadTransformationMatrix(Matrix4f matrix)
 {
     base.loadMatrix(location_transformationMatrix, matrix);
 }
        private void prepareInstance(Entity entity)
        {
            Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.position, entity.rotX, entity.rotY, entity.rotZ, entity.scale);

            shader.loadTransformationMatrix(transformationMatrix);
        }
        private void loadModelMatrix(Terrain terrain)
        {
            Matrix4f transformationMatrix = Maths.createTransformationMatrix(new Vertex3f(terrain.x, 0, terrain.z), 0, 0, 0, 1);

            shader.loadTransformationMatrix(transformationMatrix);
        }