Example #1
0
        public static GLDisplayList CreateNodeOrb(GLContext ctx)
        {
            GLDisplayList circle = ctx.GetRingList();
            GLDisplayList orb    = new GLDisplayList(ctx);

            orb.Begin();
            ctx.glPushMatrix();

            ctx.glScale(_nodeRadius, _nodeRadius, _nodeRadius);
            circle.Call();
            ctx.glRotate(90.0f, 0.0f, 1.0f, 0.0f);
            circle.Call();
            ctx.glRotate(90.0f, 1.0f, 0.0f, 0.0f);
            circle.Call();

            ctx.glPopMatrix();
            orb.End();
            return(orb);
        }
Example #2
0
        public static GLDisplayList CreateNodeOrb()
        {
            GLDisplayList circle = TKContext.GetRingList();
            GLDisplayList orb    = new GLDisplayList();

            orb.Begin();
            GL.PushMatrix();

            GL.Scale(_nodeRadius, _nodeRadius, _nodeRadius);
            circle.Call();
            GL.Rotate(90.0f, 0.0f, 1.0f, 0.0f);
            circle.Call();
            GL.Rotate(90.0f, 1.0f, 0.0f, 0.0f);
            circle.Call();

            GL.PopMatrix();
            orb.End();
            return(orb);
        }
Example #3
0
        public static GLDisplayList CreateNodeOrb(GLContext ctx)
        {
            GLDisplayList circle = ctx.GetRingList();
            GLDisplayList orb    = new GLDisplayList(ctx);

            orb.Begin();
            ctx.glPushMatrix();
            ctx.glScale(_nodeRadius, _nodeRadius, _nodeRadius);

            circle.Call();
            ctx.glRotate(90.0f, 0.0f, 1.0f, 0.0f);
            circle.Call();
            ctx.glRotate(90.0f, 1.0f, 0.0f, 0.0f);
            circle.Call();

            ctx.glPopMatrix();
            orb.End();
            return(orb);

            //GLDisplayList ndl = ctx.FindOrCreate<GLDisplayList>("OrbOrients", CreateOrbOrients);
            //GLDisplayList orb = new GLDisplayList(ctx);

            //int quad = ctx.gluNewQuadric();
            //ctx.gluQuadricDrawStyle(quad, GLUQuadricDrawStyle.GLU_FILL);
            //ctx.gluQuadricOrientation(quad, GLUQuadricOrientation.Outside);

            //orb.Begin();

            //ctx.gluSphere(quad, _nodeRadius, 20, 20);
            //ndl.Call();

            //orb.End();

            //ctx.gluDeleteQuadric(quad);

            //return orb;
        }
