00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00025
00026 #ifndef RealtimeAttractor_H
00027 #define RealtimeAttractor_H
00028
00029
00030
00031
00032
00033 #include "H3DNetworkingUtils/Config.h"
00034 #include "H3DNetworkingUtils/Attractor.h"
00035 #include <H3DUtil/Threads.h>
00036 #include "H3DUtil/TimeStamp.h"
00037
00038 namespace H3DNetworkingUtils {
00039
00049
00050 class H3D_NETWORKING_UTILS_DLL_SPEC RealtimeAttractor : public Attractor {
00051 public:
00052 class LockableSFVec3f;
00053
00055 RealtimeAttractor(H3D::Inst<LockableSFVec3f> _realtimePoint = 0);
00056
00058 virtual ~RealtimeAttractor();
00059
00061 static H3D::H3DNodeDatabase database;
00062
00072 auto_ptr<LockableSFVec3f> realtimePoint;
00073
00075 class LockableSFVec3f : public H3D::AutoUpdate<H3D::SFVec3f> {
00076 public:
00077
00078 virtual const H3D::Vec3f & getValue(int id = 0) {
00079 point_lock.lock();
00080 ret_value = H3D::SFVec3f::getValue(id);
00081
00082 point_lock.unlock();
00083 return ret_value;
00084 }
00085
00086 virtual void propagateEvent( Event e ) {
00087 point_lock.lock();
00088 H3D::AutoUpdate<H3D::SFVec3f>::propagateEvent(e);
00089 point_lock.unlock();
00090 }
00091
00092 virtual void update() {
00093 value = static_cast<SFVec3f*>(event.ptr)->getValue();
00094 }
00095
00096 virtual void setValue(H3D::Vec3f const & val, int id = 0) {
00097 point_lock.lock();
00098 H3D::SFVec3f::setValue(val, id);
00099 point_lock.unlock();
00100
00101 }
00102
00103 private:
00104 H3DUtil::MutexLock point_lock;
00105 H3D::Vec3f ret_value;
00106 };
00107
00108 protected:
00109 virtual Attractor::AttractForce * createAttractForce(H3D::H3DTime t,
00110 H3D::Vec3f const & _point,
00111 bool _repel,
00112 H3D::H3DFloat maxForce,
00113 H3D::H3DFloat maxDeltaForce,
00114 H3D::H3DFloat _radius,
00115 H3D::H3DFloat _scale,
00116 H3D::Vec3f const & offset);
00117
00118
00119
00120
00121
00122 class RTAttractForce : public Attractor::AttractForce {
00123 public:
00124 RTAttractForce(H3D::H3DTime t,
00125 H3D::Vec3f const & point,
00126 bool repel,
00127 H3D::H3DFloat maxForce,
00128 H3D::H3DFloat maxDeltaForce,
00129 H3D::H3DFloat radius,
00130 H3D::H3DFloat scale,
00131 H3D::Vec3f const & offset,
00132 Attractor * attrP) :
00133 AttractForce(t, point, repel, maxForce, maxDeltaForce, radius, scale, offset, attrP) {}
00134
00135 protected:
00136 virtual H3D::Vec3f getLatestAttractionPoint() {
00137 return static_cast<RealtimeAttractor*>(attrP.get())->realtimePoint->getValue();
00138 }
00139 };
00140
00141 virtual H3D::Vec3f getPoint() {
00142 return realtimePoint->getValue();
00143 }
00144
00145
00146
00147
00148 };
00149
00150 }
00151
00152 #endif