Merge branch 'master' of https://github.com/highfidelity/hifi into yellow

This commit is contained in:
Sam Cake 2015-05-15 15:27:14 -07:00
commit c3dfd574b4
7 changed files with 70 additions and 75 deletions

View file

@ -13,7 +13,6 @@
var isGrabbing = false; var isGrabbing = false;
var grabbedEntity = null; var grabbedEntity = null;
var lineEntityID = null;
var prevMouse = {}; var prevMouse = {};
var deltaMouse = { var deltaMouse = {
z: 0 z: 0
@ -39,9 +38,9 @@ var angularVelocity = {
var grabSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/CloseClamp.wav"); var grabSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/CloseClamp.wav");
var releaseSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/ReleaseClamp.wav"); var releaseSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/ReleaseClamp.wav");
var VOLUME = 0.10; var VOLUME = 0.0;
var DROP_DISTANCE = 5.0; var DROP_DISTANCE = 0.10;
var DROP_COLOR = { var DROP_COLOR = {
red: 200, red: 200,
green: 200, green: 200,
@ -92,14 +91,6 @@ function mousePressEvent(event) {
gravity: {x: 0, y: 0, z: 0} gravity: {x: 0, y: 0, z: 0}
}); });
lineEntityID = Entities.addEntity({
type: "Line",
position: nearLinePoint(targetPosition),
dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition)),
color: { red: 255, green: 255, blue: 255 },
lifetime: 300 // if someone crashes while moving something, don't leave the line there forever.
});
Audio.playSound(grabSound, { Audio.playSound(grabSound, {
position: props.position, position: props.position,
volume: VOLUME volume: VOLUME
@ -145,8 +136,6 @@ function mouseReleaseEvent() {
}); });
targetPosition = null; targetPosition = null;
Entities.deleteEntity(lineEntityID);
Audio.playSound(releaseSound, { Audio.playSound(releaseSound, {
position: entityProps.position, position: entityProps.position,
volume: VOLUME volume: VOLUME
@ -193,10 +182,6 @@ function mouseMoveEvent(event) {
angularVelocity = Vec3.multiply((theta / dT), axisAngle); angularVelocity = Vec3.multiply((theta / dT), axisAngle);
} }
Entities.editEntity(lineEntityID, {
position: nearLinePoint(targetPosition),
dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition))
});
} }
prevMouse.x = event.x; prevMouse.x = event.x;
prevMouse.y = event.y; prevMouse.y = event.y;

View file

@ -13,7 +13,6 @@
var isGrabbing = false; var isGrabbing = false;
var grabbedEntity = null; var grabbedEntity = null;
var lineEntityID = null;
var prevMouse = {}; var prevMouse = {};
var deltaMouse = { var deltaMouse = {
z: 0 z: 0
@ -91,14 +90,6 @@ function mousePressEvent(event) {
gravity: {x: 0, y: 0, z: 0} gravity: {x: 0, y: 0, z: 0}
}); });
lineEntityID = Entities.addEntity({
type: "Line",
position: nearLinePoint(targetPosition),
dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition)),
color: { red: 255, green: 255, blue: 255 },
lifetime: 300 // if someone crashes while moving something, don't leave the line there forever.
});
Audio.playSound(grabSound, { Audio.playSound(grabSound, {
position: props.position, position: props.position,
volume: 0.4 volume: 0.4
@ -144,8 +135,6 @@ function mouseReleaseEvent() {
}); });
targetPosition = null; targetPosition = null;
Entities.deleteEntity(lineEntityID);
Audio.playSound(grabSound, { Audio.playSound(grabSound, {
position: entityProps.position, position: entityProps.position,
volume: 0.25 volume: 0.25
@ -191,11 +180,6 @@ function mouseMoveEvent(event) {
axisAngle = Quat.axis(dQ); axisAngle = Quat.axis(dQ);
angularVelocity = Vec3.multiply((theta / dT), axisAngle); angularVelocity = Vec3.multiply((theta / dT), axisAngle);
} }
Entities.editEntity(lineEntityID, {
position: nearLinePoint(targetPosition),
dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition))
});
} }
prevMouse.x = event.x; prevMouse.x = event.x;
prevMouse.y = event.y; prevMouse.y = event.y;

View file