Example #4
0
        private unsafe void modelPanel1_PostRender(object sender, TKContext context)
        {
            //GL.LineWidth(2.0f);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.DepthTest);

            //Attributes.PostRender();

            //Render hurtboxes
            if (chkHurtboxes.Checked)
            {
                for (int i = 0; i < listPanel.lstHurtboxes.Items.Count; i++)
                {
                    if (listPanel.lstHurtboxes.GetItemChecked(i))
                    {
                        ((MiscHurtBox)listPanel.lstHurtboxes.Items[i]).Render(SelectedHurtbox != null && SelectedHurtbox.Index == i, Scriptor._hurtBoxType);
                    }
                }
            }

            //Render hitboxes
            if (chkHitboxes.Checked && Manager.Moveset != null)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                GLDisplayList c = context.GetRingList();
                GLDisplayList s = context.GetSphereList();

                foreach (HitBox e in RunTime._hitBoxes)
                {
                    e.Render(context, modelPanel._camera.GetPoint());
                }
            }

            GL.Enable(EnableCap.DepthTest);

            //Show the user where the light source is
            if (_renderLightDisplay)
            {
                GL.PushAttrib(AttribMask.AllAttribBits);

                GL.Color4(Color.Blue);
                GL.Disable(EnableCap.Lighting);
                GL.Disable(EnableCap.DepthTest);

                GL.Scale(modelPanel.LightPosition._x, modelPanel.LightPosition._x, modelPanel.LightPosition._x);

                GL.Rotate(90.0f, 1, 0, 0);

                float azimuth   = modelPanel.LightPosition._y.Clamp180Deg();
                float elevation = modelPanel.LightPosition._z.Clamp180Deg();

                if (Math.Abs(azimuth) == Math.Abs(elevation) && azimuth % 180.0f == 0 && elevation % 180.0f == 0)
                {
                    azimuth   = 0;
                    elevation = 0;
                }

                int   i; float x;
                float e = azimuth;

                bool flip = false;
                if (e < 0)
                {
                    e    = -e;
                    flip = true;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                float f    = (float)((int)e);
                float diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }
                GL.End();

                if (flip)
                {
                    GL.Rotate(-180.0f, 1, 0, 0);
                }

                GL.Rotate(90.0f, 0, 1, 0);
                GL.Rotate(90.0f, 0, 0, 1);
                GL.Rotate(180.0f, 1, 0, 0);
                GL.Rotate(90.0f - azimuth, 0, 1, 0);

                e = elevation;

                if (e < 0)
                {
                    e = -e;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                f    = (float)((int)e);
                diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }

                GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                GL.Color4(Color.Orange);
                GL.Vertex3(0, 0, 0);

                GL.End();

                GL.PopAttrib();
            }

            GL.Clear(ClearBufferMask.DepthBufferBit);

            RenderTransformControl(context);

            if (!modelPanel._grabbing && !modelPanel._scrolling && !_playing)
            {
                GL.Color4(Color.Black);
                GL.ColorMask(false, false, false, false);

                if (RenderBones)
                {
                    //Render invisible depth orbs
                    GLDisplayList list = context.GetSphereList();
                    if (_editingAll)
                    {
                        foreach (MDL0Node m in _targetModels)
                        {
                            foreach (MDL0BoneNode bone in m._linker.BoneCache)
                            {
                                if (bone != SelectedBone)
                                {
                                    RenderOrb(bone, list);
                                }
                            }
                        }
                    }
                    else if (TargetModel != null && TargetModel._linker != null && TargetModel._linker.BoneCache != null)
                    {
                        foreach (MDL0BoneNode bone in _targetModel._linker.BoneCache)
                        {
                            if (bone != SelectedBone)
                            {
                                RenderOrb(bone, list);
                            }
                        }
                    }
                }

                //Render invisible depth planes for translation and scale controls
                if (_editType != 0 && SelectedBone != null && RenderBones)
                {
                    #region Axis Selection Display List

                    GLDisplayList selList = new GLDisplayList();

                    selList.Begin();

                    GL.Begin(BeginMode.Quads);

                    //X Axis
                    //XY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, -_axisSelectRange, 0.0f);
                    //XZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, -_axisSelectRange);

                    //Y Axis
                    //YX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, _axisLDist, 0.0f);
                    GL.Vertex3(-_axisSelectRange, _axisLDist, 0.0f);
                    //YZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, -_axisSelectRange);

                    //Z Axis
                    //ZX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, _axisLDist);
                    GL.Vertex3(-_axisSelectRange, 0.0f, _axisLDist);
                    //ZY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, _axisLDist);
                    GL.Vertex3(0.0f, -_axisSelectRange, _axisLDist);

                    GL.End();

                    selList.End();

                    #endregion

                    if (_editType != 0 && SelectedBone != null)
                    {
                        Matrix m = Matrix.TransformMatrix(new Vector3(OrbRadius), new Vector3(), BoneLoc);
                        GL.PushMatrix();
                        GL.MultMatrix((float *)&m);

                        selList.Call();

                        if (_editType == TransformType.Translation)
                        {
                            GL.Begin(BeginMode.Quads);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);
                            GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);
                            GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);

                            GL.End();
                        }
                        else
                        {
                            GL.Begin(BeginMode.Triangles);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_scaleHalf2LDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, _axisSelectRange);
                            GL.Vertex3(0.0f, 0.0f, _scaleHalf2LDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _scaleHalf2LDist);
                            GL.Vertex3(_scaleHalf2LDist, 0.0f, 0.0f);

                            GL.End();
                        }

                        GL.PopMatrix();
                    }
                }
                GL.ColorMask(true, true, true, true);
            }
        }
