public Bounds3(Vector3f p1, Vector3f p2, Vector3f p3) { pMin = Vector3f.Min(Vector3f.Min(p1, p2), p3); pMax = Vector3f.Max(Vector3f.Max(p1, p2), p3); ExpandMargin(); }
public static uint CompressColor(Vector3 color, float alpha = 1.0f, bool average = true) { float multiplier = average ? 128.0f : 255.0f; color = Vector3.Max(new Vector3(), Vector3.Min(new Vector3(255.0f), color * multiplier + new Vector3(0.5f))); return(((uint)color.X) | (((uint)color.Y) << 8) | (((uint)color.Z) << 16) | ((uint)(MathC.Clamp(alpha, 0, 1) * 255.0f) << 24)); }
/// <summary> /// 并运算 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static Bounds3 Union(Bounds3 a, Vector3f b) { Bounds3 ret = new Bounds3(); ret.pMin = Vector3f.Min(a.pMin, b); ret.pMax = Vector3f.Max(a.pMax, b); return(ret); }
/// <summary> /// 判断光线与包围盒是否相交 /// </summary> /// <param name="ray"></param> /// <returns>是否相交,相交点到ray.d距离</returns> public (bool, float) Intersection(Ray ray) { Vector3f tmins = (pMin - ray.Origin) * ray.Direction_Inv; Vector3f tmaxs = (pMax - ray.Origin) * ray.Direction_Inv; float tmin = Tools.MaxElement(Vector3f.Min(tmins, tmaxs)); float tmax = Tools.MinElement(Vector3f.Max(tmins, tmaxs)); return(tmin < tmax, tmin); }
public static Vec3 Clamp(this Vec3 value, Vec3 min, Vec3 max) { return(Vec3.Max(min, Vec3.Min(max, value))); }