Ejemplo n.º 1
0
        public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            PortVisual port = rayMeshResult.VisualHit as PortVisual;
            if (port !=null)
            {
                board.ShowSideNeighbours(port.XmlPort.SideLocation);
                return BehaviourResult.NoSuccess;
            }

            HexVisual hex = rayMeshResult.VisualHit as HexVisual;
            if (hex != null)
            {
                List<HexPoint> temp = new List<HexPoint>();
                List<HexPoint> temp2 = hex.Hex.Location.GetNeighbourPoints();
                temp.Add(temp2[0]);
                temp.Add(temp2[1]);
                temp.Add(temp2[4]);
                board.ShowPoints(temp);
            }

            Road road = rayMeshResult.VisualHit as Road;
            if (road != null)
            {
                //board.Game.PlayerOnTurn.Towns.Add(buildPoint.Location);
                //board.ShowNeighbours(road.Location);
                board.ShowSideNeighbours(road.Location);
                return BehaviourResult.NoSuccess;
            }

            return BehaviourResult.NoSuccess;
        }
Ejemplo n.º 2
0
        public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            //find an appropriate visual user clicked,
            // can be hex or simply the chitnumber
            ResourceHex resourceHex = null;
            HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
            if (hexVisual != null)
            {
                resourceHex = hexVisual.Hex as ResourceHex;
            }
            ChitVisual chitVisual = rayMeshResult.VisualHit as ChitVisual;
            if (chitVisual != null)
            {
                resourceHex = (ResourceHex)((HexVisual)chitVisual.Parent).Hex;
            }

            //when we found a suitable visual, update the chit number.
            if (resourceHex != null)
            {
                resourceHex.XmlChit = new Chit() { ChitNumber = _Number };
                return BehaviourResult.Success;
            }
            else
            {
                return BehaviourResult.NoSuccess;
            }
        }
