Beispiel #1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(backgroundColor);

            basicEffect.View       = mainCamera.ViewMatrix;
            basicEffect.Projection = mainCamera.ProjectionMatrix;

            Object3D.Draw3DGrid(graphics, basicEffect, rasterSolidNoCull);
            Controls.DrawLookAt(graphics, basicEffect, rasterSolidNoCull);

            foreach (Object3D obj in Object3D.objectList)
            {
                obj.Draw(graphics, basicEffect, rasterSolid);
            }

            transformationBox.Draw(graphics, basicEffect, rasterSolidNoCull);

            base.Draw(gameTime);
        }
Beispiel #2
0
        void UpdateMouse()
        {
            this.mouseState    = Mouse.GetState(Program.MainView.Window);
            this.keyboardState = Keyboard.GetState();

            if (View.Controls.keyboardState.IsKeyDown(Keys.LeftShift))
            {
                return;
            }


            if (View.Controls.MouseDragState == 0)
            {
                dragInstance = -1;
            }

            if (dragInstance > -1)
            {
                if (this.ID != dragInstance)
                {
                    this.Highlight = false;
                    return;
                }
            }

            Vector2 centre = Object3D.GetOrtho(this.position);

            double xDiff = mouseState.X - centre.X;
            double yDiff = mouseState.Y - centre.Y;


            Vector2 angle0      = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3(this.rayon, 0, 0), this.Matrice));
            Vector2 anglePIsur2 = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3(0, this.rayon, 0), this.Matrice));

            if (angle0.X < centre.X)
            {
                xDiff = -xDiff;
            }
            if (anglePIsur2.Y < centre.Y)
            {
                yDiff = -yDiff;
            }

            double hypo       = Math.Pow(xDiff * xDiff + yDiff * yDiff, 0.5);
            float  angleMouse = (float)Math.Atan2(yDiff / hypo, xDiff / hypo);

            Object3D.MesurePositive(ref angleMouse);


            double smallest       = Single.MaxValue;
            double realAngleMouse = 0;
            int    smallestI      = 0;

            for (int i = 0; i < 100; i++)
            {
                double  angle    = (i / 100d) * Math.PI * 2;
                Vector2 posOrtho = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3((float)(this.rayon * Math.Cos(angle)),
                                                                                                   (float)(this.rayon * Math.Sin(angle)), 0), this.Matrice));

                double xDiffSeek = posOrtho.X - centre.X;
                double yDiffSeek = posOrtho.Y - centre.Y;

                if (angle0.X < centre.X)
                {
                    xDiffSeek = -xDiffSeek;
                }
                if (anglePIsur2.Y < centre.Y)
                {
                    yDiffSeek = -yDiffSeek;
                }
                double hypoSeek = Math.Pow(xDiffSeek * xDiffSeek + yDiffSeek * yDiffSeek, 0.5);

                float angleOrtho = (float)Math.Atan2(yDiffSeek / hypoSeek, xDiffSeek / hypoSeek);
                Object3D.MesurePositive(ref angleOrtho);

                double diff = Math.Abs(angleOrtho - angleMouse);

                if (diff < smallest)
                {
                    realAngleMouse = angle;
                    smallest       = diff;
                    smallestI      = i;
                }
            }

            Vector2 posRayonOrthoAtMouseAngle = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3((float)(this.rayon * Math.Cos(realAngleMouse)),
                                                                                                                (float)(this.rayon * Math.Sin(realAngleMouse)), 0), this.Matrice));

            xDiff = posRayonOrthoAtMouseAngle.X - centre.X;
            yDiff = posRayonOrthoAtMouseAngle.Y - centre.Y;

            if (angle0.X < centre.X)
            {
                xDiff = -xDiff;
            }
            if (anglePIsur2.Y < centre.Y)
            {
                yDiff = -yDiff;
            }

            double hypo2     = Math.Pow(xDiff * xDiff + yDiff * yDiff, 0.5);
            bool   highlight = View.Controls.keyboardState.IsKeyUp(Keys.LeftShift) && Math.Abs(hypo - hypo2) <= hypo2 * 0.1f;


            if (highlight)
            {
                dragInstance = this.ID;
            }

            this.Highlight = View.Controls.MouseDragState > 0;

            if (View.Controls.mouseState.LeftButton == ButtonState.Released && View.Controls.MouseDragState == 2)
            {
                this.Release?.Invoke(null, null);
                this.endAngle   = 0;
                this.startAngle = 0;
                View.Controls.MouseDragState = 0;
            }

            if (highlight)
            {
                if (View.Controls.MouseDragState == 0 && View.Controls.mouseState.LeftButton == ButtonState.Released)
                {
                    View.Controls.MouseDragState = 1;
                }

                if (View.Controls.mouseState.LeftButton == ButtonState.Pressed)
                {
                    if (View.Controls.MouseDragState == 1)
                    {
                        this.endAngle   = (float)realAngleMouse;
                        this.startAngle = (float)realAngleMouse;
                        View.Controls.MouseDragState = 2;
                    }
                }
                else
                {
                    View.Controls.MouseDragState = 1;
                }
            }
            else
            {
                if (View.Controls.MouseDragState == 1)
                {
                    View.Controls.MouseDragState = 0;
                }
            }

            if (View.Controls.MouseDragState == 2)
            {
                this.endAngle = (float)realAngleMouse;
                float start = this.startAngle;
                float end   = this.endAngle;

                float val = end - start;
                this.ValueChanged?.Invoke(val, null);
            }
            oldKeyboardState = keyboardState;
            oldMouseState    = mouseState;
        }
