- Main Page
- Classes
- Files

- Search for |

# RealtimeAttractor.h

Go to the documentation of this file.

    00001 /*****************************
    00002 File:     RealtimeAttractor.h
    00003 Language:   C++ (header)
    00004 Project:    H3DNetworkingUtils
    00005 The contents of this file are subject to the Mozilla Public License
    00006 Version 1.1 (the "License"); you may not use this file except in
    00007 compliance with the License. You may obtain a copy of the License at
    00008 http://www.mozilla.org/MPL/
    00009
    00010 Software distributed under the License is distributed on an "AS IS"
    00011 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    00012 License for the specific language governing rights and limitations
    00013 under the License.
    00014
    00015 The Original Code is H3DNetworkingUtils v1.0.
    00016
    00017 The Initial Developer of the Original Code is CSIRO.
    00018 Portions created by the Initial Developer are Copyright (C) 1009 CSIRO. All Rights Reserved.
    00019 Contributor(s):
    00020     Chris Gunn  <Chris.Gunn@csiro.au> <ChrisJGunn@gmail.com>
    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    // AttractForce is the same as the one in the parent class, except when the
    00119    // point of attraction is required during the haptics cycle, it retrieves it
    00120    // from the relatimePoint field, because it may have been updated at haptics
    00121    // rates, or at least faster than graphics rates.
    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    // Overrides the base class's function to get the value from the field
    00145    // This gets called each haptics cycle, so it is accessing a field in
    00146    // the haptics loop, and must have locking protection.
    00147
    00148 };
    00149
    00150 }
    00151
    00152 #endif