mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 14:03:55 +02:00
introduce Planar3DOverlay for common features of rectangle and circle, introduced rectanglular 3D plane
This commit is contained in:
parent
7fc6eecca7
commit
c3b0700601
14 changed files with 424 additions and 98 deletions
|
@ -1582,13 +1582,37 @@ var SelectionDisplay = function (opts) {
|
|||
visible: false
|
||||
});
|
||||
|
||||
var baseOverlayAngles = { x: 0, y: 0, z: 0 };
|
||||
var baseOverlayRotation = Quat.fromVec3Degrees(baseOverlayAngles);
|
||||
|
||||
var baseOfEntityOverlay = Overlays.addOverlay("rectangle3d", {
|
||||
position: { x:0, y: 0, z: 0},
|
||||
size: 1,
|
||||
color: { red: 0, green: 0, blue: 0},
|
||||
alpha: 1,
|
||||
solid: false,
|
||||
visible: false,
|
||||
rotation: baseOverlayRotation
|
||||
});
|
||||
|
||||
var baseOfEntityProjectionOverlay = Overlays.addOverlay("rectangle3d", {
|
||||
position: { x:0, y: 0, z: 0},
|
||||
size: 1,
|
||||
color: { red: 51, green: 152, blue: 203 },
|
||||
alpha: 0.5,
|
||||
solid: true,
|
||||
visible: false,
|
||||
rotation: baseOverlayRotation
|
||||
});
|
||||
|
||||
|
||||
var yawOverlayAngles = { x: 90, y: 0, z: 0 };
|
||||
var yawOverlayRotation = Quat.fromVec3Degrees(yawOverlayAngles);
|
||||
var yawOverlayInner = Overlays.addOverlay("circle3d", {
|
||||
position: { x:0, y: 0, z: 0},
|
||||
size: 1,
|
||||
color: { red: 0, green: 195, blue: 255},
|
||||
alpha: 0.1,
|
||||
color: { red: 51, green: 152, blue: 203 },
|
||||
alpha: 0.2,
|
||||
solid: true,
|
||||
visible: false,
|
||||
rotation: yawOverlayRotation
|
||||
|
@ -1597,8 +1621,8 @@ var SelectionDisplay = function (opts) {
|
|||
var yawOverlayOuter = Overlays.addOverlay("circle3d", {
|
||||
position: { x:0, y: 0, z: 0},
|
||||
size: 1,
|
||||
color: { red: 0, green: 195, blue: 215},
|
||||
alpha: 0.1,
|
||||
color: { red: 51, green: 152, blue: 203 },
|
||||
alpha: 0.2,
|
||||
solid: true,
|
||||
visible: false,
|
||||
rotation: yawOverlayRotation
|
||||
|
@ -1607,10 +1631,9 @@ var SelectionDisplay = function (opts) {
|
|||
var yawOverlayCurrent = Overlays.addOverlay("circle3d", {
|
||||
position: { x:0, y: 0, z: 0},
|
||||
size: 1,
|
||||
color: { red: 255, green: 190, blue: 190},
|
||||
alpha: 1,
|
||||
solid: false,
|
||||
isDashedLine: true,
|
||||
color: { red: 224, green: 67, blue: 36},
|
||||
alpha: 0.8,
|
||||
solid: true,
|
||||
visible: false,
|
||||
rotation: yawOverlayRotation,
|
||||
});
|
||||
|
@ -1681,6 +1704,8 @@ var SelectionDisplay = function (opts) {
|
|||
|
||||
this.cleanup = function () {
|
||||
Overlays.deleteOverlay(selectionBox);
|
||||
Overlays.deleteOverlay(baseOfEntityOverlay);
|
||||
Overlays.deleteOverlay(baseOfEntityProjectionOverlay);
|
||||
Overlays.deleteOverlay(yawOverlayInner);
|
||||
Overlays.deleteOverlay(yawOverlayOuter);
|
||||
Overlays.deleteOverlay(yawOverlayCurrent);
|
||||
|
@ -1694,12 +1719,21 @@ var SelectionDisplay = function (opts) {
|
|||
this.showSelection = function (properties) {
|
||||
|
||||
var diagonal = (Vec3.length(properties.dimensions) / 2) * 1.1;
|
||||
var halfDimensions = Vec3.multiply(properties.dimensions, 0.5);
|
||||
var innerRadius = diagonal;
|
||||
var outerRadius = diagonal * 1.15;
|
||||
var innerActive = false;
|
||||
var innerAlpha = 0.2;
|
||||
var outerAlpha = 0.2;
|
||||
if (innerActive) {
|
||||
innerAlpha = 0.5;
|
||||
} else {
|
||||
outerAlpha = 0.5;
|
||||
}
|
||||
|
||||
Overlays.editOverlay(selectionBox,
|
||||
{
|
||||
visible: true,
|
||||
visible: false,
|
||||
solid:false,
|
||||
lineWidth: 2.0,
|
||||
position: { x: properties.position.x,
|
||||
|
@ -1715,25 +1749,51 @@ var SelectionDisplay = function (opts) {
|
|||
glowLevelPulse: 1.0,
|
||||
alphaPulse: 0.5,
|
||||
colorPulse: -0.5
|
||||
|
||||
});
|
||||
|
||||
Overlays.editOverlay(baseOfEntityOverlay,
|
||||
{
|
||||
visible: true,
|
||||
solid:false,
|
||||
lineWidth: 2.0,
|
||||
position: { x: properties.position.x,
|
||||
y: properties.position.y - halfDimensions.y,
|
||||
z: properties.position.z },
|
||||
|
||||
dimensions: { x: properties.dimensions.x, y: properties.dimensions.z },
|
||||
rotation: properties.rotation,
|
||||
});
|
||||
|
||||
Overlays.editOverlay(baseOfEntityProjectionOverlay,
|
||||
{
|
||||
visible: true,
|
||||
solid:true,
|
||||
lineWidth: 2.0,
|
||||
position: { x: properties.position.x,
|
||||
y: 0,
|
||||
z: properties.position.z },
|
||||
|
||||
dimensions: { x: properties.dimensions.x, y: properties.dimensions.z },
|
||||
rotation: properties.rotation,
|
||||
});
|
||||
|
||||
|
||||
|
||||
Overlays.editOverlay(yawOverlayInner,
|
||||
{
|
||||
visible: true,
|
||||
lineWidth: 5.0,
|
||||
position: { x: properties.position.x,
|
||||
y: properties.position.y - (properties.dimensions.y / 2),
|
||||
z: properties.position.z},
|
||||
|
||||
size: innerRadius,
|
||||
innerRadius: 0.9
|
||||
innerRadius: 0.9,
|
||||
alpha: innerAlpha
|
||||
});
|
||||
|
||||
Overlays.editOverlay(yawOverlayOuter,
|
||||
{
|
||||
visible: true,
|
||||
lineWidth: 5.0,
|
||||
position: { x: properties.position.x,
|
||||
y: properties.position.y - (properties.dimensions.y / 2),
|
||||
z: properties.position.z},
|
||||
|
@ -1742,12 +1802,12 @@ var SelectionDisplay = function (opts) {
|
|||
innerRadius: 0.9,
|
||||
startAt: 90,
|
||||
endAt: 405,
|
||||
alpha: outerAlpha
|
||||
});
|
||||
|
||||
Overlays.editOverlay(yawOverlayCurrent,
|
||||
{
|
||||
visible: true,
|
||||
lineWidth: 5.0,
|
||||
position: { x: properties.position.x,
|
||||
y: properties.position.y - (properties.dimensions.y / 2),
|
||||
z: properties.position.z},
|
||||
|
@ -1817,6 +1877,8 @@ var SelectionDisplay = function (opts) {
|
|||
|
||||
this.hideSelection = function () {
|
||||
Overlays.editOverlay(selectionBox, { visible: false });
|
||||
Overlays.editOverlay(baseOfEntityOverlay, { visible: false });
|
||||
Overlays.editOverlay(baseOfEntityProjectionOverlay, { visible: false });
|
||||
Overlays.editOverlay(yawOverlayInner, { visible: false });
|
||||
Overlays.editOverlay(yawOverlayOuter, { visible: false });
|
||||
Overlays.editOverlay(yawOverlayCurrent, { visible: false });
|
||||
|
|
|
@ -18,10 +18,15 @@
|
|||
|
||||
const glm::vec3 DEFAULT_POSITION = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
const float DEFAULT_LINE_WIDTH = 1.0f;
|
||||
const bool DEFAULT_IS_SOLID = false;
|
||||
const bool DEFAULT_IS_DASHED_LINE = false;
|
||||
|
||||
Base3DOverlay::Base3DOverlay() :
|
||||
_position(DEFAULT_POSITION),
|
||||
_lineWidth(DEFAULT_LINE_WIDTH)
|
||||
_lineWidth(DEFAULT_LINE_WIDTH),
|
||||
_isSolid(DEFAULT_IS_SOLID),
|
||||
_isDashedLine(DEFAULT_IS_DASHED_LINE),
|
||||
_rotation()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -60,4 +65,51 @@ void Base3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
if (properties.property("lineWidth").isValid()) {
|
||||
setLineWidth(properties.property("lineWidth").toVariant().toFloat());
|
||||
}
|
||||
|
||||
QScriptValue rotation = properties.property("rotation");
|
||||
|
||||
if (rotation.isValid()) {
|
||||
glm::quat newRotation;
|
||||
|
||||
// size, scale, dimensions is special, it might just be a single scalar, or it might be a vector, check that here
|
||||
QScriptValue x = rotation.property("x");
|
||||
QScriptValue y = rotation.property("y");
|
||||
QScriptValue z = rotation.property("z");
|
||||
QScriptValue w = rotation.property("w");
|
||||
|
||||
|
||||
if (x.isValid() && y.isValid() && z.isValid() && w.isValid()) {
|
||||
newRotation.x = x.toVariant().toFloat();
|
||||
newRotation.y = y.toVariant().toFloat();
|
||||
newRotation.z = z.toVariant().toFloat();
|
||||
newRotation.w = w.toVariant().toFloat();
|
||||
setRotation(newRotation);
|
||||
}
|
||||
}
|
||||
|
||||
if (properties.property("isSolid").isValid()) {
|
||||
setIsSolid(properties.property("isSolid").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("isFilled").isValid()) {
|
||||
setIsSolid(properties.property("isSolid").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("isWire").isValid()) {
|
||||
setIsSolid(!properties.property("isWire").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("solid").isValid()) {
|
||||
setIsSolid(properties.property("solid").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("filled").isValid()) {
|
||||
setIsSolid(properties.property("filled").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("wire").isValid()) {
|
||||
setIsSolid(!properties.property("wire").toVariant().toBool());
|
||||
}
|
||||
|
||||
if (properties.property("isDashedLine").isValid()) {
|
||||
setIsDashedLine(properties.property("isDashedLine").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("dashed").isValid()) {
|
||||
setIsDashedLine(!properties.property("dashed").toVariant().toBool());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#define hifi_Base3DOverlay_h
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
//#include <glm/gtx/extented_min_max.hpp>
|
||||
|
||||
#include "Overlay.h"
|
||||
|
||||
|
@ -24,17 +26,28 @@ public:
|
|||
|
||||
// getters
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
const glm::vec3& getCenter() const { return _position; } // TODO: consider implementing registration points in this class
|
||||
float getLineWidth() const { return _lineWidth; }
|
||||
bool getIsSolid() const { return _isSolid; }
|
||||
bool getIsDashedLine() const { return _isDashedLine; }
|
||||
bool getIsSolidLine() const { return !_isDashedLine; }
|
||||
const glm::quat& getRotation() const { return _rotation; }
|
||||
|
||||
// setters
|
||||
void setPosition(const glm::vec3& position) { _position = position; }
|
||||
void setLineWidth(float lineWidth) { _lineWidth = lineWidth; }
|
||||
void setIsSolid(bool isSolid) { _isSolid = isSolid; }
|
||||
void setIsDashedLine(bool isDashedLine) { _isDashedLine = isDashedLine; }
|
||||
void setRotation(const glm::quat& value) { _rotation = value; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
|
||||
protected:
|
||||
glm::vec3 _position;
|
||||
float _lineWidth;
|
||||
glm::quat _rotation;
|
||||
bool _isSolid;
|
||||
bool _isDashedLine;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -56,16 +56,16 @@ void BillboardOverlay::render() {
|
|||
|
||||
glPushMatrix(); {
|
||||
glTranslatef(_position.x, _position.y, _position.z);
|
||||
glm::quat rotation;
|
||||
if (_isFacingAvatar) {
|
||||
// rotate about vertical to face the camera
|
||||
glm::quat rotation = Application::getInstance()->getCamera()->getRotation();
|
||||
rotation = Application::getInstance()->getCamera()->getRotation();
|
||||
rotation *= glm::angleAxis(glm::pi<float>(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
} else {
|
||||
glm::vec3 axis = glm::axis(_rotation);
|
||||
glRotatef(glm::degrees(glm::angle(_rotation)), axis.x, axis.y, axis.z);
|
||||
rotation = getRotation();
|
||||
}
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
glScalef(_scale, _scale, _scale);
|
||||
|
||||
if (_billboardTexture) {
|
||||
|
@ -140,20 +140,6 @@ void BillboardOverlay::setProperties(const QScriptValue &properties) {
|
|||
_scale = scaleValue.toVariant().toFloat();
|
||||
}
|
||||
|
||||
QScriptValue rotationValue = properties.property("rotation");
|
||||
if (rotationValue.isValid()) {
|
||||
QScriptValue x = rotationValue.property("x");
|
||||
QScriptValue y = rotationValue.property("y");
|
||||
QScriptValue z = rotationValue.property("z");
|
||||
QScriptValue w = rotationValue.property("w");
|
||||
if (x.isValid() && y.isValid() && z.isValid() && w.isValid()) {
|
||||
_rotation.x = x.toVariant().toFloat();
|
||||
_rotation.y = y.toVariant().toFloat();
|
||||
_rotation.z = z.toVariant().toFloat();
|
||||
_rotation.w = w.toVariant().toFloat();
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue isFacingAvatarValue = properties.property("isFacingAvatar");
|
||||
if (isFacingAvatarValue.isValid()) {
|
||||
_isFacingAvatar = isFacingAvatarValue.toVariant().toBool();
|
||||
|
|
|
@ -39,8 +39,7 @@ private:
|
|||
QScopedPointer<Texture> _billboardTexture;
|
||||
|
||||
QRect _fromImage; // where from in the image to sample
|
||||
|
||||
glm::quat _rotation;
|
||||
|
||||
float _scale;
|
||||
bool _isFacingAvatar;
|
||||
};
|
||||
|
|
|
@ -49,7 +49,7 @@ void Circle3DOverlay::render() {
|
|||
|
||||
glm::vec3 position = getPosition();
|
||||
glm::vec3 center = getCenter();
|
||||
glm::vec3 dimensions = getDimensions();
|
||||
glm::vec2 dimensions = getDimensions();
|
||||
glm::quat rotation = getRotation();
|
||||
|
||||
float glowLevel = getGlowLevel();
|
||||
|
@ -65,7 +65,7 @@ void Circle3DOverlay::render() {
|
|||
glPushMatrix();
|
||||
glm::vec3 positionToCenter = center - position;
|
||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||
glScalef(dimensions.x, dimensions.y, 1.0f);
|
||||
|
||||
// Create the circle in the coordinates origin
|
||||
float outerRadius = getOuterRadius();
|
||||
|
@ -153,7 +153,7 @@ void Circle3DOverlay::render() {
|
|||
}
|
||||
|
||||
void Circle3DOverlay::setProperties(const QScriptValue &properties) {
|
||||
Volume3DOverlay::setProperties(properties);
|
||||
Planar3DOverlay::setProperties(properties);
|
||||
|
||||
QScriptValue startAt = properties.property("startAt");
|
||||
if (startAt.isValid()) {
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
#ifndef hifi_Circle3DOverlay_h
|
||||
#define hifi_Circle3DOverlay_h
|
||||
|
||||
#include "Volume3DOverlay.h"
|
||||
#include "Planar3DOverlay.h"
|
||||
|
||||
class Circle3DOverlay : public Volume3DOverlay {
|
||||
class Circle3DOverlay : public Planar3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "LocalVoxelsOverlay.h"
|
||||
#include "ModelOverlay.h"
|
||||
#include "Overlays.h"
|
||||
#include "Rectangle3DOverlay.h"
|
||||
#include "Sphere3DOverlay.h"
|
||||
#include "TextOverlay.h"
|
||||
|
||||
|
@ -154,6 +155,12 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope
|
|||
thisOverlay->setProperties(properties);
|
||||
created = true;
|
||||
is3D = true;
|
||||
} else if (type == "rectangle3d") {
|
||||
thisOverlay = new Rectangle3DOverlay();
|
||||
thisOverlay->init(_parent);
|
||||
thisOverlay->setProperties(properties);
|
||||
created = true;
|
||||
is3D = true;
|
||||
} else if (type == "line3d") {
|
||||
thisOverlay = new Line3DOverlay();
|
||||
thisOverlay->init(_parent);
|
||||
|
|
76
interface/src/ui/overlays/Planar3DOverlay.cpp
Normal file
76
interface/src/ui/overlays/Planar3DOverlay.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
//
|
||||
// Planar3DOverlay.cpp
|
||||
// interface/src/ui/overlays
|
||||
//
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <SharedUtil.h>
|
||||
#include <StreamUtils.h>
|
||||
|
||||
#include "Planar3DOverlay.h"
|
||||
|
||||
const float DEFAULT_SIZE = 1.0f;
|
||||
|
||||
Planar3DOverlay::Planar3DOverlay() :
|
||||
_dimensions(glm::vec2(DEFAULT_SIZE, DEFAULT_SIZE))
|
||||
{
|
||||
}
|
||||
|
||||
Planar3DOverlay::~Planar3DOverlay() {
|
||||
}
|
||||
|
||||
void Planar3DOverlay::setProperties(const QScriptValue& properties) {
|
||||
Base3DOverlay::setProperties(properties);
|
||||
|
||||
QScriptValue dimensions = properties.property("dimensions");
|
||||
|
||||
// if "dimensions" property was not there, check to see if they included aliases: scale
|
||||
if (!dimensions.isValid()) {
|
||||
dimensions = properties.property("scale");
|
||||
if (!dimensions.isValid()) {
|
||||
dimensions = properties.property("size");
|
||||
}
|
||||
}
|
||||
|
||||
if (dimensions.isValid()) {
|
||||
bool validDimensions = false;
|
||||
glm::vec2 newDimensions;
|
||||
|
||||
QScriptValue x = dimensions.property("x");
|
||||
QScriptValue y = dimensions.property("y");
|
||||
|
||||
if (x.isValid() && y.isValid()) {
|
||||
newDimensions.x = x.toVariant().toFloat();
|
||||
newDimensions.y = y.toVariant().toFloat();
|
||||
validDimensions = true;
|
||||
} else {
|
||||
QScriptValue width = dimensions.property("width");
|
||||
QScriptValue height = dimensions.property("height");
|
||||
if (width.isValid() && height.isValid()) {
|
||||
newDimensions.x = width.toVariant().toFloat();
|
||||
newDimensions.y = height.toVariant().toFloat();
|
||||
validDimensions = true;
|
||||
}
|
||||
}
|
||||
|
||||
// size, scale, dimensions is special, it might just be a single scalar, check that here
|
||||
if (!validDimensions && dimensions.isNumber()) {
|
||||
float size = dimensions.toVariant().toFloat();
|
||||
newDimensions.x = size;
|
||||
newDimensions.y = size;
|
||||
validDimensions = true;
|
||||
}
|
||||
|
||||
if (validDimensions) {
|
||||
setDimensions(newDimensions);
|
||||
}
|
||||
}
|
||||
}
|
45
interface/src/ui/overlays/Planar3DOverlay.h
Normal file
45
interface/src/ui/overlays/Planar3DOverlay.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// Planar3DOverlay.h
|
||||
// interface/src/ui/overlays
|
||||
//
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_Planar3DOverlay_h
|
||||
#define hifi_Planar3DOverlay_h
|
||||
|
||||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <QScriptValue>
|
||||
|
||||
#include "Base3DOverlay.h"
|
||||
|
||||
class Planar3DOverlay : public Base3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Planar3DOverlay();
|
||||
~Planar3DOverlay();
|
||||
|
||||
// getters
|
||||
const glm::vec2& getDimensions() const { return _dimensions; }
|
||||
|
||||
// setters
|
||||
void setSize(float size) { _dimensions = glm::vec2(size, size); }
|
||||
void setDimensions(const glm::vec2& value) { _dimensions = value; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
|
||||
protected:
|
||||
glm::vec2 _dimensions;
|
||||
};
|
||||
|
||||
|
||||
#endif // hifi_Planar3DOverlay_h
|
115
interface/src/ui/overlays/Rectangle3DOverlay.cpp
Normal file
115
interface/src/ui/overlays/Rectangle3DOverlay.cpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
//
|
||||
// Rectangle3DOverlay.cpp
|
||||
// interface/src/ui/overlays
|
||||
//
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Rectangle3DOverlay.h"
|
||||
#include "renderer/GlowEffect.h"
|
||||
|
||||
Rectangle3DOverlay::Rectangle3DOverlay() {
|
||||
}
|
||||
|
||||
Rectangle3DOverlay::~Rectangle3DOverlay() {
|
||||
}
|
||||
|
||||
void Rectangle3DOverlay::render() {
|
||||
if (!_visible) {
|
||||
return; // do nothing if we're not visible
|
||||
}
|
||||
|
||||
float alpha = getAlpha();
|
||||
xColor color = getColor();
|
||||
const float MAX_COLOR = 255;
|
||||
glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glm::vec3 position = getPosition();
|
||||
glm::vec3 center = getCenter();
|
||||
glm::vec2 dimensions = getDimensions();
|
||||
glm::vec2 halfDimensions = dimensions * 0.5f;
|
||||
glm::quat rotation = getRotation();
|
||||
|
||||
float glowLevel = getGlowLevel();
|
||||
Glower* glower = NULL;
|
||||
if (glowLevel > 0.0f) {
|
||||
glower = new Glower(glowLevel);
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
glPushMatrix();
|
||||
glm::vec3 positionToCenter = center - position;
|
||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||
//glScalef(dimensions.x, dimensions.y, 1.0f);
|
||||
|
||||
glLineWidth(_lineWidth);
|
||||
|
||||
// for our overlay, is solid means we draw a solid "filled" rectangle otherwise we just draw a border line...
|
||||
if (getIsSolid()) {
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y);
|
||||
glVertex3f(halfDimensions.x, 0.0f, -halfDimensions.y);
|
||||
glVertex3f(halfDimensions.x, 0.0f, halfDimensions.y);
|
||||
glVertex3f(-halfDimensions.x, 0.0f, halfDimensions.y);
|
||||
|
||||
glEnd();
|
||||
} else {
|
||||
if (getIsDashedLine()) {
|
||||
|
||||
// TODO: change this to be dashed!
|
||||
glBegin(GL_LINE_STRIP);
|
||||
|
||||
glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y);
|
||||
glVertex3f(halfDimensions.x, 0.0f, -halfDimensions.y);
|
||||
glVertex3f(halfDimensions.x, 0.0f, halfDimensions.y);
|
||||
glVertex3f(-halfDimensions.x, 0.0f, halfDimensions.y);
|
||||
glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y);
|
||||
|
||||
glEnd();
|
||||
} else {
|
||||
glBegin(GL_LINE_STRIP);
|
||||
|
||||
glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y);
|
||||
glVertex3f(halfDimensions.x, 0.0f, -halfDimensions.y);
|
||||
glVertex3f(halfDimensions.x, 0.0f, halfDimensions.y);
|
||||
glVertex3f(-halfDimensions.x, 0.0f, halfDimensions.y);
|
||||
glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
|
||||
if (glower) {
|
||||
delete glower;
|
||||
}
|
||||
}
|
||||
|
||||
void Rectangle3DOverlay::setProperties(const QScriptValue &properties) {
|
||||
Planar3DOverlay::setProperties(properties);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
27
interface/src/ui/overlays/Rectangle3DOverlay.h
Normal file
27
interface/src/ui/overlays/Rectangle3DOverlay.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// Rectangle3DOverlay.h
|
||||
// interface/src/ui/overlays
|
||||
//
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_Rectangle3DOverlay_h
|
||||
#define hifi_Rectangle3DOverlay_h
|
||||
|
||||
#include "Planar3DOverlay.h"
|
||||
|
||||
class Rectangle3DOverlay : public Planar3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Rectangle3DOverlay();
|
||||
~Rectangle3DOverlay();
|
||||
virtual void render();
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
};
|
||||
|
||||
|
||||
#endif // hifi_Rectangle3DOverlay_h
|
|
@ -18,11 +18,9 @@
|
|||
#include "Volume3DOverlay.h"
|
||||
|
||||
const float DEFAULT_SIZE = 1.0f;
|
||||
const bool DEFAULT_IS_SOLID = false;
|
||||
|
||||
Volume3DOverlay::Volume3DOverlay() :
|
||||
_dimensions(glm::vec3(DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE)),
|
||||
_isSolid(DEFAULT_IS_SOLID)
|
||||
_dimensions(glm::vec3(DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -81,45 +79,4 @@ void Volume3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
setDimensions(newDimensions);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue rotation = properties.property("rotation");
|
||||
|
||||
if (rotation.isValid()) {
|
||||
glm::quat newRotation;
|
||||
|
||||
// size, scale, dimensions is special, it might just be a single scalar, or it might be a vector, check that here
|
||||
QScriptValue x = rotation.property("x");
|
||||
QScriptValue y = rotation.property("y");
|
||||
QScriptValue z = rotation.property("z");
|
||||
QScriptValue w = rotation.property("w");
|
||||
|
||||
|
||||
if (x.isValid() && y.isValid() && z.isValid() && w.isValid()) {
|
||||
newRotation.x = x.toVariant().toFloat();
|
||||
newRotation.y = y.toVariant().toFloat();
|
||||
newRotation.z = z.toVariant().toFloat();
|
||||
newRotation.w = w.toVariant().toFloat();
|
||||
setRotation(newRotation);
|
||||
}
|
||||
}
|
||||
|
||||
if (properties.property("isSolid").isValid()) {
|
||||
setIsSolid(properties.property("isSolid").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("isWire").isValid()) {
|
||||
setIsSolid(!properties.property("isWire").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("solid").isValid()) {
|
||||
setIsSolid(properties.property("solid").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("wire").isValid()) {
|
||||
setIsSolid(!properties.property("wire").toVariant().toBool());
|
||||
}
|
||||
|
||||
if (properties.property("isDashedLine").isValid()) {
|
||||
setIsDashedLine(properties.property("isDashedLine").toVariant().toBool());
|
||||
}
|
||||
if (properties.property("dashed").isValid()) {
|
||||
setIsDashedLine(!properties.property("dashed").toVariant().toBool());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
#include "InterfaceConfig.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/extented_min_max.hpp>
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <QScriptValue>
|
||||
|
@ -31,28 +29,17 @@ public:
|
|||
~Volume3DOverlay();
|
||||
|
||||
// getters
|
||||
bool getIsSolid() const { return _isSolid; }
|
||||
bool getIsDashedLine() const { return _isDashedLine; }
|
||||
bool getIsSolidLine() const { return !_isDashedLine; }
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
const glm::vec3& getCenter() const { return _position; } // TODO: consider adding registration point!!
|
||||
const glm::vec3& getDimensions() const { return _dimensions; }
|
||||
const glm::quat& getRotation() const { return _rotation; }
|
||||
|
||||
// setters
|
||||
void setSize(float size) { _dimensions = glm::vec3(size, size, size); }
|
||||
void setIsSolid(bool isSolid) { _isSolid = isSolid; }
|
||||
void setIsDashedLine(bool isDashedLine) { _isDashedLine = isDashedLine; }
|
||||
void setDimensions(const glm::vec3& value) { _dimensions = value; }
|
||||
void setRotation(const glm::quat& value) { _rotation = value; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
|
||||
protected:
|
||||
glm::vec3 _dimensions;
|
||||
glm::quat _rotation;
|
||||
bool _isSolid;
|
||||
bool _isDashedLine;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue