コード例 #1
0
        public void TestPerspectiveFrustum()
        {
            PerspectiveProjectionMatrix projectionMatrix = new PerspectiveProjectionMatrix();
            ModelMatrix modelMatrix = new ModelMatrix();
            BoundingBox boundingBox;
            Vertex3f    bboxPosition;

            projectionMatrix.SetPerspective(60.0f, 1.0f, 0.5f, 15.0f);
            modelMatrix.Translate(new Vertex3f(-1000.0f, 00.0f, 0.0f));

            IEnumerable <Plane> planes = Plane.GetFrustumPlanes(projectionMatrix * modelMatrix);

            bboxPosition = new Vertex3f(-0.5f, -0.5f, -3.0f);
            boundingBox  = new BoundingBox(bboxPosition, bboxPosition + Vertex3f.One);
            Assert.IsTrue(boundingBox.IsClipped(planes));

            bboxPosition = new Vertex3f(-10.5f, -10.5f, -3.0f);
            boundingBox  = new BoundingBox(bboxPosition, bboxPosition + Vertex3f.One);
            Assert.IsTrue(boundingBox.IsClipped(planes));

            bboxPosition = new Vertex3f(999.5f, -0.5f, -3.0f);
            boundingBox  = new BoundingBox(bboxPosition, bboxPosition + Vertex3f.One);
            Assert.IsFalse(boundingBox.IsClipped(planes));

            modelMatrix.SetIdentity();
            modelMatrix.RotateY(180.0f);
            planes = Plane.GetFrustumPlanes(projectionMatrix * modelMatrix);

            bboxPosition = new Vertex3f(-10.5f, -10.5f, -3.0f);
            boundingBox  = new BoundingBox(bboxPosition, bboxPosition + Vertex3f.One);
            Assert.IsTrue(boundingBox.IsClipped(planes));

            bboxPosition = new Vertex3f(999.5f, -0.5f, -3.0f);
            boundingBox  = new BoundingBox(bboxPosition, bboxPosition + Vertex3f.One);
            Assert.IsTrue(boundingBox.IsClipped(planes));

            bboxPosition = new Vertex3f(-0.5f, -0.5f, +3.0f);
            boundingBox  = new BoundingBox(bboxPosition, bboxPosition + Vertex3f.One);
            Assert.IsFalse(boundingBox.IsClipped(planes));
        }
コード例 #2
0
ファイル: SampleForm.cs プロジェクト: raygoe/OpenGL.Net
        /// <summary>
        /// Update framebuffer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_Render(object sender, GlControlEventArgs e)
        {
            GlControl senderControl     = (GlControl)sender;
            float     senderAspectRatio = (float)senderControl.Width / senderControl.Height;

            // Clear
            Gl.Viewport(0, 0, senderControl.Width, senderControl.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _CubeScene.CurrentView.LocalModel.SetIdentity();
            _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f);
            _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth);
            _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation);
            _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever);

            _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.5f, 10000.0f);

            _CubeScene.Draw(_Context);

            // Overlay
            ProjectionMatrix overlayProjection = new OrthoProjectionMatrix(0.0f, ClientSize.Width, 0.0f, ClientSize.Height);
            ModelMatrix      overlayModel      = new ModelMatrix();

            overlayModel.Translate(0.375f, 0.375f);

            Gl.Clear(ClearBufferMask.DepthBufferBit);

            ColorRGBAF fpsColor = ColorRGBAF.ColorGreen;
            int        fps      = senderControl.Fps;

            if (fps >= 59)
            {
                fpsColor = ColorRGBAF.ColorGreen;
            }
            else if (fps >= 29)
            {
                fpsColor = ColorRGBAF.ColorBlue;
            }
            else if (fps >= 24)
            {
                fpsColor = ColorRGBAF.ColorYellow;
            }
            else
            {
                fpsColor = ColorRGBAF.ColorRed;
            }

            fontPatch.DrawString(
                _Context, overlayProjection * overlayModel, fpsColor,
                String.Format("FPS: {0}", senderControl.Fps)
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 64 + 0.375f);
            fontTitle.DrawString(
                _Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                "Hello Objects example ~(^.^)~"
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 128 + 0.375f);
            fontTitleV.DrawString(_Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                                  "Hello Objects example ~(^.^)~"
                                  );
        }
コード例 #3
0
        /// <summary>
        /// Update framebuffer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_Render(object sender, GlControlEventArgs e)
        {
            GlControl senderControl     = (GlControl)sender;
            float     senderAspectRatio = (float)senderControl.Width / senderControl.Height;

            KhronosApi.LogEnabled = false;
            KhronosApi.LogComment("--------------------------------------------------");
            KhronosApi.LogComment("*** Draw");

            // Clear
            Gl.Viewport(0, 0, senderControl.Width, senderControl.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.1f, 100.0f);
            _CubeScene.CurrentView.LocalModel.SetIdentity();
            _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f);
            _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth);
            _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation);
            _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever);
            _CubeScene.UpdateViewMatrix();

            _CubeScene.Draw(_Context);

            KhronosApi.LogEnabled = false;

            return;

            // Overlay
            ProjectionMatrix overlayProjection = new OrthoProjectionMatrix(0.0f, ClientSize.Width, 0.0f, ClientSize.Height);
            ModelMatrix      overlayModel      = new ModelMatrix();

            overlayModel.Translate(0.375f, 0.375f);

            Gl.Clear(ClearBufferMask.DepthBufferBit);

            ColorRGBAF fpsColor = ColorRGBAF.ColorGreen;
            int        fps      = (int)Math.Floor(1000.0 / senderControl.FrameSwapTime.TotalMilliseconds);

            if (fps >= 59)
            {
                fpsColor = ColorRGBAF.ColorGreen;
            }
            else if (fps >= 29)
            {
                fpsColor = ColorRGBAF.ColorBlue;
            }
            else if (fps >= 24)
            {
                fpsColor = ColorRGBAF.ColorYellow;
            }
            else
            {
                fpsColor = ColorRGBAF.ColorRed;
            }

            fontPatch.DrawString(
                _Context, overlayProjection * overlayModel, fpsColor,
                String.Format("FPS: {0}", fps)
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 64 + 0.375f);
            fontTitle.DrawString(
                _Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                "Hello Objects example ~(^.^)~"
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 128 + 0.375f);
            fontTitleV.DrawString(_Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                                  "Hello Objects example ~(^.^)~"
                                  );

            // Release resources
            _Context.DisposeResources();
        }