- Main Page
- Classes
- Files

- Search for |

# GrabableDynamic.h

Go to the documentation of this file.

    00001 /*****************************
    00002 File:      GrabableDynamic.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 GrabableDynamic_H
    00027 #define GrabableDynamic_H
    00028
    00029 #include "H3DNetworkingUtils/Config.h"
    00030 #include "H3DNetworkingUtils/CollidableDynamic.h"
    00031 #include <H3d/SFTime.h>
    00032
    00033 namespace H3DNetworkingUtils {
    00034
    00049
    00050 class H3D_NETWORKING_UTILS_DLL_SPEC GrabableDynamic : public CollidableDynamic {
    00051 public:
    00052
    00053    struct MovedPos;
    00054    struct GrabTorque;
    00055    struct NegVec3f;
    00056    class GrabSpring;
    00057    struct DiffVec3f;
    00058    struct SlaveSwitch;
    00059
    00061    GrabableDynamic(H3D::Inst< AddChildren       > _addChildren        = 0,
    00062             H3D::Inst< RemoveChildren           > _removeChildren     = 0,
    00063             H3D::Inst< MFChild                  > _children           = 0,
    00064             H3D::Inst< H3D::SFNode              > _metadata           = 0,
    00065             H3D::Inst< SFBound                  > _bound              = 0,
    00066             H3D::Inst< H3D::SFVec3f             > _bboxCenter         = 0,
    00067             H3D::Inst< H3D::SFVec3f             > _bboxSize           = 0,
    00068             H3D::Inst< SFTransformedBound       > _transformedBound   = 0,
    00069             H3D::Inst< SFMatrix4f               > _matrix             = 0,
    00070             H3D::Inst< SFMatrix4f               > _accumulatedForward = 0,
    00071             H3D::Inst< SFMatrix4f               > _accumulatedInverse = 0,
    00072             H3D::Inst< H3D::SFVec3f             > _position           = 0,
    00073             H3D::Inst< H3D::SFRotation          > _orientation        = 0,
    00074             H3D::Inst< SFVelocity               > _velocity           = 0,
    00075             H3D::Inst< H3D::SFVec3f             > _momentum           = 0,
    00076
    00077             H3D::Inst< H3D::SFVec3f             > _force              = 0,
    00078             H3D::Inst< SFAngularVelocity        > _angularVelocity    = 0,
    00079             H3D::Inst< H3D::SFVec3f             > _angularMomentum    = 0,
    00080             H3D::Inst< SFSpin                   > _spin               = 0,
    00081             H3D::Inst< H3D::SFVec3f             > _torque             = 0,
    00082             H3D::Inst< H3D::SFFloat             > _mass               = 0,
    00083             H3D::Inst< H3D::SFMatrix3f          > _inertiaTensor      = 0,
    00084             H3D::Inst< SFMotion                 > _motion             = 0,
    00085
    00086             H3D::Inst<H3D::MFVec3f              > _contactForces      = 0,
    00087             H3D::Inst<H3D::MFVec3f              > _contactTorques     = 0,
    00088             H3D::Inst<SumMFVec3f                > _totalContactForce  = 0,
    00089             H3D::Inst<CalcTorque                > _totalContactTorque = 0,
    00090             H3D::Inst<SumForces                 > _externalForces     = 0,
    00091             H3D::Inst<SumTorques                > _externalTorques    = 0,
    00092             H3D::Inst<H3D::SFVec3f              > _freedom            = 0,
    00093             H3D::Inst<H3D::SFVec3f              > _angularFreedom     = 0,
    00094             H3D::Inst<H3D::SFFloat              > _linearDamping      = 0,
    00095             H3D::Inst<H3D::SFFloat              > _rotationalDamping  = 0,
    00096             H3D::Inst<MFCollidableGeometry      > _collisionSpheres  = 0,
    00097             H3D::Inst<H3D::SFFloat              > _collisionStiffness = 0,
    00098             H3D::Inst< H3D::SFFloat             > _collisionResolution   = 0,
    00099             H3D::Inst<H3D::SFBool               > _grabbed = 0,
    00100             H3D::Inst<H3D::SFVec3f              > _grabPoint = 0,
    00101             H3D::Inst<H3D::SFFloat              > _grabStrength = 0,
    00102             H3D::Inst<H3D::SFFloat              > _grabSlackRadius = 0,
    00103             H3D::Inst<GrabSpring                > _grabForce = 0,
    00104             H3D::Inst<NegVec3f                  > _grabReactionForce = 0,
    00105             H3D::Inst<MovedPos                  > _grabSpringAnchorPt = 0,
    00106             H3D::Inst<GrabTorque                > _grabTorque = 0,
    00107             H3D::Inst<H3D::SFInt32              > _grabSmoothing = 0,
    00108             H3D::Inst<H3D::SFFloat              > _grabDamping = 0,
    00109             H3D::Inst<SlaveSwitch               > _slaveMode = 0,
    00110             H3D::Inst<DiffVec3f                 > _appliedForce = 0,
    00111             H3D::Inst<DiffVec3f                 > _appliedTorque = 0);
    00112
    00113    static H3D::H3DNodeDatabase database;
    00114
    00120    auto_ptr<H3D::SFBool>               grabbed;
    00121
    00127    auto_ptr<H3D::SFVec3f>              grabPoint;
    00128
    00133    auto_ptr<H3D::SFFloat>              grabStrength;
    00134
    00139    auto_ptr<H3D::SFFloat>              grabDamping;
    00140
    00147    auto_ptr<H3D::SFFloat>              grabSlackRadius;
    00148
    00153    auto_ptr<GrabSpring>                grabForce;
    00154
    00159    auto_ptr<NegVec3f>                  grabReactionForce;
    00160
    00167    auto_ptr<MovedPos>                  grabSpringAnchorPt;
    00168
    00173    auto_ptr<GrabTorque>                grabTorque;
    00174
    00179    auto_ptr<H3D::SFInt32>                grabSmoothing;
    00180
    00192    auto_ptr<SlaveSwitch>                slaveMode;
    00193
    00199    auto_ptr<DiffVec3f>        appliedForce;
    00200
    00206    auto_ptr<DiffVec3f>        appliedTorque;
    00207
    00209    virtual void initialize();
    00210
    00215    struct H3D_NETWORKING_UTILS_DLL_SPEC MovedPos : public H3D::AutoUpdate< H3D::TypedField<H3D::SFVec3f,
    00216                                             H3D::Types<H3D::SFBool, H3D::SFVec3f, H3D::SFVec3f, H3D::SFRotation> > > {
    00217       MovedPos() : was_grabbed(false) {}
    00218       virtual void update();
    00219       bool was_grabbed;
    00220       H3D::Vec3f initial_anchor;
    00221       H3D::Vec3f initial_anchor_local;
    00222       H3D::Vec3f initial_position;
    00223       H3D::Rotation initial_rotation;
    00224    };
    00225
    00232    struct H3D_NETWORKING_UTILS_DLL_SPEC GrabTorque : public H3D::TypedField< H3D::SFVec3f,
    00233       H3D::Types<H3D::SFBool, H3D::SFVec3f, H3D::SFVec3f, H3D::SFVec3f, H3D::SFFloat> > {
    00234       virtual void update();
    00235   };
    00236
    00241    struct H3D_NETWORKING_UTILS_DLL_SPEC NegVec3f : public H3D::TypedField<H3D::SFVec3f,
    00242       H3D::Types<H3D::SFVec3f, H3D::SFFloat, H3D::SFTime> > {
    00243       virtual void update();
    00244       H3D::H3DTime  prev_spring_time;
    00245       H3D::Vec3f    prev_raw_force;
    00246    };
    00247
    00254    class H3D_NETWORKING_UTILS_DLL_SPEC GrabSpring : public H3D::TypedField<H3D::SFVec3f,
    00255          H3D::Types<H3D::SFBool, H3D::SFVec3f, H3D::SFVec3f,
    00256                     H3D::SFFloat, H3D::SFFloat> > {
    00257    public:
    00258       GrabSpring();
    00259       virtual void update();
    00260       virtual void initialize(u_int history_size);
    00261    protected:
    00262       H3D::Vec3f smooth(const H3D::Vec3f & v);
    00263    private:
    00264       bool was_grabbed;
    00265       H3D::H3DFloat spring_rest_length; // this gets set when user grabs
    00266       std::deque<H3D::Vec3f> history;
    00267       u_int history_size;
    00268    };
    00269
    00271    struct H3D_NETWORKING_UTILS_DLL_SPEC DiffVec3f : public H3D::TypedField<H3D::SFVec3f, H3D::Types<H3D::SFVec3f, H3D::SFVec3f> >  {
    00272       virtual void update() {
    00273          value = static_cast<H3D::SFVec3f*>(routes_in[1])->getValue() - static_cast<H3D::SFVec3f*>(routes_in[0])->getValue();
    00274       }
    00275    };
    00276
    00277    struct SlaveSwitch : public H3D::AutoUpdate<H3D::OnValueChangeSField<H3D::SFBool> > {
    00278       virtual void onValueChange(const bool & val) {
    00279          static_cast<GrabableDynamic*>(getOwner())->setSlaveMode(val);
    00280       }
    00281    };
    00282
    00283 protected:
    00284
    00285    virtual H3D::Vec3f getClosestPoint(const H3D::Vec3f & pt);
    00286    // Get the closest point in global coords to the given pt in global coords.
    00287
    00288    virtual void setSlaveMode(bool val);
    00289
    00290 };
    00291
    00292
    00293 }
    00294
    00295 #endif
    00296