Esempio n. 1
0
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }

            float z = (float)e.Delta / 120.0f;

            if (Control.ModifierKeys == Keys.Shift)
            {
                z *= 32;
            }

            ModelPanelViewport v = HighlightedViewport;

            v.Zoom(-z * v._zoomFactor);

            if (Control.ModifierKeys == Keys.Alt)
            {
                if (z < 0)
                {
                    v._multiplier /= 0.9f;
                }
                else
                {
                    v._multiplier *= 0.9f;
                }
            }

            base.OnMouseWheel(e);
        }
 /// <summary>
 /// Use this for transforming points
 /// </summary>
 public bool GetTransformPoint(
     Vector2 mousePoint,
     out Vector3 point,
     ModelPanelViewport panel,
     Vector3 center)
 {
     return(GetTransformPoint(mousePoint, out point, panel, Matrix.TranslationMatrix(center)));
 }
Esempio n. 3
0
        public unsafe void RenderTransformControls(ModelPanelViewport panel)
        {
            if (_playing || ControlType == TransformType.None)
            {
                return;
            }

            bool hasBone = SelectedBone != null;

            if (hasBone || VertexLoc.HasValue)
            {
                Vector3 pos;
                Matrix  rot = Matrix.Identity;
                float   radius;

                if (hasBone)
                {
                    pos    = BoneLoc(SelectedBone);
                    radius = OrbRadius(pos, panel.Camera);
                    switch (_coordinateTypes[(int)ControlType])
                    {
                    case CoordinateType.Local:
                        rot = GetBoneWorldMtx().GetRotationMatrix();
                        break;

                    case CoordinateType.World:
                        //rot = Matrix.Identity; //Already set to identity above
                        break;

                    case CoordinateType.Screen:
                        //rot = CameraFacingRotationMatrix(panel, pos);
                        rot = Matrix.RotationMatrix(panel.Camera._rotation);
                        break;
                    }

                    RenderTransformControl(pos, rot, radius, panel, _boneSelection);
                }

                if (VertexLoc.HasValue)
                {
                    pos    = VertexLoc.Value;
                    radius = OrbRadius(pos, panel.Camera);
                    switch (_coordinateTypes[(int)ControlType])
                    {
                    case CoordinateType.Local:
                    case CoordinateType.World:
                        //rot = Matrix.Identity; //Already set to identity above
                        break;

                    case CoordinateType.Screen:
                        rot = CameraFacingRotationMatrix(panel, pos);
                        break;
                    }

                    RenderTransformControl(pos, rot, radius, panel, _vertexSelection);
                }
            }
        }
Esempio n. 4
0
        public unsafe void RenderOrb(IBoneNode bone, GLDisplayList list, ModelPanelViewport v, bool doScale)
        {
            float radius = MDL0BoneNode._nodeRadius * (doScale ? OrbRadius(bone, v) : 1.0f);

            Matrix m = Matrix.TransformMatrix(new Vector3(radius), new Vector3(), bone.Matrix.GetPoint());

            GL.PushMatrix();
            GL.MultMatrix((float *)&m);

            list.Call();
            GL.PopMatrix();
        }
Esempio n. 5
0
        public unsafe virtual void modelPanel1_PreRender(ModelPanelViewport vp)
        {
            if (vp != null)
            {
                if (vp._renderFloor)
                {
                    OnRenderFloor();
                }

                GL.Enable(EnableCap.DepthTest);
                GL.DepthFunc(DepthFunction.Lequal);
            }
        }
Esempio n. 6
0
        private void MouseMoveTargetBone(
            ModelPanel panel,
            MouseEventArgs e,
            float depth,
            ModelPanelViewport v)
        {
            if (SelectedBone != null)
            {
                MouseMoveTarget(panel, e, depth, v, GetBoneWorldMtx(), GetBoneInvWorldMtx());
            }

            GetBone(panel, e, depth, v);
        }
Esempio n. 7
0
        private void MouseMoveTargetVertex(
            ModelPanel panel,
            MouseEventArgs e,
            float depth,
            ModelPanelViewport v)
        {
            if (VertexLoc.HasValue /* && v._renderAttrib._renderVertices*/)
            {
                Vector3 center = VertexLoc.Value;
                MouseMoveTarget(panel, e, depth, v, Matrix.TranslationMatrix(center), Matrix.TranslationMatrix(-center));
            }

            GetVertex(panel, e, depth, v);
        }
