private BindingVector3 Raycast(FRay ray, WCamera camera) { BindingVector3 selected_vec = null; List <BindingVector3> vecs_to_raycast = GetCameraVectorProperties(); List <Tuple <float, BindingVector3> > results = new List <Tuple <float, BindingVector3> >(); foreach (BindingVector3 bv in vecs_to_raycast) { FPlane plane = new FPlane(ray.Direction.Normalized(), bv.BackingVector); float dist = float.MaxValue; plane.RayIntersectsPlane(ray, out dist); Vector3 plane_intersect_point = camera.Transform.Position + (plane.Normal * dist); float distance_from_billboard_center = (plane_intersect_point - bv.BackingVector).Length; if (distance_from_billboard_center < 50.0f) { float point_dist = (camera.Transform.Position - bv.BackingVector).Length; results.Add(new Tuple <float, BindingVector3>(point_dist, bv)); } } results.Sort(delegate(Tuple <float, BindingVector3> x, Tuple <float, BindingVector3> y) { return(x.Item1.CompareTo(y.Item1)); }); if (results.Count > 0) { selected_vec = results[0].Item2; } return(selected_vec); }
public static Vector3 GetIntersectionRayPlane(FPlane plane, FRay ray) { Vector3 result; Vector3 planeNormal = new Vector3(plane.X, plane.Y, plane.Z); float timeParam = (plane.D + (Vector3.Dot(planeNormal, ray.StartPosition))) / Vector3.Dot(planeNormal, ray.Direction); result = ray.StartPosition + ray.Direction * timeParam; return(result); }
public static float GetDistanceFromPlaneToPoint(FPlane plane, Vector3 point) { Vector3 planeNormal = (Vector3)plane; float projectPointOnNormal = Vector3.Dot(planeNormal, point); float distance = projectPointOnNormal - plane.D; distance /= planeNormal.Length; return(distance); }
public readonly int iLightmassIndex; // Index to the lightmass settings public FBspSurf(FAssetArchive Ar) { Material = new FPackageIndex(Ar); PolyFlags = Ar.Read <uint>(); pBase = Ar.Read <int>(); vNormal = Ar.Read <int>(); vTextureU = Ar.Read <int>(); vTextureV = Ar.Read <int>(); iBrushPoly = Ar.Read <int>(); Actor = new FPackageIndex(Ar); Plane = Ar.Read <FPlane>(); LightMapScale = Ar.Read <float>(); iLightmassIndex = Ar.Read <int>(); }
private Vector3 GetTopBottomIntersectionPoint(Vector3 A, FPlane cbPlane, FPlane incidentPlane) { Vector3 result; Vector3 acNormal = new Vector3(incidentPlane.X, incidentPlane.Y, incidentPlane.Z); Vector3 acRayDirection = Vector3.Cross(acNormal, RightVector); Vector3 cbNormal = new Vector3(cbPlane.X, cbPlane.Y, cbPlane.Z); // if ac ray is opposite directed - invert it's direction acRayDirection *= Vector3.Dot(cbNormal, acRayDirection) > 0.0 ? 1 : -1; FRay acRay = new FRay(A, acRayDirection); result = GeometryMath.GetIntersectionRayPlane(cbPlane, acRay); return(result); }
public void Execute() { for (int index = 0; index < length; ++index) { int visible = 1; float2 distRadius = new float2(0, 0); ref FAABB sectorBound = ref sectorBounds[index]; for (int PlaneIndex = 0; PlaneIndex < 6; ++PlaneIndex) { ref FPlane plane = ref planes[PlaneIndex]; distRadius.x = math.dot(plane.normalDist.xyz, sectorBound.center) + plane.normalDist.w; distRadius.y = math.dot(math.abs(plane.normalDist.xyz), sectorBound.extents); visible = math.select(visible, 0, distRadius.x + distRadius.y < 0); }
public static bool IsPointIsidePlane(FPlane plane, Vector3 point, ConvexVolume.RelativePosition relativePosition) { bool bResult = false; float distancePointToPlane = GetDistanceFromPlaneToPoint(plane, point); if (relativePosition == ConvexVolume.RelativePosition.BEYOND_PLANE) { bResult = distancePointToPlane > 0.0f; } else if (relativePosition == ConvexVolume.RelativePosition.BEFORE_PLANE) { bResult = distancePointToPlane < 0.0f; } else { bResult = true; } return(bResult); }
/** * Checks whether two planes are equal within specified tolerance. * * @param V The other plane. * @param Tolerance Error Tolerance. * @return true if the two planes are equal within specified tolerance, otherwise false. */ public bool Equals(FPlane V, float Tolerance = Const.KINDA_SMALL_NUMBER) { return(FMath.Abs(X - V.X) < Tolerance && FMath.Abs(Y - V.Y) < Tolerance && FMath.Abs(Z - V.Z) < Tolerance && FMath.Abs(W - V.W) < Tolerance); }