Moved sixense laser stuff to MyAvatar

This commit is contained in:
barnold1953 2014-07-18 15:26:18 -07:00
parent 2cee5992a0
commit c6bda4bf16
6 changed files with 52 additions and 57 deletions

View file

@ -2805,8 +2805,11 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
bool mirrorMode = (whichCamera.getInterpolatedMode() == CAMERA_MODE_MIRROR);
{
PerformanceTimer perfTimer("avatars");
_avatarManager.renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE, selfAvatarOnly);
//Render the sixense lasers
_myAvatar->renderLaserPointers();
}
if (!selfAvatarOnly) {

View file

@ -1849,3 +1849,43 @@ void MyAvatar::applyCollision(const glm::vec3& contactPoint, const glm::vec3& pe
}
}
//Renders sixense laser pointers for UI selection with controllers
void MyAvatar::renderLaserPointers() {
const float PALM_TIP_ROD_RADIUS = 0.002f;
//If the Oculus is enabled, we will draw a blue cursor ray
for (size_t i = 0; i < getHand()->getNumPalms(); ++i) {
PalmData& palm = getHand()->getPalms()[i];
if (palm.isActive()) {
glColor4f(0, 1, 1, 1);
glm::vec3 tip = getLaserPointerTipPosition(&palm);
glm::vec3 root = palm.getPosition();
//Scale the root vector with the avatar scale
scaleVectorRelativeToPosition(root);
Avatar::renderJointConnectingCone(root, tip, PALM_TIP_ROD_RADIUS, PALM_TIP_ROD_RADIUS);
}
}
}
//Gets the tip position for the laser pointer
glm::vec3 MyAvatar::getLaserPointerTipPosition(const PalmData* palm) {
const ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay();
const float PALM_TIP_ROD_LENGTH_MULT = 40.0f;
glm::vec3 direction = glm::normalize(palm->getTipPosition() - palm->getPosition());
glm::vec3 position = palm->getPosition();
//scale the position with the avatar
scaleVectorRelativeToPosition(position);
glm::vec3 result;
if (applicationOverlay.calculateRayUICollisionPoint(position, direction, result)) {
return result;
}
return palm->getPosition();
}

View file

@ -127,6 +127,9 @@ public:
void applyCollision(const glm::vec3& contactPoint, const glm::vec3& penetration);
/// Renders a laser pointer for UI picking
void renderLaserPointers();
glm::vec3 getLaserPointerTipPosition(const PalmData* palm);
public slots:
void goHome();
void increaseSize();

View file

@ -462,52 +462,4 @@ QSize OculusManager::getRenderTargetSize() {
#else
return QSize(100, 100);
#endif
}
//Renders sixense laser pointers for UI selection in the oculus
void OculusManager::renderLaserPointers() {
#ifdef HAVE_LIBOVR
const float PALM_TIP_ROD_RADIUS = 0.002f;
MyAvatar* myAvatar = Application::getInstance()->getAvatar();
//If the Oculus is enabled, we will draw a blue cursor ray
for (size_t i = 0; i < myAvatar->getHand()->getNumPalms(); ++i) {
PalmData& palm = myAvatar->getHand()->getPalms()[i];
if (palm.isActive()) {
glColor4f(0, 1, 1, 1);
glm::vec3 tip = getLaserPointerTipPosition(&palm);
glm::vec3 root = palm.getPosition();
//Scale the root vector with the avatar scale
myAvatar->scaleVectorRelativeToPosition(root);
Avatar::renderJointConnectingCone(root, tip, PALM_TIP_ROD_RADIUS, PALM_TIP_ROD_RADIUS);
}
}
#endif
}
//Gets the tip position for the laser pointer
glm::vec3 OculusManager::getLaserPointerTipPosition(const PalmData* palm) {
#ifdef HAVE_LIBOVR
const ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay();
const float PALM_TIP_ROD_LENGTH_MULT = 40.0f;
glm::vec3 direction = glm::normalize(palm->getTipPosition() - palm->getPosition());
glm::vec3 position = palm->getPosition();
//scale the position with the avatar
Application::getInstance()->getAvatar()->scaleVectorRelativeToPosition(position);
glm::vec3 result;
if (applicationOverlay.calculateRayUICollisionPoint(position, direction, result)) {
return result;
}
return palm->getPosition();
#endif
return glm::vec3(0.0f);
}
}

View file

@ -42,10 +42,6 @@ public:
/// param \roll[out] roll in radians
static void getEulerAngles(float& yaw, float& pitch, float& roll);
static QSize getRenderTargetSize();
/// Renders a laser pointer for UI picking
static void renderLaserPointers();
static glm::vec3 getLaserPointerTipPosition(const PalmData* palm);
private:
#ifdef HAVE_LIBOVR

View file

@ -64,6 +64,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
_textureFov = Menu::getInstance()->getOculusUIAngularSize() * RADIANS_PER_DEGREE;
Application* application = Application::getInstance();
Overlays& overlays = application->getOverlays();
@ -272,7 +273,7 @@ QPoint ApplicationOverlay::getOculusPalmClickLocation(const PalmData *palm) cons
QGLWidget* glWidget = application->getGLWidget();
MyAvatar* myAvatar = application->getAvatar();
glm::vec3 tip = OculusManager::getLaserPointerTipPosition(palm);
glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm);
glm::vec3 eyePos = myAvatar->getHead()->calculateAverageEyePosition();
glm::quat orientation = glm::inverse(myAvatar->getOrientation());
glm::vec3 dir = orientation * glm::normalize(application->getCamera()->getPosition() - tip); //direction of ray goes towards camera
@ -340,7 +341,7 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
MyAvatar* myAvatar = application->getAvatar();
//Render the sixense lasers
OculusManager::renderLaserPointers();
myAvatar->renderLaserPointers();
glActiveTexture(GL_TEXTURE0);
@ -700,7 +701,7 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) {
PalmData& palm = myAvatar->getHand()->getPalms()[i];
if (palm.isActive()) {
glm::vec3 tip = OculusManager::getLaserPointerTipPosition(&palm);
glm::vec3 tip = myAvatar->getLaserPointerTipPosition(&palm);
glm::vec3 tipPos = (tip - eyePos);
float length = glm::length(eyePos - tip);