#include "PointMass.h"

PointMass::PointMass(const dms::Vector3& pos,float m)
    {
    mass_ = m;
    position_ = pos;
    velocity_.set(0,0,0);
    acceleration_.set(0,0,0);
    frozen_ = false;
    drag_ = 0;
    }


void PointMass::clearForces(void)
    {
    acceleration_.set(0,0,0);
    }


void PointMass::applyForce(const dms::Vector3& force)
    {
    if (mass_ != 0)
        acceleration_ += force / mass_;
    }


void PointMass::update(float dt)
    {
    if (frozen_)
        velocity_.set(0,0,0);
    else
        {
        applyForce(velocity_ * -drag_);
        velocity_ += acceleration_ * dt;
        position_ += velocity_ * dt;
        }
    }


void PointMass::freezePosition(void)
    {
    frozen_ = true;
    }


void PointMass::unfreezePosition(void)
    {
    frozen_ = false;
    }


void PointMass::setMass(float m)
    {
    mass_ = m;
    }


void PointMass::setPosition(const dms::Vector3& pos)
    {
    position_ = pos;
    }


void PointMass::setVelocity(const dms::Vector3& vel)
    {
    velocity_ = vel;
    }


void PointMass::setAcceleration(const dms::Vector3& acc)
    {
    acceleration_ = acc;
    }


void PointMass::setDrag(float d)
    {
    drag_ = d;
    }

