Merge remote-tracking branch 'upstream/master' into marge

This commit is contained in:
Bradley Austin Davis 2015-07-21 19:23:38 -04:00
commit bd5da87551
5 changed files with 75 additions and 55 deletions

View file

@ -1211,49 +1211,6 @@ PropertiesTool = function(opts) {
webView.setVisible(visible);
};
vecToPolar = function(direction) {
var x = direction.x;
var y = direction.y;
var z = direction.z;
var pitch, yaw;
pitch = -Math.asin(y);
var c = Math.cos(-pitch);
if (Math.abs(pitch) > (Math.PI / 2.0 - epsilon)) {
//handle gymbal lock
if (pitch > 0) {
pitch = Math.PI / 2.0;
} else {
pitch = -Math.PI / 2.0;
}
yaw = 0.0;
} else {
if (z < 0) {
if(x > 0 && x < 1) {
yaw = Math.PI - Math.asin(x / c);
} else {
yaw = -Math.asin(x / c) - Math.PI;
}
} else {
yaw = Math.asin(x / c);
}
}
return {
x: pitch * RADIANS_TO_DEGREES,
y: yaw * RADIANS_TO_DEGREES,
z: 0.0 //discard roll component
};
};
polarToVec = function(orientation) {
var pitch = orientation.x * DEGREES_TO_RADIANS;
var yaw = orientation.y * DEGREES_TO_RADIANS;
return {
x: Math.cos(pitch) * Math.sin(yaw),
y: Math.sin(-pitch),
z: Math.cos(pitch) * Math.cos(yaw)
};
}
selectionManager.addEventListener(function() {
data = {
type: 'update',
@ -1267,7 +1224,8 @@ PropertiesTool = function(opts) {
entity.properties.rotation = Quat.safeEulerAngles(entity.properties.rotation);
}
if (entity.properties.keyLightDirection !== undefined) {
entity.properties.keyLightDirection = vecToPolar(entity.properties.keyLightDirection);
entity.properties.keyLightDirection = Vec3.multiply(RADIANS_TO_DEGREES, Vec3.toPolar(entity.properties.keyLightDirection));
entity.properties.keyLightDirection.z = 0.0;
}
selections.push(entity);
}
@ -1297,7 +1255,8 @@ PropertiesTool = function(opts) {
data.properties.rotation = Quat.fromPitchYawRollDegrees(rotation.x, rotation.y, rotation.z);
}
if (data.properties.keyLightDirection !== undefined) {
data.properties.keyLightDirection = polarToVec(data.properties.keyLightDirection);
data.properties.keyLightDirection = Vec3.fromPolar(
data.properties.keyLightDirection.x * DEGREES_TO_RADIANS, data.properties.keyLightDirection.y * DEGREES_TO_RADIANS);
}
Entities.editEntity(selectionManager.selections[0], data.properties);
if (data.properties.name != undefined) {

View file

@ -483,7 +483,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo
// quick check before falling into the code below:
// (a 10 degree breadth of an almost 2 meter avatar kicks in at about 12m)
const float MIN_VOICE_SPHERE_DISTANCE = 12.0f;
if (postLighting && Menu::getInstance()->isOptionChecked(MenuOption::BlueSpeechSphere)
if (Menu::getInstance()->isOptionChecked(MenuOption::BlueSpeechSphere)
&& distanceToTarget > MIN_VOICE_SPHERE_DISTANCE) {
// render voice intensity sphere for avatars that are farther away
@ -497,7 +497,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo
float angle = abs(angleBetween(toTarget + delta, toTarget - delta));
float sphereRadius = getHead()->getAverageLoudness() * SPHERE_LOUDNESS_SCALING;
if (renderArgs->_renderMode == RenderArgs::NORMAL_RENDER_MODE && (sphereRadius > MIN_SPHERE_SIZE) &&
if (renderArgs->_renderMode == RenderArgs::DEFAULT_RENDER_MODE && (sphereRadius > MIN_SPHERE_SIZE) &&
(angle < MAX_SPHERE_ANGLE) && (angle > MIN_SPHERE_ANGLE)) {
Transform transform;
transform.setTranslation(_position);

View file

@ -79,7 +79,7 @@ const float MyAvatar::ZOOM_MAX = 25.0f;
const float MyAvatar::ZOOM_DEFAULT = 1.5f;
MyAvatar::MyAvatar() :
Avatar(),
Avatar(),
_gravity(0.0f, 0.0f, 0.0f),
_wasPushing(false),
_isPushing(false),
@ -253,6 +253,9 @@ void MyAvatar::updateFromTrackers(float deltaTime) {
return;
}
FaceTracker* tracker = Application::getInstance()->getActiveFaceTracker();
bool inFacetracker = tracker && !tracker->isMuted();
if (inHmd) {
estimatedPosition = qApp->getHeadPosition();
estimatedPosition.x *= -1.0f;
@ -260,12 +263,17 @@ void MyAvatar::updateFromTrackers(float deltaTime) {
const float OCULUS_LEAN_SCALE = 0.05f;
estimatedPosition /= OCULUS_LEAN_SCALE;
} else {
FaceTracker* tracker = Application::getInstance()->getActiveFaceTracker();
if (tracker && !tracker->isMuted()) {
estimatedPosition = tracker->getHeadTranslation();
_trackedHeadPosition = estimatedPosition;
estimatedRotation = glm::degrees(safeEulerAngles(tracker->getHeadRotation()));
} else if (inFacetracker) {
estimatedPosition = tracker->getHeadTranslation();
_trackedHeadPosition = estimatedPosition;
estimatedRotation = glm::degrees(safeEulerAngles(tracker->getHeadRotation()));
if (Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_MIRROR) {
// Invert yaw and roll when in mirror mode
// NOTE: this is kinda a hack, it's the same hack we use to make the head tilt. But it's not really a mirror
// it just makes you feel like you're looking in a mirror because the body movements of the avatar appear to
// match your body movements.
YAW(estimatedRotation) *= -1.0f;
ROLL(estimatedRotation) *= -1.0f;
}
}
@ -312,7 +320,7 @@ void MyAvatar::updateFromTrackers(float deltaTime) {
// NOTE: this is kinda a hack, it's the same hack we use to make the head tilt. But it's not really a mirror
// it just makes you feel like you're looking in a mirror because the body movements of the avatar appear to
// match your body movements.
if (inHmd && Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_MIRROR) {
if ((inHmd || inFacetracker) && Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_MIRROR) {
relativePosition.x = -relativePosition.x;
}

View file

@ -14,6 +14,7 @@
#include <QDebug>
#include "ScriptEngineLogging.h"
#include "NumericalConstants.h"
#include "Vec3.h"
glm::vec3 Vec3::reflect(const glm::vec3& v1, const glm::vec3& v2) {
@ -73,3 +74,52 @@ void Vec3::print(const QString& lable, const glm::vec3& v) {
bool Vec3::equal(const glm::vec3& v1, const glm::vec3& v2) {
return v1 == v2;
}
glm::vec3 Vec3::toPolar(const glm::vec3& v) {
float radius = length(v);
if (glm::abs(radius) < EPSILON) {
return glm::vec3(0.0f, 0.0f, 0.0f);
}
glm::vec3 u = v / radius;
float elevation, azimuth;
elevation = glm::asin(-u.y);
azimuth = atan2(v.x, v.z);
// Round off small decimal values
if (glm::abs(elevation) < EPSILON) {
elevation = 0.0f;
}
if (glm::abs(azimuth) < EPSILON) {
azimuth = 0.0f;
}
return glm::vec3(elevation, azimuth, radius);
}
glm::vec3 Vec3::fromPolar(const glm::vec3& polar) {
float x = glm::cos(polar.x) * glm::sin(polar.y);
float y = glm::sin(-polar.x);
float z = glm::cos(polar.x) * glm::cos(polar.y);
// Round small values to 0
if (glm::abs(x) < EPSILON) {
x = 0.0f;
}
if (glm::abs(y) < EPSILON) {
y = 0.0f;
}
if (glm::abs(z) < EPSILON) {
z = 0.0f;
}
return polar.z * glm::vec3(x, y, z);
}
glm::vec3 Vec3::fromPolar(float elevation, float azimuth) {
glm::vec3 v = glm::vec3(elevation, azimuth, 1.0f);
return fromPolar(v);
}

View file

@ -40,6 +40,9 @@ public slots:
glm::vec3 mix(const glm::vec3& v1, const glm::vec3& v2, float m);
void print(const QString& lable, const glm::vec3& v);
bool equal(const glm::vec3& v1, const glm::vec3& v2);
glm::vec3 toPolar(const glm::vec3& v);
glm::vec3 fromPolar(const glm::vec3& polar);
glm::vec3 fromPolar(float elevation, float azimuth);
};