BVB Source Codes

CRYENGINE Show TransformHelpers.h Source code

Return Download CRYENGINE: download TransformHelpers.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #include <CryMath/Cry_Math.h>
  6.  
  7. namespace TransformHelpers
  8. {
  9. // Format of forwardUpAxes: "<signOfForwardAxis><forwardAxis><signOfUpAxis><upAxis>".
  10. // Example of forwardUpAxes: "-Y+Z".
  11. // Returns 0 if successful, or returns a pointer to an error message in case of an error.
  12. // In case of success: X axis in res represents "forward" direction,
  13. // Y axis represents "up" direction.
  14. inline const char* GetForwardUpAxesMatrix(Matrix33& res, const char* forwardUpAxes)
  15. {
  16.         Vec3 axisX(ZERO);
  17.         Vec3 axisY(ZERO);
  18.  
  19.         for (int i = 0; i < 2; ++i)
  20.         {
  21.                 Vec3& v = (i == 0) ? axisX : axisY;
  22.  
  23.                 const float val = forwardUpAxes[i * 2 + 0] == '-' ? -1.0f : +1.0f;
  24.  
  25.                 switch (forwardUpAxes[i * 2 + 1])
  26.                 {
  27.                 case 'X':
  28.                 case 'x':
  29.                         v.x = val;
  30.                         break;
  31.                 case 'Y':
  32.                 case 'y':
  33.                         v.y = val;
  34.                         break;
  35.                 case 'Z':
  36.                 case 'z':
  37.                         v.z = val;
  38.                         break;
  39.                 default:
  40.                         return "Found a bad axis character in forwardUpAxes string";
  41.                 }
  42.         }
  43.  
  44.         if (axisX == axisY)
  45.         {
  46.                 return "Forward and up axes are equal in forwardUpAxes string";
  47.         }
  48.  
  49.         const Vec3 axisZ = axisX.cross(axisY);
  50.  
  51.         res.SetFromVectors(axisX, axisY, axisZ);
  52.  
  53.         return 0;
  54. }
  55.  
  56. // Computes transform matrix that converts everything from forwardUpAxesSrc
  57. // coordinate system to forwardUpAxesDst coordinate system.
  58. // Format of forwardUpAxesXXX: "<signOfForwardAxis><forwardAxis><signOfUpAxis><upAxis>".
  59. // Example of forwardUpAxesXXX: "-Y+Z".
  60. // Returns 0 if successful, or returns a pointer to an error message in case of an error.
  61. // In case of success puts computed transform into res.
  62. // See comments to GetForwardUpAxesMatrix().
  63. inline const char* ComputeForwardUpAxesTransform(Matrix34& res, const char* forwardUpAxesSrc, const char* forwardUpAxesDst)
  64. {
  65.         Matrix33 srcToWorld;
  66.         Matrix33 dstToWorld;
  67.  
  68.         const char* const err0 = GetForwardUpAxesMatrix(srcToWorld, forwardUpAxesSrc);
  69.         const char* const err1 = GetForwardUpAxesMatrix(dstToWorld, forwardUpAxesDst);
  70.  
  71.         if (err0 || err1)
  72.         {
  73.                 return err0 ? err0 : err1;
  74.         }
  75.  
  76.         res = Matrix34(dstToWorld * srcToWorld.GetTransposed());
  77.  
  78.         return 0;
  79. }
  80.  
  81. inline Matrix34 ComputeOrthonormalMatrix(const Matrix34& m)
  82. {
  83.         Vec3 x = m.GetColumn0();
  84.         x.Normalize();
  85.  
  86.         Vec3 y = m.GetColumn1();
  87.  
  88.         Vec3 z = x.cross(y);
  89.         z.Normalize();
  90.  
  91.         y = z.cross(x);
  92.  
  93.         Matrix34 result;
  94.         result.SetFromVectors(x, y, z, m.GetTranslation());
  95.  
  96.         return result;
  97. }
  98. }
  99.  
downloadTransformHelpers.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top