00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
#ifndef OPENCAL_SPRING_H
00012
#define OPENCAL_SPRING_H
00013
00014
00015
#include <OpenCAL/global.h>
00016
#include <OpenCAL/Force.h>
00017
00018
namespace OpenCAL
00019 {
00020
00021
class PhysicalObject;
00022
00026 class OPENCAL_API Spring:
public Force
00027 {
00028
protected:
00029
00030
PhysicalObject *m_object1, *m_object2;
00031
float m_stiffness, m_damping;
00032
float m_restLength, m_snapFactor;
00033
00034
public:
00035
00036 Spring(
PhysicsSystem *parent,
PhysicalObject *object1 = 0,
PhysicalObject *object2 = 0);
00037
virtual ~Spring();
00038
00039
00040
const PhysicalObject *getObject1()
const {
return m_object1; }
00041
PhysicalObject *getObject1() {
return m_object1; }
00042
const PhysicalObject *getObject2()
const {
return m_object2; }
00043
PhysicalObject *getObject2() {
return m_object2; }
00044
float getStiffness()
const {
return m_stiffness; }
00045
float getDamping()
const {
return m_damping; }
00046
float getRestLength()
const {
return m_restLength; }
00047
float getSnapFactor()
const {
return m_snapFactor; }
00048
bool doesSnap() {
return (m_snapFactor > 1.0f); }
00049
bool isConnected() {
return (m_object1 && m_object2); }
00050
00051
00052
void setObject1(
PhysicalObject *object) { m_object1 = object; }
00053
void setObject2(
PhysicalObject *object) { m_object2 = object; }
00054
void setStiffness(
float stiffness) { m_stiffness = stiffness; }
00055
void setDamping(
float damping) { m_damping = damping; }
00056
void setRestLength(
float restLength) { m_restLength = restLength; }
00057
void setSnapFactor(
float snapFactor) { m_snapFactor = snapFactor; }
00058
void setNoSnap() { m_snapFactor = 0.0f; }
00059
00060
00061
void initialize();
00062
void execute(
float seconds);
00063
00064
00065
void render();
00066
00067
00068
void connect(
PhysicalObject *object1,
PhysicalObject *object2) { m_object1 = object1; m_object2 = object2; }
00069
void calculateRestLength();
00070
00071
00072
00073
00074
00075 };
00076 }
00077
00078
#endif // OPENCAL_SPRING_H