Esempio n. 1
0
        public Vector3 getDesiredPositionDelta( Bounds targetBounds, Vector3 basePosition, Vector3 targetAvgVelocity )
        {
            var desiredOffset = Vector3.zero;
            var hasHorizontal = ( axis & CameraAxis.Horizontal ) == CameraAxis.Horizontal;
            var hasVertical = ( axis & CameraAxis.Vertical ) == CameraAxis.Vertical;
            var bounds = new Bounds( basePosition, new Vector3( width, height, 5f ) );

            if( !bounds.Contains( targetBounds.max ) || !bounds.Contains( targetBounds.min ) )
            {
                // figure out the minimum distance we need to move to get the player back in our bounds
                // x-axis
                if( hasHorizontal && bounds.min.x > targetBounds.min.x )
                {
                    desiredOffset.x = targetBounds.min.x - bounds.min.x;
                }
                else if( hasHorizontal && bounds.max.x < targetBounds.max.x )
                {
                    desiredOffset.x = targetBounds.max.x - bounds.max.x;
                }

                // y-axis. disregard movement above the trap when in platform snap mode
                if( hasVertical && bounds.min.y > targetBounds.min.y )
                {
                    desiredOffset.y = targetBounds.min.y - bounds.min.y;
                }
                else if( /*!inPlatformSnapMode &&*/ hasVertical && bounds.max.y < targetBounds.max.y )
                {
                    desiredOffset.y = targetBounds.max.y - bounds.max.y;
                }
            }

            return desiredOffset;
        }
        protected override void FixedUpdate()
        {
            base.FixedUpdate();

            _realDetectionBlock = DetectionBlock;
            _realDetectionBlock.center = DetectionBlock.center + this.transform.position;

            if (IsFreeToMove && !IsDead && !IsHurt) {

                if (!IsAttacking && !IsHurt && ValidateDetection()) {

                    if (AlwaysFollow) {
                        _following = true;
                    }

                    if (!IsAttacking && !IsHurt
                        && this.transform.position.x - RangeOfAttack <= ProtaController.transform.position.x
                        && this.transform.position.x + RangeOfAttack >= ProtaController.transform.position.x
                        && _realDetectionBlock.Contains(ProtaController.transform.position)) {

                        _delayToAttackCounter += Time.deltaTime;

                        if (_delayToAttackCounter >= DelayToAttack) {
                            if (!IsAttacking && !IsHurt && this.transform.position.x > ProtaController.transform.position.x) {
                                this.ChangePlayerDirection("left");
                                this.ChangePlayerState(PlayerState.Attacking);
                            } else if (!IsAttacking && !IsHurt) {
                                this.ChangePlayerDirection("right");
                                this.ChangePlayerState(PlayerState.Attacking);
                            }

                            _delayToAttackCounter = 0.0f;
                        } else {
                            this.ChangePlayerState(PlayerState.Idle);
                        }
                    } else if (!IsAttacking && !IsHurt && ( _realDetectionBlock.Contains(ProtaController.transform.position) || _following )) {
                        // At Left
                        if (!IsAttacking && !IsHurt && this.transform.position.x - RangeOfAttack > ProtaController.transform.position.x) {
                            this.HorizontalMovement("left");
                        } else if (!IsAttacking && !IsHurt && this.transform.position.x + RangeOfAttack < ProtaController.transform.position.x) {
                            this.HorizontalMovement("right");
                        } else {
                            this.ChangePlayerState(PlayerState.Idle);
                        }
                    } else if (!IsAttacking && !IsHurt) {
                        this.ChangePlayerState(PlayerState.Idle);
                    }
                } else if (!IsAttacking && !IsHurt) {
                    this.ChangePlayerState(PlayerState.Idle);
                }
            }
        }
 public static void setScope(Bounds pBounds, Transform pParent,NetworkPlayer pPlayer)
 {
     foreach (Transform lTransform in pParent)
     {
         lTransform.networkView.SetScope(pPlayer,pBounds.Contains(lTransform.position));
     }
 }
Esempio n. 4
0
    public static Vector3 BoundsInBoundsCheck( Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen)
    {
        Vector3 pos = lilB.center;
        Vector3 off = Vector3.zero;
        switch (test) {

        case BoundsTest.center:
            if (bigB.Contains(pos)){
                return(Vector3.zero);
            }

            if(pos.x > bigB.max.x){
                off.x = pos.x - bigB.max.x;
            } else if (pos.x < bigB.min.x){
                off.x = pos.x - bigB.min.x;
            }

            if(pos.y > bigB.max.y){
                off.y = pos.y - bigB.max.y;
            } else if (pos.y < bigB.min.y){
                off.y = pos.y - bigB.min.y;
            }

            if(pos.z > bigB.max.z){
                off.z = pos.z - bigB.max.z;
            } else if (pos.z < bigB.min.z){
                off.z = pos.z - bigB.min.z;
            }
            return(off);
        }
        return(Vector3.zero);
    }
    private List<Vector3> DynamicSetupList(float minX, float maxX, float minZ, float maxZ, Bounds bR, Bounds bM)
    {
        List<Vector3> checkList = new List<Vector3>();
        float Tilesize = Pathfinder.Instance.Tilesize;

        for (float i = minZ; i < maxZ; i += Tilesize / 2)
        {
            for (float j = minX; j < maxX; j += Tilesize / 2)
            {
                for (float k = bR.min.y; k < bR.max.y; k += Tilesize)
                {
                    if (k > lowestY)
                    {
                        Vector3 local = transform.InverseTransformPoint(new Vector3(j, k, i));

                        if (bM.Contains(local))
                        {
                            checkList.Add(new Vector3(j, k, i));
                        }
                    }
                }
            }
        }
        return checkList;
    }
 ZigTrackedUser LookForTrackedUserInRegion(ZigInput zig, Bounds region) {
     foreach (ZigTrackedUser trackedUser in zig.TrackedUsers.Values) {
         if (trackedUser.SkeletonTracked && region.Contains(trackedUser.Position) && trackedUser != leftTrackedUser && trackedUser != rightTrackedUser) {
             return trackedUser;
         }
     }
     return null;
 }
Esempio n. 7
0
        // Add fields here that your job needs to do its work.
        // For example,
        //    public float deltaTime;

        public void Execute(ref MoveTarget target, [ReadOnly] ref AIConstrain constrain, [ReadOnly] ref Translation translation)
        {
            UnityEngine.Bounds boundstest = new UnityEngine.Bounds(new float3(0), new float3(20));

            if (!boundstest.Contains(translation.Value))
            {
                target.Value += ((float3)boundstest.ClosestPoint(translation.Value) - translation.Value) * 10;
            }
        }