Example #5
0
        public GLDisplayList GetScaleControl()
        {
            //Create the axes.
            GLDisplayList axis = new GLDisplayList();

            axis.Begin();

            //Disable culling so square bases for the arrows aren't necessary to draw
            GL.Disable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

            GL.Begin(BeginMode.Lines);

            //X
            if ((_snapY && _snapZ) || (_hiY && _hiZ))
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Red);
            }
            GL.Vertex3(0.0f, _scaleHalf1LDist, 0.0f);
            GL.Vertex3(0.0f, 0.0f, _scaleHalf1LDist);
            GL.Vertex3(0.0f, _scaleHalf2LDist, 0.0f);
            GL.Vertex3(0.0f, 0.0f, _scaleHalf2LDist);

            if (_snapX || _hiX)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Red);
            }

            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(_dst, 0.0f, 0.0f);

            GL.End();

            GL.Begin(BeginMode.Triangles);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, _apthm, -_apthm);
            GL.Vertex3(_dst, _apthm, _apthm);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, -_apthm, _apthm);
            GL.Vertex3(_dst, -_apthm, -_apthm);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, _apthm, _apthm);
            GL.Vertex3(_dst, -_apthm, _apthm);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, -_apthm, -_apthm);
            GL.Vertex3(_dst, _apthm, -_apthm);

            GL.End();

            GL.Begin(BeginMode.Lines);

            //Y
            if ((_snapZ && _snapX) || (_hiZ && _hiX))
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Green);
            }
            GL.Vertex3(0.0f, 0.0f, _scaleHalf1LDist);
            GL.Vertex3(_scaleHalf1LDist, 0.0f, 0.0f);
            GL.Vertex3(0.0f, 0.0f, _scaleHalf2LDist);
            GL.Vertex3(_scaleHalf2LDist, 0.0f, 0.0f);

            if (_snapY || _hiY)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Green);
            }
            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(0.0f, _dst, 0.0f);

            GL.End();

            GL.Begin(BeginMode.Triangles);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(_apthm, _dst, -_apthm);
            GL.Vertex3(_apthm, _dst, _apthm);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(-_apthm, _dst, _apthm);
            GL.Vertex3(-_apthm, _dst, -_apthm);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(_apthm, _dst, _apthm);
            GL.Vertex3(-_apthm, _dst, _apthm);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(-_apthm, _dst, -_apthm);
            GL.Vertex3(_apthm, _dst, -_apthm);

            GL.End();

            GL.Begin(BeginMode.Lines);

            //Z
            if ((_snapX && _snapY) || (_hiX && _hiY))
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Blue);
            }
            GL.Vertex3(0.0f, _scaleHalf1LDist, 0.0f);
            GL.Vertex3(_scaleHalf1LDist, 0.0f, 0.0f);
            GL.Vertex3(0.0f, _scaleHalf2LDist, 0.0f);
            GL.Vertex3(_scaleHalf2LDist, 0.0f, 0.0f);

            if (_snapZ || _hiZ)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Blue);
            }
            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(0.0f, 0.0f, _dst);

            GL.End();

            GL.Begin(BeginMode.Triangles);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(_apthm, -_apthm, _dst);
            GL.Vertex3(_apthm, _apthm, _dst);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(-_apthm, _apthm, _dst);
            GL.Vertex3(-_apthm, -_apthm, _dst);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(_apthm, _apthm, _dst);
            GL.Vertex3(-_apthm, _apthm, _dst);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(-_apthm, -_apthm, _dst);
            GL.Vertex3(_apthm, -_apthm, _dst);

            GL.End();

            axis.End();

            return(axis);
        }
Example #6
0
        public GLDisplayList GetTranslationAxes(SelectionParams selection)
        {
            //Create the axes.
            GLDisplayList axis = new GLDisplayList();

            axis.Begin();

            //Disable culling so square bases for the arrows aren't necessary to draw
            GL.Disable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

            GL.Begin(BeginMode.Lines);

            //X

            if (selection._snapX && selection._snapY || selection._hiX && selection._hiY)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Red);
            }

            GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);
            GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);

            if (selection._snapX && selection._snapZ || selection._hiX && selection._hiZ)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Red);
            }

            GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);
            GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);

            if (selection._snapX || selection._hiX)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Red);
            }

            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(_dst, 0.0f, 0.0f);

            GL.End();

            GL.Begin(BeginMode.Triangles);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, _apthm, -_apthm);
            GL.Vertex3(_dst, _apthm, _apthm);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, -_apthm, _apthm);
            GL.Vertex3(_dst, -_apthm, -_apthm);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, _apthm, _apthm);
            GL.Vertex3(_dst, -_apthm, _apthm);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, -_apthm, -_apthm);
            GL.Vertex3(_dst, _apthm, -_apthm);

            GL.End();

            GL.Begin(BeginMode.Lines);

            //Y

            if (selection._snapY && selection._snapX || selection._hiY && selection._hiX)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Green);
            }

            GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);
            GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);

            if (selection._snapY && selection._snapZ || selection._hiY && selection._hiZ)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Green);
            }

            GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);
            GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);

            if (selection._snapY || selection._hiY)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Green);
            }

            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(0.0f, _dst, 0.0f);

            GL.End();

            GL.Begin(BeginMode.Triangles);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(_apthm, _dst, -_apthm);
            GL.Vertex3(_apthm, _dst, _apthm);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(-_apthm, _dst, _apthm);
            GL.Vertex3(-_apthm, _dst, -_apthm);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(_apthm, _dst, _apthm);
            GL.Vertex3(-_apthm, _dst, _apthm);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(-_apthm, _dst, -_apthm);
            GL.Vertex3(_apthm, _dst, -_apthm);

            GL.End();

            GL.Begin(BeginMode.Lines);

            //Z

            if (selection._snapZ && selection._snapX || selection._hiZ && selection._hiX)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Blue);
            }

            GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);
            GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);

            if (selection._snapZ && selection._snapY || selection._hiZ && selection._hiY)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Blue);
            }

            GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);
            GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);

            if (selection._snapZ || selection._hiZ)
            {
                GL.Color4(Color.Yellow);
            }
            else
            {
                GL.Color4(Color.Blue);
            }

            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(0.0f, 0.0f, _dst);

            GL.End();

            GL.Begin(BeginMode.Triangles);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(_apthm, -_apthm, _dst);
            GL.Vertex3(_apthm, _apthm, _dst);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(-_apthm, _apthm, _dst);
            GL.Vertex3(-_apthm, -_apthm, _dst);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(_apthm, _apthm, _dst);
            GL.Vertex3(-_apthm, _apthm, _dst);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(-_apthm, -_apthm, _dst);
            GL.Vertex3(_apthm, -_apthm, _dst);

            GL.End();

            axis.End();

            return(axis);
        }
