public override void display()
        {
            ClearDisplay();

            if (current_mesh != null)
            {
                MatrixStack modelMatrix = new MatrixStack();
                using (PushStack pushstack = new PushStack(modelMatrix))
                {
                    modelMatrix.Translate(Camera.g_camTarget);
                    modelMatrix.Translate(0f, 0f, 0f);
                    modelMatrix.Scale(15.0f, 15.0f, 15.0f);
                    modelMatrix.Rotate(axis, angle);
                    angle = angle + 1f;

                    GL.UseProgram(currentProgram.theProgram);
                    Matrix4 mm = modelMatrix.Top();

                    if (noWorldMatrix)
                    {
                        Matrix4 cm2 = Matrix4.Mult(mm, cm);
                        GL.UniformMatrix4(currentProgram.modelToCameraMatrixUnif, false, ref cm2);
                        if (currentProgram.normalModelToCameraMatrixUnif != 0)
                        {
                            Matrix3 normalModelToCameraMatrix = Matrix3.Identity;
                            Matrix4 applyMatrix = Matrix4.Mult(Matrix4.Identity,
                                                                     Matrix4.CreateTranslation(dirToLight));
                            normalModelToCameraMatrix = new Matrix3(applyMatrix);
                            normalModelToCameraMatrix.Invert();
                            GL.UniformMatrix3(currentProgram.normalModelToCameraMatrixUnif, false,
                                              ref normalModelToCameraMatrix);
                            //Matrix4 cameraToClipMatrix = Matrix4.Identity;
                            //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix);

                        }
                        //Matrix4 cameraToClipMatrix = Matrix4.Identity;
                        //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix);
                    }
                    else
                    {
                        GL.UniformMatrix4(currentProgram.modelToWorldMatrixUnif, false, ref mm);
                    }
                }
                current_mesh.Render();
                GL.UseProgram(0);
            }
        }
        public override void display()
        {
            ClearDisplay();

            if (meshes[currentMesh] != null)
            {
                MatrixStack modelMatrix = new MatrixStack();
                using (PushStack pushstack = new PushStack(modelMatrix))
                {
                    modelMatrix.Rotate(axis, angle);   // rotate last to leave in place
                    modelMatrix.Translate(Camera.g_camTarget);
                    modelMatrix.Scale(initialScale.X / scaleFactor.X,
                        initialScale.Y / scaleFactor.Y,
                        initialScale.Z / scaleFactor.Z);

                    GL.UseProgram(currentProgram.theProgram);
                    Matrix4 mm = modelMatrix.Top();

                    if (noWorldMatrix)
                    {
                        Matrix4 cm2 = Matrix4.Mult(mm, cm);
                        GL.UniformMatrix4(currentProgram.modelToCameraMatrixUnif, false, ref cm2);
                        if (currentProgram.normalModelToCameraMatrixUnif != 0)
                        {
                            Matrix3 normalModelToCameraMatrix = Matrix3.Identity;
                            Matrix4 applyMatrix = Matrix4.Mult(Matrix4.Identity,
                                                                     Matrix4.CreateTranslation(dirToLight));
                            normalModelToCameraMatrix = new Matrix3(applyMatrix);
                            normalModelToCameraMatrix.Invert();
                            GL.UniformMatrix3(currentProgram.normalModelToCameraMatrixUnif, false,
                                              ref normalModelToCameraMatrix);
                            //Matrix4 cameraToClipMatrix = Matrix4.Identity;
                            //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix);

                        }
                        //Matrix4 cameraToClipMatrix = Matrix4.Identity;
                        //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix);
                    }
                    else
                    {
                        GL.UniformMatrix4(currentProgram.modelToWorldMatrixUnif, false, ref mm);
                    }
                }
                if (renderWithString)
                {
                    try
                    {
                        meshes[currentMesh].Render(renderString);
                    }
                    catch (Exception ex)
                    {
                        renderWithString = false;
                        MessageBox.Show("Error displaying mesh wih render string " + renderString + " " + ex.ToString());
                    }
                }
                else
                {
                    meshes[currentMesh].Render();
                }
                GL.UseProgram(0);
                if (perspectiveAngle != newPerspectiveAngle)
                {
                    perspectiveAngle = newPerspectiveAngle;
                    reshape();
                }
            }
        }
        public override void display()
        {
            ClearDisplay();

            cameraMatrix = g_viewPole.CalcMatrix();

            if (meshes[currentMesh] != null)
            {
                MatrixStack modelMatrix = new MatrixStack();
                using (PushStack pushstack = new PushStack(modelMatrix))
                {
                    modelMatrix.Rotate(axis, angle);   // rotate last to leave in place
                    //modelMatrix.Translate(Camera.g_camTarget);
                    //modelMatrix.Scale(initialScale.X / scaleFactor.X,
                    //	initialScale.Y / scaleFactor.Y,
                    //	initialScale.Z / scaleFactor.Z);

                    GL.UseProgram(programs[currentProgram].theProgram);

                    GL.UniformMatrix4(programs[currentProgram].cameraToLightProjMatrixUnif, false, ref cameraToLightProjMatrix);

                    GL.Uniform3(programs[currentProgram].cameraSpaceProjLightPosUnif, cameraSpaceProjLightPos);

                    GL.Uniform1(programs[currentProgram].diffuseColorTexUnif, 0);
                    GL.Uniform1(programs[currentProgram].lightProjTexUnif, 1);

                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.BindTexture(TextureTarget.Texture2D, currentTexture);

                    GL.ActiveTexture(TextureUnit.Texture1);
                    GL.BindTexture(TextureTarget.Texture2D, lightTexture);

                    cameraMatrix = cameraMatrixStack.Top();

                    modelToCameraMatrix = Matrix4.Mult(Matrix4.Identity, cameraMatrix);
                    GL.UniformMatrix4(programs[currentProgram].modelToCameraMatrixUnif, false, ref modelToCameraMatrix);
                    if (programs[currentProgram].normalModelToCameraMatrixUnif != 0)
                    {
                        Matrix3 normalModelToCameraMatrix = Matrix3.Identity;
                        Matrix4 applyMatrix = Matrix4.Mult(Matrix4.Identity,
                            Matrix4.CreateTranslation(dirToLight));
                        normalModelToCameraMatrix = new Matrix3(applyMatrix);
                        normalModelToCameraMatrix.Invert();
                        GL.UniformMatrix3(programs[currentProgram].normalModelToCameraMatrixUnif, false,
                            ref normalModelToCameraMatrix);
                        Matrix4 cameraToClipMatrix = Matrix4.Identity;
                        GL.UniformMatrix4(programs[currentProgram].cameraToClipMatrixUnif, false, ref cameraToClipMatrix);

                    }
                }
                if (renderWithString)
                {
                    try
                    {
                        meshes[currentMesh].Render(renderStrings[renderString]);
                    }
                    catch (Exception ex)
                    {
                        renderWithString = false;
                        MessageBox.Show("Error displaying mesh wih render string " + renderStrings[renderString] + " " + ex.ToString());
                    }
                }
                else
                {
                    meshes[currentMesh].Render();
                }
                GL.UseProgram(0);
                if (perspectiveAngle != newPerspectiveAngle)
                {
                    perspectiveAngle = newPerspectiveAngle;
                    reshape();
                }
            }
        }
