Arduino STK  4.6.2
Sphere.h
1 #ifndef STK_SPHERE_H
2 #define STK_SPHERE_H
3 
4 #include "Stk.h"
5 #include "Vector3D.h"
6 
7 namespace stk {
8 
9 /***************************************************/
18 /***************************************************/
19 
20 class Sphere : public Stk
21 {
22 public:
24  Sphere( StkFloat radius = 1.0 ) { radius_ = radius; mass_ = 1.0; };
25 
27  void setPosition( StkFloat x, StkFloat y, StkFloat z ) { position_.setXYZ(x, y, z); };
28 
30  void setVelocity( StkFloat x, StkFloat y, StkFloat z ) { velocity_.setXYZ(x, y, z); };
31 
33  void setRadius( StkFloat radius ) { radius_ = radius; };
34 
36  void setMass( StkFloat mass ) { mass_ = mass; };
37 
39  Vector3D* getPosition( void ) { return &position_; };
40 
43 
45  StkFloat getVelocity( Vector3D* velocity );
46 
48  StkFloat isInside( Vector3D *position );
49 
51  StkFloat getRadius( void ) { return radius_; };
52 
54  StkFloat getMass( void ) { return mass_; };
55 
57  void addVelocity( StkFloat x, StkFloat y, StkFloat z );
58 
60  void tick( StkFloat timeIncrement );
61 
62 private:
63  Vector3D position_;
64  Vector3D velocity_;
65  Vector3D workingVector_;
66  StkFloat radius_;
67  StkFloat mass_;
68 };
69 
70 inline void Sphere::tick( StkFloat timeIncrement )
71 {
72  position_.setX(position_.getX() + (timeIncrement * velocity_.getX()));
73  position_.setY(position_.getY() + (timeIncrement * velocity_.getY()));
74  position_.setZ(position_.getZ() + (timeIncrement * velocity_.getZ()));
75 };
76 
77 } // stk namespace
78 
79 #endif
STK sphere class.
Definition: Sphere.h:21
StkFloat isInside(Vector3D *position)
Returns the distance from the sphere boundary to the given position (< 0 if inside).
StkFloat getRadius(void)
Get the current sphere radius.
Definition: Sphere.h:51
void setMass(StkFloat mass)
Set the mass of the sphere.
Definition: Sphere.h:36
void addVelocity(StkFloat x, StkFloat y, StkFloat z)
Increase the current sphere velocity by the given 3D components.
StkFloat getVelocity(Vector3D *velocity)
Set the velocity of the sphere as a 3D vector.
Vector3D * getRelativePosition(Vector3D *position)
Get the relative position of the given point to the sphere as a 3D vector.
Sphere(StkFloat radius=1.0)
Constructor taking an initial radius value.
Definition: Sphere.h:24
Vector3D * getPosition(void)
Get the current position of the sphere as a 3D vector.
Definition: Sphere.h:39
StkFloat getMass(void)
Get the current sphere mass.
Definition: Sphere.h:54
void setRadius(StkFloat radius)
Set the radius of the sphere.
Definition: Sphere.h:33
void setVelocity(StkFloat x, StkFloat y, StkFloat z)
Set the 3D velocity of the sphere.
Definition: Sphere.h:30
void setPosition(StkFloat x, StkFloat y, StkFloat z)
Set the 3D center position of the sphere.
Definition: Sphere.h:27
void tick(StkFloat timeIncrement)
Move the sphere for the given time increment.
Definition: Sphere.h:70
STK base class.
Definition: Stk.h:144
STK 3D vector class.
Definition: Vector3D.h:20
void setXYZ(StkFloat x, StkFloat y, StkFloat z)
Set the X, Y, and Z values simultaniously.
Definition: Vector3D.h:39
void setZ(StkFloat z)
Set the Z value.
Definition: Vector3D.h:48
void setY(StkFloat y)
Set the Y value.
Definition: Vector3D.h:45
void setX(StkFloat x)
Set the X value.
Definition: Vector3D.h:42
StkFloat getX(void)
Get the current X value.
Definition: Vector3D.h:27
StkFloat getZ(void)
Get the current Z value.
Definition: Vector3D.h:33
StkFloat getY(void)
Get the current Y value.
Definition: Vector3D.h:30
The STK namespace.
Definition: ADSR.h:8