Esempio n. 8
0
        protected virtual void modelPanel1_MouseDown(object sender, MouseEventArgs e)
        {
            _createdNewBone = false;

            ModelPanel         panel    = sender as ModelPanel;
            ModelPanelViewport viewport = panel.CurrentViewport;

            if (panel._draggingViewports)
            {
                return;
            }

            if (e.Button == Forms.MouseButtons.Left)
            {
                if (DoNotHighlightOnMouseMove)
                {
                    HighlightStuff(e, panel);

                    //Reset the cursor (HighlightStuff sets the cursor)
                    panel.Cursor = Cursors.Default;
                }

                //Reset snap flags
                _boneSelection.ResetSnaps();
                _vertexSelection.ResetSnaps();

                MouseDownTargetBone(e, panel);

                if (!MouseDownTargetVertex(e, panel))
                {
                    if (CurrentFrame == 0 &&
                        TargetAnimType == NW4RAnimType.CHR &&
                        CHR0Editor.chkMoveBoneOnly.Checked &&
                        TargetModel != null &&
                        TargetModel is MDL0Node)
                    {
                        MDL0Node m = TargetModel as MDL0Node;
                        m._dontUpdateMesh = true;
                    }
                }

                //Ensure a redraw so the snapping indicators are correct
                panel.Invalidate();
            }
        }
Esempio n. 9
0
        public unsafe void RenderTranslationControl(
            Vector3 position,
            float radius,
            Matrix rotation,
            ModelPanelViewport panel,
            SelectionParams selection)
        {
            Matrix m = Matrix.TransformMatrix(new Vector3(radius * 0.25f), new Vector3(), position) *
                       CameraFacingRotationMatrix(panel, position);

            GL.PushMatrix();
            GL.MultMatrix((float *)&m);

            GL.Color4(selection._hiCirc || selection._snapCirc ? Color.Yellow : Color.Gray);

            GL.Begin(PrimitiveType.LineLoop);

            GL.Vertex2(-0.5f, -0.5f);
            GL.Vertex2(-0.5f, 0.5f);
            GL.Vertex2(0.5f, 0.5f);
            GL.Vertex2(0.5f, -0.5f);
            GL.Vertex2(-0.5f, -0.5f);

            GL.End();

            GL.PopMatrix();

            //Enter local space
            m = Matrix.TransformMatrix(new Vector3(radius), new Vector3(), position) * rotation;
            GL.PushMatrix();
            GL.MultMatrix((float *)&m);

            GetTranslationAxes(selection).Call();

            GL.PopMatrix();

            panel.ScreenText["X"] = panel.Camera.Project(new Vector3(_axisLDist + 0.1f, 0, 0) * m) -
                                    new Vector3(8.0f, 8.0f, 0);
            panel.ScreenText["Y"] = panel.Camera.Project(new Vector3(0, _axisLDist + 0.1f, 0) * m) -
                                    new Vector3(8.0f, 8.0f, 0);
            panel.ScreenText["Z"] = panel.Camera.Project(new Vector3(0, 0, _axisLDist + 0.1f) * m) -
                                    new Vector3(8.0f, 8.0f, 0);
        }
        private void topToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ModelPanelViewport curViewport = modelPanel.CurrentViewport;
            ModelPanelViewport newViewport = ModelPanelViewport.DefaultPerspective;

            newViewport.BackgroundColor = curViewport.BackgroundColor;
            ModelPanel.AddViewport(newViewport);

            float xMin     = curViewport.Percentages._x;
            float yMin     = curViewport.Percentages._y;
            float xMax     = curViewport.Percentages._z;
            float yMax     = curViewport.Percentages._w;
            float averageY = (yMin + yMax) / 2.0f;

            curViewport.SetPercentages(xMin, averageY, xMax, yMax);
            newViewport.SetPercentages(xMin, yMin, xMax, averageY);

            ModelPanel.Invalidate();
        }
Esempio n. 11
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }

            ModelPanelViewport highlighted = HighlightedViewport;

            if (CurrentViewport != highlighted)
            {
                CurrentViewport        = highlighted;
                CurrentViewport._lastX = e.X - CurrentViewport.Region.X;
                CurrentViewport._lastY = e.Y - CurrentViewport.Region.Y;
            }

            switch (e.Button)
            {
            case Forms.MouseButtons.Left:
                _mouseDown = true;
                if (_dragging.Count > 0 && _viewports.Count > 1)
                {
                    _draggingViewports = true;
                }
                else
                {
                    CurrentViewport.HandleLeftMouseDown(e);
                }
                break;

            case Forms.MouseButtons.Right:
                CurrentViewport._grabbing = true;
                break;

            case Forms.MouseButtons.Middle:
                CurrentViewport._scrolling = true;
                break;
            }

            base.OnMouseDown(e);
        }
Esempio n. 12
0
        public virtual void PostRender(IModel model, ModelPanelViewport vp)
        {
            if (vp._renderAttrib._renderVertices)
            {
                model.RenderVertices(false, SelectedBone, vp.Camera);
            }
            if (vp._renderAttrib._renderNormals)
            {
                model.RenderNormals();
            }
            if (vp._renderAttrib._renderBones)
            {
                model.RenderBones(vp);
            }

            model.RenderBoxes(
                vp._renderAttrib._renderModelBox,
                vp._renderAttrib._renderObjectBoxes,
                vp._renderAttrib._renderBoneBoxes,
                vp._renderAttrib._useBindStateBoxes);
        }