@ -24,23 +24,28 @@ function removeLine() {
function createOrUpdateLine(event) { function createOrUpdateLine(event) {
var pickRay = Camera.computePickRay(event.x, event.y); var pickRay = Camera.computePickRay(event.x, event.y);
var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking
var props = Entities.getEntityProperties(intersection.entityID);
if (lineIsRezzed) { if (intersection.intersects) {
Entities.editEntity(lineEntityID, { var dim = Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection));
position: nearLinePoint(intersection.intersection), if (lineIsRezzed) {
dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)), Entities.editEntity(lineEntityID, {
lifetime: 30 // renew lifetime position: nearLinePoint(intersection.intersection),
}); dimensions: dim,
lifetime: 60 + props.lifespan // renew lifetime
});
} else {
lineIsRezzed = true;
lineEntityID = Entities.addEntity({
type: "Line",
position: nearLinePoint(intersection.intersection),
dimensions: dim,
color: { red: 255, green: 255, blue: 255 },
lifetime: 60 // if someone crashes while pointing, don't leave the line there forever.
});
}
} else { } else {
lineIsRezzed = true; removeLine();
lineEntityID = Entities.addEntity({
type: "Line",
position: nearLinePoint(intersection.intersection),
dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)),
color: { red: 255, green: 255, blue: 255 },
lifetime: 30 // if someone crashes while pointing, don't leave the line there forever.
});
} }
} }

View file

