예제 #1
0
        /// <summary>
        /// Render the camera's overlay
        /// </summary>
        /// <param name="width">The width of the overlay</param>
        /// <param name="height">The height of the overlay</param>
        public void renderOverlay(float width, float height)
        {
            this.width  = width;
            this.height = height;

            GL.PushAttrib(AttribMask.AllAttribBits);
            {
                GL.LineWidth(2);
                GL.LogicOp(LogicOp.Invert);
                GL.Enable(EnableCap.ColorLogicOp);

                if (currentMode == Mode.ORBIT)
                {
                    float radius = Math.Min(width, height) * 0.3f;

                    GL.PushMatrix();
                    {
                        GL.Translate(width / 2, height / 2, 0);
                        OGLDrawing.drawArc(new BXDVector3(0, 0, 1), new BXDVector3(0, 1, 0), 0, 6.28f, radius, Color4.Gray, Color4.Gray);

                        GL.Begin(PrimitiveType.Lines);
                        {
                            // Center crosshairs
                            GL.Vertex2(-radius / 4.0f, 0);
                            GL.Vertex2(radius / 4.0f, 0);
                            GL.Vertex2(0, -radius / 4.0f);
                            GL.Vertex2(0, radius / 4.0f);

                            //Other things
                            GL.Vertex2(-radius, 0);
                            GL.Vertex2(-radius - (radius / 8.0f), 0);
                            GL.Vertex2(radius, 0);
                            GL.Vertex2(radius + (radius / 8.0f), 0);

                            GL.Vertex2(0, -radius);
                            GL.Vertex2(0, -radius - (radius / 8.0f));
                            GL.Vertex2(0, radius);
                            GL.Vertex2(0, radius + (radius / 8.0f));
                        }
                        GL.End();
                    }
                    GL.PopMatrix();
                }
            }
            GL.PopAttrib();
        }
