50#include <ACG/GL/acg_glew.hh>
52#include "PlaneNode.hh"
54#include <ACG/GL/ShaderGenerator.hh>
55#include <ACG/GL/ShaderCache.hh>
64 vboNeedsUpdate_(true),
82 plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
94 _bbMin.
minimize(pos0 + xDird + yDird);
98 _bbMax.
maximize(pos1 + xDird + yDird);
103 _bbMin.
minimize(pos1 + xDird + yDird);
107 _bbMax.
maximize(pos0 + xDird + yDird);
123 const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
126 float vboData_[9 * 3] = {0.0,
129 (float)plane_.xDirection[0],
130 (
float)plane_.xDirection[1],
131 (float)plane_.xDirection[2],
135 (float)plane_.yDirection[0],
136 (
float)plane_.yDirection[1],
137 (float)plane_.yDirection[2],
141 (
float)plane_.yDirection[0],
142 (float)plane_.yDirection[1],
143 (
float)plane_.yDirection[2],
147 (
float)plane_.xDirection[0],
148 (float)plane_.xDirection[1],
149 (
float)plane_.xDirection[2],
162 glDrawArrays(GL_LINE_STRIP, 0, 5);
177 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
182 glDrawArrays(GL_TRIANGLE_FAN, 5, 4);
198 glPushAttrib(GL_COLOR_BUFFER_BIT);
199 glPushAttrib(GL_LIGHTING_BIT);
201 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
207 plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
210 _state.
translate(pos[0], pos[1], pos[2]);
227 unsigned int vertexOffset = 0;
242 const bool fixedFunctionGL = _state.compatibilityProfile();
246 if (!fixedFunctionGL)
249 desc.fragmentTemplateFile =
"Picking/single_color_fs.glsl";
250 desc.vertexTemplateFile =
"Picking/vertex.glsl";
260 ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
263 _state.
translate(pos[0], pos[1], pos[2]);
276 glBindBuffer(GL_ARRAY_BUFFER,
vbo_);
280 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
284 glBindBuffer(GL_ARRAY_BUFFER, 0);
290 glBindBuffer(GL_ARRAY_BUFFER,
vbo_);
296 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
301 glBindBuffer(GL_ARRAY_BUFFER, 0);
310 float sphereRadius = 0.05f;
315 ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
321 _state.
translate(pos[0], pos[1], pos[2]);
324 mWVP.
scale(sphereRadius, sphereRadius, sphereRadius);
327 sphere_->draw_primitive(pickShader);
333 _state.
translate(plane_.xDirection[0] , plane_.xDirection[1], plane_.xDirection[2]);
336 mWVP.
scale(sphereRadius, sphereRadius, sphereRadius);
339 sphere_->draw_primitive(pickShader);
345 _state.
translate(plane_.yDirection[0] , plane_.yDirection[1], plane_.yDirection[2]);
348 mWVP.
scale(sphereRadius, sphereRadius, sphereRadius);
351 sphere_->draw_primitive(pickShader);
357 _state.
translate(-plane_.xDirection[0] , -plane_.xDirection[1], -plane_.xDirection[2]);
360 mWVP.
scale(sphereRadius, sphereRadius, sphereRadius);
363 sphere_->draw_primitive(pickShader);
370 ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
376 _state.
translate(pos[0], pos[1], pos[2]);
378 sphere_->draw(_state,sphereRadius);
384 _state.
translate(plane_.xDirection[0] , plane_.xDirection[1], plane_.xDirection[2]);
386 sphere_->draw(_state,sphereRadius);
392 _state.
translate(plane_.yDirection[0] , plane_.yDirection[1], plane_.yDirection[2]);
394 sphere_->draw(_state,sphereRadius);
400 _state.
translate(-plane_.xDirection[0] , -plane_.xDirection[1], -plane_.xDirection[2]);
402 sphere_->draw(_state,sphereRadius);
452 shifted[0] = shifted[0] + (double)_state.
point_size() / 2.0;
458 ACG::Vec3d difference = unProjectedShifted - _pos;
460 const double sphereSize = difference.
norm();
462 sphere_->addToRenderer(_renderer, _ro, sphereSize,
ACG::Vec3f(_pos));
473 vboNeedsUpdate_ =
true;
479 if (!vboNeedsUpdate_)
return;
482 glGenBuffers(1, &
vbo_);
485 const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
487 (plane_.xDirection % plane_.yDirection).normalized();
492 const size_t vboSize = 8 * (3 + 3 + 2);
493 float vboData[vboSize] = {
498 (
float)plane_.xDirection[0], (float)plane_.xDirection[1],
499 (
float)plane_.xDirection[2], (float)
normal[0], (
float)
normal[1],
500 (float)
normal[2], 1.f, 0.f,
502 (
float)xy[0], (float)xy[1], (
float)xy[2], (float)
normal[0],
505 (
float)plane_.yDirection[0], (float)plane_.yDirection[1],
506 (
float)plane_.yDirection[2], (float)
normal[0], (
float)
normal[1],
507 (float)
normal[2], 0.f, 1.f,
509 (
float)plane_.yDirection[0], (float)plane_.yDirection[1],
510 (
float)plane_.yDirection[2], (float)-
normal[0], (
float)-
normal[1],
511 (float)-
normal[2], 0.f, 1.f,
513 (
float)xy[0], (float)xy[1], (
float)xy[2], (float)-
normal[0],
516 (
float)plane_.xDirection[0], (float)plane_.xDirection[1],
517 (
float)plane_.xDirection[2], (float)-
normal[0], (
float)-
normal[1],
518 (float)-
normal[2], 1.f, 0.f,
524 glBindBuffer(GL_ARRAY_BUFFER_ARB,
vbo_);
527 glBufferData(GL_ARRAY_BUFFER_ARB, vboSize *
sizeof(
float), &vboData[0],
534 vboNeedsUpdate_ =
false;
552 plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
553 const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
557 _state.
translate(pos[0], pos[1], pos[2]);
570 for (
unsigned int i = 0; i < _drawMode.
getNumLayers(); ++i) {
578 switch (props->primitive()) {
579 case ACG::SceneGraph::DrawModes::PRIMITIVE_POINT:
588 ro.setMaterial(&localMaterial);
594 ro.debugName =
"Plane Sphere x";
595 addSphereAt(plane_.xDirection, _renderer, _state, &ro);
597 ro.debugName =
"Plane Sphere y";
598 addSphereAt(plane_.yDirection, _renderer, _state, &ro);
600 ro.debugName =
"Plane Sphere xy";
601 addSphereAt(xy, _renderer, _state, &ro);
603 ro.debugName =
"Plane Sphere 0";
604 addSphereAt(
ACG::Vec3d(0.0, 0.0, 0.0), _renderer, _state, &ro);
613 ro.blendSrc = GL_SRC_ALPHA;
622 ro.debugName =
"PlaneNode.plane_front ";
624 if (ro.textures().size() != 0) {
630 ro.setMaterial(&localMaterial);
632 ro.glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
638 ro.debugName =
"PlaneNode.plane_back";
640 if (ro.textures().size() != 0) {
646 ro.setMaterial(&localMaterial);
648 ro.glDrawArrays(GL_TRIANGLE_FAN, 4, 4);
void scale(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with scaling matrix (x,y,z)
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
Vec4f pick_get_name_color_norm(unsigned int _idx)
same as pick_get_name_color, but the resulting color channels are normalized in [0....
void pop_modelview_matrix()
pop modelview matrix
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
const GLMatrixd & modelview() const
get modelview matrix
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
const GLMatrixd & projection() const
get projection matrix
bool blending()
get whether transparenet or solid objects should be drawn
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void set_color(const Vec4f &_col)
set color
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
static bool isStateEnabled(GLenum _cap)
returns true, if a cpa state is enabled
void push_modelview_matrix()
push modelview matrix
float point_size() const
get point size
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
void applyRenderObjectSettings(DrawModes::DrawModePrimitive _primitive, RenderObject *_obj) const
Set shaders, textures and uniforms as provided by user to a render-object.
DrawModeProperties stores a set of properties that defines, how to render an object.
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
size_t getNumLayers() const
returns the layer count
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) )
void specularColor(const Vec4f &_s)
set the specular color
void ambientColor(const Vec4f &_a)
set the ambient color.
void diffuseColor(const Vec4f &_d)
set the diffuse color.
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
void addElement(const VertexElement *_pElement)
void deactivateShaderPipeline(GLSL::Program *_prog) const
void activateShaderPipeline(GLSL::Program *_prog) const
void use()
Enables the program object for using.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM > >().sqrnorm()))
compute euclidean norm
void updateVBO()
create and update VBO
unsigned int vbo_
VBO used to render the plane.
void setPlane(Plane plane)
Set a new plane for rendering.
void update()
updates the plane before the next render call
void pick(ACG::GLState &_state, ACG::SceneGraph::PickTarget _target) override
draw Plane for object picking
void draw(ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode) override
draw Plane
ACG::Vec3d position()
get center position of the plane
void getRenderObjects(ACG::IRenderer *_renderer, ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat) override
Add the objects to the given renderer.
ACG::Vec3d xDirection()
local x direction (multiplied with width)
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const override
return available draw modes
void boundingBox(ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax) override
update bounding box
PlaneNode(Plane &_plane, BaseNode *_parent=0, std::string _name="<PlaneNode>")
Construct a plane rendering node.
ACG::Vec3d yDirection()
local y direction (multiplied with height)
Plane & getPlane()
Get the currently rendered plane.
ACG::Vec3d normal()
get current normal
DrawMode POINTS
draw unlighted points using the default base color
DrawMode SOLID_TEXTURED
draw textured faces
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
PickTarget
What target to use for picking.
@ PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
@ PICK_FACE
picks faces (should be implemented for all nodes)
@ PICK_VERTEX
picks verices (may not be implemented for all nodes)
@ VERTEX_USAGE_NORMAL
"inNormal"
@ VERTEX_USAGE_POSITION
"inPosition"
@ VERTEX_USAGE_TEXCOORD
"inTexCoord"
VectorT< double, 3 > Vec3d
Interface class between scenegraph and renderer.
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
int priority
Priority to allow sorting of objects.
GLMatrixd modelview
Modelview transform.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
void initFromState(GLState *_glState)
Initializes a RenderObject instance.