/* Author     : Josh Grant
*/

#include <SoParticle.h>

// When creating an SoParticle type the velocity is always initialized to
// zero and the SoTransform and SoSphere are all added to the
// root node "this".
SoParticle::SoParticle() {

  velocity  = SbVec3f(0.0, 0.0, 0.0);
  
  transform = new SoTransform();
  sphere    = new SoSphere();

  this->addChild(transform);
  this->addChild(sphere);
}

SoParticle::~SoParticle() {
  this->removeAllChildren();
}

// Set the radius of the sphere to rad
void SoParticle::setRadius(float rad) {
  radius = rad;
  sphere->radius = radius;
}

// Set the location (or translation) of the sphere to loc
void SoParticle::setLocation(const SbVec3f &loc) {
  location = loc;
  transform->translation.setValue(location);
}

// Returns the current value of the sphere's radius
float SoParticle::getRadius() {
  return radius.getValue();
}

// Returns the current value of the sphere's location
SbVec3f &SoParticle::getLocation() {
  return location;
}

// When called the location of the sphere is updated by simply adding the
// velocity to the current location.
void SoParticle::moveParticle() {
  location += velocity;
  transform->translation.setValue(location);
}
