Cone.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /******************************************************************************
  2. Use 'Cone' to handle cone shapes.
  3. /******************************************************************************/
  4. struct Cone // Cone Shape
  5. {
  6. Flt r_low , // lower radius
  7. r_high; // higher radius
  8. Flt h ; // height
  9. Vec pos , // bottom position
  10. up ; // up direction
  11. // set
  12. Cone& set(Flt r_low, Flt r_high, Flt h, C Vec &pos=VecZero, C Vec &up=Vec(0,1,0)) {T.r_low=r_low; T.r_high=r_high; T.h=h; T.pos=pos; T.up=up; return T;}
  13. // get
  14. Flt area ()C; // get surface area
  15. Flt volume()C; // get volume
  16. Str asText()C {return S+"LowerRadius: "+r_low+", HigherRadius: "+r_high+", Height: "+h+", Pos: "+pos+", Up: "+up;} // get text description
  17. // transform
  18. Cone& operator+=(C Vec &v) {pos+=v; return T;}
  19. Cone& operator-=(C Vec &v) {pos-=v; return T;}
  20. Cone& operator*=( Flt f);
  21. Cone& operator/=( Flt f);
  22. Cone& operator*=(C Matrix3 &m);
  23. Cone& operator*=(C Matrix &m);
  24. friend Cone operator+ (C Cone &cone, C Vec &v){return Cone(cone)+=v;}
  25. friend Cone operator- (C Cone &cone, C Vec &v){return Cone(cone)-=v;}
  26. friend Cone operator* (C Cone &cone, Flt f){return Cone(cone)*=f;}
  27. friend Cone operator/ (C Cone &cone, Flt f){return Cone(cone)/=f;}
  28. friend Cone operator* (C Cone &cone, C Matrix3 &m){return Cone(cone)*=m;}
  29. friend Cone operator* (C Cone &cone, C Matrix &m){return Cone(cone)*=m;}
  30. // draw
  31. void draw(C Color &color=WHITE, Bool fill=false, Int resolution=-1)C; // this relies on active object matrix which can be set using 'SetMatrix' function
  32. Cone() {}
  33. Cone(Flt r_low, Flt r_high, Flt h, C Vec &pos=VecZero, C Vec &up=Vec(0,1,0)) {set(r_low, r_high, h, pos, up);}
  34. };
  35. /******************************************************************************/
  36. Bool Cuts(C Vec &point, C Cone &cone); // if point cuts cone
  37. /******************************************************************************/