Added rotation and scale to overlay anchers

This commit is contained in:
Atlante45 2014-05-16 17:36:27 -07:00
parent 18251d7251
commit 0edcd732fe
2 changed files with 19 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,23 @@ void Overlays::render2D() {
}
void Overlays::render3D() {
glm::vec3 myAvatarPosition = Application::getInstance()->getAvatar()->getPosition();
if (_overlays3D.size() == 0) {
return;
}
MyAvatar* avatar = Application::getInstance()->getAvatar();
glm::quat myAvatarRotation = avatar->getOrientation();
glm::vec3 myAvatarPosition = avatar->getPosition();
float angle = glm::degrees(glm::angle(myAvatarRotation));
glm::vec3 axis = glm::axis(myAvatarRotation);
float myAvatarScale = avatar->getScale();
foreach(Overlay* thisOverlay, _overlays3D) {
glPushMatrix();
switch (thisOverlay->getAnchor()) {
case Overlay::MY_AVATAR:
glTranslatef(myAvatarPosition.x, myAvatarPosition.y, myAvatarPosition.z);
glRotatef(angle, axis.x, axis.y, axis.z);
glScalef(myAvatarScale, myAvatarScale, myAvatarScale);
break;
default:
break;