Torque3D Documentation / _generateds / openVRTrackedObject.h

openVRTrackedObject.h

Engine/source/platform/input/openVR/openVRTrackedObject.h

More...

Classes:

class

Implements a GameObject which tracks an OpenVR controller.

Detailed Description

  1
  2#ifndef _OPENVR_TRACKED_OBJECT_H_
  3#define _OPENVR_TRACKED_OBJECT_H_
  4
  5#ifndef _GAMEBASE_H_
  6#include "T3D/gameBase/gameBase.h"
  7#endif
  8#ifndef _GFXVERTEXBUFFER_H_
  9#include "gfx/gfxVertexBuffer.h"
 10#endif
 11#ifndef _GFXPRIMITIVEBUFFER_H_
 12#include "gfx/gfxPrimitiveBuffer.h"
 13#endif
 14#ifndef _TSSHAPEINSTANCE_H_
 15#include "ts/tsShapeInstance.h"
 16#endif
 17#include "collision/earlyOutPolyList.h"
 18
 19#include <openvr.h>
 20
 21class BaseMatInstance;
 22class OpenVRRenderModel;
 23class PhysicsBody;
 24
 25class OpenVRTrackedObjectData : public GameBaseData {
 26public:
 27   typedef GameBaseData Parent;
 28
 29   StringTableEntry mShapeFile;
 30   Resource<TSShape> mShape; ///< Torque model
 31
 32   Point3F mCollisionBoxMin;
 33   Point3F mCollisionBoxMax;
 34
 35public:
 36
 37   OpenVRTrackedObjectData();
 38   ~OpenVRTrackedObjectData();
 39
 40   DECLARE_CONOBJECT(OpenVRTrackedObjectData);
 41
 42   bool onAdd();
 43   bool preload(bool server, String &errorStr);
 44
 45   static void  initPersistFields();
 46
 47   virtual void packData(BitStream* stream);
 48   virtual void unpackData(BitStream* stream);
 49};
 50
 51/// Implements a GameObject which tracks an OpenVR controller
 52class OpenVRTrackedObject : public GameBase
 53{
 54   typedef GameBase Parent;
 55
 56   enum MaskBits
 57   {
 58      UpdateMask = Parent::NextFreeMask << 0,
 59      NextFreeMask = Parent::NextFreeMask << 1
 60   };
 61
 62   struct RenderModelSlot
 63   {
 64      StringTableEntry componentName; ///< Component name
 65      S16 mappedNodeIdx; ///< Mapped node idx in mShape
 66      OpenVRRenderModel *nativeModel; ///< Native model
 67   };
 68
 69   OpenVRTrackedObjectData *mDataBlock;
 70
 71   /// @name Rendering
 72   /// {
 73   TSShapeInstance *mShapeInstance; ///< Shape used to render controller (uses native model otherwise)
 74   StringTableEntry mModelName;
 75   OpenVRRenderModel *mBasicModel; ///< Basic model
 76   Vector<RenderModelSlot> mRenderComponents;
 77   /// }
 78
 79   S32 mDeviceIndex; ///< Controller idx in openvr (for direct updating)
 80   S32 mMappedMoveIndex; ///< Movemanager move index for rotation
 81
 82   vr::VRControllerState_t mCurrentControllerState;
 83   vr::VRControllerState_t mPreviousControllerState;
 84
 85   IDevicePose mPose; ///< Current openvr pose data, or reconstructed data from the client
 86
 87   Convex* mConvexList;
 88   EarlyOutPolyList     mClippedList;
 89   PhysicsBody *mPhysicsRep;
 90
 91   SimObjectPtr<SceneObject> mCollisionObject; ///< Object we're currently colliding with
 92   SimObjectPtr<SceneObject> mInteractObject;  ///< Object we've designated as important to interact with
 93
 94   bool mHoldInteractedObject; ///< Performs pickup logic with mInteractObject
 95   bool mIgnoreParentRotation; ///< Ignores the rotation of the parent object
 96
 97   static bool smDebugControllerPosition; ///< Shows latest controller position in DebugDrawer
 98   static bool smDebugControllerMovePosition; ///< Shows move position in DebugDrawer
 99   static U32 sServerCollisionMask;
100   static U32 sClientCollisionMask;
101
102public:
103   OpenVRTrackedObject();
104   virtual ~OpenVRTrackedObject();
105
106   void updateRenderData();
107   void setupRenderDataFromModel(bool loadComponentModels);
108
109   void clearRenderData();
110
111   DECLARE_CONOBJECT(OpenVRTrackedObject);
112
113   static void initPersistFields();
114
115   virtual void inspectPostApply();
116
117   bool onAdd();
118   void onRemove();
119
120
121   void _updatePhysics();
122   bool onNewDataBlock(GameBaseData *dptr, bool reload);
123
124   void setInteractObject(SceneObject* object, bool holding);
125
126   void setTransform(const MatrixF &mat);
127   void setModelName(String &modelName);
128
129   U32  packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
130   void unpackUpdate(NetConnection *conn, BitStream *stream);
131   void writePacketData(GameConnection *conn, BitStream *stream);
132   void readPacketData(GameConnection *conn, BitStream *stream);
133
134   void prepRenderImage(SceneRenderState *state);
135
136   MatrixF getTrackedTransform();
137   MatrixF getLastTrackedTransform();
138   MatrixF getBaseTrackingTransform();
139
140   U32 getCollisionMask();
141   void updateWorkingCollisionSet();
142
143   // Time management
144   void updateMove(const Move *move);
145   void processTick(const Move *move);
146   void interpolateTick(F32 delta);
147   void advanceTime(F32 dt);
148
149   // Collision
150   bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
151   void buildConvex(const Box3F& box, Convex* convex);
152   bool testObject(SceneObject* enter);
153
154};
155
156#endif // _OPENVR_TRACKED_OBJECT_H_
157