/// <summary>Gets the current intensity glow intensity, using the glow attenuation factor</summary> /// <param name="Vertices">The verticies to which the glow is to be applied</param> /// <param name="Face">The face which these vertices make up</param> /// <param name="GlowAttenuationData">The current glow attenuation</param> /// <param name="Camera">The camera position</param> /// <returns></returns> public static double GetDistanceFactor(VertexTemplate[] Vertices, ref MeshFace Face, ushort GlowAttenuationData, Vector3 Camera) { if (Face.Vertices.Length == 0) { return(1.0); } GlowAttenuationMode mode; double halfdistance; Glow.SplitAttenuationData(GlowAttenuationData, out mode, out halfdistance); int i = (int)Face.Vertices[0].Index; double dx = Vertices[i].Coordinates.X - Camera.X; double dy = Vertices[i].Coordinates.Y - Camera.Y; double dz = Vertices[i].Coordinates.Z - Camera.Z; switch (mode) { case GlowAttenuationMode.DivisionExponent2: { double t = dx * dx + dy * dy + dz * dz; return(t / (t + halfdistance * halfdistance)); } case GlowAttenuationMode.DivisionExponent4: { double t = dx * dx + dy * dy + dz * dz; t *= t; halfdistance *= halfdistance; return(t / (t + halfdistance * halfdistance)); } default: return(1.0); } }
/// <summary>Gets the current intensity glow intensity, using the glow attenuation factor</summary> /// <param name="ModelMatrix">The model transformation matrix to apply</param> /// <param name="Vertices">The verticies to which the glow is to be applied</param> /// <param name="Face">The face which these vertices make up</param> /// <param name="GlowAttenuationData">The current glow attenuation</param> /// <param name="mode">The returned glow attenuation mode</param> /// <returns></returns> public static double GetDistanceFactor(Matrix4D ModelMatrix, VertexTemplate[] Vertices, ref MeshFace Face, ushort GlowAttenuationData, out GlowAttenuationMode mode) { mode = GlowAttenuationMode.None; if (Face.Vertices.Length == 0) { return(1.0); } double halfdistance; Glow.SplitAttenuationData(GlowAttenuationData, out mode, out halfdistance); int i = (int)Face.Vertices[0].Index; Vector3 d = new Vector3(Vertices[i].Coordinates.X, Vertices[i].Coordinates.Y, -Vertices[i].Coordinates.Z); d.Transform(ModelMatrix); switch (mode) { case GlowAttenuationMode.DivisionExponent2: { double t = d.NormSquared(); return(t / (t + halfdistance * halfdistance)); } case GlowAttenuationMode.DivisionExponent4: { double t = d.NormSquared(); t *= t; halfdistance *= halfdistance; return(t / (t + halfdistance * halfdistance)); } default: return(1.0); } }
/// <summary>Gets the current intensity glow intensity, using the glow attenuation factor</summary> /// <param name="ModelMatrix">The model transformation matrix to apply</param> /// <param name="Vertices">The vertices to which the glow is to be applied</param> /// <param name="Face">The face which these vertices make up</param> /// <param name="GlowAttenuationData">The current glow attenuation</param> /// <returns></returns> public static double GetDistanceFactor(Matrix4D ModelMatrix, VertexTemplate[] Vertices, ref MeshFace Face, ushort GlowAttenuationData) { GlowAttenuationMode mode; return(GetDistanceFactor(ModelMatrix, Vertices, ref Face, GlowAttenuationData, out mode)); }