コード例 #1
0
ファイル: SampleForm.cs プロジェクト: vazgriz/OpenGL.Net
        private void SampleGraphicsControl_Render(object sender, GraphicsControlEventArgs e)
        {
            GraphicsContext ctx         = e.Context;
            GraphicsSurface framebuffer = e.Framebuffer;

            if (_AnimationBegin == DateTime.MinValue)
            {
                _AnimationBegin = DateTime.UtcNow;
            }

            PerspectiveProjectionMatrix matrixProjection = new PerspectiveProjectionMatrix();
            Matrix4x4 matrixView;

            // Set projection
            matrixProjection.SetPerspective(60.0f, (float)ClientSize.Width / (float)ClientSize.Height, 1.0f, 1000.0f);
            // Set view
            ModelMatrix matrixViewModel = new ModelMatrix();

            matrixViewModel.RotateX(_ViewElevation);
            matrixViewModel.RotateY(_ViewAzimuth);
            matrixViewModel.Translate(0.0f, 0.0f, _ViewDistance);
            matrixView = matrixViewModel.GetInverseMatrix();

            _NewtonProgram.Bind(ctx);
            _NewtonProgram.SetUniform(ctx, "hal_ModelViewProjection", matrixProjection * matrixView);
            _NewtonProgram.SetUniform(ctx, "hal_FrameTimeInterval", (float)(DateTime.UtcNow - _AnimationBegin).TotalSeconds);

            _NewtonVertexArray.Draw(ctx, _NewtonProgram);

            SwapNewtonVertexArrays();

            // Issue another rendering
            SampleGraphicsControl.Invalidate();
        }
コード例 #2
0
ファイル: Plane.cs プロジェクト: lwansbrough/OpenGL.Net
        public void TestPerspectiveFrustum()
        {
            PerspectiveProjectionMatrix projectionMatrix = new PerspectiveProjectionMatrix();

            projectionMatrix.SetPerspective(60.0f, 1.0f, 0.5f, 100.0f);

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

            foreach (Plane plane in planes)
            {
                Assert.GreaterOrEqual(plane.GetDistance(-Vertex3f.UnitZ), 0.0f);
            }
        }
コード例 #3
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));
        }