コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
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;

            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);
        }
コード例 #5
0
        public void render(Entity entity, StaticShader shader)
        {
            TexturedModel model    = entity.model;
            RawModel      rawModel = model.rawModel;

            Gl.BindVertexArray(rawModel.vaoID);
            Gl.EnableVertexAttribArray(0);
            Gl.EnableVertexAttribArray(1);
            Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.position, entity.rotX, entity.rotY, entity.rotZ, entity.scale);

            shader.loadTransformationMatrix(transformationMatrix);
            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(TextureTarget.Texture2d, model.modelTexture.textureId);
            Gl.DrawElements(PrimitiveType.Triangles, rawModel.vertexCount, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.DisableVertexAttribArray(0);
            Gl.DisableVertexAttribArray(1);
            Gl.BindVertexArray(0);
        }
コード例 #6
0
 protected void loadMatrix(int location, Matrix4f matrix)
 {
     Gl.UniformMatrix4(location, false, matrix.Buffer);
 }
コード例 #7
0
        public void loadViewMatrix(Camera camera)
        {
            Matrix4f viewMatrix = Maths.createViewMatrix(camera);

            base.loadMatrix(location_viewMatrix, viewMatrix);
        }
コード例 #8
0
 public void loadProjectionMatrix(Matrix4f projection)
 {
     base.loadMatrix(location_projectionMatrix, projection);
 }
コード例 #9
0
 public void loadTransformationMatrix(Matrix4f matrix)
 {
     base.loadMatrix(location_transformationMatrix, matrix);
 }