Pyramid.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /******************************************************************************
  2. Use 'Pyramid' to handle pyramid shapes.
  3. /******************************************************************************/
  4. STRUCT(Pyramid , OrientP) // Pyramid Shape
  5. //{
  6. Flt scale, // proportional scale of side to height (0..Inf), default=1
  7. h ; // height
  8. // set
  9. Pyramid& set(Flt scale, Flt h, C Vec &pos=VecZero, C Vec &dir=Vec(0,1,0)) {T.scale=scale; T.h=h; setPosDir(pos, dir); return T;} // 'dir' must be normalized
  10. // transform
  11. Pyramid& operator*=( Flt f);
  12. Pyramid& operator/=( Flt f);
  13. Pyramid& operator*=(C Matrix3 &m);
  14. Pyramid& operator*=(C Matrix &m);
  15. friend Pyramid operator* (C Pyramid &pyramid, Flt f) {return Pyramid(pyramid)*=f;}
  16. friend Pyramid operator/ (C Pyramid &pyramid, Flt f) {return Pyramid(pyramid)/=f;}
  17. friend Pyramid operator* (C Pyramid &pyramid, C Matrix3 &m) {return Pyramid(pyramid)*=m;}
  18. friend Pyramid operator* (C Pyramid &pyramid, C Matrix &m) {return Pyramid(pyramid)*=m;}
  19. // get
  20. Flt side ()C {return scale*h*2;} // get pyramid side size
  21. Flt area ()C; // get surface area
  22. Flt volume()C; // get volume
  23. Str asText()C {return S+"Scale: "+scale+", Height: "+h+", Pos: "+pos+", Dir: "+dir;} // get text description
  24. void toCorners(Vec (&v)[5])C; // convert to 5 corner points, where v[0] is the pyramid tip, and v[1..4] are the pyramid base
  25. // draw
  26. void draw(Color color=WHITE, Bool fill=false)C; // this relies on active object matrix which can be set using 'SetMatrix' function
  27. Pyramid() {}
  28. Pyramid(Flt scale, Flt h, C Vec &pos=VecZero, C Vec &dir=Vec(0,1,0)) {set(scale, h, pos, dir);} // 'dir' must be normalized
  29. };
  30. /******************************************************************************/
  31. STRUCT(PyramidM , OrientM) // Pyramid Shape (mixed precision)
  32. //{
  33. Flt scale, // proportional scale of side to height (0..Inf), default=1
  34. h ; // height
  35. // set
  36. PyramidM& set(Flt scale, Flt h, C VecD &pos=0, C Vec &dir=Vec(0,1,0)) {T.scale=scale; T.h=h; setPosDir(pos, dir); return T;} // 'dir' must be normalized
  37. PyramidM() {}
  38. PyramidM(Flt scale, Flt h, C VecD &pos=0, C Vec &dir=Vec(0,1,0)) {set(scale, h, pos, dir);} // 'dir' must be normalized
  39. };
  40. /******************************************************************************/
  41. Bool Cuts(C Vec &point, C Pyramid &pyramid); // if point cuts a pyramid
  42. Bool Cuts(C VecD &point, C Pyramid &pyramid); // if point cuts a pyramid
  43. Bool Cuts(C VecD &point, C PyramidM &pyramid); // if point cuts a pyramid
  44. /******************************************************************************/