Example #7
0
        private unsafe void modelPanel1_PostRender(object sender, TKContext context)
        {
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.Lighting);
            GL.Enable(EnableCap.DepthTest);

            if (RenderVertices)
            {
                if (_editingAll && _targetModels != null)
                {
                    foreach (MDL0Node m in _targetModels)
                    {
                        m.RenderVertices(context, false);
                    }
                }
                else if (TargetModel != null)
                {
                    TargetModel.RenderVertices(context, false);
                }
            }

            if (RenderNormals)
            {
                if (_editingAll && _targetModels != null)
                {
                    foreach (MDL0Node m in _targetModels)
                    {
                        m.RenderNormals(context);
                    }
                }
                else if (TargetModel != null)
                {
                    TargetModel.RenderNormals(context);
                }
            }

            //Show the user where the light source is
            if (_renderLightDisplay)
            {
                GL.Color4(Color.Blue);
                GL.Disable(EnableCap.Lighting);
                GL.Disable(EnableCap.DepthTest);

                GL.Scale(ModelPanel.LightPosition._x, ModelPanel.LightPosition._x, ModelPanel.LightPosition._x);

                GL.Rotate(90.0f, 1, 0, 0);

                float azimuth   = ModelPanel.LightPosition._y.Clamp180Deg();
                float elevation = ModelPanel.LightPosition._z.Clamp180Deg();

                if (Math.Abs(azimuth) == Math.Abs(elevation) && azimuth % 180.0f == 0 && elevation % 180.0f == 0)
                {
                    azimuth   = 0;
                    elevation = 0;
                }

                int   i; float x;
                float e = azimuth;

                bool flip = false;
                if (e < 0)
                {
                    e    = -e;
                    flip = true;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                float f    = (float)((int)e);
                float diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }
                GL.End();

                if (flip)
                {
                    GL.Rotate(-180.0f, 1, 0, 0);
                }

                GL.Rotate(90.0f, 0, 1, 0);
                GL.Rotate(90.0f, 0, 0, 1);
                GL.Rotate(180.0f, 1, 0, 0);
                GL.Rotate(90.0f - azimuth, 0, 1, 0);

                e = elevation;

                if (e < 0)
                {
                    e = -e;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                f    = (float)((int)e);
                diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }

                GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                GL.Color4(Color.Orange);
                GL.Vertex3(0, 0, 0);

                GL.End();
            }

            GL.Clear(ClearBufferMask.DepthBufferBit);

            RenderSCN0Controls(context);
            RenderTransformControl(context);

            if (!ModelPanel._grabbing && !ModelPanel._scrolling && !_playing)
            {
                GL.Color4(Color.Black);
                GL.ColorMask(false, false, false, false);

                if (RenderVertices)
                {
                    if (_editingAll && _targetModels != null)
                    {
                        foreach (MDL0Node m in _targetModels)
                        {
                            m.RenderVertices(context, true);
                        }
                    }
                    else if (TargetModel != null)
                    {
                        TargetModel.RenderVertices(context, true);
                    }
                }

                if (RenderBones)
                {
                    //Render invisible depth orbs
                    GLDisplayList list = context.GetSphereList();
                    if (_editingAll)
                    {
                        foreach (MDL0Node m in _targetModels)
                        {
                            foreach (MDL0BoneNode bone in m._linker.BoneCache)
                            {
                                if (bone != SelectedBone)
                                {
                                    RenderOrb(bone, list);
                                }
                            }
                        }
                    }
                    else if (TargetModel != null && TargetModel._linker != null && TargetModel._linker.BoneCache != null)
                    {
                        foreach (MDL0BoneNode bone in _targetModel._linker.BoneCache)
                        {
                            if (bone != SelectedBone)
                            {
                                RenderOrb(bone, list);
                            }
                        }
                    }
                }

                //Render invisible depth planes for translation and scale controls
                if (_editType != TransformType.Rotation && ((SelectedBone != null && RenderBones) || (VertexLoc != null && RenderVertices)))
                {
                    #region Axis Selection Display List

                    GLDisplayList selList = new GLDisplayList();

                    selList.Begin();

                    GL.Begin(BeginMode.Quads);

                    //X Axis
                    //XY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, -_axisSelectRange, 0.0f);
                    //XZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, -_axisSelectRange);

                    //Y Axis
                    //YX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, _axisLDist, 0.0f);
                    GL.Vertex3(-_axisSelectRange, _axisLDist, 0.0f);
                    //YZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, -_axisSelectRange);

                    //Z Axis
                    //ZX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, _axisLDist);
                    GL.Vertex3(-_axisSelectRange, 0.0f, _axisLDist);
                    //ZY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, _axisLDist);
                    GL.Vertex3(0.0f, -_axisSelectRange, _axisLDist);

                    GL.End();

                    selList.End();

                    #endregion

                    if (_editType != TransformType.Rotation && SelectedBone != null)
                    {
                        Matrix m = Matrix.TransformMatrix(new Vector3(OrbRadius), new Vector3(), BoneLoc);
                        GL.PushMatrix();
                        GL.MultMatrix((float *)&m);

                        selList.Call();

                        if (_editType == TransformType.Translation)
                        {
                            GL.Begin(BeginMode.Quads);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);
                            GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);
                            GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);

                            GL.End();
                        }
                        else
                        {
                            GL.Begin(BeginMode.Triangles);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_scaleHalf2LDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, _axisSelectRange);
                            GL.Vertex3(0.0f, 0.0f, _scaleHalf2LDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _scaleHalf2LDist);
                            GL.Vertex3(_scaleHalf2LDist, 0.0f, 0.0f);

                            GL.End();
                        }

                        GL.PopMatrix();
                    }

                    if (VertexLoc != null && RenderVertices)
                    {
                        Matrix m = Matrix.TransformMatrix(new Vector3(VertexOrbRadius), new Vector3(), ((Vector3)VertexLoc));
                        GL.PushMatrix();
                        GL.MultMatrix((float *)&m);

                        selList.Call();

                        GL.Begin(BeginMode.Quads);

                        //XY
                        GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                        GL.Vertex3(_axisHalfLDist, _axisSelectRange, 0.0f);
                        GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);
                        GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);

                        //YZ
                        GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                        GL.Vertex3(0.0f, _axisHalfLDist, _axisSelectRange);
                        GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);
                        GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);

                        //XZ
                        GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                        GL.Vertex3(_axisSelectRange, 0.0f, _axisHalfLDist);
                        GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);
                        GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);

                        GL.End();

                        GL.PopMatrix();
                    }
                }

                GL.ColorMask(true, true, true, true);
            }
        }
        private unsafe void modelPanel1_PostRender(object sender, TKContext context)
        {
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.Lighting);
            GL.Enable(EnableCap.DepthTest);

            if (RenderVertices)
                if (_editingAll && _targetModels != null)
                    foreach (MDL0Node m in _targetModels)
                        m.RenderVertices(context, false);
                else if (TargetModel != null)
                    TargetModel.RenderVertices(context, false);

            if (RenderNormals)
                if (_editingAll && _targetModels != null)
                    foreach (MDL0Node m in _targetModels)
                        m.RenderNormals(context);
                else if (TargetModel != null)
                    TargetModel.RenderNormals(context);

            //Show the user where the light source is
            if (_renderLightDisplay)
            {
                GL.Color4(Color.Blue);
                GL.Disable(EnableCap.Lighting);
                GL.Disable(EnableCap.DepthTest);

                GL.Scale(ModelPanel.LightPosition._x, ModelPanel.LightPosition._x, ModelPanel.LightPosition._x);

                GL.Rotate(90.0f, 1, 0, 0);

                float azimuth = ModelPanel.LightPosition._y.Clamp180Deg();
                float elevation = ModelPanel.LightPosition._z.Clamp180Deg();

                if (Math.Abs(azimuth) == Math.Abs(elevation) && azimuth % 180.0f == 0 && elevation % 180.0f == 0)
                {
                    azimuth = 0;
                    elevation = 0;
                }

                int i; float x;
                float e = azimuth;

                bool flip = false;
                if (e < 0)
                {
                    e = -e;
                    flip = true;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                float f = (float)((int)e);
                float diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }
                GL.End();

                if (flip) GL.Rotate(-180.0f, 1, 0, 0);

                GL.Rotate(90.0f, 0, 1, 0);
                GL.Rotate(90.0f, 0, 0, 1);
                GL.Rotate(180.0f, 1, 0, 0);
                GL.Rotate(90.0f - azimuth, 0, 1, 0);

                e = elevation;

                if (e < 0)
                {
                    e = -e;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                f = (float)((int)e);
                diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }

                GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                GL.Color4(Color.Orange);
                GL.Vertex3(0, 0, 0);

                GL.End();
            }

            GL.Clear(ClearBufferMask.DepthBufferBit);

            RenderSCN0Controls(context);
            RenderTransformControl(context);

            if (!ModelPanel._grabbing && !ModelPanel._scrolling && !_playing)
            {
                GL.Color4(Color.Black);
                GL.ColorMask(false, false, false, false);

                if (RenderVertices)
                    if (_editingAll && _targetModels != null)
                        foreach (MDL0Node m in _targetModels)
                            m.RenderVertices(context, true);
                    else if (TargetModel != null)
                        TargetModel.RenderVertices(context, true);

                if (RenderBones)
                {
                    //Render invisible depth orbs
                    GLDisplayList list = context.GetSphereList();
                    if (_editingAll)
                    {
                        foreach (MDL0Node m in _targetModels)
                            foreach (MDL0BoneNode bone in m._linker.BoneCache)
                                if (bone != SelectedBone)
                                    RenderOrb(bone, list);
                    }
                    else if (TargetModel != null && TargetModel._linker != null && TargetModel._linker.BoneCache != null)
                        foreach (MDL0BoneNode bone in _targetModel._linker.BoneCache)
                            if (bone != SelectedBone)
                                RenderOrb(bone, list);
                }

                //Render invisible depth planes for translation and scale controls
                if (_editType != TransformType.Rotation && ((SelectedBone != null && RenderBones) || (VertexLoc != null && RenderVertices)))
                {
                    #region Axis Selection Display List

                    GLDisplayList selList = new GLDisplayList();

                    selList.Begin();

                    GL.Begin(BeginMode.Quads);

                    //X Axis
                    //XY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, -_axisSelectRange, 0.0f);
                    //XZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, -_axisSelectRange);

                    //Y Axis
                    //YX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, _axisLDist, 0.0f);
                    GL.Vertex3(-_axisSelectRange, _axisLDist, 0.0f);
                    //YZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, -_axisSelectRange);

                    //Z Axis
                    //ZX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, _axisLDist);
                    GL.Vertex3(-_axisSelectRange, 0.0f, _axisLDist);
                    //ZY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, _axisLDist);
                    GL.Vertex3(0.0f, -_axisSelectRange, _axisLDist);

                    GL.End();

                    selList.End();

                    #endregion

                    if (_editType != TransformType.Rotation && SelectedBone != null)
                    {
                        Matrix m = Matrix.TransformMatrix(new Vector3(OrbRadius), new Vector3(), BoneLoc);
                        GL.PushMatrix();
                        GL.MultMatrix((float*)&m);

                        selList.Call();

                        if (_editType == TransformType.Translation)
                        {
                            GL.Begin(BeginMode.Quads);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);
                            GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);
                            GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);

                            GL.End();
                        }
                        else
                        {
                            GL.Begin(BeginMode.Triangles);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_scaleHalf2LDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, _axisSelectRange);
                            GL.Vertex3(0.0f, 0.0f, _scaleHalf2LDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _scaleHalf2LDist);
                            GL.Vertex3(_scaleHalf2LDist, 0.0f, 0.0f);

                            GL.End();
                        }

                        GL.PopMatrix();
                    }

                    if (VertexLoc != null && RenderVertices)
                    {
                        Matrix m = Matrix.TransformMatrix(new Vector3(VertexOrbRadius), new Vector3(), ((Vector3)VertexLoc));
                        GL.PushMatrix();
                        GL.MultMatrix((float*)&m);

                        selList.Call();

                        GL.Begin(BeginMode.Quads);

                        //XY
                        GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                        GL.Vertex3(_axisHalfLDist, _axisSelectRange, 0.0f);
                        GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);
                        GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);

                        //YZ
                        GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                        GL.Vertex3(0.0f, _axisHalfLDist, _axisSelectRange);
                        GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);
                        GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);

                        //XZ
                        GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                        GL.Vertex3(_axisSelectRange, 0.0f, _axisHalfLDist);
                        GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);
                        GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);

                        GL.End();

                        GL.PopMatrix();
                    }
                }

                GL.ColorMask(true, true, true, true);
            }
        }
        public GLDisplayList GetScaleControl()
        {
            //Create the axes.
            GLDisplayList axis = new GLDisplayList();
            axis.Begin();

            //Disable culling so square bases for the arrows aren't necessary to draw
            GL.Disable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

            GL.Begin(BeginMode.Lines);

            //X
            if ((_snapY && _snapZ) || (_hiY && _hiZ))
                GL.Color4(Color.Yellow);
            else
                GL.Color4(Color.Red);
            GL.Vertex3(0.0f, _scaleHalf1LDist, 0.0f);
            GL.Vertex3(0.0f, 0.0f, _scaleHalf1LDist);
            GL.Vertex3(0.0f, _scaleHalf2LDist, 0.0f);
            GL.Vertex3(0.0f, 0.0f, _scaleHalf2LDist);

            if (_snapX || _hiX)
                GL.Color4(Color.Yellow);
            else
                GL.Color4(Color.Red);

            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(_dst, 0.0f, 0.0f);

            GL.End();

            GL.Begin(BeginMode.Triangles);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, _apthm, -_apthm);
            GL.Vertex3(_dst, _apthm, _apthm);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, -_apthm, _apthm);
            GL.Vertex3(_dst, -_apthm, -_apthm);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, _apthm, _apthm);
            GL.Vertex3(_dst, -_apthm, _apthm);

            GL.Vertex3(_axisLDist, 0.0f, 0.0f);
            GL.Vertex3(_dst, -_apthm, -_apthm);
            GL.Vertex3(_dst, _apthm, -_apthm);

            GL.End();

            GL.Begin(BeginMode.Lines);

            //Y
            if ((_snapZ && _snapX) || (_hiZ && _hiX))
                GL.Color4(Color.Yellow);
            else
                GL.Color4(Color.Green);
            GL.Vertex3(0.0f, 0.0f, _scaleHalf1LDist);
            GL.Vertex3(_scaleHalf1LDist, 0.0f, 0.0f);
            GL.Vertex3(0.0f, 0.0f, _scaleHalf2LDist);
            GL.Vertex3(_scaleHalf2LDist, 0.0f, 0.0f);

            if (_snapY || _hiY)
                GL.Color4(Color.Yellow);
            else
                GL.Color4(Color.Green);
            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(0.0f, _dst, 0.0f);

            GL.End();

            GL.Begin(BeginMode.Triangles);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(_apthm, _dst, -_apthm);
            GL.Vertex3(_apthm, _dst, _apthm);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(-_apthm, _dst, _apthm);
            GL.Vertex3(-_apthm, _dst, -_apthm);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(_apthm, _dst, _apthm);
            GL.Vertex3(-_apthm, _dst, _apthm);

            GL.Vertex3(0.0f, _axisLDist, 0.0f);
            GL.Vertex3(-_apthm, _dst, -_apthm);
            GL.Vertex3(_apthm, _dst, -_apthm);

            GL.End();

            GL.Begin(BeginMode.Lines);

            //Z
            if ((_snapX && _snapY) || (_hiX && _hiY))
                GL.Color4(Color.Yellow);
            else
                GL.Color4(Color.Blue);
            GL.Vertex3(0.0f, _scaleHalf1LDist, 0.0f);
            GL.Vertex3(_scaleHalf1LDist, 0.0f, 0.0f);
            GL.Vertex3(0.0f, _scaleHalf2LDist, 0.0f);
            GL.Vertex3(_scaleHalf2LDist, 0.0f, 0.0f);

            if (_snapZ || _hiZ)
                GL.Color4(Color.Yellow);
            else
                GL.Color4(Color.Blue);
            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(0.0f, 0.0f, _dst);

            GL.End();

            GL.Begin(BeginMode.Triangles);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(_apthm, -_apthm, _dst);
            GL.Vertex3(_apthm, _apthm, _dst);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(-_apthm, _apthm, _dst);
            GL.Vertex3(-_apthm, -_apthm, _dst);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(_apthm, _apthm, _dst);
            GL.Vertex3(-_apthm, _apthm, _dst);

            GL.Vertex3(0.0f, 0.0f, _axisLDist);
            GL.Vertex3(-_apthm, -_apthm, _dst);
            GL.Vertex3(_apthm, -_apthm, _dst);

            GL.End();

            axis.End();

            return axis;
        }
        private unsafe void modelPanel1_PostRender(object sender, TKContext context)
        {
            //GL.LineWidth(2.0f);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.DepthTest);

            //Attributes.PostRender();

            //Render hurtboxes
            if (chkHurtboxes.Checked)
                for (int i = 0; i < listPanel.lstHurtboxes.Items.Count; i++)
                    if (listPanel.lstHurtboxes.GetItemChecked(i))
                        ((MiscHurtBox)listPanel.lstHurtboxes.Items[i]).Render(SelectedHurtbox != null && SelectedHurtbox.Index == i, Scriptor._hurtBoxType);

            //Render hitboxes
            if (chkHitboxes.Checked && Manager.Moveset != null)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                GLDisplayList c = context.GetRingList();
                GLDisplayList s = context.GetSphereList();

                foreach (HitBox e in RunTime._hitBoxes)
                    e.Render(context, modelPanel._camera.GetPoint());
            }

            GL.Enable(EnableCap.DepthTest);

            //Show the user where the light source is
            if (_renderLightDisplay)
            {
                GL.PushAttrib(AttribMask.AllAttribBits);

                GL.Color4(Color.Blue);
                GL.Disable(EnableCap.Lighting);
                GL.Disable(EnableCap.DepthTest);

                GL.Scale(modelPanel.LightPosition._x, modelPanel.LightPosition._x, modelPanel.LightPosition._x);

                GL.Rotate(90.0f, 1, 0, 0);

                float azimuth = modelPanel.LightPosition._y.Clamp180Deg();
                float elevation = modelPanel.LightPosition._z.Clamp180Deg();

                if (Math.Abs(azimuth) == Math.Abs(elevation) && azimuth % 180.0f == 0 && elevation % 180.0f == 0)
                {
                    azimuth = 0;
                    elevation = 0;
                }

                int i; float x;
                float e = azimuth;

                bool flip = false;
                if (e < 0)
                {
                    e = -e;
                    flip = true;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                float f = (float)((int)e);
                float diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }
                GL.End();

                if (flip) GL.Rotate(-180.0f, 1, 0, 0);

                GL.Rotate(90.0f, 0, 1, 0);
                GL.Rotate(90.0f, 0, 0, 1);
                GL.Rotate(180.0f, 1, 0, 0);
                GL.Rotate(90.0f - azimuth, 0, 1, 0);

                e = elevation;

                if (e < 0)
                {
                    e = -e;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                f = (float)((int)e);
                diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }

                GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                GL.Color4(Color.Orange);
                GL.Vertex3(0, 0, 0);

                GL.End();

                GL.PopAttrib();
            }

            GL.Clear(ClearBufferMask.DepthBufferBit);

            RenderTransformControl(context);

            if (!modelPanel._grabbing && !modelPanel._scrolling && !_playing)
            {
                GL.Color4(Color.Black);
                GL.ColorMask(false, false, false, false);

                if (RenderBones)
                {
                    //Render invisible depth orbs
                    GLDisplayList list = context.GetSphereList();
                    if (_editingAll)
                    {
                        foreach (MDL0Node m in _targetModels)
                            foreach (MDL0BoneNode bone in m._linker.BoneCache)
                                if (bone != SelectedBone)
                                    RenderOrb(bone, list);
                    }
                    else if (TargetModel != null && TargetModel._linker != null && TargetModel._linker.BoneCache != null)
                        foreach (MDL0BoneNode bone in _targetModel._linker.BoneCache)
                            if (bone != SelectedBone)
                                RenderOrb(bone, list);
                }

                //Render invisible depth planes for translation and scale controls
                if (_editType != 0 && SelectedBone != null && RenderBones)
                {
                    #region Axis Selection Display List

                    GLDisplayList selList = new GLDisplayList();

                    selList.Begin();

                    GL.Begin(BeginMode.Quads);

                    //X Axis
                    //XY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, -_axisSelectRange, 0.0f);
                    //XZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, -_axisSelectRange);

                    //Y Axis
                    //YX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, _axisLDist, 0.0f);
                    GL.Vertex3(-_axisSelectRange, _axisLDist, 0.0f);
                    //YZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, -_axisSelectRange);

                    //Z Axis
                    //ZX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, _axisLDist);
                    GL.Vertex3(-_axisSelectRange, 0.0f, _axisLDist);
                    //ZY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, _axisLDist);
                    GL.Vertex3(0.0f, -_axisSelectRange, _axisLDist);

                    GL.End();

                    selList.End();

                    #endregion

                    if (_editType != 0 && SelectedBone != null)
                    {
                        Matrix m = Matrix.TransformMatrix(new Vector3(OrbRadius), new Vector3(), BoneLoc);
                        GL.PushMatrix();
                        GL.MultMatrix((float*)&m);

                        selList.Call();

                        if (_editType == TransformType.Translation)
                        {
                            GL.Begin(BeginMode.Quads);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);
                            GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);
                            GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);

                            GL.End();
                        }
                        else
                        {
                            GL.Begin(BeginMode.Triangles);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_scaleHalf2LDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, _axisSelectRange);
                            GL.Vertex3(0.0f, 0.0f, _scaleHalf2LDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _scaleHalf2LDist);
                            GL.Vertex3(_scaleHalf2LDist, 0.0f, 0.0f);

                            GL.End();
                        }

                        GL.PopMatrix();
                    }
                }
                GL.ColorMask(true, true, true, true);
            }
        }
        public static GLDisplayList CreateNodeOrb(TKContext ctx)
        {
            GLDisplayList circle = ctx.GetRingList();
            GLDisplayList orb = new GLDisplayList();

            orb.Begin();
            GL.PushMatrix();

            GL.Scale(_nodeRadius, _nodeRadius, _nodeRadius);
            circle.Call();
            GL.Rotate(90.0f, 0.0f, 1.0f, 0.0f);
            circle.Call();
            GL.Rotate(90.0f, 1.0f, 0.0f, 0.0f);
            circle.Call();

            GL.PopMatrix();
            orb.End();
            return orb;
        }