Esempio n. 8
0
 //Checks for containment first, then for intersection
 public static bool existsBetweenOrInside(Bounds box, Triangle3 triangle)
 {
     foreach (Vector3 p in triangle.ABC)
     {
         if(box.Contains(p))
             return true;
     }
     return existsBetween(box, triangle);
 }
Esempio n. 9
0
    // BoundsWithinPoints                                                                                      //
    // Cchecks if passed bounds contains either point (return false)                                           //
    // Then Fires rays between both points to check if the bounds are contained within both rays (return true) //
    public static bool BoundsWithinPoints( Vector3 point_a, Vector3 point_b, Bounds bounds )
    {
        // If the start or end point are within the object, do nothing
        if( bounds.Contains( point_a ) || bounds.Contains( point_b ) )
        {
            return false;
        }

        // If the object is fully on both rays
        Ray ray_forward = new Ray( point_a, point_b - point_a );
        Ray ray_backward = new Ray( point_b, point_a - point_b );
        if( bounds.IntersectRay( ray_forward ) && bounds.IntersectRay( ray_backward ))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
		public static bool AreaContainsClick(Bounds area , Vector2 mousePosition)
		{
			if (Input.GetMouseButton(0))
			{
				if (area.Contains(mousePosition))
				{
					return true;
				}
			}
			return false;
		}
        protected override void Update()
        {
            base.Update();

            if (EditorDebugMode) {
                if (!ShootAlways) {
                    DebugExtension.DebugBounds(_realDetectionBlock, Color.red);
                }
                DebugExtension.DebugBounds(_realShootRangeBlock, Color.green);
            }

            _realDetectionBlock = DetectionBlock;
            _realDetectionBlock.center = DetectionBlock.center + this.transform.position;
            _realShootRangeBlock = ShootRangeBlock;
            _realShootRangeBlock.center = ShootRangeBlock.center + this.transform.position;

            if (!IsDead && (ShootAlways || _realDetectionBlock.Contains(PlayerController.transform.position)) ) {

                _attackDelayCounter += Time.deltaTime;

                if (_attackDelayCounter >= AttackDelay) {

                    _attackDelayCounter = 0;
                    ChangePlayerState(PlayerState.Attacking);

                    if (ShootAtTarget) {
                        _BulletToSpawn = Instantiate(BulletToSpawn, this.transform.position + _upSpawnPosition, this.transform.rotation) as GameObject;
                        _BulletToSpawn.GetComponent<BulletController>().TargetPosition = PlayerController.transform.position;
                        _BulletToSpawn.GetComponent<BulletController>().SetVelocity();
                    } else {
                        if (!ChooseShootDirections || ShootLeft) {
                            _BulletToSpawn = Instantiate(BulletToSpawn, this.transform.position + _leftSpawnPosition, this.transform.rotation) as GameObject;
                            _BulletToSpawn.GetComponent<BulletController>().TargetPosition = new Vector2(_realShootRangeBlock.min.x, _BulletToSpawn.transform.position.y);
                            _BulletToSpawn.GetComponent<BulletController>().SetVelocity();
                        }

                        if (!ChooseShootDirections || ShootUp) {
                            _BulletToSpawn = Instantiate(BulletToSpawn, this.transform.position + _upSpawnPosition, this.transform.rotation) as GameObject;
                            _BulletToSpawn.GetComponent<BulletController>().TargetPosition = new Vector2(_BulletToSpawn.transform.position.x, _realShootRangeBlock.max.y);
                            _BulletToSpawn.GetComponent<BulletController>().SetVelocity();
                        }

                        if (!ChooseShootDirections || ShootRight) {
                            _BulletToSpawn = Instantiate(BulletToSpawn, this.transform.position + _rightSpawnPosition, this.transform.rotation) as GameObject;
                            _BulletToSpawn.GetComponent<BulletController>().TargetPosition = new Vector2(_realShootRangeBlock.max.x, _BulletToSpawn.transform.position.y);
                            _BulletToSpawn.GetComponent<BulletController>().SetVelocity();
                        }
                    }
                }
            }
        }
Esempio n. 12
0
 static public int Contains(IntPtr l)
 {
     try{
         UnityEngine.Bounds  self = (UnityEngine.Bounds)checkSelf(l);
         UnityEngine.Vector3 a1;
         checkType(l, 2, out a1);
         System.Boolean ret = self.Contains(a1);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Esempio n. 13
0
 public override Vector3 GetPosition(MBParticle PT)
 {
     int runs = 0;
     Bounds r = new Bounds(Vector3.zero,Scale);
     Vector3 hrs=Scale;
     hrs.Scale(Hollow);
     Bounds hr = new Bounds(Vector3.zero, hrs);
     Vector3 v = Vector3.zero;
     while (runs++ < 100) {
         v.x = Random.Range(r.min.x, r.max.x);
         v.y = Random.Range(r.min.y, r.max.y);
         v.z = Random.Range(r.min.z, r.max.z);
         if (!hr.Contains(v))
             return v;
     }
     return new Vector3(r.min.x, r.min.y, r.min.z);
 }
    public void ApplyForce(Transform transObj, float maxForce = 1, float radius = 0)
    {
        //radius = 0;
        //Debug.Log("Cube hit!");

        var b = new Bounds(FinalPosition, transform.localScale);
        b.Expand(radius * 2);

        // Why does radius need to be multiplied by 2?
        //var falloffBounds =new Bounds( new Bounds(FinalPosition, transform.localScale + (Vector3.one * Falloff) + (Vector3.one * radius * 2));

        var falloffBounds = new Bounds(FinalPosition, transform.localScale);
        falloffBounds.Expand(radius * 2 + Falloff * 2);
        if (falloffBounds.Contains(transObj.position))
        {
            //Debug.Log("Object in falloff");

            // inside the obstacle!
            if (b.Contains(transObj.position))
            {
                //Debug.Log("Object has enter bounds!");

                transObj.position = GetClosestBorderFromInsidePoint(b, transObj.position, 0.01f);
            }
            // in the fallout area
            else
            {
                var falloutClosePoint = falloffBounds.ClosestPoint(transObj.position);
                Helpers.DrawDebugPoint(falloutClosePoint, 1, Color.cyan);

                var objClosePoint = b.ClosestPoint(transObj.position);
                Helpers.DrawDebugPoint(objClosePoint, 1, Color.magenta);

                Debug.DrawLine(falloutClosePoint, objClosePoint, Color.yellow);

                var mag = (falloutClosePoint - objClosePoint).magnitude;

                var frac = Mathf.Max(1 - mag / Falloff, 0);

                //Debug.Log("mag = " + mag + " (" + frac + ")");

                var forceVector = (falloutClosePoint - objClosePoint).normalized * frac * maxForce;
                transObj.position += forceVector * Time.deltaTime;
            }
        }
    }
Esempio n. 15
0
	void FixedUpdate(){
		Vector3 delta = _player.transform.position - transform.position;
			
		if(delta.x > targetDistance.x || delta.x < -targetDistance.x){
			if(movementEnabled){
				delta.Normalize();
				_unit.Move(delta.x);
			}
		}

		if(!movementEnabled){
			Bounds bounds = new Bounds(transform.position, wakeDistance);
			if(bounds.Contains(_player.transform.position)){
				movementEnabled = true;
			}
		}
	}
Esempio n. 16
0
    void Update()
    {
        if (Vector3.Distance(transform.position, currentTarget) <= 0.1)
        {
            Vector3 newTarget = getNewPosition();
            while (!bounds.Contains(newTarget))
            {
                newTarget = getNewPosition();
            }
            currentTarget = newTarget;
        }

        Vector3    newPosition = Vector3.MoveTowards(transform.position, currentTarget, speed * Time.deltaTime);
        Quaternion newRotation = Quaternion.LookRotation(currentTarget.normalized) * transform.rotation;

        transform.position = newPosition;
        transform.rotation = Quaternion.FromToRotation(transform.up, currentTarget) * transform.rotation;
    }
Esempio n. 17
0
    public static Vector2 ClosestPoint(Bounds bounds, Vector2 point) {
        if (bounds.Contains(point)) {
            return point;
        } else {
            float x = point.x;
            float y = point.y;

            if (x < bounds.min.x) {
                x = bounds.min.x;
            } else if (x > bounds.max.x) {
                x = bounds.max.x;
            }

            if (y < bounds.min.y) {
                y = bounds.min.y;
            } else if (y > bounds.max.y) {
                y = bounds.max.y;
            }

            return new Vector2(x, y);
        }
    }
 public void updateScope(Bounds pBounds)
 {
     //Scope Transform中的子物体
     foreach (Transform lNetworkPlayerRoot in networkPlayerRoots)
     {
         setScope(pBounds, lNetworkPlayerRoot, networkPlayer);
     }
     //Scope 自定义物体
     var lNetworkViewNode = networkViewList.First;
     while (lNetworkViewNode != null)
     {
         var lNetworkView = lNetworkViewNode.Value;
         var lNextNode = lNetworkViewNode.Next;
         if (lNetworkView)
         {
             lNetworkView.SetScope(networkPlayer,
                 pBounds.Contains(lNetworkView.transform.position));
         }
         else
             networkViewList.Remove(lNetworkViewNode);
         lNetworkViewNode = lNextNode;
     }
 }
Esempio n. 19
0
		public bool OnSceneGUI(Matrix4x4 transform, Color boxColor, Color midPointHandleColor, bool handlesOnly, ref Vector3 center, ref Vector3 size)
		{
			bool flag = GUIUtility.hotControl == this.m_HandleControlID;
			if (!this.m_AlwaysDisplayHandles && !flag)
			{
				for (int i = 0; i < 6; i++)
				{
					GUIUtility.GetControlID(this.m_ControlIdHint, FocusType.Keyboard);
				}
				return false;
			}
			Color color = Handles.color;
			Handles.color = boxColor;
			Vector3 b = center - size * 0.5f;
			Vector3 a = center + size * 0.5f;
			Matrix4x4 matrix = Handles.matrix;
			Handles.matrix = transform;
			int hotControl = GUIUtility.hotControl;
			if (!handlesOnly)
			{
				this.DrawWireframeBox(center, size);
			}
			Vector3 point = transform.inverse.MultiplyPoint(Camera.current.transform.position);
			Bounds bounds = new Bounds(center, size);
			bool isCameraInsideBox = bounds.Contains(point);
			Handles.color = midPointHandleColor;
			this.MidpointHandles(ref b, ref a, Handles.matrix, isCameraInsideBox);
			if (hotControl != GUIUtility.hotControl && GUIUtility.hotControl != 0)
			{
				this.m_HandleControlID = GUIUtility.hotControl;
			}
			bool changed = GUI.changed;
			if (changed)
			{
				center = (a + b) * 0.5f;
				size = a - b;
			}
			Handles.color = color;
			Handles.matrix = matrix;
			return changed;
		}
Esempio n. 20
0
 public bool Hit(Transform target, Bounds bounds) {
     return (bounds.Contains(target.position));
 }
Esempio n. 21
0
    // Checks to see whether Bounds lilB are within Bounds bigB
    public static Vector3 BoundsInBoundsCheck( Bounds bigB, Bounds lilB,
	                                          BoundsTest test = BoundsTest.onScreen )
    {
        // The behavior of this function is different based on the BoundsTest
        // that has been selected.
        // Get the center of lilB
        Vector3 pos = lilB.center;
        // Initialize the offset at [0,0,0]
        Vector3 off = Vector3.zero;
        switch (test) {
            // The center test determines what off (offset) would have to be applied
            // to lilB to move its center back inside bigB
        case BoundsTest.center:
            if ( bigB.Contains( pos ) ) {
                return( Vector3.zero );
            }
            if (pos.x > bigB.max.x) {
                off.x = pos.x - bigB.max.x;
            } else if (pos.x < bigB.min.x) {
                off.x = pos.x - bigB.min.x;
            }
            if (pos.y > bigB.max.y) {
                off.y = pos.y - bigB.max.y;
            } else if (pos.y < bigB.min.y) {
                off.y = pos.y - bigB.min.y;
            }
            if (pos.z > bigB.max.z) {
                off.z = pos.z - bigB.max.z;
            } else if (pos.z < bigB.min.z) {
                off.z = pos.z - bigB.min.z;
            }
            return( off );
            // The onScreen test determines what off would have to be applied to
            // keep all of lilB inside bigB
        case BoundsTest.onScreen:
            if ( bigB.Contains( lilB.min ) && bigB.Contains( lilB.max ) ) {
                return( Vector3.zero );
            }
            if (lilB.max.x > bigB.max.x) {
                off.x = lilB.max.x - bigB.max.x;
            } else if (lilB.min.x < bigB.min.x) {
                off.x = lilB.min.x - bigB.min.x;
            }
            if (lilB.max.y > bigB.max.y) {
                off.y = lilB.max.y - bigB.max.y;
            } else if (lilB.min.y < bigB.min.y) {
                off.y = lilB.min.y - bigB.min.y;
            }
            if (lilB.max.z > bigB.max.z) {
                off.z = lilB.max.z - bigB.max.z;
            } else if (lilB.min.z < bigB.min.z) {
                off.z = lilB.min.z - bigB.min.z;
            }
            return( off );
            // The offScreen test determines what off would need to be applied to
            // move any tiny part of lilB inside of bigB
        case BoundsTest.offScreen:
            bool cMin = bigB.Contains( lilB.min );
            bool cMax = bigB.Contains( lilB.max );
            if ( cMin || cMax ) {
                return( Vector3.zero );
            }
            if (lilB.min.x > bigB.max.x) {
                off.x = lilB.min.x - bigB.max.x;
            } else if (lilB.max.x < bigB.min.x) {
                off.x = lilB.max.x - bigB.min.x;
            }
            if (lilB.min.y > bigB.max.y) {
                off.y = lilB.min.y - bigB.max.y;
            } else if (lilB.max.y < bigB.min.y) {
                off.y = lilB.max.y - bigB.min.y;
            }
            if (lilB.min.z > bigB.max.z) {
                off.z = lilB.min.z - bigB.max.z;
            } else if (lilB.max.z < bigB.min.z) {
                off.z = lilB.max.z - bigB.min.z;
            }
            return( off );
        }
        return( Vector3.zero );
    }
Esempio n. 22
0
	/// <summary>
	/// Calculates the influence velocities for the drone. We do this in one big loop for efficiency.
	/// </summary>
	protected virtual void CalculateVelocities()
	{
		// the general procedure is that we add up velocities based on the neighbors in our radius for a particular influence (cohesion, separation, etc.) 
		// and divide the sum by the total number of drones in our neighbor radius
		// this produces an evened-out velocity that is aligned with its neighbors to apply to the target drone		
		Vector3 separationSum = Vector3.zero;
		Vector3 alignmentSum = Vector3.zero;
		Vector3 cohesionSum = Vector3.zero;
		Vector3 boundsSum = Vector3.zero;

		int separationCount = 0;
		int alignmentCount = 0;
		int cohesionCount = 0;
		int boundsCount = 0;

		for (int i = 0; i < this.drones.Count; i++)
		{
			if (drones[i] == null) continue;

			float distance = Vector3.Distance(transform.position, drones[i].transform.position);

			// separation
			// calculate separation influence velocity for this drone, based on its preference to keep distance between itself and neighboring drones
			if (distance > 0 && distance < desiredSeparation)
			{
				// calculate vector headed away from myself
				Vector3 direction = transform.position - drones[i].transform.position;	
				direction.Normalize();
				direction = direction / distance; // weight by distance
				separationSum += direction;
				separationCount++;
			}

			// alignment & cohesion
			// calculate alignment influence vector for this drone, based on its preference to be aligned with neighboring drones
			// calculate cohesion influence vector for this drone, based on its preference to be close to neighboring drones
			if (distance > 0 && distance < neighborRadius)
			{
				alignmentSum += drones[i].rigidbody.velocity;
				alignmentCount++;

				cohesionSum += drones[i].transform.position;
				cohesionCount++;
			}

			// bounds
			// calculate the bounds influence vector for this drone, based on whether or not neighboring drones are in bounds
			Bounds bounds = new Bounds(swarm.transform.position, new Vector3(swarm.swarmBounds.x, 10000f, swarm.swarmBounds.y));
			if (distance > 0 && distance < neighborRadius && !bounds.Contains(drones[i].transform.position))
			{
				Vector3 diff = transform.position - swarm.transform.position;
				if (diff.magnitude> 0)
				{
					boundsSum += swarm.transform.position;
					boundsCount++;
				}
			}
		}

		// end
		_separation = separationCount > 0 ? separationSum / separationCount : separationSum;
		_alignment = alignmentCount > 0 ? Limit(alignmentSum / alignmentCount, maxSteer) : alignmentSum;
		_cohesion = cohesionCount > 0 ? Steer(cohesionSum / cohesionCount, false) : cohesionSum;
		_bounds = boundsCount > 0 ? Steer(boundsSum / boundsCount, false) : boundsSum;
	}
Esempio n. 23
0
		/** All nodes inside the shape or if null, the bounding box.
		 * If a shape is supplied, it is assumed to be contained inside the bounding box.
		 * \see GraphUpdateShape.GetBounds
		 */
		private List<GraphNode> GetNodesInArea (Bounds b, GraphUpdateShape shape) {
			if (nodes == null || width*depth != nodes.Length) {
				return null;
			}

			// Get a buffer we can use
			List<GraphNode> inArea = Pathfinding.Util.ListPool<GraphNode>.Claim();

			// Take the bounds and transform it using the matrix
			// Then convert that to a rectangle which contains
			// all nodes that might be inside the bounds
			Vector3 min, max;
			GetBoundsMinMax(b, inverseMatrix, out min, out max);

			int minX = Mathf.RoundToInt(min.x-0.5F);
			int maxX = Mathf.RoundToInt(max.x-0.5F);

			int minZ = Mathf.RoundToInt(min.z-0.5F);
			int maxZ = Mathf.RoundToInt(max.z-0.5F);

			var originalRect = new IntRect(minX, minZ, maxX, maxZ);

			// Rect which covers the whole grid
			var gridRect = new IntRect(0, 0, width-1, depth-1);

			// Clamp the rect to the grid
			var rect = IntRect.Intersection(originalRect, gridRect);

			// Loop through all nodes in the rectangle
			for (int x = rect.xmin; x <= rect.xmax; x++) {
				for (int z = rect.ymin; z <= rect.ymax; z++) {
					int index = z*width+x;

					GraphNode node = nodes[index];

					// If it is contained in the bounds (and optionally the shape)
					// then add it to the buffer
					if (b.Contains((Vector3)node.position) && (shape == null || shape.Contains((Vector3)node.position))) {
						inArea.Add(node);
					}
				}
			}

			return inArea;
		}
Esempio n. 24
0
    // Checks to see whether a smaller object is inside a bigger object.
    public static Vector3 BoundsInBoundsCheck( Bounds bigB, Bounds lilB, BoundsTest test =
	                                          BoundsTest.onScreen )
    {
        Vector3 pos = lilB.center;
        Vector3 off = Vector3.zero;
        switch (test) {

        case BoundsTest.center: // What offset to move lilB into bigB
            if ( bigB.Contains( pos ) ) {
                return( Vector3.zero );
            }
            if (pos.x > bigB.max.x) {
                off.x = pos.x - bigB.max.x;
            } else if (pos.x < bigB.min.x) {
                off.x = pos.x - bigB.min.x;
            }
            if (pos.y > bigB.max.y) {
                off.y = pos.y - bigB.max.y;
            } else if (pos.y < bigB.min.y) {
                off.y = pos.y - bigB.min.y;
            }
            if (pos.z > bigB.max.z) {
                off.z = pos.z - bigB.max.z;
            } else if (pos.z < bigB.min.z) {
                off.z = pos.z - bigB.min.z;
            }
            return( off );

        case BoundsTest.onScreen: //What offset keep all of lilB inside bigB
            if ( bigB.Contains( lilB.min ) && bigB.Contains( lilB.max ) ) {
                return( Vector3.zero );
            }
            if (lilB.max.x > bigB.max.x) {
                off.x = lilB.max.x - bigB.max.x;
            } else if (lilB.min.x < bigB.min.x) {
                off.x = lilB.min.x - bigB.min.x;
            }
            if (lilB.max.y > bigB.max.y) {
                off.y = lilB.max.y - bigB.max.y;
            } else if (lilB.min.y < bigB.min.y) {
                off.y = lilB.min.y - bigB.min.y;
            }
            if (lilB.max.z > bigB.max.z) {
                off.z = lilB.max.z - bigB.max.z;
            } else if (lilB.min.z < bigB.min.z) {
                off.z = lilB.min.z - bigB.min.z;
            }
            return( off );

        case BoundsTest.offScreen: //What offset move any tiny part of lilB inside of bigB
            bool cMin = bigB.Contains( lilB.min );
            bool cMax = bigB.Contains( lilB.max );
            if ( cMin || cMax ) {
                return( Vector3.zero );
            }
            if (lilB.min.x > bigB.max.x) {
                off.x = lilB.min.x - bigB.max.x;
            } else if (lilB.max.x < bigB.min.x) {
                off.x = lilB.max.x - bigB.min.x;
            }
            if (lilB.min.y > bigB.max.y) {
                off.y = lilB.min.y - bigB.max.y;
            } else if (lilB.max.y < bigB.min.y) {
                off.y = lilB.max.y - bigB.min.y;
            }
            if (lilB.min.z > bigB.max.z) {
                off.z = lilB.min.z - bigB.max.z;
            } else if (lilB.max.z < bigB.min.z) {
                off.z = lilB.max.z - bigB.min.z;
            }
            return( off );
        }
        return( Vector3.zero );
    }
Esempio n. 25
0
    // Checks to see if bounds lilb are within Bounds bigB
    public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen)
    {
        // behavior needs to be different depending on the test selected

        Vector3 pos = lilB.center;		// use center for measurement
        Vector3 off = Vector3.zero;		// offset is 0,0,0 to start

        switch (test) {
            // what is offset to move center of lilB back inside bigB
            case BoundsTest.center:
            // trivial case - we are already inside
            if (bigB.Contains(pos)) {
                return (Vector3.zero);   //no need to move
            }

            //otherwise adjust x,y,z components as needed
            if(pos.x > bigB.max.x) {
                off.x = pos.x - bigB.max.x;
            } else if (pos.x < bigB.min.x) {
                off.x = pos.x - bigB.min.x;
            }

            if(pos.y > bigB.max.y) {
                off.y = pos.y - bigB.max.y;
            } else if (pos.y < bigB.min.y) {
                off.y = pos.y - bigB.min.y;
            }

            if(pos.z > bigB.max.z) {
                off.z = pos.z - bigB.max.z;
            } else if (pos.z < bigB.min.z) {
                off.z = pos.z - bigB.min.z;
            }

            return (off);

            //-------------------------
            // what is the offset to keep ALL of lilB inside bigB
            case BoundsTest.onScreen:
            // trivial case - we are already inside
            if (bigB.Contains(lilB.max) && bigB.Contains(lilB.min)) {
                return (Vector3.zero);   //no need to move
            }

            if(lilB.max.x > bigB.max.x) {
                off.x = lilB.max.x - bigB.max.x;
            } else if (lilB.min.x < bigB.min.x) {
                off.x = lilB.min.x - bigB.min.x;
            }

            if(lilB.max.y > bigB.max.y) {
                off.y = lilB.max.y - bigB.max.y;
            } else if (lilB.min.y < bigB.min.y) {
                off.y = lilB.min.y - bigB.min.y;
            }

            if(lilB.max.z > bigB.max.z) {
                off.z = lilB.max.z - bigB.max.z;
            } else if (lilB.min.z < bigB.min.z) {
                off.z = lilB.min.z - bigB.min.z;
            }

            return (off);

            //-------------------------
            // what is the offset to keep ALL of lilB outside of bigB
            case BoundsTest.offScreen:
            bool cMin = bigB.Contains(lilB.min);
            bool cMax = bigB.Contains(lilB.max);

            if (cMin || cMax) {
                return (Vector3.zero);
            }

            if(lilB.min.x > bigB.max.x) {
                off.x = lilB.min.x - bigB.max.x;
            } else if (lilB.max.x < bigB.min.x) {
                off.x = lilB.max.x - bigB.min.x;
            }

            if(lilB.min.y > bigB.max.y) {
                off.y = lilB.min.y - bigB.max.y;
            } else if (lilB.max.y < bigB.min.y) {
                off.y = lilB.max.y - bigB.min.y;
            }

            if(lilB.min.z > bigB.max.z) {
                off.z = lilB.min.z - bigB.max.z;
            } else if (lilB.max.z < bigB.min.z) {
                off.z = lilB.max.z - bigB.min.z;
            }

            return (off);
        } // end switch BoundsTest

        return (Vector3.zero);  // if we get here something went wrong
    }
Esempio n. 26
0
// methods

    static bool Bounds_Contains__Vector3(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.Vector3 arg0    = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
            UnityEngine.Bounds  argThis = (UnityEngine.Bounds)vc.csObj;                JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(argThis.Contains(arg0)));
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
Esempio n. 27
0
    // Tests to see whether lilB is inside bigB
    public static Vector3 BoundsInBoundsCheck( Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen )
    {
        // Get the center of lilB
        Vector3 pos = lilB.center;

        // Initialize the offset at [0,0,0]
        Vector3 off = Vector3.zero;

        switch (test) {
        // The center test determines what off (offset) would have to be applied to lilB to move its center back inside bigB
        case BoundsTest.center:
            // if the center is contained, return Vector3.zero
            if ( bigB.Contains( pos ) ) {
                return( Vector3.zero );
            }
            // if not contained, find the offset
            if (pos.x > bigB.max.x) {
                off.x = pos.x - bigB.max.x;
            } else  if (pos.x < bigB.min.x) {
                off.x = pos.x - bigB.min.x;
            }
            if (pos.y > bigB.max.y) {
                off.y = pos.y - bigB.max.y;
            } else  if (pos.y < bigB.min.y) {
                off.y = pos.y - bigB.min.y;
            }
            if (pos.z > bigB.max.z) {
                off.z = pos.z - bigB.max.z;
            } else  if (pos.z < bigB.min.z) {
                off.z = pos.z - bigB.min.z;
            }
            return( off );

        // The onScreen test determines what off would have to be applied to keep all of lilB inside bigB
        case BoundsTest.onScreen:
            // find whether bigB contains all of lilB
            if ( bigB.Contains( lilB.min ) && bigB.Contains( lilB.max ) ) {
                return( Vector3.zero );
            }
            // if not, find the offset
            if (lilB.max.x > bigB.max.x) {
                off.x = lilB.max.x - bigB.max.x;
            } else  if (lilB.min.x < bigB.min.x) {
                off.x = lilB.min.x - bigB.min.x;
            }
            if (lilB.max.y > bigB.max.y) {
                off.y = lilB.max.y - bigB.max.y;
            } else  if (lilB.min.y < bigB.min.y) {
                off.y = lilB.min.y - bigB.min.y;
            }
            if (lilB.max.z > bigB.max.z) {
                off.z = lilB.max.z - bigB.max.z;
            } else  if (lilB.min.z < bigB.min.z) {
                off.z = lilB.min.z - bigB.min.z;
            }
            return( off );

        // The offScreen test determines what off would need to be applied to move any tiny part of lilB inside of bigB
        case BoundsTest.offScreen:
            // find whether bigB contains any of lilB
            bool cMin = bigB.Contains( lilB.min );
            bool cMax = bigB.Contains( lilB.max );
            if ( cMin || cMax ) {
                return( Vector3.zero );
            }
            // if not, find the offset
            if (lilB.min.x > bigB.max.x) {
                off.x = lilB.min.x - bigB.max.x;
            } else  if (lilB.max.x < bigB.min.x) {
                off.x = lilB.max.x - bigB.min.x;
            }
            if (lilB.min.y > bigB.max.y) {
                off.y = lilB.min.y - bigB.max.y;
            } else  if (lilB.max.y < bigB.min.y) {
                off.y = lilB.max.y - bigB.min.y;
            }
            if (lilB.min.z > bigB.max.z) {
                off.z = lilB.min.z - bigB.max.z;
            } else  if (lilB.max.z < bigB.min.z) {
                off.z = lilB.max.z - bigB.min.z;
            }
            return( off );

        }

        return( Vector3.zero );
    }
Esempio n. 28
0
    public static float MinDistanceToAABB(Vector3 vec, Vector3 pMin, Vector3 pMax)
    {
        var b = new Bounds();
        b.SetMinMax(pMin, pMax);

        // inside?
        if (b.Contains(vec)) return 0f;
        else return Mathf.Sqrt(b.SqrDistance(vec));
    }
Esempio n. 29
0
    public bool Raycast(UnityEngine.Ray ray)
    {
        var bounds = new UnityEngine.Bounds();

        bounds.SetMinMax(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(_sizeX * 16, _sizeY * 16, _sizeZ * 16));

        // if we're outside world bounds, first intersect the world's bounding box
        if (!bounds.Contains(ray.origin))
        {
            float dist;
            if (!bounds.IntersectRay(ray, out dist))
            {
                return(false);
            }
            ray.origin += ray.direction * dist;
        }
        // inside or at world edge, time to voxel trace

        // From "A Fast Voxel Traversal Algorithm for Ray Tracing"
        // by John Amanatides and Andrew Woo, 1987
        // <http://www.cse.yorku.ca/~amana/research/grid.pdf>
        // <http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.42.3443>

        // initialize to initial voxel coordinate
        // TODO verify that this works reliable even if we started outside the world bounds
        int x = Mathf.FloorToInt(ray.origin.x);
        int y = Mathf.FloorToInt(ray.origin.y);
        int z = Mathf.FloorToInt(ray.origin.z);

        // TODO determine initial distances to voxel edges
        float tMaxX = intbound(ray.origin.x, ray.direction.x);
        float tMaxY = intbound(ray.origin.y, ray.direction.y);
        float tMaxZ = intbound(ray.origin.z, ray.direction.z);

        // determine stepping direction
        int stepX = (int)Mathf.Sign(ray.direction.x);
        int stepY = (int)Mathf.Sign(ray.direction.y);
        int stepZ = (int)Mathf.Sign(ray.direction.z);

        // determine distance (in ray units) between voxel edges
        float tDeltaX = stepX / ray.direction.x;
        float tDeltaY = stepY / ray.direction.y;
        float tDeltaZ = stepZ / ray.direction.z;

        int wx = _sizeX * 16;
        int wy = _sizeY * 16;
        int wz = _sizeZ * 16;

        while (
            (stepX > 0 ? x < wx : x >= 0) &&
            (stepY > 0 ? y < wy : y >= 0) &&
            (stepZ > 0 ? z < wz : z >= 0))
        {
            // lalala
            // TODO WE NOW HAVE A VOXEL AT X,Y,Z

            // walk...
            if (tMaxX < tMaxY)
            {
                if (tMaxX < tMaxZ)
                {
                    x     += stepX;
                    tMaxX += tDeltaX;
                }
                else
                {
                    z     += stepZ;
                    tMaxZ += tDeltaZ;
                }
            }
            else
            {
                if (tMaxY < tMaxZ)
                {
                    y     += stepY;
                    tMaxY += tDeltaY;
                }
                else
                {
                    z     += stepZ;
                    tMaxZ += tDeltaZ;
                }
            }
        }


        return(false);
    }
    void CheckSessionStart(Vector3 point, ZigJointId joint)
    {
        if (InSession) { Debug.Log("CheckSessionStart when already in session, leaving"); return; }

        Vector3 boundsCenter = (RotateToUser) ? RotateHandPoint(trackedUser.Position) : trackedUser.Position;
        boundsCenter += SessionBoundsOffset;
        currentSessionBounds = new Bounds(boundsCenter, SessionBounds);
        Vector3 fp = (RotateToUser) ? RotateHandPoint(point) : point;
        if (currentSessionBounds.Contains(fp)) {
            focusPoint = fp;
            jointInSession = joint;
            InSession = true;
            OnSessionStart(fp);
        }
    }
    public void MoveToSpaceCell(int d)
    {
        AAgent a = AttachedAgent;
        List<AAgent> list = a.World.AllAgents.Where(x => IsInRange(a, x, d)).ToList();
        LimitedWorld lw = a.World.GetComponent<LimitedWorld>();
        Bounds b = new Bounds();
        if(lw)
            b = lw.Bound;

        List<Vector3> candidates = new List<Vector3>();
        for(int x=-d;x<=d;x++){
            for(int y=-d;y<=d;y++){
                for(int z=-d;z<=d;z++){
                    Vector3 v = ToGrid(new Vector3(x, y, z)+transform.position);
                    if(lw){
                        if(b.Contains(v)){
                            candidates.Add(v);
                        }
                    }else{
                        candidates.Add(v);
                    }
                }
            }
        }
        foreach(AAgent agent in list){
            Vector3 p = ToGrid(agent.transform.position);
            candidates.Remove(p);
        }
        candidates.Remove(transform.position);
        candidates = candidates.OrderBy(x => Vector3.Distance(transform.position, x)).ToList();

        if(candidates.Count > 0)
            Position = candidates[0];
    }
Esempio n. 32
0
		/** All nodes inside the shape or if null, the bounding box.
		 * If a shape is supplied, it is assumed to be contained inside the bounding box.
		 * \see GraphUpdateShape.GetBounds
		 */
		private List<GraphNode> GetNodesInArea (Bounds b, GraphUpdateShape shape) {
			
			if (nodes == null || width*depth != nodes.Length) {
				return null;
			}
			
			List<GraphNode> inArea = Pathfinding.Util.ListPool<GraphNode>.Claim ();
			
			Vector3 min, max;
			GetBoundsMinMax (b,inverseMatrix,out min, out max);
			
			int minX = Mathf.RoundToInt (min.x-0.5F);
			int maxX = Mathf.RoundToInt (max.x-0.5F);
			
			int minZ = Mathf.RoundToInt (min.z-0.5F);
			int maxZ = Mathf.RoundToInt (max.z-0.5F);
			
			IntRect originalRect = new IntRect(minX,minZ,maxX,maxZ);
			IntRect gridRect = new IntRect(0,0,width-1,depth-1);
			
			IntRect rect = IntRect.Intersection (originalRect, gridRect);
			
			for (int x = rect.xmin; x <= rect.xmax;x++) {
				for (int z = rect.ymin;z <= rect.ymax;z++) {
					
					int index = z*width+x;
					
					GraphNode node = nodes[index];
					
					if (b.Contains ((Vector3)node.position) && (shape == null || shape.Contains ((Vector3)node.position))) {
						inArea.Add (node);
					}
				}
			}
			
			return inArea;
		}
        void enableShielding()
        {
            // print("enableShielding()");
            disableShielding();

            var attached=getFairingParams();
            if (!sideFairing) return;

            // get all parts in range
            var parts=new List<Part>();
            var colliders=Physics.OverlapSphere(part.transform.TransformPoint(lookupCenter), lookupRad, 1);
            for (int i=colliders.Length-1; i>=0; --i)
            {
              var p=colliders[i].gameObject.GetComponentUpwards<Part>();
              if (p!=null) parts.AddUnique(p);
            }
            // print("got "+parts.Count+" nearby parts");

            // filter parts
            float sizeSqr=lookupRad*lookupRad*4;
            float boundCylRadSq=boundCylRad*boundCylRad;

            bool isInline = (sideFairing.inlineHeight>0);
            bool topClosed=false;

            Matrix4x4 w2l=Matrix4x4.identity, w2lb=Matrix4x4.identity;
            Bounds topBounds=default(Bounds);

            if (isInline)
            {
              w2l=part.transform.worldToLocalMatrix;
              w2lb=w2l;
              for (int i=0; i<3; ++i)
            for (int j=0; j<3; ++j)
              w2lb[i, j]=Mathf.Abs(w2lb[i, j]);

              topBounds=new Bounds(new Vector3(0, boundCylY1, 0), Vector3.one*(sideFairing.topRad*2));
            }

            for (int pi=0; pi<parts.Count; ++pi)
            {
              var pt=parts[pi];

              // check special cases
              if (pt==part) { shieldedParts.Add(pt); continue; }

              bool isSide=false;
              for (int i=0; i<attached.Length; ++i) if (attached[i].attachedPart==pt) { isSide=true; break; }
              if (isSide) continue;

              // print("checking part "+pt.partName+" "+pt.partInfo.title);

              // check if the top is closed in the inline case
              var bounds=pt.GetRendererBounds();
              var box=PartGeometryUtil.MergeBounds(bounds, pt.partTransform);

              if (isInline && !topClosed && pt.vessel==vessel)
              {
            var wb=box; wb.Expand(sideFairing.sideThickness*4);
            var b=new Bounds(w2l.MultiplyPoint3x4(wb.center), w2lb.MultiplyVector(wb.size));
            if (b.Contains(topBounds.min) && b.Contains(topBounds.max)) topClosed=true;
              }

              // check if too big to fit
              // if (box.size.sqrMagnitude>sizeSqr) continue;

              // check if the centroid is within fairing bounds
              var c=part.transform.InverseTransformPoint(PartGeometryUtil.FindBoundsCentroid(bounds, null));

              float y=c.y;
              if (y<boundCylY0 || y>boundCylY1) continue;

              float xsq=new Vector2(c.x, c.z).sqrMagnitude;
              if (xsq>boundCylRadSq) continue;

              // accurate centroid check
              float x=Mathf.Sqrt(xsq);
              bool inside=false;

              for (int i=1; i<shape.Length; ++i)
              {
            var p0=shape[i-1];
            var p1=shape[i];
            if (p0.y>p1.y) { var p=p0; p0=p1; p1=p; }

            if (y<p0.y || y>p1.y) continue;

            float dy=p1.y-p0.y, r;
            if (dy<=1e-6f) r=(p0.x+p1.x)*0.5f;
            else r=(p1.x-p0.x)*(y-p0.y)/dy+p0.x;

            if (x>r) continue;

            inside=true;
            break;
              }

              if (!inside) continue;

              shieldedParts.Add(pt);
              // print("shielded "+pt.partName);
            }

            if (isInline && !topClosed) { disableShielding(); return; }

            // add shielding
            for (int i=0; i<shieldedParts.Count; ++i)
              shieldedParts[i].AddShield(this);

            numShieldedDisplay=shieldedParts.Count;

            var fbase=part.GetComponent<ProceduralFairingBase>();
            if (fbase!=null) fbase.onShieldingEnabled(shieldedParts);
        }
Esempio n. 34
0
        /// <summary>
        /// Updates the graph during runtime adding or removing the waypoints associated with this starbase.
        /// The method determines add/remove based on whether the starbase has previously been recorded.
        /// </summary>
        /// <param name="baseCmd">The Starbase command.</param>
        public void UpdateGraph(StarbaseCmdItem baseCmd) {
            List<GraphUpdateObject> guos = null;
            if (_starbaseGuos.TryGetValue(baseCmd, out guos)) {
                // this base is being removed
                guos.ForAll(guo => guo.RevertFromBackup()); // reverses the node changes made when base was added
                _starbaseGuos.Remove(baseCmd);
            }
            else {
                // base is being added

                guos = new List<GraphUpdateObject>(2);

                // First, make surrounding waypoints walkable (includes base/sector position which is already walkable)
                var baseSector = SectorGrid.Instance.GetSector(baseCmd.SectorIndex);
                D.Assert(Mathfx.Approx(baseSector.Position, baseCmd.Position, .01F));   // base should be in center of sector
                float baseSectorCenterApproachWaypointDistanceWithBuffer = (baseSector.Radius * SectorItem.CenterApproachWaypointDistanceMultiplier) + 1F;
                Vector3 sectorCenterApproachWaypointAreaSize = Vector3.one * baseSectorCenterApproachWaypointDistanceWithBuffer;

                var sectorCenterApproachWaypointWalkableGuo = new GraphUpdateObject(new Bounds(baseCmd.Position, sectorCenterApproachWaypointAreaSize)) {
                    modifyWalkability = true,
                    setWalkability = true,
                    updatePhysics = true,       // default
                    trackChangedNodes = true,   // allows RevertFromBackup
                    requiresFloodFill = true    // default  // OPTIMIZE
                };
                active.UpdateGraphs(sectorCenterApproachWaypointWalkableGuo);
                guos.Add(sectorCenterApproachWaypointWalkableGuo);

                // Now, create GUO that makes the base/sector position node unwalkable
                float baseRadius = baseCmd.Data.CloseOrbitOuterRadius;
                Vector3 baseUnwalkableAreaSize = Vector3.one * baseRadius;
                Bounds baseUnwalkableBounds = new Bounds(baseCmd.Position, baseUnwalkableAreaSize);
                D.Log("{0} Unwalkable Bounds {1} contains {2} = {3}.", baseCmd.FullName, baseUnwalkableBounds, baseCmd.Position, baseUnwalkableBounds.Contains(baseCmd.Position));
                GraphUpdateObject baseUnwalkableGuo = new GraphUpdateObject(baseUnwalkableBounds) {
                    modifyWalkability = true,
                    setWalkability = false,     // default
                    updatePhysics = true,       // default
                    trackChangedNodes = true,   // allows RevertFromBackup
                    requiresFloodFill = true    // default  // OPTIMIZE
                };
                active.UpdateGraphs(baseUnwalkableGuo);
                guos.Add(baseUnwalkableGuo);

                _starbaseGuos.Add(baseCmd, guos);
            }
        }
Esempio n. 35
0
    public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen)
    {
        Vector3 pos = lilB.center;
        Vector3 off = Vector3.zero;

        switch (test) {
        case BoundsTest.center:
            if (bigB.Contains (pos)) {
                return Vector3.zero;
            }

            if (pos.x > bigB.max.x) {
                off.x = pos.x - bigB.max.x;
            } else if (pos.x < bigB.min.x) {
                off.x = pos.x - bigB.min.x;
            }

            if (pos.y > bigB.max.y) {
                off.y = pos.y - bigB.max.y;
            } else if (pos.y < bigB.min.y) {
                off.y = pos.y - bigB.min.y;
            }

            if (pos.z > bigB.max.z) {
                off.z = pos.z - bigB.max.z;
            } else if (pos.z < bigB.min.z) {
                off.z = pos.z - bigB.min.z;
            }

            return (off);
        case BoundsTest.onScreen:
            if (bigB.Contains (lilB.min) && bigB.Contains (lilB.max)) {
                return Vector3.zero;
            }

            if (lilB.max.x > bigB.max.x) {
                off.x = lilB.max.x - bigB.max.x;
            } else if (lilB.min.x < bigB.min.x) {
                off.x = lilB.min.x - bigB.min.x;
            }

            if (lilB.max.y > bigB.max.y) {
                off.y = lilB.max.y - bigB.max.y;
            } else if (lilB.min.y < bigB.min.y) {
                off.y = lilB.min.y - bigB.min.y;
            }

            if (lilB.max.z > bigB.max.z) {
                off.z = lilB.max.z - bigB.max.z;
            } else if (lilB.min.z < bigB.min.z) {
                off.z = lilB.min.z - bigB.min.z;
            }
            return off;

        case BoundsTest.offScreen:
            bool cMin = bigB.Contains (lilB.min);
            bool cMax = bigB.Contains (lilB.max);

            if (cMax || cMin) {
                return Vector3.zero;
            }

            if (lilB.min.x > bigB.max.x) {
                off.x = lilB.min.x - bigB.max.x;
            } else if (lilB.max.x < bigB.min.x) {
                off.x = lilB.max.x - bigB.min.x;
            }

            if (lilB.min.y > bigB.max.y) {
                off.y = lilB.min.y - bigB.max.y;
            } else if (lilB.max.y < bigB.min.y) {
                off.y = lilB.max.y - bigB.min.y;
            }

            if (lilB.min.z > bigB.max.z) {
                off.z = lilB.min.z - bigB.max.z;
            } else if (lilB.max.z < bigB.min.z) {
                off.z = lilB.max.z - bigB.min.z;
            }
            return off;

        }
        return Vector3.zero;
    }