Esempio n. 1
0
        private void draw()
        {
            int w = this.Width;
            int h = this.Height;

            if (h == 0)
            {
                h = 1;
            }

            Gl.glViewport(0, 0, w, h);

            double aspect = (double)w / h;

            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();

            Glu.gluPerspective(90, aspect, 0.1, 1000);

            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();

            Glu.gluLookAt(_eye.x, _eye.y, _eye.z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

            Gl.glMatrixMode(Gl.GL_MODELVIEW);

            Gl.glPushMatrix();
            Gl.glMultMatrixd(_modelViewMat.Transpose().ToArray());

            drawParts();

            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glPopMatrix();
        }
Esempio n. 2
0
        /// <summary>
        /// Renders a billboard along a line.
        /// </summary>
        /// <param name="pos">Start position.</param>
        /// <param name="p2">End position.</param>
        /// <param name="width">Width of the line.</param>
        /// <param name="facing">Facing target.</param>
        /// <param name="view">Relevant view.</param>
        public void RenderBilboardLine(Location pos, Location p2, float width, Location facing, View3D view)
        {
            Location center  = (pos + p2) * 0.5;
            double   len     = (center - facing).Length();
            Location lookdir = (center - facing) / len;
            double   len2    = (p2 - pos).Length();

            if (len < 0.001 || len2 < 0.001)
            {
                return;
            }
            Location updir = (p2 - pos) / len2;
            Location right = updir.CrossProduct(lookdir);
            Matrix4d mat   = Matrix4d.CreateTranslation(-0.5f, -0.5f, 0f) * Matrix4d.Scale((float)len2 * 0.5f, width, 1f);
            Matrix4d m2    = new Matrix4d(right.X, updir.X, lookdir.X, center.X,
                                          right.Y, updir.Y, lookdir.Y, center.Y,
                                          right.Z, updir.Z, lookdir.Z, center.Z,
                                          0, 0, 0, 1);

            m2.Transpose();
            mat *= m2;
            view.SetMatrix(2, mat);
            GL.BindVertexArray(Square._VAO);
            GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, IntPtr.Zero);
            GL.BindVertexArray(0);
        }
Esempio n. 3
0
        public static Matrix4d TranslateMatrix(double tx, double ty, double tz)
        {
            Matrix4d result = new Matrix4d(1, 0, 0, 0,
                                           0, 1, 0, 0,
                                           0, 0, 1, 0,
                                           tx, ty, tz, 1);

            result.Transpose();
            return(result);
        }
Esempio n. 4
0
        public static Matrix4d ScaleMatrix(double s)
        {
            Matrix4d result = new Matrix4d(s, 0, 0, 0,
                                           0, s, 0, 0,
                                           0, 0, s, 0,
                                           0, 0, 0, 1);

            result.Transpose();
            return(result);
        }
        public void TransposeStatic_ByRef()
        {
            var input     = GetTestMatrix();
            var inputSimd = (NMatrix4d)input;

            Matrix4d  expected;
            NMatrix4d actual;

            Matrix4d.Transpose(ref input, out expected);
            NMatrix4d.Transpose(ref inputSimd, out actual);
            Asserts.AreEqual(expected, actual, "transpose out/ref");
        }
        public void TransposeStatic()
        {
            var input     = GetTestMatrix();
            var inputSimd = (NMatrix4d)input;

            var expected = Matrix4d.Transpose(input);
            var actual   = NMatrix4d.Transpose(inputSimd);

            Asserts.AreEqual(expected, actual, "transpose");

            input     = GetTestMatrix();
            inputSimd = (NMatrix4d)input;
            Matrix4d.Transpose(ref input, out expected);
            NMatrix4d.Transpose(ref inputSimd, out actual);
            Asserts.AreEqual(expected, actual, "transpose out/ref");
        }
Esempio n. 7
0
        void CameraRotation_Drag()
        {
            Transformation tf = new Transformation(
                (Transformation)DragInfo.StartInfo);

            Matrix4d m = tf.Matrixd * Matrix4d.Identity;

            m.Transpose();
            Vector4d y = Vector4d.Transform(new Vector4d(0, 1, 0, 0), m);

            tf.Translate(0, 0, -5);
            tf.RotateAxis(y.Xyz, -DragInfo.DeltaX * (float)Math.PI / 360);
            tf.RotateX(-DragInfo.DeltaY * (float)Math.PI / 360);
            tf.Translate(0, 0, 5);
            MainCamera.Tf = tf;
        }
Esempio n. 8
0
        public void Orbit(double aYaw, double aPitch)
        {
            Matrix4d m1 = Matrix4d.CreateFromAxisAngle(mUp, aYaw);
            Matrix4d m2 = Matrix4d.CreateFromAxisAngle(mRight, aPitch);
            Matrix4d m  = m1 * m2;
            Matrix4d mI = Matrix4d.Transpose(m);

            Vector3d tmp = mEye - mCenter;
            double   dst = tmp.Length;

            tmp.Normalize();

            mUp = Vector3d.Transform(mUp, mI);
            mUp.Normalize();
            tmp = Vector3d.Transform(tmp, mI);
            tmp.Normalize();
            mRight = Vector3d.Cross(mUp, tmp);
            mEye   = tmp * dst + mCenter;
        }
