Ejemplo n.º 1
0
 public void removeFan(Fan a)
 {
     fans.Remove(a);
 }
Ejemplo n.º 2
0
        void CheckMouseClick()
        {
            MouseState mouseState = Mouse.GetState();
            if (mouseState.LeftButton == ButtonState.Pressed && previousState.LeftButton == ButtonState.Released)
            {

                Ray pickRay = GetPickRay();

                //Nullable<float> result = pickRay.Intersects(triangleBB);
                int selectedIndex = -1;
                float selectedDistance = float.MaxValue;
                for (int i = 0; i < buildingBoundingBoxes.Length; i++)
                {
                    Nullable<float> result = pickRay.Intersects(buildingBoundingBoxes[i]);
                    if (result.HasValue == true)
                    {
                        if (result.Value < selectedDistance)
                        {
                            selectedIndex = i;
                            selectedDistance = result.Value;
                        }
                    }
                }
                if (selectedIndex > -1)
                {
                    //selected grid
                    //buildingBoundingBoxes[selectedIndex].
                    //buildingBoundingBoxes[selectedIndex] = selectedTexture;
                    System.Diagnostics.Debug.WriteLine(selectedIndex);

                    bool fanExists = false;
                    Vector3 fanPosition = new Vector3((buildingBoundingBoxes[selectedIndex].GetCorners()[0].X + buildingBoundingBoxes[selectedIndex].GetCorners()[1].X)/2, buildingBoundingBoxes[selectedIndex].GetCorners()[0].Y, (buildingBoundingBoxes[selectedIndex].GetCorners()[0].Z + buildingBoundingBoxes[selectedIndex].GetCorners()[4].Z)/2);
                    foreach (Fan f in fans)
                    {
                        if(f.WorldPosition == fanPosition)
                        {
                            System.Diagnostics.Debug.WriteLine(f.WorldPosition);
                            f.CurrentAngle += MathHelper.PiOver4;
                            fanExists = true;
                            System.Diagnostics.Debug.WriteLine("ROTATED");
                            System.Diagnostics.Debug.WriteLine(f.WorldPosition);
                        }
                    }
                    if(!fanExists)
                    {
                        Fan temp = new Fan(ScreenManager.Game);
                        temp.Camera = camera;
                        temp.WorldRotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.PiOver2);
                        temp.WorldPosition = new Vector3((buildingBoundingBoxes[selectedIndex].GetCorners()[0].X + buildingBoundingBoxes[selectedIndex].GetCorners()[1].X)/2, buildingBoundingBoxes[selectedIndex].GetCorners()[0].Y, (buildingBoundingBoxes[selectedIndex].GetCorners()[0].Z + buildingBoundingBoxes[selectedIndex].GetCorners()[4].Z)/2);

                        ScreenManager.Game.Components.Add(temp);
                        fans.Add(temp);
                    }

                }

            }

            if (mouseState.RightButton == ButtonState.Pressed && previousState.RightButton == ButtonState.Released)
            {

                Ray pickRay = GetPickRay();

                //Nullable<float> result = pickRay.Intersects(triangleBB);
                int selectedIndex = -1;
                float selectedDistance = float.MaxValue;
                for (int i = 0; i < buildingBoundingBoxes.Length; i++)
                {
                    Nullable<float> result = pickRay.Intersects(buildingBoundingBoxes[i]);
                    if (result.HasValue == true)
                    {
                        if (result.Value < selectedDistance)
                        {
                            selectedIndex = i;
                            selectedDistance = result.Value;
                        }
                    }
                }
                if (selectedIndex > -1)
                {
                    //selected grid
                    //buildingBoundingBoxes[selectedIndex].
                    //buildingBoundingBoxes[selectedIndex] = selectedTexture;
                    System.Diagnostics.Debug.WriteLine(selectedIndex);

                    bool fanExists = false;
                    Vector3 fanPosition = new Vector3((buildingBoundingBoxes[selectedIndex].GetCorners()[0].X + buildingBoundingBoxes[selectedIndex].GetCorners()[1].X) / 2, buildingBoundingBoxes[selectedIndex].GetCorners()[0].Y, (buildingBoundingBoxes[selectedIndex].GetCorners()[0].Z + buildingBoundingBoxes[selectedIndex].GetCorners()[4].Z) / 2);
                    Fan toRemove = null;
                    foreach (Fan f in fans)
                    {
                        if (f.WorldPosition == fanPosition)
                        {
                            //fans.Remove(f);
                            toRemove = f;
                            ScreenManager.Game.Components.Remove(f);
                            System.Diagnostics.Debug.WriteLine("REMOVED");
                        }
                    }
                    if (toRemove != null)
                    {
                        fans.Remove(toRemove);
                    }

                    if (!fanExists)
                    {

                    }

                }

            }

            previousState = mouseState;
        }