vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConstrainedObjectMovement.h
Go to the documentation of this file.
1 #ifndef CONSTRAINED_OBJECT_MOVEMENT_H
2 #define CONSTRAINED_OBJECT_MOVEMENT_H
3 
4 
6 
7 #include <vrecko/Ability.h>
9 #include <helpers/DynamicArray.h>
10 #include <osg/Group>
11 #include <osg/ShapeDrawable>
12 #include <osg/Geode>
13 #include "ConstraintHierarchy.h"
14 
15 using namespace vrecko;
16 
17 namespace APConstrainedMovement {
18 
19 #define EPSILON 0.001
20 
23  public:
25  virtual ~ConstrainedObjectMovement();
26 
27  virtual void update(void);
28 
29  protected:
31 
32  virtual CAINFO* createInfo();
33  virtual void fillDefaultInfo();
34 
35  virtual bool activate();
36  virtual void deactivate();
37 
38  virtual void processButtonPress(CABUTTONEVENT* eventData);
39  virtual void processButtonRelease(CABUTTONEVENT* eventData);
40 
41  bool rotating; // Specifier whether the ability is being used for rotation or translation
42 
43  osg::Vec3 prevPointerPos; // Pointer position during last update
44 
45  osg::Vec3 firstPointerPos; // Pointer position when activated
46  osg::Quat firstPointerRot; // Pointer rotation when activated
47 
48  osg::Vec3 firstObjectPos; // Object position when activated
49  osg::Quat firstObjectRot; // Object rotation when activated
50 
51  unsigned long movingObjectID; // ID of the object being moved; if this is 0, the ability is inactive
52 
53  float firstTransparency; // Object transparency when activated
54 
56 
57 
58 
59  void issueRequests(bool bStopIfNoSelection);
60 
61 
62  bool objectTransformationFromPointer(EnvironmentObject *eo, osg::Matrix *outTrans, osg::Vec3 *outTranslationVector);
63  // FIRST PART of the tranformation calculations. From the pointer position/rotation the new object
64  // position/rotation is calculated. The matrix is only calculated and stored in [outTrans].
65  // The transformation will be applied afterwards, after another calculations or adjustments.
66 
67  bool applyConstrainedSnapping(EnvironmentObject *eo, osg::Matrix *inoutTrans, osg::Vec3 *inoutTranslationVector);
68  // Another PART of the transformation calculation. [inoutTrans] is already calculated.
69  // This method may adjust the transformtion matrix to snap the object to other scene objects.
70 
71 
72 
74  void readWatchedObjectIDs();
75 
76  void writeObjectPosition(int id, ofstream &stream);
77  void writeObjectRotation(int id, ofstream &stream);
78  void writeObjectFullMatrix(int id, ofstream &stream);
79  void writeObjectPositionsAndRotations();
80 
81  void compareObjectPosition(int id, ifstream &stream, double &linearDifference, double &quadraticDifference);
82  void compareObjectRotation(int id, ifstream &stream, double &linearDifference, double &quadraticDifference);
83  void compareObjectPositionsAndRotations();
84 
85  void loadObjectFullMatrix(int id, ifstream &stream);
86  void loadObjectPositionsAndRotations();
87 };
88 
89 }
90 
91 
92 #endif