Ejemplo n.º 3
0
 public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     if (rayMeshResult != null)
     {
         GeometryModel3D hitgeo = rayMeshResult.ModelHit as GeometryModel3D;
         HexVisual hex = rayMeshResult.VisualHit as HexVisual;
         if (hex != null)
         {
             // only show mouseover when we have a resourcehex
             if (hex.Hex is ResourceHex)
             {
                 // when we are removing chits, show mouseover when there is
                 // something to remove
                 if (_Number == EChitNumber.None)
                 {
                     ResourceHex resourceHex = hex.Hex as ResourceHex;
                     if (resourceHex.XmlChit.ChitNumber != EChitNumber.None)
                     {
                         SetSelectionState(hex);
                     }
                 }
                 else
                 {
                     //default on showing a mouseover
                     SetSelectionState(hex);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     Ship ship = rayMeshResult.VisualHit as Ship;
     if (ship != null)
     {
         _Location = ship.Location;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 5
0
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexSideVisual hexSideVisual = rayMeshResult.VisualHit as HexSideVisual;
     if (hexSideVisual != null)
     {
         _Location = hexSideVisual.Location;
         board.SetNeutral();
         ((BuildShipAction)_OriginatingAction).Intersection = hexSideVisual.Location;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 6
0
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     BuildPointVisual buildPoint = rayMeshResult.VisualHit as BuildPointVisual;
     if (buildPoint != null)
     {
         //board.Game.PlayerOnTurn.Towns.Add(buildPoint.Location);
         board.SetNeutral();
         ((BuildTownAction)_OriginatingAction).Location = buildPoint.Location;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 7
0
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
     if (hexVisual != null)
     {
         Hex newHex = _SelectedHexType.Copy();
         newHex.Location = hexVisual.Hex.Location;
         board.Board.Hexes[newHex.Location] = newHex;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns true and the intersection point for the given rayHitResult if there is an intersection,
        /// and false otherwise.
        /// </summary>
        /// <param name="rayHitResult"></param>
        /// <param name="outputPoint">The output point if there was an intersection</param>
        /// <returns>
        /// Returns the point of intersection in outputPoint if there is one, and returns true
        /// to indicate this.
        /// </returns>
        internal static bool GetIntersectionInfo(RayHitTestResult rayHitResult, out Point outputPoint)
        {
            bool success = false;

            outputPoint = new Point();

            // try to cast to a RaymeshGeometry3DHitTestResult
            RayMeshGeometry3DHitTestResult rayMeshResult = rayHitResult as RayMeshGeometry3DHitTestResult;

            if (rayMeshResult != null)
            {
                // we can now extract the mesh and visual for the object we hit
                MeshGeometry3D geom = rayMeshResult.MeshHit;

                // pull the barycentric coordinates of the intersection point
                double vertexWeight1 = rayMeshResult.VertexWeight1;
                double vertexWeight2 = rayMeshResult.VertexWeight2;
                double vertexWeight3 = rayMeshResult.VertexWeight3;

                // the indices in to where the actual intersection occurred
                int index1 = rayMeshResult.VertexIndex1;
                int index2 = rayMeshResult.VertexIndex2;
                int index3 = rayMeshResult.VertexIndex3;

                PointCollection textureCoordinates = geom.TextureCoordinates;

                // texture coordinates of the three vertices hit
                // in the case that no texture coordinates are supplied we will simply
                // treat it as if no intersection occurred
                if (textureCoordinates != null &&
                    index1 < textureCoordinates.Count &&
                    index2 < textureCoordinates.Count &&
                    index3 < textureCoordinates.Count)
                {
                    Point texCoord1 = textureCoordinates[index1];
                    Point texCoord2 = textureCoordinates[index2];
                    Point texCoord3 = textureCoordinates[index3];

                    // get the final uv values based on the barycentric coordinates
                    outputPoint = new Point(texCoord1.X * vertexWeight1 +
                                            texCoord2.X * vertexWeight2 +
                                            texCoord3.X * vertexWeight3,
                                            texCoord1.Y * vertexWeight1 +
                                            texCoord2.Y * vertexWeight2 +
                                            texCoord3.Y * vertexWeight3);
                    success = true;
                }
            }

            return(success);
        }
Ejemplo n.º 9
0
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
     if (hexVisual != null)
     {
         ResourceHex resourceHex = hexVisual.Hex as ResourceHex;
         if (resourceHex != null)
         {
             _Location = resourceHex.Location;
             return BehaviourResult.Success;
         }
     }
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 10
0
        public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hex = rayMeshResult.VisualHit as HexVisual;
            if (hex != null)
            {
                if (hex.Hex is ITerritoryHex)
                {
                    if (_OldMouseOverHex != null)
                        _OldMouseOverHex.Selected = false;
                    hex.Selected = true;

                    _OldMouseOverHex = hex;
                }
            }
        }
Ejemplo n.º 11
0
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     //Check if clicked hex is a LandHex, if so, put current territory
     //on the hex.
     HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
     if (hexVisual != null)
     {
         ITerritoryHex terrHex = hexVisual.Hex as ITerritoryHex;
         if (terrHex != null)
         {
             terrHex.TerritoryID = _SelectedTerritory.ID;
             return BehaviourResult.Success;
         }
     }
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 12
0
        public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hv = rayMeshResult.VisualHit as HexVisual;
            if (hv != null)
            {
                if (!_ForbiddenHexes.Contains(hv) ||
                    hv.Hex.Location.Equals(board.Game.Robber) ||
                    hv.Hex.Location.Equals(board.Game.Pirate))
                {
                    if (_OldMouseOverHex != null)
                        _OldMouseOverHex.Selected = false;
                    hv.Selected = true;

                    _OldMouseOverHex = hv;
                }
            }
        }
Ejemplo n.º 13
0
        public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
            if (hexVisual != null)
            {
                PlaceRobberPirateAction placeRobberPirate = _OriginatingAction as PlaceRobberPirateAction;
                if (placeRobberPirate != null)
                {
                    if (hexVisual.Hex is SeaHex)
                        _IsRobber = false;

                    placeRobberPirate.Location = hexVisual.Hex.Location;
                    RemoveStartState(board);
                    return BehaviourResult.Success;
                }
            }
            return BehaviourResult.NoSuccess;
        }
Ejemplo n.º 14
0
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     Road hsv = rayMeshResult.VisualHit as Road;
     if (hsv != null)
     {
         hsv.IsRoadSelected = true;
     }
     BuildPointVisual buildPoint = rayMeshResult.VisualHit as BuildPointVisual;
     if (buildPoint != null)
     {
         //board.Game.PlayerOnTurn.Cities.Add(buildPoint.Location);
         _Location = buildPoint.Location;
         board.SetNeutral();
         ((BuildCityAction)_OriginatingAction).Location = buildPoint.Location;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 15
0
        public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            Road side = rayMeshResult.VisualHit as Road;
            if (side != null)
            {
                List<BuildPointVisual> x = new List<BuildPointVisual>();
                foreach (BuildPointVisual bpv in board.Children.OfType<BuildPointVisual>())
                    x.Add(bpv);
                foreach (BuildPointVisual bp in x)
                    board.Children.Remove(bp);

                BuildPointVisual bpv1 = new BuildPointVisual(board.CalculatePosition(side.Location.HexPoint1), side.Location.HexPoint1);
                BuildPointVisual bpv2 = new BuildPointVisual(board.CalculatePosition(side.Location.HexPoint2), side.Location.HexPoint2);
                board.Children.Add(bpv1);
                board.Children.Add(bpv2);
            }
            return BehaviourResult.NoSuccess;
        }
Ejemplo n.º 16
0
        public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexSideVisual hexSideVisual = rayMeshResult.VisualHit as HexSideVisual;
            if (_OldMouseOver != null)
            {
                _OldMouseOver.Scale.ScaleX = 1;
                _OldMouseOver.Scale.ScaleY = 1;
                _OldMouseOver.Scale.ScaleZ = 1;
                _OldMouseOver = null;
            }
            if (hexSideVisual != null)
            {

                hexSideVisual.Scale.ScaleX = 2;
                hexSideVisual.Scale.ScaleY = 2;
                hexSideVisual.Scale.ScaleZ = 2;
                _OldMouseOver = hexSideVisual;
            }
        }
Ejemplo n.º 17
0
 public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     BuildPointVisual buildPoint = rayMeshResult.VisualHit as BuildPointVisual;
     if (buildPoint != null)
     {
         buildPoint.Scale.ScaleX = 2;
         buildPoint.Scale.ScaleY = 2;
         buildPoint.Scale.ScaleZ = 2;
         _OldBuildPoint = buildPoint;
     }
     else
     {
         if (_OldBuildPoint != null)
         {
             _OldBuildPoint.Scale.ScaleX = 1;
             _OldBuildPoint.Scale.ScaleY = 1;
             _OldBuildPoint.Scale.ScaleZ = 1;
         }
     }
 }
Ejemplo n.º 18
0
        public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
            if (hexVisual != null)
            {
                SeaHex seaHex = hexVisual.Hex as SeaHex;
                if (seaHex != null)
                {
                    if (((SeaHex)seaHex).XmlPort != null)
                    {
                        // we confirmed the port here, make a small animation
                        hexVisual.AnimatePortSetted();
                        return BehaviourResult.Success;
                    }
                }
            }

            // we need a seahex to move on
            return BehaviourResult.Success;
        }
Ejemplo n.º 19
0
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
     if (hexVisual != null)
     {
         SeaHex seaHex = hexVisual.Hex as SeaHex;
         if (seaHex != null)
         {
             if (_SelectedPortType == EPortType.None)
             {
                 seaHex.XmlPort = null;
                 return BehaviourResult.Success;
             }
             else
             {
                 if (seaHex.XmlPort == null)
                     seaHex.XmlPort = new Port()
                     {
                         Location = seaHex.Location,
                     };
                 seaHex.XmlPort.PortType = _SelectedPortType;
                 switch (rayMeshResult.VertexIndex3)
                 {
                     case 0: seaHex.XmlPort.PortPosition = ERotationPosition.Deg240; break;
                     case 1: seaHex.XmlPort.PortPosition = ERotationPosition.Deg180; break;
                     case 2: seaHex.XmlPort.PortPosition = ERotationPosition.Deg120; break;
                     case 3: seaHex.XmlPort.PortPosition = ERotationPosition.Deg60; break;
                     case 4: seaHex.XmlPort.PortPosition = ERotationPosition.Deg0; break;
                     case 5: seaHex.XmlPort.PortPosition = ERotationPosition.Deg300; break;
                 }
                 hexVisual.AnimatePortSetted();
                 if (_SelectedHex == null)
                     _SelectedHex = seaHex;
                 else
                     _SelectedHex = null;
                 return BehaviourResult.Success;
             }
         }
     }
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 20
0
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexSideVisual hexSide = rayMeshResult.VisualHit as HexSideVisual;
     if (hexSide != null)
     {
         if (_ShipToMove == null)
         {
             // player has not yet selected a ship to move. Show moveable ships
             //board.SetMoveShip();
             _ShipToMove = hexSide.Location;
             board.SetMoveToShip(_ShipToMove);
             return BehaviourResult.NoSuccess;
         }
         else
         {
             MoveShipAction moveShip = _OriginatingAction as MoveShipAction;
             moveShip.OldLocation = _ShipToMove;
             moveShip.NewLocation = hexSide.Location;
             board.SetNeutral();
             return BehaviourResult.Success;
         }
     }
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Performs hit testing for this residue.
 /// </summary>
 /// <param name="rayHitTestResult">A 3D mesh hit test result from the WPF visual tree hit
 /// testing framework</param>
 /// <returns>True if the mesh hit belongs to this residue, otherwise false.</returns>
 internal virtual bool HoverHitTest(RayMeshGeometry3DHitTestResult rayHitTestResult)
 {
     if (this.cartoon != null)
         return this.cartoon.HoverHitTest(rayHitTestResult);
     else
         return false;
 }
Ejemplo n.º 22
0
        static HitTestResultBehavior HitTestResultCallback(HitTestResult result)
        {
            RayMeshGeometry3DHitTestResult htr = result as RayMeshGeometry3DHitTestResult;
            if (htr != null)
            {
                if (hitTestResult == null)
                    hitTestResult = htr;

                else if (htr.DistanceToRayOrigin < hitTestResult.DistanceToRayOrigin)
                    hitTestResult = htr;
            }
            return HitTestResultBehavior.Continue;
        }
Ejemplo n.º 23
0
 public void UpdateResultInfo(RayMeshGeometry3DHitTestResult rayMeshResult)
 {
     HitVisualInfo.Text = rayMeshResult.VisualHit.ToString();
     HitModelInfo.Text = rayMeshResult.ModelHit.ToString();
     HitMeshInfo.Text = rayMeshResult.MeshHit.ToString();
     //HitMaterialInfo.Text = (rayMeshResult.ModelHit as GeometryModel3D).Material.GetType().Name;
     //HitMaterialBrushInfo.Text = ((rayMeshResult.ModelHit as GeometryModel3D).Material as DiffuseMaterial).Brush.ToString();
     HitDistanceInfo.Text = rayMeshResult.DistanceToRayOrigin.ToString();
     Vertex1Info.Text = (rayMeshResult.VertexWeight1 * 100) + "%";
     Vertex2Info.Text = (rayMeshResult.VertexWeight2 * 100) + "%";
     Vertex3Info.Text = (rayMeshResult.VertexWeight3 * 100) + "%";
 }
Ejemplo n.º 24
0
 public virtual BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     return BehaviourResult.NoSuccess;
 }
Ejemplo n.º 25
0
 public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
 }
