mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:43:50 +02:00
add 3D sphere overlay support
This commit is contained in:
parent
5abf908874
commit
7c350b3acb
8 changed files with 240 additions and 77 deletions
|
@ -117,6 +117,20 @@ var solidCube = Overlays.addOverlay("cube", {
|
|||
solid: true
|
||||
});
|
||||
|
||||
var spherePosition = { x: 5, y: 5, z: 5 };
|
||||
var sphereSize = 1;
|
||||
var minSphereSize = 0.5;
|
||||
var maxSphereSize = 10;
|
||||
var sphereSizeChange = 0.05;
|
||||
|
||||
var sphere = Overlays.addOverlay("sphere", {
|
||||
position: spherePosition,
|
||||
size: sphereSize,
|
||||
color: { red: 0, green: 0, blue: 255},
|
||||
alpha: 1,
|
||||
solid: false
|
||||
});
|
||||
|
||||
|
||||
function scriptEnding() {
|
||||
Overlays.deleteOverlay(toolA);
|
||||
|
@ -151,12 +165,20 @@ function update() {
|
|||
}
|
||||
Overlays.editOverlay(cube, { position: cubePosition } );
|
||||
|
||||
// move our solid 3D cube
|
||||
solidCubePosition.x += solidCubeMove;
|
||||
solidCubePosition.z += solidCubeMove;
|
||||
if (solidCubePosition.x > maxSolidCubeX || solidCubePosition.x < minSolidCubeX) {
|
||||
solidCubeMove = solidCubeMove * -1;
|
||||
}
|
||||
Overlays.editOverlay(solidCube, { position: solidCubePosition } );
|
||||
|
||||
// adjust our 3D sphere
|
||||
sphereSize += sphereSizeChange;
|
||||
if (sphereSize > maxSphereSize || sphereSize < minSphereSize) {
|
||||
sphereSizeChange = sphereSizeChange * -1;
|
||||
}
|
||||
Overlays.editOverlay(sphere, { size: sphereSize, solid: (sphereSizeChange < 0) } );
|
||||
}
|
||||
Script.willSendVisualDataCallback.connect(update);
|
||||
|
||||
|
|
70
interface/src/ui/Base3DOverlay.cpp
Normal file
70
interface/src/ui/Base3DOverlay.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
//
|
||||
// Base3DOverlay.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 "Base3DOverlay.h"
|
||||
#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)
|
||||
{
|
||||
}
|
||||
|
||||
Base3DOverlay::~Base3DOverlay() {
|
||||
}
|
||||
|
||||
void Base3DOverlay::setProperties(const QScriptValue& properties) {
|
||||
Overlay::setProperties(properties);
|
||||
|
||||
QScriptValue position = properties.property("position");
|
||||
if (position.isValid()) {
|
||||
QScriptValue x = position.property("x");
|
||||
QScriptValue y = position.property("y");
|
||||
QScriptValue z = position.property("z");
|
||||
if (x.isValid() && y.isValid() && z.isValid()) {
|
||||
glm::vec3 newPosition;
|
||||
newPosition.x = x.toVariant().toFloat();
|
||||
newPosition.y = y.toVariant().toFloat();
|
||||
newPosition.z = z.toVariant().toFloat();
|
||||
setPosition(newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
56
interface/src/ui/Base3DOverlay.h
Normal file
56
interface/src/ui/Base3DOverlay.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// Base3DOverlay.h
|
||||
// interface
|
||||
//
|
||||
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#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 {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Base3DOverlay();
|
||||
~Base3DOverlay();
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
|
||||
#endif /* defined(__interface__Base3DOverlay__) */
|
|
@ -12,19 +12,8 @@
|
|||
#include <SharedUtil.h>
|
||||
|
||||
#include "Cube3DOverlay.h"
|
||||
#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;
|
||||
|
||||
Cube3DOverlay::Cube3DOverlay() :
|
||||
_position(DEFAULT_POSITION),
|
||||
_size(DEFAULT_SIZE),
|
||||
_lineWidth(DEFAULT_LINE_WIDTH),
|
||||
_isSolid(DEFAULT_isSolid)
|
||||
{
|
||||
Cube3DOverlay::Cube3DOverlay() {
|
||||
}
|
||||
|
||||
Cube3DOverlay::~Cube3DOverlay() {
|
||||
|
@ -53,46 +42,3 @@ void Cube3DOverlay::render() {
|
|||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
void Cube3DOverlay::setProperties(const QScriptValue& properties) {
|
||||
Overlay::setProperties(properties);
|
||||
|
||||
QScriptValue position = properties.property("position");
|
||||
if (position.isValid()) {
|
||||
QScriptValue x = position.property("x");
|
||||
QScriptValue y = position.property("y");
|
||||
QScriptValue z = position.property("z");
|
||||
if (x.isValid() && y.isValid() && z.isValid()) {
|
||||
glm::vec3 newPosition;
|
||||
newPosition.x = x.toVariant().toFloat();
|
||||
newPosition.y = y.toVariant().toFloat();
|
||||
newPosition.z = z.toVariant().toFloat();
|
||||
setPosition(newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,35 +22,15 @@
|
|||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Overlay.h"
|
||||
#include "Base3DOverlay.h"
|
||||
|
||||
class Cube3DOverlay : public Overlay {
|
||||
class Cube3DOverlay : public Base3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Cube3DOverlay();
|
||||
~Cube3DOverlay();
|
||||
virtual void render();
|
||||
|
||||
// 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);
|
||||
|
||||
private:
|
||||
glm::vec3 _position;
|
||||
float _size;
|
||||
float _lineWidth;
|
||||
bool _isSolid;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "Cube3DOverlay.h"
|
||||
#include "ImageOverlay.h"
|
||||
#include "Overlays.h"
|
||||
#include "Sphere3DOverlay.h"
|
||||
#include "TextOverlay.h"
|
||||
|
||||
|
||||
|
@ -59,6 +60,12 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope
|
|||
thisOverlay->setProperties(properties);
|
||||
created = true;
|
||||
is3D = true;
|
||||
} else if (type == "sphere") {
|
||||
thisOverlay = new Sphere3DOverlay();
|
||||
thisOverlay->init(_parent);
|
||||
thisOverlay->setProperties(properties);
|
||||
created = true;
|
||||
is3D = true;
|
||||
}
|
||||
|
||||
if (created) {
|
||||
|
|
45
interface/src/ui/Sphere3DOverlay.cpp
Normal file
45
interface/src/ui/Sphere3DOverlay.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// Sphere3DOverlay.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 "Sphere3DOverlay.h"
|
||||
|
||||
Sphere3DOverlay::Sphere3DOverlay() {
|
||||
}
|
||||
|
||||
Sphere3DOverlay::~Sphere3DOverlay() {
|
||||
}
|
||||
|
||||
void Sphere3DOverlay::render() {
|
||||
if (!_visible) {
|
||||
return; // do nothing if we're not visible
|
||||
}
|
||||
|
||||
const float MAX_COLOR = 255;
|
||||
glColor4f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, _alpha);
|
||||
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glPushMatrix();
|
||||
glTranslatef(_position.x + _size * 0.5f,
|
||||
_position.y + _size * 0.5f,
|
||||
_position.z + _size * 0.5f);
|
||||
glLineWidth(_lineWidth);
|
||||
const int slices = 15;
|
||||
if (_isSolid) {
|
||||
glutSolidSphere(_size, slices, slices);
|
||||
} else {
|
||||
glutWireSphere(_size, slices, slices);
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
}
|
37
interface/src/ui/Sphere3DOverlay.h
Normal file
37
interface/src/ui/Sphere3DOverlay.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// Sphere3DOverlay.h
|
||||
// interface
|
||||
//
|
||||
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __interface__Sphere3DOverlay__
|
||||
#define __interface__Sphere3DOverlay__
|
||||
|
||||
// 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 "Base3DOverlay.h"
|
||||
|
||||
class Sphere3DOverlay : public Base3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Sphere3DOverlay();
|
||||
~Sphere3DOverlay();
|
||||
virtual void render();
|
||||
};
|
||||
|
||||
|
||||
#endif /* defined(__interface__Sphere3DOverlay__) */
|
Loading…
Reference in a new issue