eastNorthUpToEyeCoordinates.glsl 1.7 KB

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Computes a 3x3 rotation matrix that transforms vectors from an ellipsoid's east-north-up coordinate system
  3. * to eye coordinates. In east-north-up coordinates, x points east, y points north, and z points along the
  4. * surface normal. East-north-up can be used as an ellipsoid's tangent space for operations such as bump mapping.
  5. * <br /><br />
  6. * The ellipsoid is assumed to be centered at the model coordinate's origin.
  7. *
  8. * @name czm_eastNorthUpToEyeCoordinates
  9. * @glslFunction
  10. *
  11. * @param {vec3} positionMC The position on the ellipsoid in model coordinates.
  12. * @param {vec3} normalEC The normalized ellipsoid surface normal, at <code>positionMC</code>, in eye coordinates.
  13. *
  14. * @returns {mat3} A 3x3 rotation matrix that transforms vectors from the east-north-up coordinate system to eye coordinates.
  15. *
  16. * @example
  17. * // Transform a vector defined in the east-north-up coordinate
  18. * // system, (0, 0, 1) which is the surface normal, to eye
  19. * // coordinates.
  20. * mat3 m = czm_eastNorthUpToEyeCoordinates(positionMC, normalEC);
  21. * vec3 normalEC = m * vec3(0.0, 0.0, 1.0);
  22. */
  23. mat3 czm_eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC)
  24. {
  25. vec3 tangentMC = normalize(vec3(-positionMC.y, positionMC.x, 0.0)); // normalized surface tangent in model coordinates
  26. vec3 tangentEC = normalize(czm_normal3D * tangentMC); // normalized surface tangent in eye coordiantes
  27. vec3 bitangentEC = normalize(cross(normalEC, tangentEC)); // normalized surface bitangent in eye coordinates
  28. return mat3(
  29. tangentEC.x, tangentEC.y, tangentEC.z,
  30. bitangentEC.x, bitangentEC.y, bitangentEC.z,
  31. normalEC.x, normalEC.y, normalEC.z);
  32. }