mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 19:50:03 -06:00
Volumeraycaster now also extends renderable. Also has some interaction and cluster syncing now.
This commit is contained in:
@@ -45,13 +45,13 @@ namespace openspace {
|
||||
using namespace osp;
|
||||
|
||||
Flare::Flare() : Renderable()
|
||||
, _leftMouseButton(false)
|
||||
, _currentMouseX(0)
|
||||
, _currentMouseY(0)
|
||||
, _lastMouseX(0)
|
||||
, _lastMouseY(0)
|
||||
, _oldTime(0.0f)
|
||||
, _currentTime(0.0f) {
|
||||
, _leftMouseButton(false)
|
||||
, _currentMouseX(0)
|
||||
, _currentMouseY(0)
|
||||
, _lastMouseX(0)
|
||||
, _lastMouseY(0)
|
||||
, _oldTime(0.0f)
|
||||
, _currentTime(0.0f) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,11 +41,11 @@ public:
|
||||
Flare();
|
||||
~Flare();
|
||||
|
||||
// This is where the magic happens
|
||||
// This is where the magic happens
|
||||
void render(const Camera *camera = nullptr, const psc &thisPosition = psc(glm::vec3(0)));
|
||||
|
||||
// SGCT functions for cluster rendering and interaction.
|
||||
// Called from OpenspaceEngine.
|
||||
// SGCT functions for cluster rendering and interaction.
|
||||
// Called from OpenspaceEngine.
|
||||
void keyboard(int key, int action);
|
||||
void mouse(int button, int action);
|
||||
void preSync();
|
||||
|
||||
@@ -161,8 +161,8 @@ bool OpenSpaceEngine::initialize() {
|
||||
_engine->_interactionHandler->connectDevices();
|
||||
|
||||
// Choose rendering
|
||||
// _volumeRaycaster = new VolumeRaycaster();
|
||||
_flare = new Flare();
|
||||
_volumeRaycaster = new VolumeRaycaster();
|
||||
// _flare = new Flare();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -194,6 +194,7 @@ void OpenSpaceEngine::preSynchronization() {
|
||||
const double dt = sgct::Engine::instance()->getDt();
|
||||
|
||||
if (_flare) _flare->preSync();
|
||||
if (_volumeRaycaster) _volumeRaycaster->preSync();
|
||||
|
||||
_interactionHandler->update(dt);
|
||||
_interactionHandler->lockControls();
|
||||
@@ -229,6 +230,7 @@ void OpenSpaceEngine::mouseButtonCallback(int key, int action) {
|
||||
if (sgct::Engine::instance()->isMaster()) {
|
||||
_interactionHandler->mouseButtonCallback(key, action);
|
||||
if (_flare) _flare->mouse(key, action);
|
||||
if (_volumeRaycaster) _volumeRaycaster->mouse(key, action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,10 +244,12 @@ void OpenSpaceEngine::mouseScrollWheelCallback(int pos) {
|
||||
|
||||
void OpenSpaceEngine::encode() {
|
||||
if (_flare) _flare->encode();
|
||||
if (_volumeRaycaster) _volumeRaycaster->encode();
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::decode() {
|
||||
if (_flare) _flare->decode();
|
||||
if (_volumeRaycaster) _volumeRaycaster->decode();
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -34,7 +34,18 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
VolumeRaycaster::VolumeRaycaster() : _stepSize(0.01f) , _type(TWOPASS) {
|
||||
const float MOUSE_FACTOR = 0.05;
|
||||
|
||||
VolumeRaycaster::VolumeRaycaster() : Renderable()
|
||||
, _stepSize(0.01f)
|
||||
, _type(SINGLEPASS)
|
||||
, _leftMouseButton(false)
|
||||
, _currentMouseX(0.0)
|
||||
, _currentMouseY(0.0)
|
||||
, _lastMouseX(0.0)
|
||||
, _lastMouseY(0.0) {
|
||||
_rotateX.setVal(0.0);
|
||||
_rotateY.setVal(0.0);
|
||||
initialize();
|
||||
}
|
||||
|
||||
@@ -58,11 +69,10 @@ void VolumeRaycaster::initialize() {
|
||||
}
|
||||
|
||||
// Calculate MVP and use it to render with the chosen raycaster
|
||||
void VolumeRaycaster::render() {
|
||||
float speed = 50.0f;
|
||||
float time = sgct::Engine::getTime();
|
||||
glm::mat4 yRotation = glm::rotate(glm::mat4(1.0f), time*speed, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
glm::mat4 MVP = sgct::Engine::instance()->getActiveModelViewProjectionMatrix()*yRotation;
|
||||
void VolumeRaycaster::render(const Camera *camera, const psc &thisPosition) {
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), (float)_rotateX.getVal(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotation = glm::rotate(rotation, (float)_rotateY.getVal(), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
glm::mat4 MVP = sgct::Engine::instance()->getActiveModelViewProjectionMatrix()*rotation;
|
||||
|
||||
if (_type == SINGLEPASS) renderWithSinglepassRaycaster(MVP);
|
||||
if (_type == TWOPASS) renderWithTwopassRaycaster(MVP);
|
||||
@@ -150,7 +160,7 @@ void VolumeRaycaster::setupTwopassRaycaster() {
|
||||
// Initialize the single pass raycaster by specifying the VBO for the
|
||||
// bounding box center, calculating the focallength and setting it as a uniform
|
||||
void VolumeRaycaster::setupSinglepassRaycaster() {
|
||||
float p[] = {0, 0, 0};
|
||||
float p[] = {0.0, 0.0, 0.0};
|
||||
glGenBuffers(1, &_cubeCenterVBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _cubeCenterVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(p), &p[0], GL_STATIC_DRAW);
|
||||
@@ -267,4 +277,32 @@ void VolumeRaycaster::renderWithSinglepassRaycaster(glm::mat4 modelViewProjectio
|
||||
_singlepassProgram->deactivate();
|
||||
}
|
||||
|
||||
void VolumeRaycaster::mouse(int button, int action) {
|
||||
switch (button) {
|
||||
case GLFW_MOUSE_BUTTON_LEFT:
|
||||
_leftMouseButton = (action == GLFW_PRESS) ? true : false;
|
||||
std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId();
|
||||
sgct::Engine::getMousePos(winId, &_lastMouseX, &_lastMouseY);
|
||||
}
|
||||
}
|
||||
|
||||
void VolumeRaycaster::preSync() {
|
||||
// Update mouse
|
||||
if (_leftMouseButton) {
|
||||
std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId();
|
||||
sgct::Engine::getMousePos(winId ,&_currentMouseX, &_currentMouseY);
|
||||
_rotateX.setVal(_rotateX.getVal() + MOUSE_FACTOR*(_currentMouseX-_lastMouseX));
|
||||
_rotateY.setVal(_rotateY.getVal() + MOUSE_FACTOR*(_currentMouseY-_lastMouseY));
|
||||
}
|
||||
}
|
||||
|
||||
void VolumeRaycaster::encode() {
|
||||
sgct::SharedData::instance()->writeDouble(&_rotateX);
|
||||
sgct::SharedData::instance()->writeDouble(&_rotateY);
|
||||
}
|
||||
|
||||
void VolumeRaycaster::decode() {
|
||||
sgct::SharedData::instance()->readDouble(&_rotateX);
|
||||
sgct::SharedData::instance()->readDouble(&_rotateY);
|
||||
}
|
||||
}// namespace openspace
|
||||
|
||||
@@ -29,12 +29,14 @@
|
||||
#include <ghoul/opengl/framebufferobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <rendering/renderable.h>
|
||||
|
||||
#include <sgct.h>
|
||||
|
||||
namespace openspace {
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
class VolumeRaycaster {
|
||||
class VolumeRaycaster : public Renderable{
|
||||
public:
|
||||
enum RaycasterType {
|
||||
SINGLEPASS,
|
||||
@@ -44,7 +46,14 @@ public:
|
||||
VolumeRaycaster();
|
||||
~VolumeRaycaster();
|
||||
void initialize();
|
||||
void render();
|
||||
void render(const Camera *camera = nullptr, const psc &thisPosition = psc(glm::vec3(0)));
|
||||
|
||||
// SGCT functions for cluster rendering and interaction.
|
||||
// Called from OpenspaceEngine.
|
||||
void mouse(int button, int action);
|
||||
void preSync();
|
||||
void encode();
|
||||
void decode();
|
||||
|
||||
private:
|
||||
void setupTwopassRaycaster();
|
||||
@@ -63,6 +72,15 @@ private:
|
||||
|
||||
float _stepSize;
|
||||
RaycasterType _type;
|
||||
|
||||
// Interaction variables
|
||||
sgct::SharedDouble _rotateX;
|
||||
sgct::SharedDouble _rotateY;
|
||||
bool _leftMouseButton;
|
||||
double _currentMouseX;
|
||||
double _currentMouseY;
|
||||
double _lastMouseX;
|
||||
double _lastMouseY;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user