Exemplo n.º 1
0
        public void Init()
        {
            BrushSize = 16;                                             // brush size
            this.prevMousePosition = new MyVector2();                   // prev mouse pos
            this.mouseDownPosition = new MyVector2();                   // mouse down pos
            this.currMousePosition = new MyVector2();                   // curr mouse pos

            // initialize textures, airbrushes, and parameters
            this.LoadTextures();                                                                // load canvas, brush textures


            // 3d entities
            //this.eyePos = new MyVector3(0, 0.1, 1);				// eye (camera) position
            this.eyePos        = new MyVector3(0, 0, -0.5);                     // eye (camera) position
            this.lightPosition = new MyVector3(5, 5, 5);                        // light position


            // util
            Utils.InitialRandomColors(53);                                              // initial random colors

            // opengl
            GLBasicDraw.InitGlMaterialLights();


            // mode
            //this.currentMode = EnumOperationMode.Adjusting;
            this.currentMode = EnumOperationMode.Viewing;

            // opengl projector
            this.glProjector = new OpenGLProjector();
        }
        private void DrawScene3d()
        {
            if (this.camera.Calibrated == false)
            {
                return;
            }

            GLBasicDraw.InitGlMaterialLights(); // lights and materials
            int w = this.Canvas.Width, h = this.Canvas.Height;

            GL.Viewport(0, this.view.Height - h, w, h);

            // -------------------------------------------------------------------------
            // draw 3d sense
            MyMatrix4d m = this.arcBall.GetMatrix() * this.modelTransformation;

            m = MyMatrix4d.TranslationMatrix(this.currTransCenter) * m * MyMatrix4d.TranslationMatrix(
                new MyVector3() - this.currTransCenter);

            GL.PushMatrix();
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.LoadMatrix(this.camera.glprojMatrix);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.LoadMatrix(this.camera.glmodelViewMatrix);

            GL.PushMatrix();
            GL.MultMatrix(m.Transpose().ToArray());

            // Enable antialiased lines
            GL.Enable(EnableCap.PointSmooth);
            GL.Enable(EnableCap.LineSmooth);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);


            // draw all geometric faces (depth test enabled, blend disabled)
            if (!this.DrawTransparent)
            {
                GL.Enable(EnableCap.DepthTest);
                GL.Disable(EnableCap.Blend);
                GL.DepthFunc(DepthFunction.Less);
                GL.DepthMask(true);
            }

            if (!this.DrawTransparent)
            {
                GL.DepthFunc(DepthFunction.Lequal);
                GL.DepthMask(false); // Do not remove me, else get dotted lines
            }

            GL.Enable(EnableCap.Blend);
            /* --------------------------------------------------------------------------*/
            // draw the lines on top
            // painting goes here!
            /* --------------------------------------------------------------------------*/


            //DrawAxis();

            // draw highlights
            this.DrawHighlights3D();

            GL.Disable(EnableCap.LineSmooth);
            GL.Disable(EnableCap.PointSmooth);
            GL.Disable(EnableCap.Blend);
            GL.DepthMask(true);
            GL.PopMatrix();
            GL.PopMatrix();
        }