mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-24 13:55:34 +00:00
Add basic support for showing openvr controllers and tracked objects
This commit is contained in:
parent
1198932e87
commit
e6159a590a
12 changed files with 1903 additions and 45 deletions
|
|
@ -16,15 +16,17 @@ MODULE_BEGIN( ExtendedMoveManager )
|
|||
|
||||
MODULE_END;
|
||||
|
||||
S32 ExtendedMoveManager::mPosX[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
S32 ExtendedMoveManager::mPosY[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
S32 ExtendedMoveManager::mPosZ[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
F32 ExtendedMoveManager::mPosX[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
F32 ExtendedMoveManager::mPosY[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
F32 ExtendedMoveManager::mPosZ[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
bool ExtendedMoveManager::mRotIsEuler[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
F32 ExtendedMoveManager::mRotAX[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
F32 ExtendedMoveManager::mRotAY[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
F32 ExtendedMoveManager::mRotAZ[ExtendedMove::MaxPositionsRotations] = { 0, };
|
||||
F32 ExtendedMoveManager::mRotAA[ExtendedMove::MaxPositionsRotations] = { 1, };
|
||||
|
||||
F32 ExtendedMoveManager::mPosScale = 2.0f;
|
||||
|
||||
void ExtendedMoveManager::init()
|
||||
{
|
||||
for(U32 i = 0; i < ExtendedMove::MaxPositionsRotations; ++i)
|
||||
|
|
@ -32,17 +34,17 @@ void ExtendedMoveManager::init()
|
|||
char varName[256];
|
||||
|
||||
dSprintf(varName, sizeof(varName), "mvPosX%d", i);
|
||||
Con::addVariable(varName, TypeS32, &mPosX[i],
|
||||
Con::addVariable(varName, TypeF32, &mPosX[i],
|
||||
"X position of controller in millimeters. Only 13 bits are networked.\n"
|
||||
"@ingroup Game");
|
||||
|
||||
dSprintf(varName, sizeof(varName), "mvPosY%d", i);
|
||||
Con::addVariable(varName, TypeS32, &mPosY[i],
|
||||
Con::addVariable(varName, TypeF32, &mPosY[i],
|
||||
"Y position of controller in millimeters. Only 13 bits are networked.\n"
|
||||
"@ingroup Game");
|
||||
|
||||
dSprintf(varName, sizeof(varName), "mvPosZ%d", i);
|
||||
Con::addVariable(varName, TypeS32, &mPosZ[i],
|
||||
Con::addVariable(varName, TypeF32, &mPosZ[i],
|
||||
"Z position of controller in millimeters. Only 13 bits are networked.\n"
|
||||
"@ingroup Game");
|
||||
|
||||
|
|
@ -75,6 +77,11 @@ void ExtendedMoveManager::init()
|
|||
"Angle rotation (in degrees) component of controller.\n"
|
||||
"@ingroup Game");
|
||||
}
|
||||
|
||||
Con::addVariable("mvPosScale", TypeF32, &mPosScale,
|
||||
"@brief Indicates the scale to be given to mvPos values.\n\n"
|
||||
""
|
||||
"@ingroup Game");
|
||||
}
|
||||
|
||||
const ExtendedMove NullExtendedMove;
|
||||
|
|
@ -183,8 +190,8 @@ void ExtendedMove::unpack(BitStream *stream, const Move * basemove)
|
|||
// Position
|
||||
if (stream->readFlag())
|
||||
{
|
||||
posX[i] = stream->readInt(MaxPositionBits);
|
||||
cposX[i] = UNCLAMPPOS(posX[i]);
|
||||
cposX[i] = stream->readInt(MaxPositionBits);
|
||||
posX[i] = UNCLAMPPOS(cposX[i]) * ExtendedMoveManager::mPosScale;
|
||||
}
|
||||
else
|
||||
posX[i] = extBaseMove->posX[i];
|
||||
|
|
@ -192,7 +199,7 @@ void ExtendedMove::unpack(BitStream *stream, const Move * basemove)
|
|||
if (stream->readFlag())
|
||||
{
|
||||
cposY[i] = stream->readInt(MaxPositionBits);
|
||||
posY[i] = UNCLAMPPOS(cposY[i]);
|
||||
posY[i] = UNCLAMPPOS(cposY[i]) * ExtendedMoveManager::mPosScale;
|
||||
}
|
||||
else
|
||||
posY[i] = extBaseMove->posY[i];
|
||||
|
|
@ -200,7 +207,7 @@ void ExtendedMove::unpack(BitStream *stream, const Move * basemove)
|
|||
if (stream->readFlag())
|
||||
{
|
||||
cposZ[i] = stream->readInt(MaxPositionBits);
|
||||
posZ[i] = UNCLAMPPOS(cposZ[i]);
|
||||
posZ[i] = UNCLAMPPOS(cposZ[i]) * ExtendedMoveManager::mPosScale;
|
||||
}
|
||||
else
|
||||
posZ[i] = extBaseMove->posZ[i];
|
||||
|
|
@ -267,9 +274,9 @@ void ExtendedMove::clamp()
|
|||
for(U32 i=0; i<MaxPositionsRotations; ++i)
|
||||
{
|
||||
// Positions
|
||||
cposX[i] = CLAMPPOS(posX[i]);
|
||||
cposY[i] = CLAMPPOS(posY[i]);
|
||||
cposZ[i] = CLAMPPOS(posZ[i]);
|
||||
cposX[i] = CLAMPPOS(posX[i] / ExtendedMoveManager::mPosScale);
|
||||
cposY[i] = CLAMPPOS(posY[i] / ExtendedMoveManager::mPosScale);
|
||||
cposZ[i] = CLAMPPOS(posZ[i] / ExtendedMoveManager::mPosScale);
|
||||
|
||||
// Rotations
|
||||
if(EulerBasedRotation[i])
|
||||
|
|
@ -286,15 +293,23 @@ void ExtendedMove::clamp()
|
|||
crotW[i] = CLAMPROT(rotW[i] / M_2PI_F);
|
||||
}
|
||||
|
||||
/*if (i == 0)
|
||||
#ifdef DEBUG_CONTROLLER_MOVE
|
||||
if (i == 1)
|
||||
{
|
||||
F32 x, y, z, a;
|
||||
x = UNCLAMPPOS(crotX[i]);
|
||||
y = UNCLAMPPOS(crotY[i]);
|
||||
z = UNCLAMPPOS(crotZ[i]);
|
||||
a = UNCLAMPROT(crotW[i]) * M_2PI_F;
|
||||
//Con::printf("rot %f,%f,%f,%f clamped to %f,%f,%f,%f", rotX[i], rotY[i], rotZ[i], rotW[i], x,y,z,a);
|
||||
}*/
|
||||
|
||||
Con::printf("INPUT POS == %f,%f,%f", ExtendedMoveManager::mPosX[i], ExtendedMoveManager::mPosY[i], ExtendedMoveManager::mPosZ[i]);
|
||||
Con::printf("rot %f,%f,%f,%f clamped to %f,%f,%f,%f", rotX[i], rotY[i], rotZ[i], rotW[i], x,y,z,a);
|
||||
x = UNCLAMPPOS(cposX[i]) * ExtendedMoveManager::mPosScale;
|
||||
y = UNCLAMPPOS(cposX[i]) * ExtendedMoveManager::mPosScale;
|
||||
z = UNCLAMPPOS(cposX[i]) * ExtendedMoveManager::mPosScale;
|
||||
Con::printf("pos %f,%f,%f clamped to %f,%f,%f", posX[i], posY[i], posZ[i], x, y, z);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Perform the standard Move clamp
|
||||
|
|
@ -306,9 +321,9 @@ void ExtendedMove::unclamp()
|
|||
// Unclamp the values the same as for net traffic so the client matches the server
|
||||
for(U32 i=0; i<MaxPositionsRotations; ++i)
|
||||
{
|
||||
posX[i] = UNCLAMPPOS(cposX[i]);
|
||||
posY[i] = UNCLAMPPOS(cposY[i]);
|
||||
posZ[i] = UNCLAMPPOS(cposZ[i]);
|
||||
posX[i] = UNCLAMPPOS(cposX[i]) * ExtendedMoveManager::mPosScale;
|
||||
posY[i] = UNCLAMPPOS(cposY[i]) * ExtendedMoveManager::mPosScale;
|
||||
posZ[i] = UNCLAMPPOS(cposZ[i]) * ExtendedMoveManager::mPosScale;
|
||||
|
||||
// Rotations
|
||||
if(EulerBasedRotation[i])
|
||||
|
|
|
|||
|
|
@ -41,15 +41,17 @@ extern const ExtendedMove NullExtendedMove;
|
|||
class ExtendedMoveManager
|
||||
{
|
||||
public:
|
||||
static S32 mPosX[ExtendedMove::MaxPositionsRotations];
|
||||
static S32 mPosY[ExtendedMove::MaxPositionsRotations];
|
||||
static S32 mPosZ[ExtendedMove::MaxPositionsRotations];
|
||||
static F32 mPosX[ExtendedMove::MaxPositionsRotations];
|
||||
static F32 mPosY[ExtendedMove::MaxPositionsRotations];
|
||||
static F32 mPosZ[ExtendedMove::MaxPositionsRotations];
|
||||
static bool mRotIsEuler[ExtendedMove::MaxPositionsRotations];
|
||||
static F32 mRotAX[ExtendedMove::MaxPositionsRotations];
|
||||
static F32 mRotAY[ExtendedMove::MaxPositionsRotations];
|
||||
static F32 mRotAZ[ExtendedMove::MaxPositionsRotations];
|
||||
static F32 mRotAA[ExtendedMove::MaxPositionsRotations];
|
||||
|
||||
static F32 mPosScale;
|
||||
|
||||
static void init();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -57,11 +57,17 @@
|
|||
#include "T3D/decal/decalData.h"
|
||||
#include "materials/baseMatInstance.h"
|
||||
#include "math/mathUtils.h"
|
||||
#include "gfx/sim/debugDraw.h"
|
||||
|
||||
#ifdef TORQUE_EXTENDED_MOVE
|
||||
#include "T3D/gameBase/extended/extendedMove.h"
|
||||
#endif
|
||||
|
||||
#ifdef TORQUE_OPENVR
|
||||
#include "platform/input/openVR/openVRProvider.h"
|
||||
#include "platform/input/openVR/openVRTrackedObject.h"
|
||||
#endif
|
||||
|
||||
// Amount of time if takes to transition to a new action sequence.
|
||||
static F32 sAnimationTransitionTime = 0.25f;
|
||||
static bool sUseAnimationTransitions = true;
|
||||
|
|
@ -2496,6 +2502,19 @@ void Player::updateMove(const Move* move)
|
|||
{
|
||||
delta.move = *move;
|
||||
|
||||
#ifdef TORQUE_OPENVR
|
||||
if (mControllers[0])
|
||||
{
|
||||
mControllers[0]->processTick(move);
|
||||
}
|
||||
|
||||
if (mControllers[1])
|
||||
{
|
||||
mControllers[1]->processTick(move);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Is waterCoverage high enough to be 'swimming'?
|
||||
{
|
||||
bool swimming = mWaterCoverage > 0.65f && canSwim();
|
||||
|
|
@ -2628,18 +2647,29 @@ void Player::updateMove(const Move* move)
|
|||
AngAxisF moveRot(Point3F(emove->rotX[emoveIndex], emove->rotY[emoveIndex], emove->rotZ[emoveIndex]), emove->rotW[emoveIndex]);
|
||||
MatrixF trans(1);
|
||||
moveRot.setMatrix(&trans);
|
||||
trans.inverse();
|
||||
|
||||
Point3F vecForward(0, 1, 0);
|
||||
Point3F vecForward(0, 10, 0);
|
||||
Point3F viewAngle;
|
||||
Point3F orient;
|
||||
EulerF rot;
|
||||
trans.mulV(vecForward);
|
||||
viewAngle = vecForward;
|
||||
vecForward.z = 0; // flatten
|
||||
vecForward.normalizeSafe();
|
||||
|
||||
F32 yawAng;
|
||||
F32 pitchAng;
|
||||
MathUtils::getAnglesFromVector(vecForward, yawAng, pitchAng);
|
||||
|
||||
mRot = EulerF(0);
|
||||
mRot.z = yawAng;
|
||||
mHead = EulerF(0);
|
||||
mHead.x = -pitchAng;
|
||||
|
||||
while (mRot.z < 0.0f)
|
||||
mRot.z += M_2PI_F;
|
||||
while (mRot.z > M_2PI_F)
|
||||
mRot.z -= M_2PI_F;
|
||||
|
||||
absoluteDelta = true;
|
||||
}
|
||||
|
|
@ -7140,3 +7170,38 @@ void Player::renderConvex( ObjectRenderInst *ri, SceneRenderState *state, BaseMa
|
|||
mConvex.renderWorkingList();
|
||||
GFX->leaveDebugEvent();
|
||||
}
|
||||
|
||||
#ifdef TORQUE_OPENVR
|
||||
void Player::setControllers(Vector<OpenVRTrackedObject*> controllerList)
|
||||
{
|
||||
mControllers[0] = controllerList.size() > 0 ? controllerList[0] : NULL;
|
||||
mControllers[1] = controllerList.size() > 1 ? controllerList[1] : NULL;
|
||||
}
|
||||
|
||||
ConsoleMethod(Player, setVRControllers, void, 4, 4, "")
|
||||
{
|
||||
OpenVRTrackedObject *controllerL, *controllerR;
|
||||
Vector<OpenVRTrackedObject*> list;
|
||||
|
||||
if (Sim::findObject(argv[2], controllerL))
|
||||
{
|
||||
list.push_back(controllerL);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.push_back(NULL);
|
||||
}
|
||||
|
||||
if (Sim::findObject(argv[3], controllerR))
|
||||
{
|
||||
list.push_back(controllerR);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.push_back(NULL);
|
||||
}
|
||||
|
||||
object->setControllers(list);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class DecalData;
|
|||
class SplashData;
|
||||
class PhysicsPlayer;
|
||||
class Player;
|
||||
class OpenVRTrackedObject;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -518,6 +519,8 @@ protected:
|
|||
Point3F mLastPos; ///< Holds the last position for physics updates
|
||||
Point3F mLastWaterPos; ///< Same as mLastPos, but for water
|
||||
|
||||
SimObjectPtr<OpenVRTrackedObject> mControllers[2];
|
||||
|
||||
struct ContactInfo
|
||||
{
|
||||
bool contacted, jump, run;
|
||||
|
|
@ -577,12 +580,17 @@ protected:
|
|||
|
||||
PhysicsPlayer* getPhysicsRep() const { return mPhysicsRep; }
|
||||
|
||||
#ifdef TORQUE_OPENVR
|
||||
void setControllers(Vector<OpenVRTrackedObject*> controllerList);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void reSkin();
|
||||
|
||||
void setState(ActionState state, U32 ticks=0);
|
||||
void updateState();
|
||||
|
||||
|
||||
// Jetting
|
||||
bool mJetting;
|
||||
|
||||
|
|
|
|||
|
|
@ -1999,17 +1999,14 @@ void ShapeBase::getEyeCameraTransform(IDisplayDevice *displayDevice, U32 eyeId,
|
|||
// NOTE: currently we dont support third-person camera in this mode
|
||||
MatrixF cameraTransform(1);
|
||||
F32 fakePos = 0;
|
||||
//cameraTransform = getRenderTransform(); // use this for controllers TODO
|
||||
getCameraTransform(&fakePos, &cameraTransform);
|
||||
|
||||
QuatF baserot = cameraTransform;
|
||||
QuatF qrot = QuatF(newPose.orientation);
|
||||
//QuatF concatRot;
|
||||
//concatRot.mul(baserot, qrot);
|
||||
qrot.setMatrix(&temp);
|
||||
temp = MatrixF(1);
|
||||
newPose.orientation.setMatrix(&temp);
|
||||
temp.setPosition(newPose.position);
|
||||
|
||||
temp.setPosition(cameraTransform.getPosition() + qrot.mulP(newPose.position, &rotEyePos));
|
||||
|
||||
*outMat = temp;
|
||||
*outMat = cameraTransform * temp;
|
||||
}
|
||||
|
||||
void ShapeBase::getCameraParameters(F32 *min,F32* max,Point3F* off,MatrixF* rot)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue