00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef VRS_SG_INTERACTIONCONCEPT_H
00047 #define VRS_SG_INTERACTIONCONCEPT_H
00048
00049 #include <vrs/sg/behaviornode.h>
00050 #include <vrs/vector.h>
00051 #include <vector>
00052
00053 namespace VRS {
00054
00055 class InteractionMode;
00056 class LookAt;
00057 class PhysicalModel;
00058 class PhysicalModelSettings;
00059 class ConstraintChecker;
00060 template <typename S, typename T>
00061 class Callback2;
00062
00074
00078
00082
00087
00094
00097 class VRS_CORE_API InteractionConcept : public BehaviorNode {
00098
00099 public:
00100
00103 InteractionConcept(SO<LookAt> lookAt = NULL);
00104
00110 SO<LookAt> getLookAt() const;
00111 void setLookAt(SO<LookAt> lookAt);
00112
00114 void addInteractionMode(SO<InteractionMode> mode);
00115
00118 void removeInteractionMode(SO<InteractionMode> mode);
00119
00121 SO<Iterator<SO<InteractionMode> > > interactionModeIterator() const;
00122
00124 void selectInteractionMode(SO<InteractionMode> mode);
00125
00127 SO<InteractionMode> getSelectedInteractionMode() const;
00128
00130 virtual void setConstraintChecker(ConstraintChecker* checker);
00131
00133 virtual ConstraintChecker* getConstraintChecker() const;
00134
00137 void initParentPointers();
00138
00142 class VRS_CORE_API ViewParameterSet : public SharedObj {
00143 public:
00144 ViewParameterSet(Vector from, Vector to, Vector up);
00145 ViewParameterSet(SO<ViewParameterSet> source);
00146 void setFrom(const Vector& from);
00147 Vector getFrom() const;
00148 void setTo(const Vector& to);
00149 Vector getTo() const;
00150 void setUp(const Vector& up);
00151 Vector getUp() const;
00153 void setDirection(const Vector& dir);
00154 Vector getDirection() const;
00155 Vector getRight() const;
00156 void translate(const Vector& dir);
00157 void rotate(double angle, const Vector& axis);
00158
00159
00160 bool operator==(const ViewParameterSet& other) const;
00161
00162 VRS_TYPEINFO(ViewParameterSet, SharedObj);
00163 VRS_SERIALIZABLE(ViewParameterSet);
00164
00165 private:
00166 ViewParameterSet();
00167 Vector from_;
00168 Vector to_;
00169 Vector up_;
00170 };
00171
00173 virtual BehaviorNode::InvalidationHint handle(Event* event);
00174
00178 void brake();
00179
00185 SO<ViewParameterSet> getViewParameters() const;
00186
00189 SO<ViewParameterSet> getPreviousViewParameters() const;
00190
00197 void setMotionStateCallback(VRS::SO<VRS::Callback2<bool,bool> > callback);
00198
00199
00200 VRS_TYPEINFO(InteractionConcept, BehaviorNode);
00201 VRS_SERIALIZABLE(InteractionConcept);
00202
00203 private:
00204
00205 SO<InteractionMode> activeInteractionMode_;
00206 std::vector<SO<InteractionMode> > interactionModes_;
00207 SO<ViewParameterSet> viewParameters_;
00208 SO<ViewParameterSet> previousViewParameters_;
00209 SO<LookAt> lookAt_;
00210 SO<LookAt> lastLookAt_;
00211 bool passiveMode_;
00212 SO<PhysicalModel> physicalModel_;
00213 SO<PhysicalModelSettings> lastSettings_;
00214 SO<ConstraintChecker> constraintChecker_;
00215 SO<Callback2<bool, bool> > motionStateChangedCb_;
00216
00217 bool active_;
00218 bool modeInitialized_;
00219
00220 SO<ViewParameterSet> viewParametersForStateChangeDetection_;
00221 bool inMotion_;
00222 bool inViewDirChange_;
00223 };
00224
00225 inline InteractionConcept::ViewParameterSet::ViewParameterSet(Vector from, Vector to, Vector up) :
00226 from_(from), to_(to), up_(up) {}
00227 inline void InteractionConcept::ViewParameterSet::setFrom(const Vector& from) { from_ = from; }
00228 inline Vector InteractionConcept::ViewParameterSet::getFrom() const { return from_; }
00229 inline void InteractionConcept::ViewParameterSet::setTo(const Vector& to) { to_ = to; }
00230 inline Vector InteractionConcept::ViewParameterSet::getTo() const { return to_; }
00231 inline void InteractionConcept::ViewParameterSet::setUp(const Vector& up) { up_ = up; }
00232 inline Vector InteractionConcept::ViewParameterSet::getUp() const { return up_; }
00233 inline void InteractionConcept::ViewParameterSet::setDirection(const Vector& dir) { to_ = from_ + dir; }
00234 inline Vector InteractionConcept::ViewParameterSet::getDirection() const { return to_ - from_; }
00235 inline void InteractionConcept::ViewParameterSet::translate(const Vector& delta) { from_ += delta; to_ += delta; }
00236 inline Vector InteractionConcept::ViewParameterSet::getRight() const { return up_ * getDirection(); }
00237
00238 }
00239
00240 #endif // VRS_SG_INTERACTIONCONCEPT_H