Ejemplo n.º 4
0
        public override void display()
        {
            GL.Disable(EnableCap.DepthTest);
            ClearDisplay();
            if (drawWalls) backWall.Draw();
            if (drawWalls) leftWall.Draw();
            if (drawWalls) rightWall.Draw();
            if (drawWalls) topWall.Draw();
            if (drawWalls) bottomWall.Draw();

            ball.Draw();

            if (current_mesh != null)
            {
                MatrixStack modelMatrix = new MatrixStack();
                using (PushStack pushstack = new PushStack(modelMatrix))
                {
                    modelMatrix.Rotate(axis, angle);   // rotate last to leave in place
                    modelMatrix.Translate(position);
                    modelMatrix.Scale(15.0f, 15.0f, 15.0f);
                    ballModelMatrix = modelMatrix.Top();

                    GL.UseProgram(currentProgram.theProgram);
                    Matrix4 mm = modelMatrix.Top();

                    if (noWorldMatrix)
                    {
                        Matrix4 cm2 = Matrix4.Mult(mm, worldToCameraMatrix);
                        GL.UniformMatrix4(currentProgram.modelToCameraMatrixUnif, false, ref cm2);
                        if (currentProgram.normalModelToCameraMatrixUnif != 0)
                        {
                            Matrix3 normalModelToCameraMatrix = Matrix3.Identity;
                            Matrix4 applyMatrix = Matrix4.Mult(Matrix4.Identity,
                                                                     Matrix4.CreateTranslation(dirToLight));
                            normalModelToCameraMatrix = new Matrix3(applyMatrix);
                            normalModelToCameraMatrix.Invert();
                            GL.UniformMatrix3(currentProgram.normalModelToCameraMatrixUnif, false,
                                              ref normalModelToCameraMatrix);
                            //Matrix4 cameraToClipMatrix = Matrix4.Identity;
                            //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix);

                        }
                        //Matrix4 cameraToClipMatrix = Matrix4.Identity;
                        //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix);
                    }
                    else
                    {
                        GL.UniformMatrix4(currentProgram.modelToWorldMatrixUnif, false, ref mm);
                    }
                }
                if (renderWithString)
                {
                    current_mesh.Render(renderString);
                }
                else
                {
                    current_mesh.Render();
                }
                GL.UseProgram(0);
                if (perspectiveAngle != newPerspectiveAngle)
                {
                    perspectiveAngle = newPerspectiveAngle;
                    reshape();
                }
            }
            if (drawWalls) frontWall.Draw();
            if (pause == false)
            {
                UpdatePosition();
                if (rotateWorld)
                {
                    RotateWorldSub();
                }
            }
        }