ShaderMath.h 492 B

12345678910111213141516
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2025 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. // Calculate inValue^2
  5. inline float JPH_Square(float inValue)
  6. {
  7. return inValue * inValue;
  8. }
  9. // Get the closest point on a line segment defined by inA + x * inAB for x e [0, 1] to the origin
  10. inline float3 JPH_GetClosestPointOnLine(float3 inA, float3 inAB)
  11. {
  12. float v = clamp(-dot(inA, inAB) / dot(inAB, inAB), 0.0f, 1.0f);
  13. return inA + v * inAB;
  14. }