mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
added 3D line overlay support
This commit is contained in:
parent
6b410253d4
commit
78f4df912d
10 changed files with 220 additions and 74 deletions
|
@ -148,6 +148,14 @@ var sphere = Overlays.addOverlay("sphere", {
|
|||
solid: false
|
||||
});
|
||||
|
||||
var line3d = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z:0 },
|
||||
end: { x: 10, y: 10, z:10 },
|
||||
color: { red: 0, green: 255, blue: 255},
|
||||
alpha: 1,
|
||||
lineWidth: 5
|
||||
});
|
||||
|
||||
|
||||
// When our script shuts down, we should clean up all of our overlays
|
||||
function scriptEnding() {
|
||||
|
@ -161,6 +169,7 @@ function scriptEnding() {
|
|||
Overlays.deleteOverlay(cube);
|
||||
Overlays.deleteOverlay(solidCube);
|
||||
Overlays.deleteOverlay(sphere);
|
||||
Overlays.deleteOverlay(line3d);
|
||||
}
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
|
@ -204,6 +213,10 @@ function update() {
|
|||
sphereSizeChange = sphereSizeChange * -1;
|
||||
}
|
||||
Overlays.editOverlay(sphere, { size: sphereSize, solid: (sphereSizeChange < 0) } );
|
||||
|
||||
|
||||
// update our 3D line to go from origin to our avatar's position
|
||||
Overlays.editOverlay(line3d, { end: MyAvatar.position } );
|
||||
}
|
||||
Script.willSendVisualDataCallback.connect(update);
|
||||
|
||||
|
|
|
@ -15,15 +15,11 @@
|
|||
#include "TextRenderer.h"
|
||||
|
||||
const glm::vec3 DEFAULT_POSITION = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
const float DEFAULT_SIZE = 1.0f;
|
||||
const float DEFAULT_LINE_WIDTH = 1.0f;
|
||||
const bool DEFAULT_isSolid = false;
|
||||
|
||||
Base3DOverlay::Base3DOverlay() :
|
||||
_position(DEFAULT_POSITION),
|
||||
_size(DEFAULT_SIZE),
|
||||
_lineWidth(DEFAULT_LINE_WIDTH),
|
||||
_isSolid(DEFAULT_isSolid)
|
||||
_lineWidth(DEFAULT_LINE_WIDTH)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -34,6 +30,18 @@ void Base3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
Overlay::setProperties(properties);
|
||||
|
||||
QScriptValue position = properties.property("position");
|
||||
|
||||
// if "position" property was not there, check to see if they included aliases: start, point, p1
|
||||
if (!position.isValid()) {
|
||||
position = properties.property("start");
|
||||
if (!position.isValid()) {
|
||||
position = properties.property("p1");
|
||||
if (!position.isValid()) {
|
||||
position = properties.property("point");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (position.isValid()) {
|
||||
QScriptValue x = position.property("x");
|
||||
QScriptValue y = position.property("y");
|
||||
|
@ -47,24 +55,7 @@ void Base3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
|
||||
if (properties.property("size").isValid()) {
|
||||
setSize(properties.property("size").toVariant().toFloat());
|
||||
}
|
||||
|
||||
if (properties.property("lineWidth").isValid()) {
|
||||
setLineWidth(properties.property("lineWidth").toVariant().toFloat());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,20 +8,6 @@
|
|||
#ifndef __interface__Base3DOverlay__
|
||||
#define __interface__Base3DOverlay__
|
||||
|
||||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <QImage>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QRect>
|
||||
#include <QScriptValue>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Overlay.h"
|
||||
|
||||
class Base3DOverlay : public Overlay {
|
||||
|
@ -33,23 +19,17 @@ public:
|
|||
|
||||
// getters
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
float getSize() const { return _size; }
|
||||
float getLineWidth() const { return _lineWidth; }
|
||||
bool getIsSolid() const { return _isSolid; }
|
||||
|
||||
// setters
|
||||
void setPosition(const glm::vec3& position) { _position = position; }
|
||||
void setSize(float size) { _size = size; }
|
||||
void setLineWidth(float lineWidth) { _lineWidth = lineWidth; }
|
||||
void setIsSolid(bool isSolid) { _isSolid = isSolid; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
|
||||
protected:
|
||||
glm::vec3 _position;
|
||||
float _size;
|
||||
float _lineWidth;
|
||||
bool _isSolid;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -8,23 +8,9 @@
|
|||
#ifndef __interface__Cube3DOverlay__
|
||||
#define __interface__Cube3DOverlay__
|
||||
|
||||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
#include "Volume3DOverlay.h"
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <QImage>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QRect>
|
||||
#include <QScriptValue>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Base3DOverlay.h"
|
||||
|
||||
class Cube3DOverlay : public Base3DOverlay {
|
||||
class Cube3DOverlay : public Volume3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
60
interface/src/ui/Line3DOverlay.cpp
Normal file
60
interface/src/ui/Line3DOverlay.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
//
|
||||
// Line3DOverlay.cpp
|
||||
// interface
|
||||
//
|
||||
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#include "Line3DOverlay.h"
|
||||
|
||||
|
||||
Line3DOverlay::Line3DOverlay() {
|
||||
}
|
||||
|
||||
Line3DOverlay::~Line3DOverlay() {
|
||||
}
|
||||
|
||||
void Line3DOverlay::render() {
|
||||
if (!_visible) {
|
||||
return; // do nothing if we're not visible
|
||||
}
|
||||
|
||||
const float MAX_COLOR = 255;
|
||||
glDisable(GL_LIGHTING);
|
||||
glLineWidth(_lineWidth);
|
||||
glColor4f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, _alpha);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(_position.x, _position.y, _position.z);
|
||||
glVertex3f(_end.x, _end.y, _end.z);
|
||||
glEnd();
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void Line3DOverlay::setProperties(const QScriptValue& properties) {
|
||||
Base3DOverlay::setProperties(properties);
|
||||
|
||||
QScriptValue end = properties.property("end");
|
||||
// if "end" property was not there, check to see if they included aliases: endPoint, or p2
|
||||
if (!end.isValid()) {
|
||||
end = properties.property("endPoint");
|
||||
if (!end.isValid()) {
|
||||
end = properties.property("p2");
|
||||
}
|
||||
}
|
||||
if (end.isValid()) {
|
||||
QScriptValue x = end.property("x");
|
||||
QScriptValue y = end.property("y");
|
||||
QScriptValue z = end.property("z");
|
||||
if (x.isValid() && y.isValid() && z.isValid()) {
|
||||
glm::vec3 newEnd;
|
||||
newEnd.x = x.toVariant().toFloat();
|
||||
newEnd.y = y.toVariant().toFloat();
|
||||
newEnd.z = z.toVariant().toFloat();
|
||||
setEnd(newEnd);
|
||||
}
|
||||
}
|
||||
}
|
34
interface/src/ui/Line3DOverlay.h
Normal file
34
interface/src/ui/Line3DOverlay.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// Line3DOverlay.h
|
||||
// interface
|
||||
//
|
||||
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __interface__Line3DOverlay__
|
||||
#define __interface__Line3DOverlay__
|
||||
|
||||
#include "Base3DOverlay.h"
|
||||
|
||||
class Line3DOverlay : public Base3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Line3DOverlay();
|
||||
~Line3DOverlay();
|
||||
virtual void render();
|
||||
|
||||
// getters
|
||||
const glm::vec3& getEnd() const { return _end; }
|
||||
|
||||
// setters
|
||||
void setEnd(const glm::vec3& end) { _end = end; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
|
||||
protected:
|
||||
glm::vec3 _end;
|
||||
};
|
||||
|
||||
|
||||
#endif /* defined(__interface__Line3DOverlay__) */
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "Cube3DOverlay.h"
|
||||
#include "ImageOverlay.h"
|
||||
#include "Line3DOverlay.h"
|
||||
#include "Overlays.h"
|
||||
#include "Sphere3DOverlay.h"
|
||||
#include "TextOverlay.h"
|
||||
|
@ -66,6 +67,12 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope
|
|||
thisOverlay->setProperties(properties);
|
||||
created = true;
|
||||
is3D = true;
|
||||
} else if (type == "line3d") {
|
||||
thisOverlay = new Line3DOverlay();
|
||||
thisOverlay->init(_parent);
|
||||
thisOverlay->setProperties(properties);
|
||||
created = true;
|
||||
is3D = true;
|
||||
}
|
||||
|
||||
if (created) {
|
||||
|
|
|
@ -8,23 +8,9 @@
|
|||
#ifndef __interface__Sphere3DOverlay__
|
||||
#define __interface__Sphere3DOverlay__
|
||||
|
||||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
#include "Volume3DOverlay.h"
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <QImage>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QRect>
|
||||
#include <QScriptValue>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Base3DOverlay.h"
|
||||
|
||||
class Sphere3DOverlay : public Base3DOverlay {
|
||||
class Sphere3DOverlay : public Volume3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
47
interface/src/ui/Volume3DOverlay.cpp
Normal file
47
interface/src/ui/Volume3DOverlay.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
//
|
||||
// Volume3DOverlay.cpp
|
||||
// interface
|
||||
//
|
||||
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Volume3DOverlay.h"
|
||||
|
||||
const float DEFAULT_SIZE = 1.0f;
|
||||
const bool DEFAULT_IS_SOLID = false;
|
||||
|
||||
Volume3DOverlay::Volume3DOverlay() :
|
||||
_size(DEFAULT_SIZE),
|
||||
_isSolid(DEFAULT_IS_SOLID)
|
||||
{
|
||||
}
|
||||
|
||||
Volume3DOverlay::~Volume3DOverlay() {
|
||||
}
|
||||
|
||||
void Volume3DOverlay::setProperties(const QScriptValue& properties) {
|
||||
Base3DOverlay::setProperties(properties);
|
||||
|
||||
if (properties.property("size").isValid()) {
|
||||
setSize(properties.property("size").toVariant().toFloat());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
42
interface/src/ui/Volume3DOverlay.h
Normal file
42
interface/src/ui/Volume3DOverlay.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// Volume3DOverlay.h
|
||||
// interface
|
||||
//
|
||||
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __interface__Volume3DOverlay__
|
||||
#define __interface__Volume3DOverlay__
|
||||
|
||||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <QScriptValue>
|
||||
|
||||
#include "Base3DOverlay.h"
|
||||
|
||||
class Volume3DOverlay : public Base3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Volume3DOverlay();
|
||||
~Volume3DOverlay();
|
||||
|
||||
// getters
|
||||
float getSize() const { return _size; }
|
||||
bool getIsSolid() const { return _isSolid; }
|
||||
|
||||
// setters
|
||||
void setSize(float size) { _size = size; }
|
||||
void setIsSolid(bool isSolid) { _isSolid = isSolid; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
|
||||
protected:
|
||||
float _size;
|
||||
bool _isSolid;
|
||||
};
|
||||
|
||||
|
||||
#endif /* defined(__interface__Volume3DOverlay__) */
|
Loading…
Reference in a new issue