@ -3077,13 +3077,10 @@ PickRay Application::computePickRay(float x, float y) const {
y /= size.y; y /= size.y;
PickRay result; PickRay result;
if (isHMDMode()) { if (isHMDMode()) {
ApplicationOverlay::computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction); getApplicationOverlay().computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction);
} else { } else {
if (activeRenderingThread) { auto frustum = activeRenderingThread ? getDisplayViewFrustum() : getViewFrustum();
getDisplayViewFrustum()->computePickRay(x, y, result.origin, result.direction); frustum->computePickRay(x, y, result.origin, result.direction);
} else {
getViewFrustum()->computePickRay(x, y, result.origin, result.direction);
}
} }
return result; return result;
} }
@ -3111,8 +3108,8 @@ QImage Application::renderAvatarBillboard() {
ViewFrustum* Application::getViewFrustum() { ViewFrustum* Application::getViewFrustum() {
#ifdef DEBUG #ifdef DEBUG
if (QThread::currentThread() == activeRenderingThread) { if (QThread::currentThread() == activeRenderingThread) {
// FIXME, should this be an assert? // FIXME, figure out a better way to do this
qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; //qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?";
} }
#endif #endif
return &_viewFrustum; return &_viewFrustum;
@ -3121,8 +3118,8 @@ ViewFrustum* Application::getViewFrustum() {
const ViewFrustum* Application::getViewFrustum() const { const ViewFrustum* Application::getViewFrustum() const {
#ifdef DEBUG #ifdef DEBUG
if (QThread::currentThread() == activeRenderingThread) { if (QThread::currentThread() == activeRenderingThread) {
// FIXME, should this be an assert? // FIXME, figure out a better way to do this
qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; //qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?";
} }
#endif #endif
return &_viewFrustum; return &_viewFrustum;
@ -3131,8 +3128,8 @@ const ViewFrustum* Application::getViewFrustum() const {
ViewFrustum* Application::getDisplayViewFrustum() { ViewFrustum* Application::getDisplayViewFrustum() {
#ifdef DEBUG #ifdef DEBUG
if (QThread::currentThread() != activeRenderingThread) { if (QThread::currentThread() != activeRenderingThread) {
// FIXME, should this be an assert? // FIXME, figure out a better way to do this
qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; // qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?";
} }
#endif #endif
return &_displayViewFrustum; return &_displayViewFrustum;
@ -3141,8 +3138,8 @@ ViewFrustum* Application::getDisplayViewFrustum() {
const ViewFrustum* Application::getDisplayViewFrustum() const { const ViewFrustum* Application::getDisplayViewFrustum() const {
#ifdef DEBUG #ifdef DEBUG
if (QThread::currentThread() != activeRenderingThread) { if (QThread::currentThread() != activeRenderingThread) {
// FIXME, should this be an assert? // FIXME, figure out a better way to do this
qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; // qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?";
} }
#endif #endif
return &_displayViewFrustum; return &_displayViewFrustum;

View file

@ -301,9 +301,14 @@ void ApplicationOverlay::displayOverlayTextureHmd(Camera& whichCamera) {
//Update and draw the magnifiers //Update and draw the magnifiers
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
const glm::quat& orientation = myAvatar->getOrientation(); const glm::quat& orientation = myAvatar->getOrientation();
const glm::vec3& position = myAvatar->getDefaultEyePosition(); // Always display the HMD overlay relative to the camera position but
// remove the HMD pose offset. This results in an overlay that sticks with you
// even in third person mode, but isn't drawn at a fixed distance.
glm::vec3 position = whichCamera.getPosition();
position -= qApp->getCamera()->getHmdPosition();
const float scale = myAvatar->getScale() * _oculusUIRadius; const float scale = myAvatar->getScale() * _oculusUIRadius;
// glm::vec3 eyeOffset = setEyeOffsetPosition;
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); { glPushMatrix(); {
glTranslatef(position.x, position.y, position.z); glTranslatef(position.x, position.y, position.z);
@ -453,19 +458,32 @@ void ApplicationOverlay::displayOverlayTextureStereo(Camera& whichCamera, float
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
} }
void ApplicationOverlay::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) { void ApplicationOverlay::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) const {
const MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); cursorPos *= qApp->getCanvasSize();
cursorPos = 0.5f - cursorPos; const glm::vec2 projection = screenToSpherical(cursorPos);
cursorPos *= MOUSE_RANGE; // The overlay space orientation of the mouse coordinates
const glm::quat orientation(glm::vec3(cursorPos, 0.0f)); const glm::quat orientation(glm::vec3(-projection.y, projection.x, 0.0f));
const glm::vec3 localDirection = orientation * IDENTITY_FRONT; // FIXME We now have the direction of the ray FROM THE DEFAULT HEAD POSE.
// Now we need to account for the actual camera position relative to the overlay
glm::vec3 overlaySpaceDirection = glm::normalize(orientation * IDENTITY_FRONT);
// Get cursor position
const glm::vec3 cursorDir = myAvatar->getDefaultEyePosition() + myAvatar->getOrientation() * localDirection;
// Ray start where the eye position is and stop where the cursor is const glm::vec3& hmdPosition = qApp->getCamera()->getHmdPosition();
origin = myAvatar->getEyePosition(); const glm::quat& hmdOrientation = qApp->getCamera()->getHmdRotation();
direction = cursorDir - origin;
// We need the RAW camera orientation and position, because this is what the overlay is
// rendered relative to
const glm::vec3 overlayPosition = qApp->getCamera()->getPosition() - hmdPosition;
const glm::quat overlayOrientation = qApp->getCamera()->getRotation() * glm::inverse(hmdOrientation);
// Intersection UI overlay space
glm::vec3 worldSpaceDirection = overlayOrientation * overlaySpaceDirection;
glm::vec3 intersectionWithUi = glm::normalize(worldSpaceDirection) * _oculusUIRadius;
intersectionWithUi += overlayPosition;
// Intersection in world space
origin = overlayPosition + hmdPosition;
direction = glm::normalize(intersectionWithUi - origin);
} }
//Caculate the click location using one of the sixense controllers. Scale is not applied //Caculate the click location using one of the sixense controllers. Scale is not applied

View file

@ -58,12 +58,12 @@ public:
glm::vec2 overlayToSpherical(const glm::vec2 & overlayPos) const; glm::vec2 overlayToSpherical(const glm::vec2 & overlayPos) const;
glm::vec2 screenToOverlay(const glm::vec2 & screenPos) const; glm::vec2 screenToOverlay(const glm::vec2 & screenPos) const;
glm::vec2 overlayToScreen(const glm::vec2 & overlayPos) const; glm::vec2 overlayToScreen(const glm::vec2 & overlayPos) const;
void computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) const;
static glm::vec2 directionToSpherical(const glm::vec3 & direction); static glm::vec2 directionToSpherical(const glm::vec3 & direction);
static glm::vec3 sphericalToDirection(const glm::vec2 & sphericalPos); static glm::vec3 sphericalToDirection(const glm::vec2 & sphericalPos);
static glm::vec2 screenToSpherical(const glm::vec2 & screenPos); static glm::vec2 screenToSpherical(const glm::vec2 & screenPos);
static glm::vec2 sphericalToScreen(const glm::vec2 & sphericalPos); static glm::vec2 sphericalToScreen(const glm::vec2 & sphericalPos);
static void computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction);
private: private:
// Interleaved vertex data // Interleaved vertex data

View file

@ -53,6 +53,12 @@ class LineEntityItem : public EntityItem {
virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; } virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; }
// never have a ray intersection pick a LineEntityItem.
virtual bool supportsDetailedRayIntersection() const { return true; }
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const { return false; }
virtual void debugDump() const; virtual void debugDump() const;
protected: protected: