You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.3KB

  1. #ifndef STK_SPHERE_H
  2. #define STK_SPHERE_H
  3. #include "Stk.h"
  4. #include "Vector3D.h"
  5. namespace stk {
  6. /***************************************************/
  7. /*! \class Sphere
  8. \brief STK sphere class.
  9. This class implements a spherical ball with
  10. radius, mass, position, and velocity parameters.
  11. by Perry R. Cook, 1995--2017.
  12. */
  13. /***************************************************/
  14. class Sphere : public Stk
  15. {
  16. public:
  17. //! Constructor taking an initial radius value.
  18. Sphere( StkFloat radius = 1.0 ) { radius_ = radius; mass_ = 1.0; };
  19. //! Set the 3D center position of the sphere.
  20. void setPosition( StkFloat x, StkFloat y, StkFloat z ) { position_.setXYZ(x, y, z); };
  21. //! Set the 3D velocity of the sphere.
  22. void setVelocity( StkFloat x, StkFloat y, StkFloat z ) { velocity_.setXYZ(x, y, z); };
  23. //! Set the radius of the sphere.
  24. void setRadius( StkFloat radius ) { radius_ = radius; };
  25. //! Set the mass of the sphere.
  26. void setMass( StkFloat mass ) { mass_ = mass; };
  27. //! Get the current position of the sphere as a 3D vector.
  28. Vector3D* getPosition( void ) { return &position_; };
  29. //! Get the relative position of the given point to the sphere as a 3D vector.
  30. Vector3D* getRelativePosition( Vector3D *position );
  31. //! Set the velocity of the sphere as a 3D vector.
  32. StkFloat getVelocity( Vector3D* velocity );
  33. //! Returns the distance from the sphere boundary to the given position (< 0 if inside).
  34. StkFloat isInside( Vector3D *position );
  35. //! Get the current sphere radius.
  36. StkFloat getRadius( void ) { return radius_; };
  37. //! Get the current sphere mass.
  38. StkFloat getMass( void ) { return mass_; };
  39. //! Increase the current sphere velocity by the given 3D components.
  40. void addVelocity( StkFloat x, StkFloat y, StkFloat z );
  41. //! Move the sphere for the given time increment.
  42. void tick( StkFloat timeIncrement );
  43. private:
  44. Vector3D position_;
  45. Vector3D velocity_;
  46. Vector3D workingVector_;
  47. StkFloat radius_;
  48. StkFloat mass_;
  49. };
  50. inline void Sphere::tick( StkFloat timeIncrement )
  51. {
  52. position_.setX(position_.getX() + (timeIncrement * velocity_.getX()));
  53. position_.setY(position_.getY() + (timeIncrement * velocity_.getY()));
  54. position_.setZ(position_.getZ() + (timeIncrement * velocity_.getZ()));
  55. };
  56. } // stk namespace
  57. #endif