Example #1
0
        private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            if (isDrawing)
            {
                OpenGL gl = openGLControl1.OpenGL;
                // Clear vung nho dem
                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

                // ===========================Ve he truc va mat phang day====================================
                SystemDraw(gl);

                //=================================CAMERA ROTATION============================================
                // Camera rotation
                gl.MatrixMode(OpenGL.GL_MODELVIEW);
                gl.LoadIdentity();

                /*gl.LookAt(rotate_x, rotate_y, rotate_z, // camera position (-4,4,-4)
                 *                                1, 0, 1, // look at
                 *                                0, 1, 0); // vector up*/
                cam.calDist();
                double x = cam.getX();
                double y = cam.getY();
                double z = cam.getZ();

                double u_x = cam.getU_X();
                double u_y = cam.getU_Y();
                double u_z = cam.getU_Z();

                // goc quay
                double angle = cam.getAngle();

                gl.LookAt(x, y, z,
                          1, 0, 1,
                          u_x, u_y, u_z);

                //============================================================================================

                // Kiem tra khi nguoi dung select 1 doi tuong va co thay doi mau to khong
                if (isChangedColor)
                {
                    // Doi mau nguoi chung luc click vao listbox
                    drObj.setColorOfOneObj(indexCurrentObj, currentColor);
                    isChangedColor = false;                     // reset lai
                }

                if (isAffine)
                {
                    switch (currentAffine)
                    {
                    case AFFINE.TRANSLATE:
                        drObj.updateTranCoor(indexCurrentObj, pos.x, pos.y, pos.z);
                        break;

                    case AFFINE.ROTATE:
                        drObj.updateRotaCoor(indexCurrentObj, rotation.x, rotation.y, rotation.z);
                        break;

                    case AFFINE.SCALE:
                        drObj.updateScaleCoor(indexCurrentObj, scale.x, scale.y, scale.z);
                        break;
                    }
                }


                // Draw object
                if (angle != 90 && angle != 270)
                {
                    drObj.draw(gl, indexCurrentObj);
                }

                // Reset lai isDrawing
                isDrawing = false;
            }
        }