59 #define CAMERAVISNODE_C 62 #include "CameraNode.hh" 64 #include <OpenMesh/Core/Utils/vector_cast.hh> 66 #include <ACG/GL/IRenderer.hh> 67 #include <ACG/GL/ShaderCache.hh> 68 #include <ACG/ShaderUtils/GLSLShader.hh> 80 bbmin_(FLT_MAX,FLT_MAX,FLT_MAX),
81 bbmax_(FLT_MIN,FLT_MIN,FLT_MIN),
98 cylinder_ =
new GLCylinder(8, 4, 1.0f,
false,
false);
99 cone_ =
new GLCone(8, 1, 1.0f, 0.0f,
true,
false);
129 glPushAttrib(GL_LIGHTING_BIT);
130 glPushAttrib(GL_ENABLE_BIT);
152 glPushAttrib(GL_LIGHTING_BIT);
159 GLsizei lineOffset = offsetLines_;
165 glColor4f(0.66f, 0.66f, 0.66f, 1.0f);
167 glDrawElements(GL_TRIANGLES, lineOffset, GL_UNSIGNED_INT, (GLvoid*)(offsetTris_ *
sizeof(
int)));
170 GLsizei lineCount = hasOrigin ? 4 * 7 : 4 * 6;
172 glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
173 glDrawElements(GL_LINES, lineCount * 2, GL_UNSIGNED_INT, (GLvoid*)(lineOffset *
sizeof(
int)));
177 glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
180 GLsizei lineCount = hasOrigin ? 4 * 2 : 4 * 1;
182 glDrawElements(GL_LINES, lineCount * 2, GL_UNSIGNED_INT, (GLvoid*)(offsetFront_ *
sizeof(
int)));
201 _state.
rotate(90, 0.0, 1.0, 0.0);
207 cylinder_->setBottomRadius(axis_length_/20.0f);
208 cylinder_->setTopRadius(axis_length_/20.0f);
209 cylinder_->draw(_state, axis_length_);
212 _state.
translate(0.0, 0.0, axis_length_ );
213 cone_->setBottomRadius(axis_length_/5.0f);
214 cone_->setTopRadius(0.0f);
215 cone_->draw(_state, axis_length_/2.0f);
216 _state.
translate(0.0, 0.0, -axis_length_ );
219 _state.
rotate(-90, 1.0, 0.0, 0.0);
225 cylinder_->draw(_state, axis_length_);
228 _state.
translate(0.0, 0.0, axis_length_ );
229 cone_->draw(_state, axis_length_/2.0f);
230 _state.
translate(0.0, 0.0, -axis_length_ );
233 _state.
rotate(-90, 0.0, 1.0, 0.0);
239 cylinder_->draw(_state, axis_length_);
242 _state.
translate(0.0, 0.0, axis_length_ );
243 cone_->draw(_state, axis_length_/2.0f);
244 _state.
translate(0.0, 0.0, -axis_length_ );
266 obj.depthTest =
true;
276 GLsizei lineOffset = offsetLines_;
281 obj.debugName =
"CameraNode.frustum_tris";
282 obj.emissive =
Vec3f(0.66f, 0.66f, 0.66f);
283 obj.glDrawElements(GL_TRIANGLES, lineOffset, GL_UNSIGNED_INT, (GLvoid*)(offsetTris_ *
sizeof(
int)));
290 GLsizei lineCount = hasOrigin ? 4 * 7 : 4 * 6;
292 obj.debugName =
"CameraNode.frustum_lines";
293 obj.emissive =
Vec3f(0.0f, 0.0f, 0.0f);
299 obj.glDrawElements(GL_LINES, lineCount * 2, GL_UNSIGNED_INT, (GLvoid*)(lineOffset *
sizeof(
int)));
306 obj.debugName =
"CameraNode.frustum_lines";
307 obj.emissive =
Vec3f(0.0f, 0.0f, 0.0f);
310 GLsizei lineCount = hasOrigin ? 4 * 2 : 4 * 1;
314 obj.glDrawElements(GL_LINES, lineCount * 2, GL_UNSIGNED_INT, (GLvoid*)(offsetFront_ *
sizeof(
int)));
326 cylinder_->setBottomRadius(axis_length_/20.0f);
327 cylinder_->setTopRadius(axis_length_/20.0f);
329 cone_->setBottomRadius(axis_length_/5.0f);
330 cone_->setTopRadius(0.0f);
335 obj.debugName =
"CameraNode.right_vec";
336 obj.emissive =
Vec3f(1.0f, 0.0f, 0.0f);
338 obj.ambient =
Vec3f(1.0f, 0.0f, 0.0f);
339 obj.specular =
Vec3f(1.0f, 0.4f, 0.4f);
344 cylinder_->addToRenderer_primitive(_renderer, &obj);
347 obj.debugName =
"CameraNode.right_top";
352 cone_->addToRenderer_primitive(_renderer, &obj);
356 obj.debugName =
"CameraNode.up_vec";
357 obj.emissive =
Vec3f(0.0f, 1.0f, 0.0f);
359 obj.ambient =
Vec3f(0.0f, 1.0f, 0.0f);
360 obj.specular =
Vec3f(0.4f, 1.0f, 0.4f);
365 cylinder_->addToRenderer_primitive(_renderer, &obj);
368 obj.debugName =
"CameraNode.up_top";
373 cone_->addToRenderer_primitive(_renderer, &obj);
378 obj.debugName =
"CameraNode.view_vec";
379 obj.emissive =
Vec3f(0.0f, 0.0f, 1.0f);
381 obj.ambient =
Vec3f(0.0f, 0.0f, 1.0f);
382 obj.specular =
Vec3f(0.4f, 0.4f, 1.0f);
386 cylinder_->addToRenderer_primitive(_renderer, &obj);
389 obj.debugName =
"CameraNode.view_top";
393 cone_->addToRenderer_primitive(_renderer, &obj);
410 desc.vertexTemplateFile =
"Picking/vertex.glsl";
411 desc.fragmentTemplateFile =
"Picking/single_color_fs.glsl";
414 if (pickShader && pickShader->
isLinked())
431 GLsizei lineOffset = offsetLines_;
434 glDrawElements(GL_TRIANGLES, lineOffset, GL_UNSIGNED_INT, (GLvoid*)(offsetTris_ *
sizeof(
int)));
438 GLsizei lineCount = hasOrigin ? 4 * 2 : 4 * 1;
440 glDrawElements(GL_LINES, lineCount * 2, GL_UNSIGNED_INT, (GLvoid*)(offsetFront_ *
sizeof(
int)));
452 cylinder_->setBottomRadius(axis_length_/20.0f);
453 cylinder_->setTopRadius(axis_length_/20.0f);
455 cone_->setBottomRadius(axis_length_/5.0f);
456 cone_->setTopRadius(0.0f);
459 GLMatrixf matVP = matFrustum * modelViewInv_;
467 cylinder_->draw_primitive(pickShader);
473 mat.
scale(
Vec3f(1.0, 1.0, axis_length_ * 0.5));
475 cone_->draw_primitive(pickShader);
483 cylinder_->draw_primitive(pickShader);
489 mat.
scale(
Vec3f(1.0, 1.0, axis_length_ * 0.5));
491 cone_->draw_primitive(pickShader);
499 cylinder_->draw_primitive(pickShader);
504 mat.
scale(
Vec3f(1.0, 1.0, axis_length_ * 0.5));
506 cone_->draw_primitive(pickShader);
522 GLsizei lineOffset = offsetLines_;
533 glDrawElements(GL_TRIANGLES, lineOffset, GL_UNSIGNED_INT, (GLvoid*)(offsetTris_ *
sizeof(
int)));
536 GLsizei lineCount = hasOrigin ? 4 * 7 : 4 * 6;
537 glDrawElements(GL_LINES, lineCount * 2, GL_UNSIGNED_INT, (GLvoid*)(lineOffset *
sizeof(
int)));
542 GLsizei lineCount = hasOrigin ? 4 * 2 : 4 * 1;
544 glDrawElements(GL_LINES, lineCount * 2, GL_UNSIGNED_INT, (GLvoid*)(offsetFront_ *
sizeof(
int)));
563 _state.
rotate(90, 0.0, 1.0, 0.0);
565 cylinder_->setBottomRadius(axis_length_/20.0f);
566 cylinder_->setTopRadius(axis_length_/20.0f);
567 cylinder_->draw(_state, axis_length_);
570 _state.
translate(0.0, 0.0, axis_length_ );
571 cone_->setBottomRadius(axis_length_/5.0f);
572 cone_->setTopRadius(0.0f);
573 cone_->draw(_state, axis_length_/2.0f);
574 _state.
translate(0.0, 0.0, -axis_length_ );
577 _state.
rotate(-90, 1.0, 0.0, 0.0);
579 cylinder_->draw(_state, axis_length_);
582 _state.
translate(0.0, 0.0, axis_length_ );
583 cone_->draw(_state, axis_length_/2.0f);
584 _state.
translate(0.0, 0.0, -axis_length_ );
587 _state.
rotate(-90, 0.0, 1.0, 0.0);
589 cylinder_->draw(_state, axis_length_);
592 _state.
translate(0.0, 0.0, axis_length_ );
593 cone_->draw(_state, axis_length_/2.0f);
594 _state.
translate(0.0, 0.0, -axis_length_ );
606 void CameraNode::updateVBO()
613 vbo_.upload(
sizeof(
Vec4f) * vboData_.size(), &vboData_[0], GL_STATIC_DRAW);
621 updateBoundingBoxes();
624 if (!ibo_.is_valid())
650 offsetFront_ = offsetLines_ + 8*5;
653 ibo_.upload(
sizeof(data), data, GL_STATIC_DRAW);
660 void CameraNode::updateBoundingBoxes()
662 bbmin_ =
Vec3d(DBL_MAX, DBL_MAX, DBL_MAX);
663 bbmax_ =
Vec3d(-DBL_MAX, -DBL_MAX, -DBL_MAX);
665 if (update_vbo_ || vboData_.empty())
668 for (
size_t i = 0; i < vboData_.size(); ++i)
676 bbmin_ -=
Vec3d(axis_length_ * 2.0);
677 bbmax_ +=
Vec3d(axis_length_ * 2.0);
682 void CameraNode::updateFrustumWS()
690 Vec4f(-1, -1, -1, 1),
701 GLMatrixf camWorldToClip = projection_ * modelView_;
703 GLMatrixf camClipToWorld(camWorldToClip);
706 for (
int i= 0; i < 8; ++i)
708 Vec4f posWS = camClipToWorld * posCS[i];
714 Vec4f camOriginWS(modelViewInv_(0, 3),
719 vboData_[8] = camOriginWS;
725 axis_length_ = std::min(rightVec.
norm(), upVec.norm()) * 0.015f;
728 axis_length_ = std::max(axis_length_, 0.05f);
void perspective(Scalar fovY, Scalar aspect, Scalar near_plane, Scalar far_plane)
multiply self with a perspective projection matrix
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
void pop_modelview_matrix()
pop modelview matrix
const Vec4f & specular_color() const
get specular color
void set_diffuse_color(const Vec4f &_col)
set diffuse color
void use()
Enables the program object for using.
void rotateX(Scalar _angle, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with a rotation matrix (angle in degree, x-axis)
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
int viewport_width() const
get viewport width
VectorT< float, 2 > Vec2f
void resetLineRendering()
Reset shader template names blocked by line rendering.
Namespace providing different geometric functions concerning angles.
VectorT< float, 4 > Vec4f
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
const Vec4f & base_color() const
get base color (used when lighting is off)
ShaderGenDesc shaderDesc
Drawmode and other shader params.
void translate(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with translation matrix (x,y,z)
void deactivateShaderPipeline(GLSL::Program *_prog) const
void identity()
setup an identity matrix
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Vec4f pick_get_name_color_norm(unsigned int _idx)
same as pick_get_name_color, but the resulting color channels are normalized in [0.0, 1.0] range
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
const Vec4f & diffuse_color() const
get diffuse color
DrawModes::DrawMode availableDrawModes() const override
return available draw modes
bool isLinked()
Returns if the program object has been succesfully linked.
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode) override
drawing
PickTarget
What target to use for picking.
Vec2f depthRange
glDepthRange: (znear, zmax)
bool invert()
matrix inversion (returns true on success)
void push_modelview_matrix()
push modelview matrix
void set_modelview(const GLMatrixd &_m)
set modelview
void rotateY(Scalar _angle, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with a rotation matrix (angle in degree, y-axis)
void activateFixedFunction() const
VectorT< float, 3 > Vec3f
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
Vec3f diffuse
material definitions
void addElement(const VertexElement *_pElement)
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
void scale(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with scaling matrix (x,y,z)
virtual ~CameraNode()
Destructor.
GLuint indexBuffer
Use vertex array object.
int viewport_height() const
get viewport height
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM >>().sqrnorm()))
compute euclidean norm
void disable()
Resets to standard rendering pipeline.
DrawMode POINTS
draw unlighted points using the default base color
void set_specular_color(const Vec4f &_col)
set specular color
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat) override
create render objects
bool isPerspective() const
check if the matrix is a perspective projection matrix
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
CameraNode(BaseNode *_parent=0, std::string _name="<CameraVis>")
Default constructor.
DrawMode WIREFRAME
draw wireframe
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
void set_base_color(const Vec4f &_col)
set base color (used when lighting is off)
const GLMatrixd & modelview() const
get modelview matrix
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
float line_width() const
get line width
void activateShaderPipeline(GLSL::Program *_prog) const
const GLMatrixd & projection() const
get projection matrix
void pick(GLState &_state, PickTarget _target) override
picking
Interface class between scenegraph and renderer.
void deactivateFixedFunction() const
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
VectorT< double, 3 > Vec3d
GLMatrixd modelview
Modelview transform.