Esempio n. 9
0
        /// <summary>
        /// Renders a flat billboard (a sprite).
        /// </summary>
        /// <param name="center">The center of it.</param>
        /// <param name="scale">The scale of it.</param>
        /// <param name="facing">Where it's facing.</param>
        /// <param name="view">The relevant view.</param>
        /// <param name="pzr">Z rotation if any.</param>
        public void RenderBillboard(Location center, Location scale, Location facing, View3D view, float pzr = 0f)
        {
            Location lookdir = (facing - center).Normalize();
            Location right   = lookdir.CrossProduct(Location.UnitZ); // TODO: Camera up vector!
            Location updir   = right.CrossProduct(lookdir);
            Matrix4d mat     = Matrix4d.CreateTranslation(-0.5f, -0.5f, 0f) * Matrix4d.Scale((float)scale.X, (float)scale.Y, (float)scale.Z);
            Matrix4d m2      = new Matrix4d(right.X, updir.X, lookdir.X, center.X,
                                            right.Y, updir.Y, lookdir.Y, center.Y,
                                            right.Z, updir.Z, lookdir.Z, center.Z,
                                            0, 0, 0, 1);

            m2.Transpose();
            mat *= m2;
            view.SetMatrix(2, mat);
            GL.BindVertexArray(Square._VAO);
            GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, IntPtr.Zero);
            GL.BindVertexArray(0);

            /*
             * // TODO: Quaternion magic?
             * Location relang = Utilities.VectorToAngles(pos - facing);
             * if (relang.IsInfinite() || relang.IsNaN())
             * {
             *  throw new Exception("Unable to handle billboard: relang=" + relang);
             * }
             * Matrix4d mat =
             *  Matrix4d.Scale(ClientUtilities.ConvertD(scale))
             * Matrix4d.CreateTranslation(-0.5f, -0.5f, 0f)
             * Matrix4d.CreateRotationY((float)((relang.Y - 90) * Utilities.PI180))
             * Matrix4d.CreateRotationZ((float)(relang.Z * Utilities.PI180))
             * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(pos + new Location(scale.X * 0.5, scale.Y * 0.5, 0.0)));
             * Client.Central.MainWorldView.SetMatrix(2, mat); // TODO: Client reference!
             * GL.BindVertexArray(Square._VAO);
             * GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, IntPtr.Zero);
             * GL.BindVertexArray(0);
             */
        }
 private void UpdateTransposeInverse()
 {
     if (!transposeInverseDirty) {
         return;
     }
     transposeInverseDirty = false;
     transposeInverse = Matrix4d.Scale(scale);
     // TODO: Apply rotation
     transposeInverse = Matrix4d.Mult(Matrix4d.CreateTranslation(translation), transposeInverse);
     transposeInverse.Invert();
     transposeInverse.Transpose();
 }
Esempio n. 11
0
        public override void glDraw()
        {
            base.glDraw();
            GL.glClear(GL.GL_COLOR_BUFFER_BIT);
            if (this.DesignMode == true)
            {
                return;
            }
            if (currMeshRecord == null)
            {
                return;
            }

            lock ((currMeshRecord.Skeletonizer == null)? new Object(): currMeshRecord.Skeletonizer)
            {
                Matrix4d m = ball.GetMatrix() * currTransformation;
                GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                GL.glMatrixMode(GL.GL_MODELVIEW);
                GL.glLoadMatrixd(m.Transpose().ToArray());


                switch (Program.displayProperty.MeshDisplayMode)
                {
                case DisplayProperty.EnumMeshDisplayMode.Points:
                    DrawPoints();
                    break;

                case DisplayProperty.EnumMeshDisplayMode.Wireframe:
                    DrawWireframe();
                    break;

                case DisplayProperty.EnumMeshDisplayMode.FlatShaded:
                    DrawFlatShaded();
                    break;

                case DisplayProperty.EnumMeshDisplayMode.SmoothShaded:
                    DrawSmoothShaded();
                    break;

                case DisplayProperty.EnumMeshDisplayMode.FlatShadedHiddenLine:
                    DrawFlatHiddenLine();
                    break;

                case DisplayProperty.EnumMeshDisplayMode.SmoothShadedHiddenLine:
                    DrawSmoothHiddenLine();
                    break;

                case DisplayProperty.EnumMeshDisplayMode.TransparentSmoothShaded:
                    if (isMouseDown && skeHandleIndex == -1)
                    {
                        DrawSmoothShaded();
                    }
                    else
                    {
                        DrawTransparentSmoothShaded();
                    }
                    break;

                case DisplayProperty.EnumMeshDisplayMode.TransparentFlatShaded:
                    if (isMouseDown && skeHandleIndex == -1)
                    {
                        DrawFlatShaded();
                    }
                    else
                    {
                        DrawTransparentFlatShaded();
                    }
                    break;

                    /*
                     *                              case DisplayProperty.EnumMeshDisplayMode.TransparentSmoothShaded2:
                     *                                      if (isMouseDown)
                     *                                              DrawSmoothShaded();
                     *                                      else
                     *                                              DrawTransparentSmoothShaded2();
                     *                                      break;
                     */
                }

/**/
                if (currMeshRecord.Deformer != null)
                {
                    currMeshRecord.Deformer.Display();
                }

                if (currMeshRecord.Skeletonizer != null &&
                    currMeshRecord.Segmentation == null)
                {
                    currMeshRecord.Skeletonizer.Display();
                }

                if (currMeshRecord.Segmentation != null)
                {
                    currMeshRecord.Segmentation.DisplayRefinedSkeleton();
                    currMeshRecord.Segmentation.DisplayCurrentSlicer();
                }

                switch (Program.currentMode)
                {
                case Program.EnumOperationMode.Selection:
                    if (isMouseDown)
                    {
                        DrawSelectionRect();
                    }
                    break;
                }

                if (Program.displayProperty.DisplaySelectedVertices)
                {
                    DrawSelectedVertice_ByPoint();
                }

                // debug display
                DebugMethod.DisplayVertexArray();
                DebugMethod.DisplaySlicerArray();
                DebugMethod.DisplaySlicerUniformArray();
            }
        }