Beispiel #1
0
        // tick for OpenGL rendering code
        public void RenderGL()
        {
            // measure frame duration
            float frameDuration = timer.ElapsedMilliseconds;

            timer.Reset();
            timer.Start();

            // update rotation
            Tpot.angle.Y += 0.001f * frameDuration;
            if (Tpot.angle.Y > 2 * PI)
            {
                Tpot.angle.Y -= 2 * PI;
            }

            Tpot2.angle.X += 0.001f * frameDuration;
            if (Tpot2.angle.X > 2 * PI)
            {
                Tpot2.angle.X -= 2 * PI;
            }

            Tpot3.angle.Y += 0.001f * frameDuration;
            if (Tpot3.angle.Y > 2 * PI)
            {
                Tpot3.angle.Y -= 2 * PI;
            }

            Tfloor.angle.Y += 0.001f * frameDuration;
            if (Tfloor.angle.Y > 2 * PI)
            {
                Tfloor.angle.Y -= 2 * PI;
            }

            Tfloor3.angle.X += 0.001f * frameDuration;
            if (Tfloor3.angle.X > 2 * PI)
            {
                Tfloor3.angle.X -= 2 * PI;
            }


            // render scene
            sceneGraph.Render();
        }
Beispiel #2
0
        // tick for OpenGL rendering code
        public void RenderGL()
        {
            // measure frame duration
            float frameDuration = timer.ElapsedMilliseconds;

            timer.Reset();
            timer.Start();

            // prepare matrix for vertex shader
            float   angle90degrees = PI / 2;
            Vector3 cameraPos      = new Vector3(0, 50f, 0);
            int     cameraID       = GL.GetUniformLocation(shader.programID, "cameraPos");

            GL.UseProgram(shader.programID);
            GL.Uniform3(cameraID, cameraPos);

            Matrix4 Tcar    = Matrix4.CreateScale(0.5f) * Matrix4.CreateRotationY(10f) * Matrix4.CreateTranslation(new Vector3(0, 0, 0)) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 9 + 0) * Matrix4.CreateTranslation(new Vector3(0, 0, 0));
            Matrix4 Tflag   = Matrix4.CreateScale(0.08f) * Tcar * Matrix4.CreateTranslation(new Vector3(0, 2, 0));
            Matrix4 toWorld = Tflag;
            Matrix4 Tfloor  = Matrix4.CreateScale(4.0f) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 0);
            Matrix4 Tcamera = Matrix4.CreateTranslation(-cameraPos) * Matrix4.CreateFromAxisAngle(new Vector3(1, 0, 0), angle90degrees);
            Matrix4 Tview   = Matrix4.CreatePerspectiveFieldOfView(1.2f, 1.3f, .1f, 1000);

            // defining the model view matrix for the mesh object
            flag.modelViewMatrix  = Tflag * Tcamera * Tview;
            flag.toWorld          = toWorld;
            car.modelViewMatrix   = Tcar * Tcamera * Tview;
            car.toWorld           = toWorld;
            floor.modelViewMatrix = Tfloor * Tcamera * Tview;
            floor.toWorld         = toWorld;

            SceneGraph floor_sg = new SceneGraph(floor);

            floor_sg.pos      = new Vector3(0, 0, 0);
            floor_sg.rotation = a;
            floor_sg.scale    = new Vector3(4, 2, 2);

            // update rotation
            a += 0.0005f * frameDuration;
            if (a > 2 * PI)
            {
                a -= 2 * PI;
            }

            b = a * a;
            if (a > 6 * PI)
            {
                a -= 10 * PI;
            }

            if (useRenderTarget)
            {
                // enable render target
                target.Bind();

                // render scene via Scenegraph
                floor_sg.Render(Tcamera * Tview);


                // render scene to render target

                /*
                 * flag.Render(shader, Tflag * Tcamera * Tview, toWorld, dark);
                 * car.Render( shader, Tcar*Tcamera*Tview, toWorld, silver);
                 * floor.Render( shader, Tfloor * Tcamera * Tview, toWorld, wood ); */


                // render quad
                target.Unbind();
                quad.Render(postproc, target.GetTextureID());
            }
            else
            {
                // render scene via SceneGraph
                floor_sg.Render(Tcamera);

                // render scene directly to the

                /*
                 * flag.Render(shader, Tflag * Tcamera * Tview, toWorld, dark);
                 * car.Render(shader, Tcar * Tcamera * Tview, toWorld, silver);
                 * floor.Render(shader, Tfloor * Tcamera * Tview, toWorld, wood); */
            }
        }