Beispiel #3
0
        public void DrawLineChildren(Bone currBone)
        {
            Vector3 bonePos  = Vector3.Transform(Vector3.Zero, this.BonesReMatrices[currBone.ID]);
            Vector3 position = View.mainCamera.GlobalPosition();

            Vector2 mouseV2 = new Vector2(this.mouseState.Position.X, this.mouseState.Position.Y);

            Vector2 startOrtho = Object3D.GetOrtho(bonePos);

            if (Vector2.Distance(mouseV2, startOrtho) < 10)
            {
                bool hasChildren = false;
                for (int i = 0; i < this.Bones.Length; i++)
                {
                    if (this.Bones[i].ParentID == currBone.ID)
                    {
                        hasChildren = true;
                        break;
                    }
                }
                if (!hasChildren)
                {
                    this.HighlightedBoneParentID = currBone.ID;
                    this.HighlightedBoneMiddle   = bonePos;
                    this.HighlightedBone         = true;
                }
            }

            float  diffX = position.X - (bonePos.X + objet.Position.X);
            float  diffY = position.Y - (bonePos.Y + objet.Position.Y);
            float  diffZ = position.Z - (bonePos.Z + objet.Position.Z);
            double hypo  = Math.Pow(diffX * diffX + diffY * diffY + diffZ * diffZ, 0.5f);


            for (int i = 0; i < this.Bones.Length; i++)
            {
                if (this.Bones[i].ParentID == currBone.ID)
                {
                    Vector3 boneChildrenPos = Vector3.Transform(Vector3.Zero, this.BonesReMatrices[i]);
                    if (Vector3.Distance(bonePos, boneChildrenPos) > 0.001f)
                    {
                        for (int j = 0; j < 1000; j++)
                        {
                            if (!this.bonesTextureLinesUsed[j])
                            {
                                this.bonesTextureLinesUsed[j]     = true;
                                this.bonesTextureLinesUsed[j + 1] = true;
                                this.bonesTextureLinesUsed[j + 2] = true;
                                this.bonesTextureLinesUsed[j + 3] = true;

                                this.bonesTextureLines[j].Position  = new Vector3(0, -(float)hypo / 220f, 0);
                                this.bonesTextureLines[j].Position  = Vector3.Transform(this.bonesTextureLines[j].Position, Matrix.CreateFromYawPitchRoll(View.mainCamera.Yaw, View.mainCamera.Pitch, 0));
                                this.bonesTextureLines[j].Position += bonePos;

                                this.bonesTextureLines[j].Color = UnselectedColor;
                                if (this.Bones[i].Selected && this.Bones[i].ParentID > -1 && this.Bones[this.Bones[i].ParentID].Selected)
                                {
                                    this.bonesTextureLines[j].Color = SelectedColor;
                                }

                                this.bonesTextureLines[j].TextureCoordinate = new Vector2(279 / 382f, 243 / 382f);


                                this.bonesTextureLines[j + 1].TextureCoordinate = this.bonesTextureLines[j].TextureCoordinate;
                                this.bonesTextureLines[j + 1].Position          = boneChildrenPos;

                                this.bonesTextureLines[j + 2].Position  = new Vector3(0, (float)hypo / 220f, 0);
                                this.bonesTextureLines[j + 2].Position  = Vector3.Transform(this.bonesTextureLines[j + 2].Position, Matrix.CreateFromYawPitchRoll(View.mainCamera.Yaw, View.mainCamera.Pitch, 0));
                                this.bonesTextureLines[j + 2].Position += bonePos;


                                this.bonesTextureLines[j + 2].TextureCoordinate = new Vector2(279 / 382f, 243 / 382f);

                                this.bonesTextureLines[j + 3].TextureCoordinate = this.bonesTextureLines[j].TextureCoordinate;
                                this.bonesTextureLines[j + 3].Position          = boneChildrenPos;

                                bool boneZero      = currBone.Grayed || Vector3.DistanceSquared(bonePos, Vector3.Zero) < 0.001f;
                                bool boneChildZero = this.Bones[i].Grayed || Vector3.DistanceSquared(boneChildrenPos, Vector3.Zero) < 0.001f;

                                if (boneZero || boneChildZero)
                                {
                                    if (boneZero)
                                    {
                                        currBone.Grayed = true;
                                    }
                                    if (boneChildZero)
                                    {
                                        this.Bones[i].Grayed = true;
                                    }
                                    this.bonesTextureLines[j].Color   = this.bonesTextureLines[j].Color * 0.5f;
                                    this.bonesTextureLines[j].Color.A = 50;
                                }

                                this.bonesTextureLines[j + 1].Color = this.bonesTextureLines[j].Color;
                                this.bonesTextureLines[j + 2].Color = this.bonesTextureLines[j].Color;
                                this.bonesTextureLines[j + 3].Color = this.bonesTextureLines[j].Color;

                                Vector3 start      = bonePos;// this.bonesTextureLines[j + 0].Position + this.objet.Position;
                                Vector3 end        = boneChildrenPos;
                                float   sansEnfant = Vector2.Distance(mouseV2, Object3D.GetOrtho(boneChildrenPos));

                                Vector3 middle = (start + end) / 2f;

                                if (View.Controls.MouseDragState == 0)
                                {
                                    if (sansEnfant > 10 && !this.HighlightedBone)
                                    {
                                        Vector2 childPosOtrho = Object3D.GetOrtho(middle);

                                        /* Optimisation */
                                        if (Vector2.Distance(childPosOtrho, mouseV2) < Program.MainView.graphics.PreferredBackBufferWidth / 3)
                                        {
                                            Vector3 diff = end - start;

                                            for (int h = 0; h < 101; h++)
                                            {
                                                Vector3 toDist      = start + diff * (h / 100f);
                                                Vector2 toDistOrtho = Object3D.GetOrtho(toDist);
                                                if (Vector2.Distance(toDistOrtho, mouseV2) < 10)
                                                {
                                                    this.HighlightedBoneParentID = currBone.ID;
                                                    this.HighlightedBoneMiddle   = middle;
                                                    this.HighlightedBone         = true;
                                                    break;
                                                }
                                            }
                                        }
                                        //this.mousePos
                                    }

                                    if (this.HighlightedBone && Vector3.Distance(middle, this.HighlightedBoneMiddle) < 0.01 && currBone.ID == this.HighlightedBoneParentID)
                                    {
                                        this.bonesTextureLines[j + 0].Color = HighligthedColor;
                                        this.bonesTextureLines[j + 1].Color = HighligthedColor;
                                        this.bonesTextureLines[j + 2].Color = HighligthedColor;
                                        this.bonesTextureLines[j + 3].Color = HighligthedColor;
                                    }
                                }

                                this.bonesTextureLinesLength += 4;
                                break;
                            }
                        }
                    }

                    DrawLineChildren(this.Bones[i]);
                }
            }
        }