Remove test script for now, working on actual edits.

This commit is contained in:
Andrzej Kapolka 2014-01-22 15:58:41 -08:00
parent e545cfe406
commit ba8791274f
4 changed files with 44 additions and 29 deletions

View file

@ -6,8 +6,6 @@
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include <QFile>
#include <QTextStream>
#include <QtDebug>
#include <SharedUtil.h>
@ -40,14 +38,6 @@ void MetavoxelSystem::init() {
connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), SLOT(nodeAdded(SharedNodePointer)));
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
AttributeRegistry::getInstance()->configureScriptEngine(&_scriptEngine);
QFile scriptFile("resources/scripts/sphere.js");
scriptFile.open(QIODevice::ReadOnly);
QScriptValue guideFunction = _scriptEngine.evaluate(QTextStream(&scriptFile).readAll());
_data.setAttributeValue(MetavoxelPath(), AttributeValue(AttributeRegistry::getInstance()->getGuideAttribute(),
encodeInline(PolymorphicDataPointer(new ScriptedMetavoxelGuide(guideFunction)))));
_buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
_buffer.create();
}

View file

@ -11,7 +11,6 @@
#include <QList>
#include <QOpenGLBuffer>
#include <QScriptEngine>
#include <QVector>
#include <glm/glm.hpp>
@ -30,6 +29,7 @@ class MetavoxelSystem : public QObject {
Q_OBJECT
public:
MetavoxelSystem();
void init();
@ -40,8 +40,10 @@ public:
void render();
public slots:
void nodeAdded(SharedNodePointer node);
void nodeKilled(SharedNodePointer node);
private:
Q_INVOKABLE void addClient(const QUuid& uuid, const HifiSockAddr& address);
@ -67,7 +69,6 @@ private:
static ProgramObject _program;
static int _pointScaleLocation;
QScriptEngine _scriptEngine;
MetavoxelData _data;
QVector<Point> _points;
PointVisitor _pointVisitor;

View file

@ -112,6 +112,19 @@ bool MetavoxelEditor::eventFilter(QObject* watched, QEvent* event) {
case RAISING_STATE:
if (event->type() == QEvent::MouseButtonPress) {
if (_height != 0) {
// find the start and end corners in X/Y
float base = _gridPosition->value();
float top = base + _height;
glm::quat rotation = getGridRotation();
glm::vec3 start = rotation * glm::vec3(glm::min(_startPosition, _endPosition), glm::min(base, top));
float spacing = _gridSpacing->value();
glm::vec3 end = rotation * glm::vec3(glm::max(_startPosition, _endPosition) +
glm::vec2(spacing, spacing), glm::max(base, top));
// find the minimum and maximum extents after rotation
applyValue(glm::min(start, end), glm::max(start, end));
}
resetState();
return true;
}
@ -188,28 +201,19 @@ void MetavoxelEditor::render() {
glPushMatrix();
glm::quat rotation;
switch (_gridPlane->currentIndex()) {
case GRID_PLANE_XZ:
rotation = glm::angleAxis(90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
break;
case GRID_PLANE_YZ:
rotation = glm::angleAxis(-90.0f, 0.0f, 1.0f, 0.0f);
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
break;
}
glm::quat rotation = getGridRotation();
glm::vec3 axis = glm::axis(rotation);
glRotatef(glm::angle(rotation), axis.x, axis.y, axis.z);
glm::vec3 rayOrigin = rotation * Application::getInstance()->getMouseRayOrigin();
glm::vec3 rayDirection = rotation * Application::getInstance()->getMouseRayDirection();
glm::quat inverseRotation = glm::inverse(rotation);
glm::vec3 rayOrigin = inverseRotation * Application::getInstance()->getMouseRayOrigin();
glm::vec3 rayDirection = inverseRotation * Application::getInstance()->getMouseRayDirection();
float spacing = _gridSpacing->value();
float position = _gridPosition->value();
if (_state == RAISING_STATE) {
// find the plane at the mouse position, orthogonal to the plane, facing the eye position
glLineWidth(4.0f);
glm::vec3 eyePosition = rotation * Application::getInstance()->getViewFrustum()->getOffsetPosition();
glm::vec3 eyePosition = inverseRotation * Application::getInstance()->getViewFrustum()->getOffsetPosition();
glm::vec3 mousePoint = glm::vec3(_mousePosition, position);
glm::vec3 right = glm::cross(glm::vec3(0.0f, 0.0f, 1.0f), eyePosition - mousePoint);
glm::vec3 normal = glm::cross(right, glm::vec3(0.0f, 0.0f, 1.0f));
@ -263,7 +267,7 @@ void MetavoxelEditor::render() {
glLineWidth(1.0f);
// center the grid around the camera position on the plane
glm::vec3 rotated = rotation * Application::getInstance()->getCamera()->getPosition();
glm::vec3 rotated = inverseRotation * Application::getInstance()->getCamera()->getPosition();
const int GRID_DIVISIONS = 300;
glTranslatef(spacing * (floorf(rotated.x / spacing) - GRID_DIVISIONS / 2),
spacing * (floorf(rotated.y / spacing) - GRID_DIVISIONS / 2), position);
@ -308,10 +312,28 @@ QString MetavoxelEditor::getSelectedAttribute() const {
return selectedItems.isEmpty() ? QString() : selectedItems.first()->text();
}
glm::quat MetavoxelEditor::getGridRotation() const {
// for simplicity, we handle the other two planes by rotating them onto X/Y and performing computation there
switch (_gridPlane->currentIndex()) {
case GRID_PLANE_XY:
return glm::quat();
case GRID_PLANE_XZ:
return glm::angleAxis(-90.0f, 1.0f, 0.0f, 0.0f);
case GRID_PLANE_YZ:
return glm::angleAxis(90.0f, 0.0f, 1.0f, 0.0f);
}
}
void MetavoxelEditor::resetState() {
_state = HOVERING_STATE;
_startPosition = INVALID_VECTOR;
_height = 0.0f;
}
void MetavoxelEditor::applyValue(const glm::vec3& minimum, const glm::vec3& maximum) {
}
ProgramObject MetavoxelEditor::_gridProgram;

View file

@ -40,7 +40,9 @@ private:
void updateAttributes(const QString& select = QString());
QString getSelectedAttribute() const;
glm::quat getGridRotation() const;
void resetState();
void applyValue(const glm::vec3& minimum, const glm::vec3& maximum);
QListWidget* _attributes;
QComboBox* _gridPlane;