/lib/ode/ode_source/OPCODE/Ice/IceHPoint.cpp

http://narutortsproject.googlecode.com/ · C++ · 70 lines · 26 code · 9 blank · 35 comment · 0 complexity · 250794010d246a5ed9e7c071285689a5 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. /**
  3. * Contains code for homogeneous points.
  4. * \file IceHPoint.cpp
  5. * \author Pierre Terdiman
  6. * \date April, 4, 2000
  7. */
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. /**
  11. * Homogeneous point.
  12. *
  13. * Use it:
  14. * - for clipping in homogeneous space (standard way)
  15. * - to differentiate between points (w=1) and vectors (w=0).
  16. * - in some cases you can also use it instead of Point for padding reasons.
  17. *
  18. * \class HPoint
  19. * \author Pierre Terdiman
  20. * \version 1.0
  21. * \warning No cross-product in 4D.
  22. * \warning HPoint *= Matrix3x3 doesn't exist, the matrix is first casted to a 4x4
  23. */
  24. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  26. // Precompiled Header
  27. #include "Stdafx.h"
  28. using namespace IceMaths;
  29. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  30. // Point Mul = HPoint * Matrix3x3;
  31. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  32. Point HPoint::operator*(const Matrix3x3& mat) const
  33. {
  34. return Point(
  35. x * mat.m[0][0] + y * mat.m[1][0] + z * mat.m[2][0],
  36. x * mat.m[0][1] + y * mat.m[1][1] + z * mat.m[2][1],
  37. x * mat.m[0][2] + y * mat.m[1][2] + z * mat.m[2][2] );
  38. }
  39. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  40. // HPoint Mul = HPoint * Matrix4x4;
  41. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42. HPoint HPoint::operator*(const Matrix4x4& mat) const
  43. {
  44. return HPoint(
  45. x * mat.m[0][0] + y * mat.m[1][0] + z * mat.m[2][0] + w * mat.m[3][0],
  46. x * mat.m[0][1] + y * mat.m[1][1] + z * mat.m[2][1] + w * mat.m[3][1],
  47. x * mat.m[0][2] + y * mat.m[1][2] + z * mat.m[2][2] + w * mat.m[3][2],
  48. x * mat.m[0][3] + y * mat.m[1][3] + z * mat.m[2][3] + w * mat.m[3][3]);
  49. }
  50. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. // HPoint *= Matrix4x4
  52. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  53. HPoint& HPoint::operator*=(const Matrix4x4& mat)
  54. {
  55. float xp = x * mat.m[0][0] + y * mat.m[1][0] + z * mat.m[2][0] + w * mat.m[3][0];
  56. float yp = x * mat.m[0][1] + y * mat.m[1][1] + z * mat.m[2][1] + w * mat.m[3][1];
  57. float zp = x * mat.m[0][2] + y * mat.m[1][2] + z * mat.m[2][2] + w * mat.m[3][2];
  58. float wp = x * mat.m[0][3] + y * mat.m[1][3] + z * mat.m[2][3] + w * mat.m[3][3];
  59. x = xp; y = yp; z = zp; w = wp;
  60. return *this;
  61. }