Merge pull request #2874 from Atlante45/anchers_apply_rotation_and_scale

Added rotation and scale to overlay anchers
This commit is contained in:
Brad Hefta-Gaub 2014-05-18 19:40:28 -07:00
commit c5cfca25a3
2 changed files with 31 additions and 3 deletions

View file

@ -174,8 +174,14 @@ function controller(wichSide) {
}
this.moveLaser = function () {
var startPosition = Vec3.subtract(this.palmPosition, MyAvatar.position);
var endPosition = Vec3.sum(startPosition, Vec3.multiply(this.front, LASER_LENGTH_FACTOR));
// the overlays here are anchored to the avatar, which means they are specified in the avatar's local frame
var inverseRotation = Quat.inverse(MyAvatar.orientation);
var startPosition = Vec3.multiplyQbyV(inverseRotation, Vec3.subtract(this.palmPosition, MyAvatar.position));
var direction = Vec3.multiplyQbyV(inverseRotation, Vec3.subtract(this.tipPosition, this.palmPosition));
var distance = Vec3.length(direction);
direction = Vec3.multiply(direction, LASER_LENGTH_FACTOR / distance);
var endPosition = Vec3.sum(startPosition, direction);
Overlays.editOverlay(this.laser, {
position: startPosition,

View file

@ -58,13 +58,35 @@ void Overlays::render2D() {
}
void Overlays::render3D() {
glm::vec3 myAvatarPosition = Application::getInstance()->getAvatar()->getPosition();
if (_overlays3D.size() == 0) {
return;
}
bool myAvatarComputed = false;
MyAvatar* avatar;
glm::quat myAvatarRotation;
glm::vec3 myAvatarPosition;
float angle;
glm::vec3 axis;
float myAvatarScale;
foreach(Overlay* thisOverlay, _overlays3D) {
glPushMatrix();
switch (thisOverlay->getAnchor()) {
case Overlay::MY_AVATAR:
if (!myAvatarComputed) {
avatar = Application::getInstance()->getAvatar();
myAvatarRotation = avatar->getOrientation();
myAvatarPosition = avatar->getPosition();
angle = glm::degrees(glm::angle(myAvatarRotation));
axis = glm::axis(myAvatarRotation);
myAvatarScale = avatar->getScale();
myAvatarComputed = true;
}
glTranslatef(myAvatarPosition.x, myAvatarPosition.y, myAvatarPosition.z);
glRotatef(angle, axis.x, axis.y, axis.z);
glScalef(myAvatarScale, myAvatarScale, myAvatarScale);
break;
default:
break;