Merge remote-tracking branch 'origin/kameleon' into properties

This commit is contained in:
Alexander Bock
2014-05-03 12:01:47 +02:00
9 changed files with 77 additions and 57 deletions

View File

@@ -59,6 +59,7 @@ public:
private:
glm::vec3 mapToTrackball(glm::vec2 mousePos);
glm::vec3 mapToCamera(glm::vec3 trackballPos);
void trackballRotate(int x, int y);
Camera* camera_;

View File

@@ -40,6 +40,9 @@ public:
void setScaling(const glm::vec2 &scaling);
const glm::vec2 & getScaling() const;
void setLookUp(glm::vec3 lookUp);
const glm::vec3 getLookUp() const;
private:
float maxFov_;
float sinMaxFov_;
@@ -51,8 +54,10 @@ private:
glm::quat viewRotation_;
glm::mat4 viewRotationMatrix_; // compiled from the quaternion
glm::vec3 lookUp_;
};
} // namespace openspace
#endif
#endif

View File

@@ -1,4 +1,13 @@
#ifdef CL_VERSION_1_2
#define RC_TF_TYPE image1d_t
#define RC_TF_MAP(intensity) intensity
#else
#define RC_TF_TYPE image1d_t
#define RC_TF_MAP(intensity) (float2)(intensity,0.0f)
#endif
#define EARLY_RAY_TERMINATION_OPACITY 0.95
void raySetup(float3 first, float3 last, float3 dimension, float3* rayDirection, float* tIncr, float* tEnd);
@@ -37,8 +46,8 @@ void raySetup(float3 first, float3 last, float3 dimension, float3* rayDirection,
* 1.0 and true is returned, otherwise false is returned.
***/
bool earlyRayTermination(float4* color, float maxOpacity) {
if ((*color).a >= maxOpacity) {
(*color).a = 1.0f;
if ((*color).w >= maxOpacity) {
(*color).w = 1.0f;
return true;
} else {
return false;

View File

@@ -18,13 +18,12 @@ std::string _loggerCat = "InteractionHandler";
namespace openspace {
InteractionHandler::InteractionHandler() {
// initiate pointers
camera_ = nullptr;
enabled_ = true;
node_ = nullptr;
dt_ = 0.0;
_lastTrackballPos = glm::vec3(0.5);
_lastTrackballPos = glm::vec3(0.0, 0.0, 0.5);
_leftMouseButtonDown = false;
_isMouseBeingPressedAndHeld = false;
}
@@ -100,8 +99,7 @@ void InteractionHandler::connectDevices() {
void InteractionHandler::addExternalControl(ExternalControl* controller) {
//assert(this_);
if (controller != nullptr)
{
if (controller != nullptr) {
controllers_.push_back(controller);
}
}
@@ -113,8 +111,7 @@ void InteractionHandler::setCamera(Camera *camera) {
Camera * InteractionHandler::getCamera() const {
//assert(this_);
if (enabled_)
{
if (enabled_) {
return camera_;
}
return nullptr;
@@ -174,7 +171,6 @@ void InteractionHandler::orbit(const glm::quat &rotation) {
void InteractionHandler::distance(const pss &distance) {
//assert(this_);
lockControls();
psc relative = camera_->getPosition();
psc origin;
@@ -210,12 +206,9 @@ void InteractionHandler::setRotation(const glm::quat &rotation) {
void InteractionHandler::update(const double dt) {
//assert(this_);
// setting dt_ for use in callbacks
dt_ = dt;
if (enabled_ && camera_) {
// fetch data from joysticks
DeviceIdentifier::ref().update();
@@ -223,7 +216,6 @@ void InteractionHandler::update(const double dt) {
for (size_t i = 0; i < controllers_.size(); ++i) {
controllers_[i]->update();
}
}
}
@@ -249,12 +241,30 @@ glm::vec3 InteractionHandler::mapToTrackball(glm::vec2 mousePos) {
return glm::normalize(out);
}
glm::vec3 InteractionHandler::mapToCamera(glm::vec3 trackballPos) {
// return glm::vec3((sgct::Engine::instance()->getActiveViewMatrix() * glm::vec4(trackballPos,0)));
//Get x,y,z axis vectors of current camera view
glm::vec3 currentViewYaxis = glm::normalize(camera_->getLookUp());
psc viewDir = camera_->getPosition() - node_->getWorldPosition();
glm::vec3 currentViewZaxis = glm::normalize(viewDir.getVec3f());
glm::vec3 currentViewXaxis = glm::normalize(glm::cross(currentViewYaxis, currentViewZaxis));
//mapping to camera co-ordinate
currentViewXaxis*=trackballPos.x;
currentViewYaxis*=trackballPos.y;
currentViewZaxis*=trackballPos.z;
return (currentViewXaxis + currentViewYaxis + currentViewZaxis);
}
void InteractionHandler::trackballRotate(int x, int y) {
// Normalize mouse coordinates to [0,1]
float width = sgct::Engine::instance()->getActiveXResolution();
float height = sgct::Engine::instance()->getActiveYResolution();
glm::vec2 mousePos = glm::vec2((float)x/width, (float)y/height);
mousePos[1] = 0.5;
mousePos = glm::clamp(mousePos, -0.5, 1.5); // Ugly fix #1: Camera position becomes NaN on mouse values outside [-0.5, 1.5]
mousePos[1] = 0.5; // Ugly fix #2: Tempoarily only allow rotation around y
glm::vec3 curTrackballPos = mapToTrackball(mousePos);
// LDEBUG(mousePos.x << ", " << mousePos.y << " = " << curTrackballPos.x << ", " << curTrackballPos.y << ", " << curTrackballPos.z);
@@ -266,36 +276,24 @@ void InteractionHandler::trackballRotate(int x, int y) {
}
if (curTrackballPos != _lastTrackballPos) {
// calculate rotation angle (in radians), rotation axis and quaternion
// calculate rotation angle (in radians)
float rotationAngle = glm::angle(curTrackballPos, _lastTrackballPos);
rotationAngle *= getDt()*100.0f;
rotationAngle *= getDt()*100.0f;
// Map trackballpos to camera
// glm::vec3 trackballMappedToCamera = mapToCamera(_lastTrackballPos - curTrackballPos);
// psc currentCamPos = camera_->getPosition();
// glm::vec3 nextCamPos = currentCamPos.getVec3f() + trackballMappedToCamera;
// glm::vec3 rotationAxis = glm::cross(currentCamPos.getVec3f(), nextCamPos);
glm::vec3 rotationAxis = glm::cross(_lastTrackballPos, curTrackballPos);
rotationAxis = glm::normalize(rotationAxis);
glm::quat quaternion = glm::angleAxis(rotationAngle, rotationAxis);
// -----------------------------------------------------------------
// Apply quaternion to camera
orbit(glm::inverse(quaternion));
camera_->rotate(quaternion);
// camera_->compileViewRotationMatrix();
/*
psc nodePos = node_->getWorldPosition();
psc camPos = camera_->getPosition();
glm::mat4 transMatrix = glm::translate(glm::mat4(1.0), nodePos.getVec3f()-camPos.getVec3f());
glm::mat4 transBackMatrix = glm::translate(glm::mat4(1.0), camPos.getVec3f()-nodePos.getVec3f());
glm::vec4 translated = transMatrix*glm::vec4(camPos.getVec3f(), 1.0);
glm::vec4 postRot = glm::rotate(quaternion, translated);
glm::vec4 newCamPos = transBackMatrix*glm::vec4(postRot.x, postRot.y, postRot.z, 1.0);
camera_->setPosition(psc::CreatePSC(newCamPos.x, newCamPos.y, newCamPos.z));
camera_->rotate(glm::inverse(quaternion));
camera_->compileViewRotationMatrix();
*/
// node_->calculateBoundingSphere();
// glm::vec3 camPos = *sgct::Engine::instance()->getUserPtr()->getPosPtr();
// sgct::Engine::instance()->getUserPtr()->setOrientation(quaternion.w, quaternion.x, quaternion.y, quaternion.z);
// sgct::Engine::instance()->getUserPtr()->setPos(glm::rotate(quaternion, camPos));
camera_->setLookUp(glm::rotate(quaternion, camera_->getLookUp()));
_lastTrackballPos = curTrackballPos;
}

View File

@@ -298,7 +298,6 @@ bool RenderableVolumeExpert::initialize() {
_colorBoxRenderer->initialize();
glm::size2_t dimensions = _colorBoxRenderer->dimensions();
ghoul::opengl::Texture* backTexture = _colorBoxRenderer->backFace();
ghoul::opengl::Texture* frontTexture = _colorBoxRenderer->frontFace();
_output = new ghoul::opengl::Texture(glm::size3_t(dimensions[0],dimensions[1],1));
@@ -342,15 +341,14 @@ void RenderableVolumeExpert::render(const Camera *camera, const psc &thisPositio
if( ! _kernel.isValidKernel())
return;
psc camPos = camera->getPosition();
psc relative = thisPosition-camPos;
double factor = pow(10.0,relative[3]);
glm::mat4 camTransform = camera->getViewRotationMatrix();
glm::mat4 transform = camera->getViewProjectionMatrix();
glm::mat4 camTransform = camera->getViewRotationMatrix();
psc relative = thisPosition-camera->getPosition();
transform = transform*camTransform;
transform = glm::translate(transform, glm::vec3(relative[0]*factor, relative[1]*factor, relative[2]*factor));
transform = glm::translate(transform, relative.getVec3f());
transform = glm::scale(transform, _boxScaling);
_colorBoxRenderer->render(transform);
_textureLock->lock();
@@ -450,6 +448,7 @@ void RenderableVolumeExpert::safeKernelCompilation() {
if(argumentError)
return;
tmpKernel.setArgument(0, &_clFrontTexture);
tmpKernel.setArgument(1, &_clBackTexture);
tmpKernel.setArgument(2, &_clOutput);
@@ -494,6 +493,7 @@ void RenderableVolumeExpert::safeUpdateTexture(const ghoul::filesystem::File& fi
// create the new texture
ghoul::opengl::Texture* newTexture = loadTransferFunction(file.path());
if(newTexture) {
// upload the new texture and create a cl memory

View File

@@ -66,7 +66,7 @@ bool RenderEngine::initialize() {
bool RenderEngine::initializeGL() {
#define SGCT_WPTR sgct::Engine::instance()->getWindowPtr(0)
#define SGCT_WPTR sgct::Engine::instance()->getActiveWindowPtr()
using sgct_core::Viewport;
// TODO: Fix the power scaled coordinates in such a way that these values can be set
@@ -107,6 +107,7 @@ using sgct_core::Viewport;
// get viewdirection, stores the direction in the camera, used for culling
glm::vec3 viewdir = glm::normalize(eyePosition- center);
_mainCamera->setCameraDirection(-viewdir);
_mainCamera->setLookUp(glm::vec3(0.0, 1.0, 0.0));
// set the initial fov to be 0.0 which means everything will be culled
float maxFov = 0.0f;
@@ -142,14 +143,13 @@ void RenderEngine::postSynchronizationPreDraw() {
}
void RenderEngine::render() {
// SGCT resets certian settings
glEnable (GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
// setup the camera for the current frame
const glm::vec3 eyePosition = sgct_core::ClusterManager::instance()->getUserPtr()->getPos();
glm::mat4 view = glm::translate(glm::mat4(1.0), eyePosition); // make sure the eye is in the center
const glm::vec3 eyePosition = sgct_core::ClusterManager::instance()->getUserPtr()->getPos();
glm::mat4 view = glm::translate(glm::mat4(1.0), eyePosition); // make sure the eye is in the center
_mainCamera->setViewProjectionMatrix(sgct::Engine::instance()->getActiveModelViewProjectionMatrix()*view);
// render the scene starting from the root node

View File

@@ -171,7 +171,7 @@ bool SceneGraph::initialize() {
// TODO: Set scaling dependent on the position and distance
// set position for camera
psc cameraPosition = positionNode->getPosition();
cameraPosition += psc(0.0,0.0,2.0,0.0);
cameraPosition += psc(0.0,0.0,1.0,2.0);
c->setPosition(cameraPosition);
c->setCameraDirection(glm::vec3(0,0,-1));
c->setScaling(glm::vec2(1.0,0.0));

View File

@@ -5,6 +5,8 @@
// sgct includes
#include "sgct.h"
#include <glm/gtx/vector_angle.hpp>
namespace openspace {
Camera::Camera() {
@@ -44,14 +46,11 @@ const glm::mat4 & Camera::getViewRotationMatrix() const {
void Camera::compileViewRotationMatrix() {
// convert from quaternion to rotationmatrix using glm
viewRotationMatrix_ = glm::mat4_cast(viewRotation_);
// the camera matrix needs to be rotated inverse to the world
glm::mat4 camrotmatrix = glm::mat4_cast(glm::inverse(viewRotation_));
glm::vec4 camdir(cameraDirection_[0],cameraDirection_[1],cameraDirection_[2],0);
camdir = camrotmatrix* camdir;
viewDirection_ = glm::normalize(glm::vec3(camdir[0],camdir[1],camdir[2]));
viewDirection_ = glm::rotate(glm::inverse(viewRotation_), cameraDirection_);
viewDirection_ = glm::normalize(viewDirection_);
}
void Camera::rotate(glm::quat rotation) {
@@ -91,5 +90,13 @@ void Camera::setScaling(const glm::vec2 &scaling) {
const glm::vec2 & Camera::getScaling() const {
return scaling_;
}
void Camera::setLookUp(glm::vec3 lookUp) {
lookUp_ = lookUp;
}
const glm::vec3 Camera::getLookUp() const {
return lookUp_;
}
} // namespace openspace
} // namespace openspace