Esempio n. 13
0
        private bool CompareBoneDistanceRecursive(IBoneNode bone, Vector3 point, ref IBoneNode match,
                                                  ModelPanelViewport v, bool doScale)
        {
            float dist = bone.Matrix.GetPoint().TrueDistance(point) / (doScale ? OrbRadius(bone, v) : 1.0f);

            if (Math.Abs(dist - MDL0BoneNode._nodeRadius) < 0.01f)
            {
                match = bone;
                return(true);
            }

            foreach (IBoneNode b in ((ResourceNode)bone).Children)
            {
                if (CompareBoneDistanceRecursive(b, point, ref match, v, doScale))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 14
0
        public unsafe void RenderScaleControl(
            Vector3 pos,
            float radius,
            Matrix rotation,
            ModelPanelViewport panel,
            SelectionParams selection)
        {
            //Enter local space
            Matrix m = Matrix.TransformMatrix(new Vector3(radius), new Vector3(), pos) * rotation;

            GL.PushMatrix();
            GL.MultMatrix((float *)&m);

            GetScaleAxes(selection).Call();

            GL.PopMatrix();

            panel.ScreenText["X"] = panel.Camera.Project(new Vector3(_axisLDist + 0.1f, 0, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            panel.ScreenText["Y"] = panel.Camera.Project(new Vector3(0, _axisLDist + 0.1f, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            panel.ScreenText["Z"] = panel.Camera.Project(new Vector3(0, 0, _axisLDist + 0.1f) * m) - new Vector3(8.0f, 8.0f, 0);
        }
Esempio n. 15
0
        public ModelPanelViewport AsViewport()
        {
            ModelPanelViewport v = ModelPanelViewport.DefaultPerspective;

            v.Camera = new GLCamera(1, 1, (Vector3)_defaultTranslate, (Vector3)_defaultRotate, (Vector3)_defaultScale)
            {
                _farZ         = _farZ,
                _fovY         = _fovY,
                _nearZ        = _nearZ,
                _ortho        = _ortho,
                _restrictXRot = _restrictXRot,
                _restrictYRot = _restrictYRot,
                _restrictZRot = _restrictZRot,
            };
            v.SetPercentages(_percentages);
            v.LightPosition       = _lightPosition;
            v.Enabled             = _enabled;
            v.BackgroundColor     = (Color)_backColor;
            v.BackgroundImageType = _bgType;
            v._allowSelection     = _allowSelection;
            v._showCamCoords      = _showCamCoords;
            v._textEnabled        = _textEnabled;
            v._type               = _type;
            v._diffuse            = _diffuse;
            v._ambient            = _ambient;
            v._emission           = _emission;
            v._renderAttrib       = _renderAttrib;
            v._renderFloor        = _renderFloor;
            v._firstPersonCamera  = _firstPersonCamera;
            v._rotFactor          = _rotFactor;
            v._specular           = _specular;
            v._spotCutoff         = _spotCutoff;
            v._spotExponent       = _spotExponent;
            v._transFactor        = _transFactor;
            v._viewDistance       = _viewDistance;
            v._zoomFactor         = _zoomFactor;
            v._lightEnabled       = _lightEnabled;
            v._renderSCN0Controls = _renderSCN0Controls;
            return(v);
        }
Esempio n. 16
0
        public void HighlightStuff(MouseEventArgs e, ModelPanel panel)
        {
            panel.Capture();

            _hiX = _hiY = _hiZ = _hiCirc = _hiSphere = false;

            float depth          = panel.GetDepth(e.X, e.Y);
            ModelPanelViewport v = panel.HighlightedViewport;

            foreach (var targetFunc in _mouseMoveTargetType)
            {
                targetFunc(panel, e, depth, v);
            }

#if DEBUG
            if (_renderDepth)
            {
                v.ScreenText["Depth: " + depth.ToString()] = new Vector3(5.0f, v.Height - 20.0f, 0.5f);
                panel.Invalidate();
            }
#endif
        }
Esempio n. 17
0
        public void RenderTransformControl(
            Vector3 pos,
            Matrix rot,
            float radius,
            ModelPanelViewport panel,
            SelectionParams selection)
        {
            switch (ControlType)
            {
            case TransformType.Translation:
                RenderTranslationControl(pos, radius, rot, panel, selection);
                break;

            case TransformType.Rotation:
                RenderRotationControl(pos, radius, rot, panel, selection);
                break;

            case TransformType.Scale:
                RenderScaleControl(pos, radius, rot, panel, selection);
                break;
            }
        }
Esempio n. 18
0
        public void HighlightStuff(MouseEventArgs e, ModelPanel panel)
        {
            panel.Capture();

            _boneSelection.ResetHighlights();
            _vertexSelection.ResetHighlights();

            float depth          = panel.GetDepth(e.X, e.Y);
            ModelPanelViewport v = panel.HighlightedViewport;

            foreach (MouseMoveTargetType targetFunc in _mouseMoveTargetType)
            {
                targetFunc(panel, e, depth, v);
            }

#if DEBUG
            if (_renderDepth)
            {
                v.ScreenText["Depth: " + depth.ToString()] = new Vector3(5.0f, v.Height - 20.0f, 0.5f);
                panel.Invalidate();
            }
#endif
        }
Esempio n. 19
0
        public unsafe virtual void modelPanel1_PostRender(ModelPanelViewport vp)
        {
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.Lighting);

            if (_targetModels != null)
            {
                foreach (IModel m in _targetModels)
                {
                    PostRender(m, vp);
                }
            }

            GL.Disable(EnableCap.DepthTest);

            if (RenderLightDisplay /* && vp == ModelPanel.CurrentViewport*/)
            {
                OnRenderLightDisplay(vp);
            }

            if (TargetAnimType == NW4RAnimType.SCN && vp.RenderSCN0Controls)
            {
                RenderSCN0Controls(vp);
            }

            //For now we'll clear the depth buffer bit here.
            //We're not using the model depth in any way so it doesn't matter
            //The problem with not doing this at the moment is the rotation control clips with the model.
            //This is because the rotation axes need to be lequal depth tested against an invisible sphere
            //I don't know how to test a sub depth buffer and then always make it pass on the actual buffer
            GL.Clear(ClearBufferMask.DepthBufferBit);

            RenderTransformControls(vp);
            RenderDepth(vp);
        }
Esempio n. 20
0
 public void LinkTranslate(ModelPanelViewport control, ModelPanelViewport affected)
 {
     control.Translated += affected.Translate;
 }
Esempio n. 21
0
 public void LinkZoom(ModelPanelViewport control, ModelPanelViewport affected)
 {
     control.Zoomed += affected.Zoom;
 }
Esempio n. 22
0
        public void RenderBrawlStageData(ModelPanelViewport panel)
        {
            //If you ever make changes to GL attributes (enabled and disabled things)
            //and don't want to keep track of what you changed,
            //you can push all attributes and then pop them when you're done, like this.
            //This will make sure the GL state is back to how it was before you changed it.
            GL.PushAttrib(AttribMask.AllAttribBits);

            GL.Disable(EnableCap.DepthTest);

            if (RenderCollisions)
            {
                foreach (CollisionNode node in _collisions)
                {
                    node.Render();
                }
            }

            #region RenderOverlays
            List <MDL0BoneNode> ItemBones = new List <MDL0BoneNode>();

            MDL0Node stgPos = null;

            MDL0BoneNode CamBone0 = null, CamBone1 = null,
                         DeathBone0 = null, DeathBone1 = null;

            //Get bones and render spawns if checked
            if (_targetModel != null &&
                _targetModel is MDL0Node &&
                ((((ResourceNode)_targetModel).Name.Contains("StgPosition")) ||
                 ((ResourceNode)_targetModel).Name.Contains("stagePosition")))
            {
                stgPos = _targetModel as MDL0Node;
            }
            else if (_targetModels != null)
            {
                stgPos = _targetModels.Find(x => x is MDL0Node &&
                                            ((ResourceNode)x).Name.Contains("StgPosition") ||
                                            ((ResourceNode)x).Name.Contains("stagePosition")) as MDL0Node;
            }

            if (stgPos != null)
            {
                foreach (MDL0BoneNode bone in stgPos._linker.BoneCache)
                {
                    if (bone._name == "CamLimit0N")
                    {
                        CamBone0 = bone;
                    }
                    else if (bone.Name == "CamLimit1N")
                    {
                        CamBone1 = bone;
                    }
                    else if (bone.Name == "Dead0N")
                    {
                        DeathBone0 = bone;
                    }
                    else if (bone.Name == "Dead1N")
                    {
                        DeathBone1 = bone;
                    }
                    else if (bone._name.Contains("Player") && chkSpawns.Checked)
                    {
                        Vector3 position = bone._frameMatrix.GetPoint();

                        if (PointCollides(position))
                        {
                            GL.Color4(0.0f, 1.0f, 0.0f, 0.5f);
                        }
                        else
                        {
                            GL.Color4(1.0f, 0.0f, 0.0f, 0.5f);
                        }

                        TKContext.DrawSphere(position, 5.0f, 32);
                    }
                    else if (bone._name.Contains("Rebirth") && chkSpawns.Checked)
                    {
                        GL.Color4(1.0f, 1.0f, 1.0f, 0.1f);
                        TKContext.DrawSphere(bone._frameMatrix.GetPoint(), 5.0f, 32);
                    }
                    else if (bone._name.Contains("Item"))
                    {
                        ItemBones.Add(bone);
                    }
                }
            }

            //Render item fields if checked
            if (ItemBones != null && chkItems.Checked)
            {
                GL.Color4(0.5f, 0.0f, 1.0f, 0.4f);
                for (int i = 0; i < ItemBones.Count; i += 2)
                {
                    Vector3 pos1 = new Vector3(ItemBones[i]._frameMatrix.GetPoint()._x, ItemBones[i]._frameMatrix.GetPoint()._y + 3.0f, 1.0f);
                    Vector3 pos2 = new Vector3(ItemBones[i + 1]._frameMatrix.GetPoint()._x, ItemBones[i + 1]._frameMatrix.GetPoint()._y - 3.0f, 1.0f);

                    TKContext.DrawBox(pos1, pos2);
                }
            }

            //Render boundaries if checked
            if (CamBone0 != null && CamBone1 != null && chkBoundaries.Checked)
            {
                //GL.Clear(ClearBufferMask.DepthBufferBit);
                GL.Disable(EnableCap.DepthTest);
                GL.Disable(EnableCap.Lighting);
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                GL.Enable(EnableCap.CullFace);
                GL.CullFace(CullFaceMode.Front);

                GL.Color4(Color.Blue);
                GL.Begin(BeginMode.LineLoop);
                GL.LineWidth(15.0f);

                Vector3
                    camBone0   = CamBone0._frameMatrix.GetPoint(),
                    camBone1   = CamBone1._frameMatrix.GetPoint(),
                    deathBone0 = DeathBone0._frameMatrix.GetPoint(),
                    deathBone1 = DeathBone1._frameMatrix.GetPoint();

                GL.Vertex2(camBone0._x, camBone0._y);
                GL.Vertex2(camBone1._x, camBone0._y);
                GL.Vertex2(camBone1._x, camBone1._y);
                GL.Vertex2(camBone0._x, camBone1._y);
                GL.End();
                GL.Begin(BeginMode.LineLoop);
                GL.Color4(Color.Red);
                GL.Vertex2(deathBone0._x, deathBone0._y);
                GL.Vertex2(deathBone1._x, deathBone0._y);
                GL.Vertex2(deathBone1._x, deathBone1._y);
                GL.Vertex2(deathBone0._x, deathBone1._y);
                GL.End();
                GL.Color4(0.0f, 0.5f, 1.0f, 0.3f);
                GL.Begin(BeginMode.TriangleFan);
                GL.Vertex2(camBone0._x, camBone0._y);
                GL.Vertex2(deathBone0._x, deathBone0._y);
                GL.Vertex2(deathBone1._x, deathBone0._y);
                GL.Vertex2(camBone1._x, camBone0._y);
                GL.End();
                GL.Begin(BeginMode.TriangleFan);
                GL.Vertex2(camBone1._x, camBone1._y);
                GL.Vertex2(deathBone1._x, deathBone1._y);
                GL.Vertex2(deathBone0._x, deathBone1._y);
                GL.Vertex2(camBone0._x, camBone1._y);
                GL.End();
                GL.Begin(BeginMode.TriangleFan);
                GL.Vertex2(camBone1._x, camBone0._y);
                GL.Vertex2(deathBone1._x, deathBone0._y);
                GL.Vertex2(deathBone1._x, deathBone1._y);
                GL.Vertex2(camBone1._x, camBone1._y);
                GL.End();
                GL.Begin(BeginMode.TriangleFan);
                GL.Vertex2(camBone0._x, camBone1._y);
                GL.Vertex2(deathBone0._x, deathBone1._y);
                GL.Vertex2(deathBone0._x, deathBone0._y);
                GL.Vertex2(camBone0._x, camBone0._y);
                GL.End();
            }

            #endregion

            GL.PopAttrib();
        }
Esempio n. 23
0
 public unsafe override void modelPanel1_PostRender(ModelPanelViewport panel)
 {
     RenderBrawlStageData(panel);
     base.modelPanel1_PostRender(panel);
 }
Esempio n. 24
0
 public void LinkPivot(ModelPanelViewport control, ModelPanelViewport affected)
 {
     control.Pivoted += affected.Pivot;
 }
Esempio n. 25
0
        private void MouseMoveTarget(
            ModelPanel panel,
            MouseEventArgs e,
            float depth,
            ModelPanelViewport v,
            Matrix transformMatrix,
            Matrix invTransformMatrix,
            SelectionParams selection)
        {
            if (ControlType == TransformType.None)
            {
                return;
            }

            CoordinateType coord = _coordinateTypes[(int)ControlType];

            //Get the location of the bone
            Vector3 center = transformMatrix.GetPoint();

            //Standard radius scaling snippet. This is used for orb scaling depending on camera distance.
            float radius = CamDistance(center, v);

            bool snapFound = false;

            if (ControlType == TransformType.Rotation)
            {
                //Get point projected onto our orb.
                Vector3 point = v.ProjectCameraSphere(new Vector2(e.X, e.Y), center, radius, false);

                //Get the distance of the mouse point from the bone
                float distance = point.TrueDistance(center);

                if (Math.Abs(distance - radius) < (radius * _selectOrbScale)) //Point lies within orb radius
                {
                    selection._hiSphere = true;

                    //Determine axis snapping
                    Vector3 angles = (invTransformMatrix * point).GetAngles() * Maths._rad2degf;
                    angles._x = (float)Math.Abs(angles._x);
                    angles._y = (float)Math.Abs(angles._y);
                    angles._z = (float)Math.Abs(angles._z);

                    if (Math.Abs(angles._y - 90.0f) <= _axisSnapRange)
                    {
                        selection._hiX = true;
                    }
                    else if (angles._x >= (180.0f - _axisSnapRange) || angles._x <= _axisSnapRange)
                    {
                        selection._hiY = true;
                    }
                    else if (angles._y >= (180.0f - _axisSnapRange) || angles._y <= _axisSnapRange)
                    {
                        selection._hiZ = true;
                    }
                }
                else if (Math.Abs(distance - (radius * _circOrbScale)) < (radius * _selectOrbScale)) //Point lies on circ line
                {
                    selection._hiCirc = true;
                }

                if (selection._hiX || selection._hiY || selection._hiZ || selection._hiCirc)
                {
                    snapFound = true;
                }
            }
            else if (ControlType == TransformType.Translation || ControlType == TransformType.Scale)
            {
                //No more need to use depth!!! Just some nice math

                if (_coordinateTypes[(int)ControlType] == CoordinateType.World)
                {
                    transformMatrix = Matrix.TranslationMatrix(center) * Matrix.ScaleMatrix(transformMatrix.GetScale());
                }

                Vector3[] planePoints = new Vector3[3]; //xy, yz, xz
                v.ProjectCameraPlanes(new Vector2(e.X, e.Y), transformMatrix,
                                      out planePoints[0], out planePoints[1], out planePoints[2]);

                List <Vector3> testDiffs = new List <Vector3>();
                foreach (Vector3 planePoint in planePoints)
                {
                    Vector3 d =
                        coord == CoordinateType.World ? (planePoint - center) / radius :
                        coord == CoordinateType.Local ? (invTransformMatrix * planePoint) / radius :
                        (panel.Camera._matrix * planePoint - panel.Camera._matrix * center) / radius;

                    if (d._x > -_axisSelectRange && d._x < (_axisLDist + 0.01f) &&
                        d._y > -_axisSelectRange && d._y < (_axisLDist + 0.01f) &&
                        d._z > -_axisSelectRange && d._z < (_axisLDist + 0.01f))
                    {
                        testDiffs.Add(d);
                    }
                }

                //Check if point lies on a specific axis
                foreach (Vector3 diff in testDiffs)
                {
                    float errorRange = _axisSelectRange;

                    if (diff._x > _axisHalfLDist &&
                        Math.Abs(diff._y) < errorRange &&
                        Math.Abs(diff._z) < errorRange)
                    {
                        selection._hiX = true;
                    }
                    if (diff._y > _axisHalfLDist &&
                        Math.Abs(diff._x) < errorRange &&
                        Math.Abs(diff._z) < errorRange)
                    {
                        selection._hiY = true;
                    }
                    if (diff._z > _axisHalfLDist &&
                        Math.Abs(diff._x) < errorRange &&
                        Math.Abs(diff._y) < errorRange)
                    {
                        selection._hiZ = true;
                    }

                    if (snapFound = selection._hiX || selection._hiY || selection._hiZ)
                    {
                        break;
                    }
                }

                if (!snapFound)
                {
                    foreach (Vector3 diff in testDiffs)
                    {
                        if (ControlType == TransformType.Translation)
                        {
                            if (diff._x < _axisHalfLDist &&
                                diff._y < _axisHalfLDist &&
                                diff._z < _axisHalfLDist)
                            {
                                //Point lies inside the double drag areas
                                if (diff._x > _axisSelectRange)
                                {
                                    selection._hiX = true;
                                }
                                if (diff._y > _axisSelectRange)
                                {
                                    selection._hiY = true;
                                }
                                if (diff._z > _axisSelectRange)
                                {
                                    selection._hiZ = true;
                                }

                                selection._hiCirc =
                                    !selection._hiX &&
                                    !selection._hiY &&
                                    !selection._hiZ;

                                snapFound = true;
                            }
                        }
                        else if (ControlType == TransformType.Scale)
                        {
                            //Determine if the point is in the double or triple drag triangles
                            float halfDist   = _scaleHalf2LDist;
                            float centerDist = _scaleHalf1LDist;
                            if (diff.IsInTriangle(new Vector3(), new Vector3(halfDist, 0, 0), new Vector3(0, halfDist, 0)))
                            {
                                if (diff.IsInTriangle(new Vector3(), new Vector3(centerDist, 0, 0), new Vector3(0, centerDist, 0)))
                                {
                                    selection._hiX = selection._hiY = selection._hiZ = true;
                                }
                                else
                                {
                                    selection._hiX = selection._hiY = true;
                                }
                            }
                            else if (diff.IsInTriangle(new Vector3(), new Vector3(halfDist, 0, 0), new Vector3(0, 0, halfDist)))
                            {
                                if (diff.IsInTriangle(new Vector3(), new Vector3(centerDist, 0, 0), new Vector3(0, 0, centerDist)))
                                {
                                    selection._hiX = selection._hiY = selection._hiZ = true;
                                }
                                else
                                {
                                    selection._hiX = selection._hiZ = true;
                                }
                            }
                            else if (diff.IsInTriangle(new Vector3(), new Vector3(0, halfDist, 0), new Vector3(0, 0, halfDist)))
                            {
                                if (diff.IsInTriangle(new Vector3(), new Vector3(0, centerDist, 0), new Vector3(0, 0, centerDist)))
                                {
                                    selection._hiX = selection._hiY = selection._hiZ = true;
                                }
                                else
                                {
                                    selection._hiY = selection._hiZ = true;
                                }
                            }

                            snapFound = selection._hiX || selection._hiY || selection._hiZ;
                        }

                        if (snapFound)
                        {
                            break;
                        }
                    }
                }
            }

            if (snapFound)
            {
                panel.Cursor = Cursors.Hand;
                panel.Invalidate();
            }
        }
Esempio n. 26
0
 public void LinkScale(ModelPanelViewport control, ModelPanelViewport affected)
 {
     control.Scaled += affected.Scale;
 }
Esempio n. 27
0
 public void LinkRotate(ModelPanelViewport control, ModelPanelViewport affected)
 {
     control.Rotated += affected.Rotate;
 }
Esempio n. 28
0
        private void GetBone(ModelPanel panel, MouseEventArgs e, float depth, ModelPanelViewport v)
        {
            if (!_boneSelection.IsMoving() && depth < 1.0f)
            {
                IBoneNode o = null;

                Vector3 point   = v.UnProject(e.X, e.Y, depth);
                bool    doScale = v._renderAttrib._scaleBones;

                //Find orb near chosen point
                if (EditingAll)
                {
                    foreach (IModel m in _targetModels)
                    {
                        foreach (IBoneNode b in m.RootBones)
                        {
                            if (CompareBoneDistanceRecursive(b, point, ref o, v, doScale))
                            {
                                break;
                            }
                        }
                    }
                }
                else if (_targetModel != null)
                {
                    foreach (IBoneNode b in _targetModel.RootBones)
                    {
                        if (CompareBoneDistanceRecursive(b, point, ref o, v, doScale))
                        {
                            break;
                        }
                    }
                }

                bool update = false;
                if (_hiBone != null && _hiBone != SelectedBone && (update = _hiBone.NodeColor != Color.Transparent))
                {
                    _hiBone.NodeColor = Color.Transparent;
                }

                if ((_hiBone = o) != null)
                {
                    _hiBone.NodeColor = Color.FromArgb(255, 128, 0);
                    panel.Cursor      = Cursors.Hand;
                    update            = true;
                }

                if (update)
                {
                    panel.Invalidate();
                }
            }
            else if (_hiBone != null)
            {
                if (_hiBone != SelectedBone)
                {
                    _hiBone.NodeColor = Color.Transparent;
                    panel.Invalidate();
                }
                _hiBone = null;
            }
        }
Esempio n. 29
0
        private void modelPanel_OnCurrentViewportChanged(GLViewport p)
        {
            ModelPanelViewport v = p as ModelPanelViewport;

            stretchToolStripMenuItem1.Checked = p.BackgroundImageType == BGImageType.Stretch;
            centerToolStripMenuItem1.Checked  = p.BackgroundImageType == BGImageType.Center;
            resizeToolStripMenuItem1.Checked  = p.BackgroundImageType == BGImageType.ResizeWithBars;

            bool camDefaultSet =
                p.Camera._defaultRotate != p.GetDefaultRotate() ||
                p.Camera._defaultScale != p.GetDefaultScale() ||
                p.Camera._defaultTranslate != new Vector3();

            btnSaveCam.Text = camDefaultSet ? "Clear Camera" : "Save Camera";

            modelPanel_RenderBonesChanged(ModelPanel, v.RenderBones);
            modelPanel_RenderFloorChanged(ModelPanel, v.RenderFloor);
            modelPanel_RenderModelBoxChanged(ModelPanel, v.RenderModelBox);
            modelPanel_RenderNormalsChanged(ModelPanel, v.RenderNormals);
            modelPanel_RenderObjectBoxChanged(ModelPanel, v.RenderObjectBox);
            modelPanel_RenderOffscreenChanged(ModelPanel, v.DontRenderOffscreen);
            ModelPanel_RenderPolygonsChanged(ModelPanel, v.RenderPolygons);
            ModelPanel_RenderVerticesChanged(ModelPanel, v.RenderVertices);
            modelPanel_RenderVisBoneBoxChanged(ModelPanel, v.RenderVisBoneBox);
            ModelPanel_RenderWireframeChanged(ModelPanel, v.RenderWireframe);
            ModelPanel_ScaleBonesChanged(ModelPanel, v.ScaleBones);
            ModelPanel_ApplyBillboardBonesChanged(ModelPanel, v.ApplyBillboardBones);
            modelPanel_FirstPersonCameraChanged(ModelPanel, v._firstPersonCamera);
            ModelPanel_RenderShadersChanged(ModelPanel, v._renderAttrib._renderShaders);
            ModelPanel_UseBindStateBoxesChanged(ModelPanel, v.UseBindStateBoxes);
            sCN0ToolStripMenuItem.Checked = v.RenderSCN0Controls;

            _currentProjBox.Checked = false;
            switch (p.ViewType)
            {
            case ViewportProjection.Perspective:
                _currentProjBox = perspectiveToolStripMenuItem; break;

            case ViewportProjection.Orthographic:
                _currentProjBox = orthographicToolStripMenuItem; break;

            case ViewportProjection.Top:
                _currentProjBox = topToolStripMenuItem; break;

            case ViewportProjection.Bottom:
                _currentProjBox = bottomToolStripMenuItem; break;

            case ViewportProjection.Left:
                _currentProjBox = leftToolStripMenuItem; break;

            case ViewportProjection.Right:
                _currentProjBox = rightToolStripMenuItem; break;

            case ViewportProjection.Front:
                _currentProjBox = frontToolStripMenuItem; break;

            case ViewportProjection.Back:
                _currentProjBox = backToolStripMenuItem; break;
            }
            _currentProjBox.Checked = true;

            showCameraCoordinatesToolStripMenuItem.Checked = v._showCamCoords;
            loadImageToolStripMenuItem.Text = v.BackgroundImage == null ? "Load Image" : "Clear Image";
        }
Esempio n. 30
0
        private void GetVertex(ModelPanel panel, MouseEventArgs e, float depth, ModelPanelViewport v)
        {
            //Try targeting a vertex
            if (RenderVertices)
            {
                if (panel.CurrentViewport.Selecting)
                {
                    if (NotCtrlAlt)
                    {
                        ClearSelectedVertices();
                    }

                    bool selected = false;
                    if (TargetModel != null)
                    {
                        if (TargetModel.SelectedObjectIndex < 0)
                        {
                            foreach (IObject o in TargetModel.Objects)
                            {
                                if (o.IsRendering)
                                {
                                    SelectVertices(o, panel);
                                    selected = true;
                                }
                            }
                        }
                        else
                        {
                            IObject w = TargetModel.Objects[TargetModel.SelectedObjectIndex];
                            if (w.IsRendering)
                            {
                                SelectVertices(w, panel);
                                selected = true;
                            }
                            else
                            {
                                foreach (IObject h in TargetModel.Objects)
                                {
                                    if (h.IsRendering)
                                    {
                                        SelectVertices(h, panel);
                                        selected = true;
                                    }
                                }
                            }
                        }
                    }
                    else if (_targetModels != null)
                    {
                        foreach (IModel m in _targetModels)
                        {
                            if (m.SelectedObjectIndex < 0)
                            {
                                foreach (IObject o in m.Objects)
                                {
                                    if (o.IsRendering)
                                    {
                                        SelectVertices(o, panel);
                                        selected = true;
                                    }
                                }
                            }
                            else
                            {
                                IObject w = m.Objects[m.SelectedObjectIndex];
                                if (w.IsRendering)
                                {
                                    SelectVertices(w, panel);
                                    selected = true;
                                }
                                else
                                {
                                    foreach (IObject h in m.Objects)
                                    {
                                        if (h.IsRendering)
                                        {
                                            SelectVertices(h, panel);
                                            selected = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (selected)
                    {
                        OnSelectedVerticesChanged();
                    }
                }
                else
                {
                    if (depth < 1.0f && _targetModel != null)
                    {
                        Vector3 point  = v.UnProject(e.X, e.Y, depth);
                        Vertex3 vertex = CompareVertexDistance(point);
                        bool    update = false;
                        if (_hiVertex != null && !_hiVertex._selected)
                        {
                            update = true;
                            _hiVertex._highlightColor = Color.Transparent;
                            ModelPanel.CurrentViewport.AllowSelection = true;
                        }
                        if ((_hiVertex = vertex) != null)
                        {
                            update = true;
                            _hiVertex._highlightColor = Color.Orange;
                            panel.Cursor = Cursors.Cross;
                            ModelPanel.CurrentViewport.AllowSelection = false;
                        }
                        if (update)
                        {
                            panel.Invalidate();
                        }
                    }
                    else if (_hiVertex != null)
                    {
                        if (!_hiVertex._selected)
                        {
                            _hiVertex._highlightColor = Color.Transparent;
                            ModelPanel.CurrentViewport.AllowSelection = true;
                            panel.Invalidate();
                        }
                        _hiVertex = null;
                    }
                }
            }
        }