GetDistance() public method

This is a pseudodistance. The sign of the return value is positive if the point is on the positive side of the plane, negative if the point is on the negative side, and zero if the point is on the plane. The absolute value of the return value is the true distance only when the plane normal is a unit length vector.
public GetDistance ( Axiom.Math.Vector3 point ) : Real
point Axiom.Math.Vector3
return Real
Ejemplo n.º 1
0
        /// <summary>
        ///		Intersection test with <see cref="Sphere"/>.
        /// </summary>
        /// <param name="sphere">Sphere to test.</param>
        /// <returns>True if the sphere intersects this volume, and false otherwise.</returns>
        public bool Intersects(Sphere sphere)
        {
            for (int i = 0; i < planes.Count; i++)
            {
                Plane plane = (Plane)planes[i];

                // Test which side of the plane the sphere is
                Real d = plane.GetDistance(sphere.Center);

                // Negate d if planes point inwards
                if (outside == PlaneSide.Negative)
                {
                    d = -d;
                }

                if ((d - sphere.Radius) > 0)
                {
                    return(false);
                }
            }

            // assume intersecting
            return(true);
        }
Ejemplo n.º 2
0
		protected bool CalculateForPointLight( Plane plane, Vector3[] vertices, out Vector2[] texCoors, out ColorEx[] colors )
		{
			texCoors = new Vector2[ vertices.Length ];
			colors = new ColorEx[ vertices.Length ];

			Vector3 lightPos, faceLightPos;

			lightPos = this.GetDerivedPosition();

			float dist = plane.GetDistance( lightPos );
			if ( Utility.Abs( dist ) < range )
			{
				// light is visible

				//light pos on face
				faceLightPos = lightPos - plane.Normal * dist;

				Vector3 verAxis = plane.Normal.Perpendicular();
				Vector3 horAxis = verAxis.Cross( plane.Normal );
				Plane verPlane = new Plane( verAxis, faceLightPos );
				Plane horPlane = new Plane( horAxis, faceLightPos );

				float lightRadiusSqr = range * range;
				float relRadiusSqr = lightRadiusSqr - dist * dist;
				float relRadius = Utility.Sqrt( relRadiusSqr );
				float scale = 0.5f / relRadius;

				float brightness = relRadiusSqr / lightRadiusSqr;
				ColorEx lightCol = new ColorEx( brightness * textureColor.a,
					textureColor.r, textureColor.g, textureColor.b );

				for ( int i = 0; i < vertices.Length; i++ )
				{
					texCoors[ i ].x = horPlane.GetDistance( vertices[ i ] ) * scale + 0.5f;
					texCoors[ i ].y = verPlane.GetDistance( vertices[ i ] ) * scale + 0.5f;
					colors[ i ] = lightCol;
				}

				return true;
			}

			return false;
		}