Commit 1dfda3e9 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'CameraNode' into 'master'

CameraNode

Draw CameraNode frustum as defined by the view and projection transform. Some functions are made obsolete and have no effect anymore: setNearPlane, setFarPlane, setSize. These settings have to be defined by the projection matrix instead. #81

See merge request !201
parents 6d0648b3 59c221a9
Pipeline #3752 passed with stage
in 103 minutes and 4 seconds
......@@ -193,7 +193,9 @@ bool GLPrimitive::checkVBO()
delete[] vboData_;
vboData_ = 0;
} else if (vboDataInvalid_) {
}
if (vboDataInvalid_) {
updateVBOData();
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
glBufferData(GL_ARRAY_BUFFER, bufSize, vboData_, GL_STATIC_DRAW);
......
......@@ -1813,7 +1813,7 @@ void GLState::bindBuffer(GLenum _target, GLuint _buffer)
if (stateStack_.back().glBufferTargetState_[idx] != _buffer)
#endif
{
glBindBufferARB(_target, _buffer);
glBindBuffer(_target, _buffer);
stateStack_.back().glBufferTargetState_[idx] = _buffer;
}
}
......
......@@ -737,11 +737,11 @@ bool Texture2D::checkTextureMem( GLenum _internalFormat, GLsizei _width, GLsizei
//-----------------------------------------------------------------------------
#if defined(GL_ARB_vertex_buffer_object)
#if defined(GL_VERSION_1_5)
void VertexBufferObject::del() {
if (valid)
glDeleteBuffersARB(1, &vbo);
glDeleteBuffers(1, &vbo);
valid = false;
}
......@@ -753,17 +753,17 @@ void VertexBufferObject::upload(
bind();
glBufferDataARB(target, size, data, usage);
glBufferData(target, size, data, usage);
}
void VertexBufferObject::uploadSubData(
GLuint _offset, GLuint _size, const GLvoid* _data ) {
glBufferSubDataARB(target, _offset, _size, _data);
glBufferSubData(target, _offset, _size, _data);
}
void VertexBufferObject::gen() {
glGenBuffersARB(1, &vbo);
glGenBuffers(1, &vbo);
if(vbo > 0u)
valid = true;
}
......
......@@ -128,7 +128,7 @@ private:
//== CLASS DEFINITION =========================================================
#if defined(GL_ARB_vertex_buffer_object)
#if defined(GL_VERSION_1_5)
class ACGDLLEXPORT VertexBufferObject
{
......@@ -172,14 +172,14 @@ private:
class GeometryBuffer : public VertexBufferObject
{
public:
GeometryBuffer() : VertexBufferObject(GL_ARRAY_BUFFER_ARB) {}
GeometryBuffer() : VertexBufferObject(GL_ARRAY_BUFFER) {}
};
class IndexBuffer : public VertexBufferObject
{
public:
IndexBuffer() : VertexBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB) {}
IndexBuffer() : VertexBufferObject(GL_ELEMENT_ARRAY_BUFFER) {}
};
......
This diff is collapsed.
......@@ -66,6 +66,7 @@
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/GL/GLPrimitives.hh>
#include <ACG/GL/globjects.hh>
#include <string>
#include <vector>
......@@ -107,29 +108,41 @@ public:
/// drawing
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// create render objects
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/// picking
void pick(GLState& _state, PickTarget _target);
/// set model view matrix
void setModelView(ACG::GLMatrixd _modelView) { modelView_ = _modelView; };
void setModelView(ACG::GLMatrixd _modelView) { modelView_ = _modelView; modelViewInv_ = _modelView; modelViewInv_.invert(); update_vbo_ = true; }
/// Returns the modelview matrix
const ACG::GLMatrixd& modelview() const {return modelView_;}
/// Set projection Matrix ( used to calculate frustum ... )
void setProjection(ACG::GLMatrixd _projection) { projection_ = _projection; };
void setProjection(ACG::GLMatrixd _projection) { projection_ = _projection; update_vbo_ = true; }
/// Returns the projection matrix
const ACG::GLMatrixd& projection() const {return projection_;}
/// Set viewport size ( This will be used to compute the aspect ratio )
void setSize(int _w, int _h) { width_ = _w; height_ = _h; aspectRatio_ = (double)width_ / (double)height_; }
DEPRECATED("setSize() is redundant, because it is already defined by the projection matrix.")
void setSize(int _w, int _h) { /*obsolete*/ }
/// Return encoded view string
void setEncodedView(QString _encodedView) { encodedView_ = _encodedView; };
void setEncodedView(QString _encodedView) { encodedView_ = _encodedView; }
/// Set distance to far plane ( e.g. scene radius )
void setFarPlane(double _far) { far_ = _far; };
DEPRECATED("setFarPlane() is redundant, because it is already defined by the projection matrix.")
void setFarPlane(double _far) { /*obsolete*/ }
/// Set distance to near plane
void setNearPlane(double _near) { near_ = _near; };
DEPRECATED("setNearPlane() is redundant, because it is already defined by the projection matrix.")
void setNearPlane(double _near) { /*obsolete*/ }
/// Return encoded view string
QString getEncodedView() { return encodedView_; };
QString getEncodedView() { return encodedView_; }
/// Set if viewing frustum should be shown or not
void showFrustum(bool _showFrustum) { showFrustum_ = _showFrustum; }
......@@ -137,33 +150,35 @@ public:
/// Returns true if camera renders its whole frustum
bool showFrustum() { return showFrustum_; }
private:
void updateBoundingBoxes(GLMatrixd& _modelview);
void updateVBO();
void updateBoundingBoxes();
// recalculate frustum positions in world space
void updateFrustumWS();
OpenMesh::Vec3d bbmin_;
OpenMesh::Vec3d bbmax_;
ACG::GLMatrixd modelView_;
ACG::GLMatrixd modelViewInv_;
ACG::GLMatrixd projection_;
int width_, height_;
double fovy_;
double half_height_;
double half_width_;
double far_half_height_;
double far_half_width_;
double aspectRatio_;
double near_;
double far_;
GLCylinder* cylinder_;
GLCone* cone_;
GLCone* cone_;
float axis_length_;
GeometryBuffer vbo_;
IndexBuffer ibo_;
VertexDeclaration vdecl_;
bool update_vbo_;
std::vector<Vec4f> vboData_; // 8 frustum vertices + camera position
int offsetTris_; // offsets into index buffer
int offsetLines_;
int offsetFront_;
QString encodedView_;
......
// picking - all fragments have the same pick id
#version 130
uniform vec4 color;
out vec4 outColor;
void main()
{
outColor = color;
}
\ No newline at end of file
......@@ -54,7 +54,7 @@
#include <OpenFlipper/common/GlobalOptions.hh>
TypeCameraPlugin::TypeCameraPlugin() :
contextMenu_(0)
contextMenu_(0), showFrustumAction_(0)
{
}
......@@ -62,15 +62,17 @@ TypeCameraPlugin::TypeCameraPlugin() :
void TypeCameraPlugin::pluginsInitialized() {
if ( OpenFlipper::Options::gui() ){
contextMenu_ = new QMenu(tr("Rendering"));
contextMenu_ = new QMenu(tr("CameraNode"));
QAction* lastAction;
showFrustumAction_ = contextMenu_->addAction( tr("Show viewing frustum") );
showFrustumAction_->setCheckable(true);
showFrustumAction_->setChecked(false);
showFrustumAction_->setToolTip(tr("Visualize cameras viewing frustum."));
showFrustumAction_->setStatusTip( showFrustumAction_->toolTip() );
lastAction = contextMenu_->addAction( tr("Show viewing frustum") );
lastAction->setCheckable(true);
lastAction->setChecked(false);
lastAction->setToolTip(tr("Visualize cameras viewing frustum."));
lastAction->setStatusTip( lastAction->toolTip() );
QAction* flyAction = contextMenu_->addAction( tr("Fly to") );
flyAction->setToolTip(tr("Fly viewer to the camera position."));
flyAction->setStatusTip( flyAction->toolTip() );
// Add context menu
emit addContextMenuItem(contextMenu_->menuAction(), DATA_CAMERA, CONTEXTOBJECTMENU);
......@@ -79,8 +81,17 @@ void TypeCameraPlugin::pluginsInitialized() {
}
}
void TypeCameraPlugin::slotUpdateContextMenuObject(int _objectId) {
void TypeCameraPlugin::slotUpdateContextMenu(int _objectId) {
if (_objectId < 0)
return;
CameraObject* object;
if (!PluginFunctions::getObject(_objectId, object))
return;
if (showFrustumAction_)
showFrustumAction_->setChecked(object->cameraNode()->showFrustum());
}
void TypeCameraPlugin::contextMenuClicked(QAction* _contextAction) {
......@@ -100,6 +111,23 @@ void TypeCameraPlugin::contextMenuClicked(QAction* _contextAction) {
// Set frustum flag to whether action is checked or not
object->cameraNode()->showFrustum(_contextAction->isChecked());
emit updatedObject(objectId, UPDATE_VISIBILITY);
}
else if (_contextAction->text() == tr("Fly to")) {
// calculate camera position and view direction in world space
ACG::GLMatrixd m = object->cameraNode()->modelview();
ACG::GLMatrixd mInv = m;
mInv.invert();
ACG::Vec3d camPosWS(mInv(0,3), mInv(1,3), mInv(2,3));
ACG::Vec3d camViewWS(mInv(0,2), mInv(1,2), mInv(2,2));
ACG::Vec3d camCenterWS = camPosWS - camViewWS;
// target up vector can't be specified unfortunately
PluginFunctions::flyTo(camPosWS, camCenterWS, 500.0);
}
}
......
......@@ -95,7 +95,7 @@ class TypeCameraPlugin : public QObject, BaseInterface, LoadSaveInterface, Loggi
void pluginsInitialized();
// ContextMenuInterface
void slotUpdateContextMenuObject( int _objectId );
void slotUpdateContextMenu( int _objectId );
public :
......@@ -122,6 +122,7 @@ class TypeCameraPlugin : public QObject, BaseInterface, LoadSaveInterface, Loggi
private:
QMenu* contextMenu_;
QAction* showFrustumAction_;
};
......
......@@ -569,19 +569,6 @@ void TypeSplatCloudPlugin::addCameraObjects( SplatCloudObject *_splatCloudObject
CameraNode *cameraNode = cameraObject->cameraNode();
if( cameraNode != 0 )
{
// set matrix
ACG::GLMatrixd matrix;
{
const SplatCloud_Projection &proj = camera.projection_;
matrix(0,0) = proj.r_[0][0]; matrix(0,1) = proj.r_[1][0]; matrix(0,2) = proj.r_[2][0];
matrix(1,0) = proj.r_[0][1]; matrix(1,1) = proj.r_[1][1]; matrix(1,2) = proj.r_[2][1];
matrix(2,0) = proj.r_[0][2]; matrix(2,1) = proj.r_[1][2]; matrix(2,2) = proj.r_[2][2];
matrix(0,3) = -(proj.r_[0][0]*proj.t_[0] + proj.r_[1][0]*proj.t_[1] + proj.r_[2][0]*proj.t_[2]);
matrix(1,3) = -(proj.r_[0][1]*proj.t_[0] + proj.r_[1][1]*proj.t_[1] + proj.r_[2][1]*proj.t_[2]);
matrix(2,3) = -(proj.r_[0][2]*proj.t_[0] + proj.r_[1][2]*proj.t_[1] + proj.r_[2][2]*proj.t_[2]);
matrix(3,0) = 0.0; matrix(3,1) = 0.0; matrix(3,2) = 0.0; matrix(3,3) = 1.0;
}
// set resolution
unsigned int width = camera.imageWidth_;
unsigned int height = camera.imageHeight_;
......@@ -591,9 +578,25 @@ void TypeSplatCloudPlugin::addCameraObjects( SplatCloudObject *_splatCloudObject
height = 1;
}
// set matrix
ACG::GLMatrixd matrixView, matrixProj;
{
const SplatCloud_Projection &proj = camera.projection_;
matrixView(0,0) = proj.r_[0][0]; matrixView(0,1) = proj.r_[1][0]; matrixView(0,2) = proj.r_[2][0];
matrixView(1,0) = proj.r_[0][1]; matrixView(1,1) = proj.r_[1][1]; matrixView(1,2) = proj.r_[2][1];
matrixView(2,0) = proj.r_[0][2]; matrixView(2,1) = proj.r_[1][2]; matrixView(2,2) = proj.r_[2][2];
matrixView(0,3) = -(proj.r_[0][0]*proj.t_[0] + proj.r_[1][0]*proj.t_[1] + proj.r_[2][0]*proj.t_[2]);
matrixView(1,3) = -(proj.r_[0][1]*proj.t_[0] + proj.r_[1][1]*proj.t_[1] + proj.r_[2][1]*proj.t_[2]);
matrixView(2,3) = -(proj.r_[0][2]*proj.t_[0] + proj.r_[1][2]*proj.t_[1] + proj.r_[2][2]*proj.t_[2]);
matrixView(3,0) = 0.0; matrixView(3,1) = 0.0; matrixView(3,2) = 0.0; matrixView(3,3) = 1.0;
matrixProj.identity();
matrixProj.perspective(proj.f_, double(width) / double(height), proj.k1_, proj.k2_);
}
// set camera parameters
cameraNode->setModelView( matrix );
cameraNode->setSize( width, height );
cameraNode->setModelView( matrixView );
cameraNode->setProjection( matrixProj );
// emit signal that the camera-object has to be updated
emit updatedObject( camera.objectId_, UPDATE_ALL );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment