/// <summary> /// Constructor. /// </summary> /// <param name="v">4D vector to set up plane.</param> public FPlane(FVector4 v) { X = v.X; Y = v.Y; Z = v.Z; W = v.W; }
/// <summary> /// Constructor /// </summary> /// <param name="vector">float vector converted to int</param> public FIntVector4(FVector4 vector) { X = FMath.TruncToInt(vector.X); Y = FMath.TruncToInt(vector.Y); Z = FMath.TruncToInt(vector.Z); W = FMath.TruncToInt(vector.W); }
/// <summary> /// Performs a linear interpolation between two values, Alpha ranges from 0-1 /// </summary> public static FVector4 LerpStable(FVector4 a, FVector4 b, float alpha) { return(new FVector4( FMath.LerpStable(a.X, b.X, alpha), FMath.LerpStable(a.Y, b.Y, alpha), FMath.LerpStable(a.Z, b.Z, alpha), FMath.LerpStable(a.W, b.W, alpha))); }
/// <summary> /// Transforms and projects a world bounding box to screen space /// </summary> /// <param name="projM">The projection matrix.</param> /// <returns>The transformed box.</returns> /// <see cref="TransformBy(FMatrix)"/> public FBox TransformProjectBy(FMatrix projM) { FVector[] vertices = new FVector[8] { Min, new FVector(Min.X, Min.Y, Max.Z), new FVector(Min.X, Max.Y, Min.Z), new FVector(Max.X, Min.Y, Min.Z), new FVector(Max.X, Max.Y, Min.Z), new FVector(Max.X, Min.Y, Max.Z), new FVector(Min.X, Max.Y, Max.Z), Max }; FBox newBox = default(FBox); for (int vertexIndex = 0; vertexIndex < vertices.Length; vertexIndex++) { FVector4 projectedVertex = projM.TransformPosition(vertices[vertexIndex]); newBox += ((FVector)projectedVertex) / projectedVertex.W; } return(newBox); }
/// <summary> /// Gets a bounding volume transformed by an inverted FTransform object. /// </summary> /// <param name="m">The transformation object to perform the inversely transform this box with.</param> /// <returns>The transformed box.</returns> public FBox InverseTransformBy(FTransform m) { FVector[] vertices = new FVector[8] { Min, new FVector(Min.X, Min.Y, Max.Z), new FVector(Min.X, Max.Y, Min.Z), new FVector(Max.X, Min.Y, Min.Z), new FVector(Max.X, Max.Y, Min.Z), new FVector(Max.X, Min.Y, Max.Z), new FVector(Min.X, Max.Y, Max.Z), Max }; FBox newBox = default(FBox); for (int vertexIndex = 0; vertexIndex < vertices.Length; vertexIndex++) { FVector4 projectedVertex = m.InverseTransformPosition(vertices[vertexIndex]); newBox += (FVector)projectedVertex; } return(newBox); }