public static MatrixSingle CreateBillboard(Vector128 <float> objectPosition, Vector128 <float> cameraPosition, Vector128 <float> cameraUpVector, Vector128 <float> cameraForwardVector) { Vector128 <float> z = Vector.Subtract(objectPosition, cameraPosition); Vector128 <float> norm = LengthSquared3D(z); z = CompareLessThan(norm, BillboardEpsilon).AnyTrue() ? Vector.Negate(cameraForwardVector) : Multiply(z, Divide(SingleConstants.AllBitsSet, Sqrt(norm))); Vector128 <float> x = Normalize3D(Cross3D(cameraUpVector, z)); Vector128 <float> y = Cross3D(z, x); // We need W to be zero for x, y, and z, and 1.0f for objectPosition. They are currently undefined x = And(x, SingleConstants.MaskW); y = And(y, SingleConstants.MaskW); z = And(z, SingleConstants.MaskW); // Get objectPosition to be (X, Y, Z, 0) and the mask to be (0, 0, 0, 1.0f) and OR them Vector128 <float> newObjectPosition = And(objectPosition, SingleConstants.MaskW); newObjectPosition = Or(newObjectPosition, And(SingleConstants.MaskXYZ, SingleConstants.AllBitsSet)); return(new MatrixSingle(x, y, z, newObjectPosition)); }
public static Vec4 randInBox(Vec4 min, Vec4 max) { var extent = VecOps.Subtract(max, min); var randMult = create(s_rand.NextDouble(), s_rand.NextDouble(), s_rand.NextDouble(), s_rand.NextDouble()); var normalizedPt = VecOps.Multiply(extent, randMult); var shiftedPt = VecOps.Add(min, normalizedPt); return(shiftedPt); }
public static HwVector2 operator -(HwVector2 left, HwVector2 right) => Vector.Subtract(left, right);