예제 #2
0
        /// <summary>
        /// Render the node's center of mass and limits of motion along the joint it is connected to (If any)
        /// </summary>
        public void renderDebug(bool drawAxes)
        {
            // Debug Settings
            GL.UseProgram(0);
            GL.Disable(EnableCap.Lighting);
            GL.LineWidth(2f);

            GL.PushMatrix();
            {
                GL.MultMatrix(ref myTrans);

                GL.PushAttrib(AttribMask.AllAttribBits);
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);

                    float lerp = 0;
                    foreach (VBOMesh mesh in colliders)
                    {
                        GL.Color4(0f, lerp, 1f - lerp, 1f);
                        lerp += (1f / colliders.Count);
                        mesh.draw();
                    }
                }
                GL.PopAttrib();

                if (GetSkeletalJoint() != null && drawAxes)
                {
                    float crosshairLength = 100;

                    bool hasLinearDOF = GetSkeletalJoint().GetLinearDOF().GetEnumerator().MoveNext();

                    #region ROTATIONAL_SPEC
                    foreach (AngularDOF dof in GetSkeletalJoint().GetAngularDOF())
                    {
                        BXDVector3 dirCOM  = centerOfMass.Copy().Subtract(dof.basePoint);
                        float      offset  = BXDVector3.DotProduct(dirCOM, dof.rotationAxis);
                        BXDVector3 baseCOM = dof.basePoint.Copy();

                        if (BXDVector3.CrossProduct(dirCOM, dof.rotationAxis).Magnitude() < 1E-10) // COM is on the axis. (>.>)  Pick randomlyish.
                        {
                            dirCOM = new BXDVector3(.123213, 123213, 0.82134);                     // Certain to be random.
                        }

                        dirCOM.Multiply(1f / dirCOM.Magnitude());
                        baseCOM.Add(dof.rotationAxis.Copy().Multiply(offset / dof.rotationAxis.Magnitude()));

                        BXDVector3 direction = BXDVector3.CrossProduct(dirCOM, dof.rotationAxis);
                        direction = BXDVector3.CrossProduct(direction, dof.rotationAxis);
                        if (BXDVector3.DotProduct(dirCOM, direction) < 0)
                        {
                            direction.Multiply(-1f);
                        }

                        GL.PushMatrix();
                        {
                            GL.Translate(baseCOM.x, baseCOM.y, baseCOM.z);

                            if (!hasLinearDOF) // Linear limits show the axis anyways, and clipping is UGLY
                            {
                                // Rotational Axis
                                GL.Begin(PrimitiveType.Lines);
                                {
                                    GL.Color3(1f, 0f, 0f);
                                    GL.Vertex3(-dof.rotationAxis.x * crosshairLength, -dof.rotationAxis.y * crosshairLength,
                                               -dof.rotationAxis.z * crosshairLength);
                                    GL.Vertex3(dof.rotationAxis.x * crosshairLength, dof.rotationAxis.y * crosshairLength,
                                               dof.rotationAxis.z * crosshairLength);
                                }
                                GL.End();
                            }

                            // Current
                            GL.Begin(PrimitiveType.Lines);
                            {
                                GL.Color3(1f, 0f, 1f);
                                GL.Vertex3(0, 0, 0);
                                GL.Vertex3(direction.x * crosshairLength, direction.y * crosshairLength, direction.z * crosshairLength);
                            }
                            GL.End();

                            #region ROTATIONAL_LIMITS
                            if (dof.hasAngularLimits())
                            {
                                // Minpos
                                GL.PushMatrix();
                                {
                                    GL.Rotate(180.0f / 3.14f * (dof.lowerLimit - requestedRotation), dof.rotationAxis.ToTK());

                                    GL.Begin(PrimitiveType.Lines);
                                    {
                                        GL.Color3(0f, 1f, 1f);
                                        GL.Vertex3(0, 0, 0);
                                        GL.Vertex3(direction.x * crosshairLength, direction.y * crosshairLength, direction.z * crosshairLength);
                                    }
                                    GL.End();

                                    OGLDrawing.drawArc(dof.rotationAxis, direction, dof.lowerLimit, dof.upperLimit, crosshairLength,
                                                       Color4.Cyan, Color4.Green);
                                }
                                GL.PopMatrix(); // Begin limit matrix

                                // Maxpos
                                GL.PushMatrix();
                                {
                                    GL.Rotate(180.0f / 3.14f * (dof.upperLimit - requestedRotation), dof.rotationAxis.ToTK());

                                    GL.Begin(PrimitiveType.Lines);
                                    {
                                        GL.Color3(0f, 1f, 0f);
                                        GL.Vertex3(0, 0, 0);
                                        GL.Vertex3(direction.x * crosshairLength, direction.y * crosshairLength, direction.z * crosshairLength);
                                    }
                                    GL.End();
                                }
                                GL.PopMatrix(); // End limit matrix
                            }
                            else
                            {
                                // Full arc!
                                OGLDrawing.drawArc(dof.rotationAxis, direction, 0, 6.28f, crosshairLength, Color4.Cyan, Color4.Green);
                            }
                            #endregion
                        }
                        GL.PopMatrix();  // part -> COM-basepoint
                    }
                    #endregion

                    #region LINEAR_SPEC
                    foreach (LinearDOF dof in GetSkeletalJoint().GetLinearDOF())
                    {
                        float lower = (dof.hasLowerLinearLimit() ? dof.lowerLimit : -crosshairLength) - requestedTranslation;
                        float upper = (dof.hasUpperLinearLimit() ? dof.upperLimit : crosshairLength) - requestedTranslation;

                        BXDVector3 dirCOM  = centerOfMass.Copy().Subtract(dof.basePoint);
                        float      offset  = BXDVector3.DotProduct(dirCOM, dof.translationalAxis);
                        BXDVector3 baseCOM = dof.basePoint.Copy();

                        if (BXDVector3.CrossProduct(dirCOM, dof.translationalAxis).Magnitude() < 1E-10) // COM is on the axis. (>.>)  Pick randomlyish.
                        {
                            dirCOM = new BXDVector3(.123213, 123213, 0.82134);                          // Certain to be random.
                        }

                        dirCOM.Multiply(1f / dirCOM.Magnitude());
                        baseCOM.Add(dof.translationalAxis.Copy().Multiply(offset / dof.translationalAxis.Magnitude()));

                        BXDVector3 direction = BXDVector3.CrossProduct(dirCOM, dof.translationalAxis);
                        direction = BXDVector3.CrossProduct(direction, dof.translationalAxis);
                        if (BXDVector3.DotProduct(dirCOM, direction) < 0)
                        {
                            direction.Multiply(-1f);
                        }

                        GL.PushMatrix();
                        {
                            GL.Translate(baseCOM.x, baseCOM.y, baseCOM.z);

                            #region LIMITS
                            BXDVector3 otherDirection = BXDVector3.CrossProduct(dof.translationalAxis, direction);

                            GL.Begin(PrimitiveType.Lines);
                            {
                                GL.Color3(0f, 1f, 0f);
                                GL.Vertex3(dof.translationalAxis.ToTK() * lower);
                                GL.Vertex3(dof.translationalAxis.ToTK() * upper);
                            }
                            GL.End();

                            if (dof.hasLowerLinearLimit())
                            {
                                GL.PushMatrix();
                                {
                                    GL.Translate(dof.translationalAxis.ToTK() * lower);
                                    OGLDrawing.drawCrossHair(dof.translationalAxis, direction, crosshairLength);
                                }
                                GL.PopMatrix();
                            }

                            if (dof.hasUpperLinearLimit())
                            {
                                GL.PushMatrix();
                                {
                                    GL.Translate(dof.translationalAxis.ToTK() * upper);
                                    OGLDrawing.drawCrossHair(dof.translationalAxis, direction, crosshairLength);
                                }
                                GL.PopMatrix();
                            }
                            #endregion
                        }
                        GL.PopMatrix();  // part -> COM-basepoint
                    }
                    #endregion
                }
            }
            GL.PopMatrix();  // World -> part matrix

            // Revert Debug Settings
            GL.Enable(EnableCap.Lighting);
        }