2
0

IceHPoint.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include "../Opcode.h"
  27. using namespace IceMaths;
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  29. // Point Mul = HPoint * Matrix3x3;
  30. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  31. Point HPoint::operator*(const Matrix3x3& mat) const
  32. {
  33. return Point(
  34. x * mat.m[0][0] + y * mat.m[1][0] + z * mat.m[2][0],
  35. x * mat.m[0][1] + y * mat.m[1][1] + z * mat.m[2][1],
  36. x * mat.m[0][2] + y * mat.m[1][2] + z * mat.m[2][2] );
  37. }
  38. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  39. // HPoint Mul = HPoint * Matrix4x4;
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. HPoint HPoint::operator*(const Matrix4x4& mat) const
  42. {
  43. return HPoint(
  44. x * mat.m[0][0] + y * mat.m[1][0] + z * mat.m[2][0] + w * mat.m[3][0],
  45. x * mat.m[0][1] + y * mat.m[1][1] + z * mat.m[2][1] + w * mat.m[3][1],
  46. x * mat.m[0][2] + y * mat.m[1][2] + z * mat.m[2][2] + w * mat.m[3][2],
  47. x * mat.m[0][3] + y * mat.m[1][3] + z * mat.m[2][3] + w * mat.m[3][3]);
  48. }
  49. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. // HPoint *= Matrix4x4
  51. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  52. HPoint& HPoint::operator*=(const Matrix4x4& mat)
  53. {
  54. float xp = x * mat.m[0][0] + y * mat.m[1][0] + z * mat.m[2][0] + w * mat.m[3][0];
  55. float yp = x * mat.m[0][1] + y * mat.m[1][1] + z * mat.m[2][1] + w * mat.m[3][1];
  56. float zp = x * mat.m[0][2] + y * mat.m[1][2] + z * mat.m[2][2] + w * mat.m[3][2];
  57. float wp = x * mat.m[0][3] + y * mat.m[1][3] + z * mat.m[2][3] + w * mat.m[3][3];
  58. x = xp; y = yp; z = zp; w = wp;
  59. return *this;
  60. }