mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 19:50:38 +02:00
Merge pull request #2864 from Atlante45/fix_jittery_overlays
Add ability to anchor an overlay
This commit is contained in:
commit
ecbe61e32a
4 changed files with 52 additions and 19 deletions
|
@ -76,38 +76,42 @@ function controller(wichSide) {
|
||||||
this.oldModelRadius;
|
this.oldModelRadius;
|
||||||
|
|
||||||
this.laser = Overlays.addOverlay("line3d", {
|
this.laser = Overlays.addOverlay("line3d", {
|
||||||
position: this.palmPosition,
|
position: { x: 0, y: 0, z: 0 },
|
||||||
end: this.tipPosition,
|
end: { x: 0, y: 0, z: 0 },
|
||||||
color: LASER_COLOR,
|
color: LASER_COLOR,
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
visible: false,
|
visible: false,
|
||||||
lineWidth: LASER_WIDTH
|
lineWidth: LASER_WIDTH,
|
||||||
|
anchor: "MyAvatar"
|
||||||
});
|
});
|
||||||
|
|
||||||
this.guideScale = 0.02;
|
this.guideScale = 0.02;
|
||||||
this.ball = Overlays.addOverlay("sphere", {
|
this.ball = Overlays.addOverlay("sphere", {
|
||||||
position: this.palmPosition,
|
position: { x: 0, y: 0, z: 0 },
|
||||||
size: this.guideScale,
|
size: this.guideScale,
|
||||||
solid: true,
|
solid: true,
|
||||||
color: { red: 0, green: 255, blue: 0 },
|
color: { red: 0, green: 255, blue: 0 },
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
visible: false,
|
visible: false,
|
||||||
|
anchor: "MyAvatar"
|
||||||
});
|
});
|
||||||
this.leftRight = Overlays.addOverlay("line3d", {
|
this.leftRight = Overlays.addOverlay("line3d", {
|
||||||
position: this.palmPosition,
|
position: { x: 0, y: 0, z: 0 },
|
||||||
end: this.tipPosition,
|
end: { x: 0, y: 0, z: 0 },
|
||||||
color: { red: 0, green: 0, blue: 255 },
|
color: { red: 0, green: 0, blue: 255 },
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
visible: false,
|
visible: false,
|
||||||
lineWidth: LASER_WIDTH
|
lineWidth: LASER_WIDTH,
|
||||||
|
anchor: "MyAvatar"
|
||||||
});
|
});
|
||||||
this.topDown = Overlays.addOverlay("line3d", {
|
this.topDown = Overlays.addOverlay("line3d", {
|
||||||
position: this.palmPosition,
|
position: { x: 0, y: 0, z: 0 },
|
||||||
end: this.tipPosition,
|
end: { x: 0, y: 0, z: 0 },
|
||||||
color: { red: 0, green: 0, blue: 255 },
|
color: { red: 0, green: 0, blue: 255 },
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
visible: false,
|
visible: false,
|
||||||
lineWidth: LASER_WIDTH
|
lineWidth: LASER_WIDTH,
|
||||||
|
anchor: "MyAvatar"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -170,10 +174,11 @@ function controller(wichSide) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.moveLaser = function () {
|
this.moveLaser = function () {
|
||||||
var endPosition = Vec3.sum(this.palmPosition, Vec3.multiply(this.front, LASER_LENGTH_FACTOR));
|
var startPosition = Vec3.subtract(this.palmPosition, MyAvatar.position);
|
||||||
|
var endPosition = Vec3.sum(startPosition, Vec3.multiply(this.front, LASER_LENGTH_FACTOR));
|
||||||
|
|
||||||
Overlays.editOverlay(this.laser, {
|
Overlays.editOverlay(this.laser, {
|
||||||
position: this.palmPosition,
|
position: startPosition,
|
||||||
end: endPosition,
|
end: endPosition,
|
||||||
visible: true
|
visible: true
|
||||||
});
|
});
|
||||||
|
@ -219,11 +224,11 @@ function controller(wichSide) {
|
||||||
position: newPosition,
|
position: newPosition,
|
||||||
modelRotation: newRotation
|
modelRotation: newRotation
|
||||||
});
|
});
|
||||||
print("Moving " + this.modelID.id);
|
// print("Moving " + this.modelID.id);
|
||||||
// Vec3.print("Old Position: ", this.oldModelPosition);
|
// Vec3.print("Old Position: ", this.oldModelPosition);
|
||||||
// Vec3.print("Sav Position: ", newPosition);
|
// Vec3.print("Sav Position: ", newPosition);
|
||||||
Quat.print("Old Rotation: ", this.oldModelRotation);
|
// Quat.print("Old Rotation: ", this.oldModelRotation);
|
||||||
Quat.print("New Rotation: ", newRotation);
|
// Quat.print("New Rotation: ", newRotation);
|
||||||
|
|
||||||
this.oldModelRotation = newRotation;
|
this.oldModelRotation = newRotation;
|
||||||
this.oldModelPosition = newPosition;
|
this.oldModelPosition = newPosition;
|
||||||
|
@ -301,7 +306,7 @@ var rightController = new controller(RIGHT);
|
||||||
|
|
||||||
function moveModels() {
|
function moveModels() {
|
||||||
if (leftController.grabbing && rightController.grabbing && rightController.modelID.id == leftController.modelID.id) {
|
if (leftController.grabbing && rightController.grabbing && rightController.modelID.id == leftController.modelID.id) {
|
||||||
print("Both controllers");
|
//print("Both controllers");
|
||||||
var oldLeftPoint = Vec3.sum(leftController.oldPalmPosition, Vec3.multiply(leftController.oldFront, leftController.x));
|
var oldLeftPoint = Vec3.sum(leftController.oldPalmPosition, Vec3.multiply(leftController.oldFront, leftController.x));
|
||||||
var oldRightPoint = Vec3.sum(rightController.oldPalmPosition, Vec3.multiply(rightController.oldFront, rightController.x));
|
var oldRightPoint = Vec3.sum(rightController.oldPalmPosition, Vec3.multiply(rightController.oldFront, rightController.x));
|
||||||
|
|
||||||
|
@ -319,7 +324,7 @@ function moveModels() {
|
||||||
|
|
||||||
var newPosition = Vec3.sum(middle,
|
var newPosition = Vec3.sum(middle,
|
||||||
Vec3.multiply(Vec3.subtract(leftController.oldModelPosition, oldMiddle), ratio));
|
Vec3.multiply(Vec3.subtract(leftController.oldModelPosition, oldMiddle), ratio));
|
||||||
Vec3.print("Ratio : " + ratio + " New position: ", newPosition);
|
//Vec3.print("Ratio : " + ratio + " New position: ", newPosition);
|
||||||
var rotation = Quat.multiply(leftController.rotation,
|
var rotation = Quat.multiply(leftController.rotation,
|
||||||
Quat.inverse(leftController.oldRotation));
|
Quat.inverse(leftController.oldRotation));
|
||||||
rotation = Quat.multiply(rotation, leftController.oldModelRotation);
|
rotation = Quat.multiply(rotation, leftController.oldModelRotation);
|
||||||
|
|
|
@ -23,7 +23,8 @@ Overlay::Overlay() :
|
||||||
_parent(NULL),
|
_parent(NULL),
|
||||||
_alpha(DEFAULT_ALPHA),
|
_alpha(DEFAULT_ALPHA),
|
||||||
_color(DEFAULT_BACKGROUND_COLOR),
|
_color(DEFAULT_BACKGROUND_COLOR),
|
||||||
_visible(true)
|
_visible(true),
|
||||||
|
_anchor(NO_ANCHOR)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +52,15 @@ void Overlay::setProperties(const QScriptValue& properties) {
|
||||||
if (properties.property("alpha").isValid()) {
|
if (properties.property("alpha").isValid()) {
|
||||||
setAlpha(properties.property("alpha").toVariant().toFloat());
|
setAlpha(properties.property("alpha").toVariant().toFloat());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (properties.property("visible").isValid()) {
|
if (properties.property("visible").isValid()) {
|
||||||
setVisible(properties.property("visible").toVariant().toBool());
|
setVisible(properties.property("visible").toVariant().toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (properties.property("anchor").isValid()) {
|
||||||
|
QString property = properties.property("anchor").toVariant().toString();
|
||||||
|
if (property == "MyAvatar") {
|
||||||
|
setAnchor(MY_AVATAR);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,11 @@ class Overlay : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum Anchor {
|
||||||
|
NO_ANCHOR,
|
||||||
|
MY_AVATAR
|
||||||
|
};
|
||||||
|
|
||||||
Overlay();
|
Overlay();
|
||||||
~Overlay();
|
~Overlay();
|
||||||
void init(QGLWidget* parent);
|
void init(QGLWidget* parent);
|
||||||
|
@ -38,11 +43,13 @@ public:
|
||||||
bool getVisible() const { return _visible; }
|
bool getVisible() const { return _visible; }
|
||||||
const xColor& getColor() const { return _color; }
|
const xColor& getColor() const { return _color; }
|
||||||
float getAlpha() const { return _alpha; }
|
float getAlpha() const { return _alpha; }
|
||||||
|
Anchor getAnchor() const { return _anchor; }
|
||||||
|
|
||||||
// setters
|
// setters
|
||||||
void setVisible(bool visible) { _visible = visible; }
|
void setVisible(bool visible) { _visible = visible; }
|
||||||
void setColor(const xColor& color) { _color = color; }
|
void setColor(const xColor& color) { _color = color; }
|
||||||
void setAlpha(float alpha) { _alpha = alpha; }
|
void setAlpha(float alpha) { _alpha = alpha; }
|
||||||
|
void setAnchor(Anchor anchor) { _anchor = anchor; }
|
||||||
|
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
|
|
||||||
|
@ -51,6 +58,7 @@ protected:
|
||||||
float _alpha;
|
float _alpha;
|
||||||
xColor _color;
|
xColor _color;
|
||||||
bool _visible; // should the overlay be drawn at all
|
bool _visible; // should the overlay be drawn at all
|
||||||
|
Anchor _anchor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
|
||||||
#include "Cube3DOverlay.h"
|
#include "Cube3DOverlay.h"
|
||||||
#include "ImageOverlay.h"
|
#include "ImageOverlay.h"
|
||||||
|
@ -57,8 +58,19 @@ void Overlays::render2D() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Overlays::render3D() {
|
void Overlays::render3D() {
|
||||||
|
glm::vec3 myAvatarPosition = Application::getInstance()->getAvatar()->getPosition();
|
||||||
|
|
||||||
foreach(Overlay* thisOverlay, _overlays3D) {
|
foreach(Overlay* thisOverlay, _overlays3D) {
|
||||||
|
glPushMatrix();
|
||||||
|
switch (thisOverlay->getAnchor()) {
|
||||||
|
case Overlay::MY_AVATAR:
|
||||||
|
glTranslatef(myAvatarPosition.x, myAvatarPosition.y, myAvatarPosition.z);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
thisOverlay->render();
|
thisOverlay->render();
|
||||||
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue