Ejemplo n.º 1
0
        public static void AddWall(AbstractTerrainObject selectedObject, Ray ray)
        {
            if (selectedObject != null)
            {
                Vector3?wallAnchor = VoxelRaycastUtility.GetNearestWallAnchor(VoxelRaycastUtility.GetNearestCollisionFace(selectedObject.GetCollisionFaces(), ray), ray);

                if (wallAnchor != null)
                {
                    Vector3 anchor = (Vector3)wallAnchor;

                    if (TEMP_secondWallPoint == null)
                    {
                        if (TEMP_firstWallPoint == null)//If no existing point
                        {
                            TEMP_firstWallPoint = anchor;
                        }
                        else if ((Vector3)TEMP_firstWallPoint != anchor)//If current point = existing point
                        {
                            //NOTE: Check that second point is within range of first
                            TEMP_secondWallPoint = new Vector3(anchor.X, ((Vector3)TEMP_firstWallPoint).Y, anchor.Z);//Ensure that both points have same Y value
                        }
                    }

                    if (TEMP_secondWallPoint != null)
                    {
                        if (Math.Abs(((Vector3)TEMP_firstWallPoint).X - ((Vector3)anchor).X) <= 1 &&
                            Math.Abs(((Vector3)TEMP_firstWallPoint).Z - ((Vector3)anchor).Z) <= 1 &&
                            ((Vector3)TEMP_firstWallPoint).Y == ((Vector3)anchor).Y)
                        {
                            TEMP_secondWallPoint = anchor;
                        }
                        else
                        {
                            //Check that second point is within range of first
                            if (Math.Abs(((Vector3)TEMP_firstWallPoint).X - ((Vector3)TEMP_secondWallPoint).X) <= 1 &&
                                Math.Abs(((Vector3)TEMP_firstWallPoint).Z - ((Vector3)TEMP_secondWallPoint).Z) <= 1 &&
                                ((Vector3)TEMP_firstWallPoint).Y == ((Vector3)TEMP_secondWallPoint).Y)
                            {
                                for (int i = 1; i <= TEMP_WallHeight; i++)
                                {
                                    ChunkManager.GetInstance().AddWall((Vector3)TEMP_firstWallPoint + new Vector3(0, i - 1, 0), (Vector3)TEMP_secondWallPoint + new Vector3(0, i - 1, 0));
                                }
                            }
                            TEMP_firstWallPoint  = TEMP_secondWallPoint;
                            TEMP_secondWallPoint = null;
                        }
                    }
                }
            }
        }
        public override void OnClick(InputState input)
        {
            //Attempt to place the first point of the wall
            Ray?mouseRay = input.GetMouseRay();

            if (mouseRay != null)
            {
                AbstractWorldObject selectedObject = VoxelRaycastUtility.GetNearestIntersectingWorldObject((Ray)mouseRay);

                if (selectedObject != null)
                {
                    Vector3?wallAnchor = VoxelRaycastUtility.GetNearestWallAnchor(VoxelRaycastUtility.GetNearestCollisionFace(selectedObject.GetCollisionFaces(), (Ray)mouseRay), (Ray)mouseRay);

                    if (wallAnchor != null)
                    {
                        Vector3 anchor = (Vector3)wallAnchor;


                        //Add anchor to start of collection of wall points...
                    }
                }
            }
        }