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] = {
495 0.0, 0.0, 0.0, (float)normal[0], (
float)normal[1], (float)normal[2], 0.f,
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],
503 (
float)normal[1], (float)normal[2], 1.f, 1.f,
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],
514 (
float)-normal[1], (float)-normal[2], 1.f, 1.f,
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,
520 0.0, 0.0, 0.0, (
float)-normal[0], (float)-normal[1], (
float)-normal[2],
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) {
633 ro.setMaterial(&localMaterial);
635 ro.glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
641 ro.debugName =
"PlaneNode.plane_back";
643 if (ro.textures().size() != 0) {
653 ro.setMaterial(&localMaterial);
655 ro.glDrawArrays(GL_TRIANGLE_FAN, 4, 4);
void draw(ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode) override
draw Plane
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void pop_modelview_matrix()
pop modelview matrix
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const override
return available draw modes
float point_size() const
get point size
void use()
Enables the program object for using.
picks faces (should be implemented for all nodes)
ACG::Vec3d yDirection()
local y direction (multiplied with height)
void update()
updates the plane before the next render call
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) ) ...
void boundingBox(ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax) override
update bounding box
void deactivateShaderPipeline(GLSL::Program *_prog) const
ACG::Vec3d xDirection()
local x direction (multiplied with width)
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.
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
static bool isStateEnabled(GLenum _cap)
returns true, if a cpa state is enabled
void updateVBO()
create and update VBO
Plane & getPlane()
Get the currently rendered plane.
PickTarget
What target to use for picking.
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
void ambientColor(const Vec4f &_a)
set the ambient color.
void push_modelview_matrix()
push modelview matrix
void diffuseColor(const Vec4f &_d)
set the diffuse color.
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
void setPlane(Plane plane)
Set a new plane for rendering.
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
void addElement(const VertexElement *_pElement)
pick any of the prior targets (should be implemented for all nodes)
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
DrawMode SOLID_TEXTURED
draw textured faces
void scale(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with scaling matrix (x,y,z)
picks verices (may not be implemented for all nodes)
PlaneNode(Plane &_plane, BaseNode *_parent=0, std::string _name="<PlaneNode>")
Construct a plane rendering node.
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.
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
ACG::Vec3d position()
get center position of the plane
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 applyRenderObjectSettings(DrawModes::DrawModePrimitive _primitive, RenderObject *_obj) const
Set shaders, textures and uniforms as provided by user to a render-object.
DrawMode POINTS
draw unlighted points using the default base color
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
DrawModeProperties stores a set of properties that defines, how to render an object.
void set_color(const Vec4f &_col)
set color
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
int priority
Priority to allow sorting of objects.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
unsigned int vbo_
VBO used to render the plane.
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
void specularColor(const Vec4f &_s)
set the specular color
const GLMatrixd & modelview() const
get modelview matrix
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
bool blending()
get whether transparenet or solid objects should be drawn
void pick(ACG::GLState &_state, ACG::SceneGraph::PickTarget _target) override
draw Plane for object picking
void activateShaderPipeline(GLSL::Program *_prog) const
ACG::Vec3d normal()
get current normal
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
const GLMatrixd & projection() const
get projection matrix
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
Interface class between scenegraph and renderer.
size_t getNumLayers() const
returns the layer count
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.