Ejemplo n.º 26
0
        public override void Moved(
            RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
            if (hexVisual != null)
            {
                // make sure we are applying mouseovers only to sea hexes
                SeaHex seaHex = hexVisual.Hex as SeaHex;
                if (seaHex != null)
                {
                    // user has clicked a hex, and wants to set a port on a certain direction
                    if (_SelectedHex != null)
                    {
                        if (seaHex == _SelectedHex)
                        {
                            seaHex.XmlPort.PortType = _SelectedPortType;

                            // map the vertex to the RotationPosition
                            switch (rayMeshResult.VertexIndex3)
                            {
                                case 0: seaHex.XmlPort.PortPosition = ERotationPosition.Deg240; break;
                                case 1: seaHex.XmlPort.PortPosition = ERotationPosition.Deg180; break;
                                case 2: seaHex.XmlPort.PortPosition = ERotationPosition.Deg120; break;
                                case 3: seaHex.XmlPort.PortPosition = ERotationPosition.Deg60; break;
                                case 4: seaHex.XmlPort.PortPosition = ERotationPosition.Deg0; break;
                                case 5: seaHex.XmlPort.PortPosition = ERotationPosition.Deg300; break;
                            }
                        }
                    }
                    // user simply hovers over a hex
                    else
                    {
                        // user is removing ports, so only show mouseover when
                        // there is a port present
                        if (_SelectedPortType == EPortType.None &&
                            seaHex.XmlPort != null)
                        {
                            base.Moved(rayMeshResult, board);
                        }
                        // user is setting any other port type, so show mouseover
                        // on each seahex
                        if (_SelectedPortType != EPortType.None)
                        {
                            base.Moved(rayMeshResult, board);
                        }
                    }

                }
            }
        }
 private VideoSurface GetByHitTest(RayMeshGeometry3DHitTestResult result)
 {
     return this.videos.Where(v => v.ModelVisual3D == result.VisualHit as ModelVisual3D).First();
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Performs a 3D hit test. Point pt is a 2D point in viewport space. 
        /// The object needs to be a Viewport3D or a ModelVisual3D.
        /// </summary>
        public static RayMeshGeometry3DHitTestResult HitTest(object obj, Point pt)
        {
            hitTestResult = null;

            Viewport3D viewport = obj as Viewport3D;
            if (viewport != null)
            {
                VisualTreeHelper.HitTest(viewport, null, HitTestResultCallback, new PointHitTestParameters(pt));
            }
            else
            {
                ModelVisual3D model = obj as ModelVisual3D;
                if (model != null)
                {
                    Point3D ptNear, ptFar;
                    if (GetRay(pt, model, out ptNear, out ptFar))
                    {
                        RayHitTestParameters paras = new RayHitTestParameters(ptNear, ptFar - ptNear);
                        VisualTreeHelper.HitTest(model, null, HitTestResultCallback, paras);
                    }
                }
            }

            return hitTestResult;
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Performs hit testing for this cartoon mesh.
 /// </summary>
 /// <param name="rayHitTestResult">A 3D mesh hit test result from the WPF visual tree hit
 /// testing framework</param>
 /// <returns>
 /// True if the mesh hit belongs to this residue, otherwise false.
 /// </returns>
 internal bool HoverHitTest(RayMeshGeometry3DHitTestResult rayHitTestResult)
 {
     return this.model.Children.Contains(rayHitTestResult.ModelHit);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Performs hit testing for this atom.
 /// </summary>
 /// <param name="rayHitTestResult">A 3D mesh hit test result from the WPF visual tree hit
 /// testing framework</param>
 /// <returns>True if the mesh hit belongs to this atom, otherwise false.</returns>
 internal virtual bool HoverHitTest(RayMeshGeometry3DHitTestResult rayHitTestResult)
 {
     return (this.selectionModel == rayHitTestResult.ModelHit || (this.atomModel != null &&
         this.atomModel.Children.Contains(rayHitTestResult.ModelHit)));
 }
Ejemplo n.º 31
0
 public MyHitTestResult(RayMeshGeometry3DHitTestResult modelHit)
 {
     this.ModelHit = modelHit;
 }