Developer Documentation
PlaneNode.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 #include <ACG/GL/acg_glew.hh>
51 
52 #include "PlaneNode.hh"
53 
54 #include <ACG/GL/ShaderGenerator.hh>
55 #include <ACG/GL/ShaderCache.hh>
56 
57 
58 //== IMPLEMENTATION ==========================================================
59 
60 PlaneNode::PlaneNode(Plane& _plane, BaseNode* _parent, std::string _name)
61  : BaseNode(_parent, _name),
62  plane_(_plane),
63  vbo_(0),
64  vboNeedsUpdate_(true), // not initialized, so we need an update
65  sphere_(0)
66 
67 {
68  vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_POSITION);
69  vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_NORMAL);
70  vertexDecl_.addElement(GL_FLOAT, 2, ACG::VERTEX_USAGE_TEXCOORD);
71 
72  sphere_ = new ACG::GLSphere(10, 10);
73  setPlane(_plane);
74 }
75 
77  if (vbo_) glDeleteBuffers(1, &vbo_);
78 }
79 
81  ACG::Vec3d pos =
82  plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
83 
84  // add a little offset in normal direction
85  ACG::Vec3d pos0 = ACG::Vec3d(pos + plane_.normal * 0.1);
86  ACG::Vec3d pos1 = ACG::Vec3d(pos - plane_.normal * 0.1);
87 
88  ACG::Vec3d xDird = ACG::Vec3d(plane_.xDirection);
89  ACG::Vec3d yDird = ACG::Vec3d(plane_.yDirection);
90 
91  _bbMin.minimize(pos0);
92  _bbMin.minimize(pos0 + xDird);
93  _bbMin.minimize(pos0 + yDird);
94  _bbMin.minimize(pos0 + xDird + yDird);
95  _bbMax.maximize(pos1);
96  _bbMax.maximize(pos1 + xDird);
97  _bbMax.maximize(pos1 + yDird);
98  _bbMax.maximize(pos1 + xDird + yDird);
99 
100  _bbMin.minimize(pos1);
101  _bbMin.minimize(pos1 + xDird);
102  _bbMin.minimize(pos1 + yDird);
103  _bbMin.minimize(pos1 + xDird + yDird);
104  _bbMax.maximize(pos0);
105  _bbMax.maximize(pos0 + xDird);
106  _bbMax.maximize(pos0 + yDird);
107  _bbMax.maximize(pos0 + xDird + yDird);
108 }
109 
110 //----------------------------------------------------------------------------
111 
116 }
117 
118 //----------------------------------------------------------------------------
119 
120 //----------------------------------------------------------------------------
121 
122 void PlaneNode::drawPlane(ACG::GLState& _state) {
123  const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
124 
125  // Array of coordinates for the plane
126  float vboData_[9 * 3] = {0.0,
127  0.0,
128  0.0,
129  (float)plane_.xDirection[0],
130  (float)plane_.xDirection[1],
131  (float)plane_.xDirection[2],
132  (float)xy[0],
133  (float)xy[1],
134  (float)xy[2],
135  (float)plane_.yDirection[0],
136  (float)plane_.yDirection[1],
137  (float)plane_.yDirection[2],
138  0.0,
139  0.0,
140  0.0,
141  (float)plane_.yDirection[0],
142  (float)plane_.yDirection[1],
143  (float)plane_.yDirection[2],
144  (float)xy[0],
145  (float)xy[1],
146  (float)xy[2],
147  (float)plane_.xDirection[0],
148  (float)plane_.xDirection[1],
149  (float)plane_.xDirection[2],
150  0.0,
151  0.0,
152  0.0};
153 
154  // Enable the arrays
155  _state.enableClientState(GL_VERTEX_ARRAY);
156  _state.vertexPointer(3, GL_FLOAT, 0, &vboData_[0]);
157 
158  // first draw the lines
159  _state.set_color(ACG::Vec4f(1.0, 1.0, 1.0, 1.0));
160  glLineWidth(2.0);
161 
162  glDrawArrays(GL_LINE_STRIP, 0, 5);
163 
164  glLineWidth(1.0);
165 
166  // Remember blending state
167  bool blending = _state.blending();
168  bool culling = _state.isStateEnabled(GL_CULL_FACE);
169 
170  // then the red front side
171  ACG::GLState::enable(GL_BLEND);
172  ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
173 
174  ACG::GLState::enable(GL_CULL_FACE);
175 
176  _state.set_color(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
177  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
178 
179  // finally the green back side
180  _state.set_color(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
181 
182  glDrawArrays(GL_TRIANGLE_FAN, 5, 4);
183 
184  if (!blending) ACG::GLState::disable(GL_BLEND);
185 
186  if (!culling) ACG::GLState::disable(GL_CULL_FACE);
187 
188  // deactivate vertex arrays after drawing
189  _state.disableClientState(GL_VERTEX_ARRAY);
190 }
191 
192 //----------------------------------------------------------------
193 
195  ACG::GLState& _state,
196  const ACG::SceneGraph::DrawModes::DrawMode& /*_drawMode*/) {
197  _state.push_modelview_matrix();
198  glPushAttrib(GL_COLOR_BUFFER_BIT);
199  glPushAttrib(GL_LIGHTING_BIT);
200 
201  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
202  ACG::GLState::enable(GL_COLOR_MATERIAL);
203 
204  // plane_.position represents the center of the plane.
205  // Compute the corner position
206  ACG::Vec3d pos =
207  plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
208 
209  // translate to corner position
210  _state.translate(pos[0], pos[1], pos[2]);
211 
212  // draw the plane
213  drawPlane(_state);
214 
215  glPopAttrib();
216  glPopAttrib();
217  _state.pop_modelview_matrix();
218 }
219 
220 //----------------------------------------------------------------
221 
223  ACG::SceneGraph::PickTarget _target) {
224 
225  updateVBO();
226 
227  unsigned int vertexOffset = 0;
228 
229  if ( _target == ACG::SceneGraph::PICK_ANYTHING ) {
230  // Anything is plane + 4 corners
231  _state.pick_set_maximum(1+4);
232  vertexOffset = 1;
233  } else if ( _target == ACG::SceneGraph::PICK_FACE ) {
234  // Only the Face
235  _state.pick_set_maximum(1);
236  } else if ( _target == ACG::SceneGraph::PICK_VERTEX ) {
237  // 4 Vertices
238  _state.pick_set_maximum(4);
239  }
240 
241  // use fixed function or shaders to draw pick geometry
242  const bool fixedFunctionGL = _state.compatibilityProfile();
243 
244  // load picking shader from cache
245  GLSL::Program* pickShader = 0;
246  if (!fixedFunctionGL)
247  {
248  static ACG::ShaderGenDesc desc;
249  desc.fragmentTemplateFile = "Picking/single_color_fs.glsl";
250  desc.vertexTemplateFile = "Picking/vertex.glsl";
251  pickShader = ACG::ShaderCache::getInstance()->getProgram(&desc, nullptr);
252  if (!pickShader)
253  return;
254 
255  pickShader->use();
256  }
257 
258  if (_target == ACG::SceneGraph::PICK_ANYTHING || _target == ACG::SceneGraph::PICK_FACE) {
259 
260  ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
261 
262  _state.push_modelview_matrix();
263  _state.translate(pos[0], pos[1], pos[2]);
264 
265  // We only draw one plane. So we start at element 0 and have a maximum of one elements
266  _state.pick_set_name(0);
267 
268  if (pickShader)
269  {
270 
271  pickShader->setUniform("color", _state.pick_get_name_color_norm(0));
272 
273  ACG::GLMatrixf mWVP = _state.projection() * _state.modelview();
274  pickShader->setUniform("mWVP", mWVP);
275 
276  glBindBuffer(GL_ARRAY_BUFFER, vbo_);
277  vertexDecl_.activateShaderPipeline(pickShader);
278 
279 
280  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
281 
282 
283  vertexDecl_.deactivateShaderPipeline(pickShader);
284  glBindBuffer(GL_ARRAY_BUFFER, 0);
285 
286  }
287  else
288  {
289 
290  glBindBuffer(GL_ARRAY_BUFFER, vbo_);
291 
292  _state.enableClientState(GL_VERTEX_ARRAY);
293 
294  _state.vertexPointer(3, GL_FLOAT, 8 * sizeof(float), 0);
295 
296  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
297 
298  // deactivate vertex arrays after drawing
299  _state.disableClientState(GL_VERTEX_ARRAY);
300 
301  glBindBuffer(GL_ARRAY_BUFFER, 0);
302  }
303 
304  _state.pop_modelview_matrix();
305 
306  }
307 
308  if (_target == ACG::SceneGraph::PICK_ANYTHING || _target == ACG::SceneGraph::PICK_VERTEX) {
309 
310  float sphereRadius = 0.05f;
311 
312  if (pickShader)
313  {
314  // Compute zero corner of plane ( Shifted by half such that center of plane is 0,0
315  ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
316 
317  //==========================================
318  // Draw 0 Corner:
319  //==========================================
320  _state.push_modelview_matrix();
321  _state.translate(pos[0], pos[1], pos[2]);
322 
323  ACG::GLMatrixf mWVP = _state.projection() * _state.modelview();
324  mWVP.scale(sphereRadius, sphereRadius, sphereRadius);
325  pickShader->setUniform("mWVP", mWVP);
326  pickShader->setUniform("color", _state.pick_get_name_color_norm(vertexOffset));
327  sphere_->draw_primitive(pickShader);
328 
329  //==========================================
330  // Draw x Corner:
331  //==========================================
332  vertexOffset++;
333  _state.translate(plane_.xDirection[0] , plane_.xDirection[1], plane_.xDirection[2]);
334 
335  mWVP = _state.projection() * _state.modelview();
336  mWVP.scale(sphereRadius, sphereRadius, sphereRadius);
337  pickShader->setUniform("mWVP", mWVP);
338  pickShader->setUniform("color", _state.pick_get_name_color_norm(vertexOffset));
339  sphere_->draw_primitive(pickShader);
340 
341  //==========================================
342  // Draw xy Corner:
343  //==========================================
344  vertexOffset++;
345  _state.translate(plane_.yDirection[0] , plane_.yDirection[1], plane_.yDirection[2]);
346 
347  mWVP = _state.projection() * _state.modelview();
348  mWVP.scale(sphereRadius, sphereRadius, sphereRadius);
349  pickShader->setUniform("mWVP", mWVP);
350  pickShader->setUniform("color", _state.pick_get_name_color_norm(vertexOffset));
351  sphere_->draw_primitive(pickShader);
352 
353  //==========================================
354  // Draw y Corner:
355  //==========================================
356  vertexOffset++;
357  _state.translate(-plane_.xDirection[0] , -plane_.xDirection[1], -plane_.xDirection[2]);
358 
359  mWVP = _state.projection() * _state.modelview();
360  mWVP.scale(sphereRadius, sphereRadius, sphereRadius);
361  pickShader->setUniform("mWVP", mWVP);
362  pickShader->setUniform("color", _state.pick_get_name_color_norm(vertexOffset));
363  sphere_->draw_primitive(pickShader);
364 
365  _state.pop_modelview_matrix();
366 
367  } else {
368 
369  // Compute zero corner of plane ( Shifted by half such that center of plane is 0,0
370  ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
371 
372  //==========================================
373  // Draw 0 Corner:
374  //==========================================
375  _state.push_modelview_matrix();
376  _state.translate(pos[0], pos[1], pos[2]);
377  _state.pick_set_name (vertexOffset);
378  sphere_->draw(_state,sphereRadius);
379 
380  //==========================================
381  // Draw x Corner:
382  //==========================================
383  vertexOffset++;
384  _state.translate(plane_.xDirection[0] , plane_.xDirection[1], plane_.xDirection[2]);
385  _state.pick_set_name(vertexOffset);
386  sphere_->draw(_state,sphereRadius);
387 
388  //==========================================
389  // Draw xy Corner:
390  //==========================================
391  vertexOffset++;
392  _state.translate(plane_.yDirection[0] , plane_.yDirection[1], plane_.yDirection[2]);
393  _state.pick_set_name(vertexOffset);
394  sphere_->draw(_state,sphereRadius);
395 
396  //==========================================
397  // Draw y Corner:
398  //==========================================
399  vertexOffset++;
400  _state.translate(-plane_.xDirection[0] , -plane_.xDirection[1], -plane_.xDirection[2]);
401  _state.pick_set_name(vertexOffset);
402  sphere_->draw(_state,sphereRadius);
403 
404  _state.pop_modelview_matrix();
405  }
406 
407  }
408 
409 }
410 
411 
412 
413 
414 //----------------------------------------------------------------
415 
416 ACG::Vec3d PlaneNode::position() { return plane_.position; }
417 
418 //----------------------------------------------------------------
419 
420 ACG::Vec3d PlaneNode::normal() { return plane_.normal; }
421 
422 //----------------------------------------------------------------
423 
424 ACG::Vec3d PlaneNode::xDirection() { return plane_.xDirection; }
425 
426 //----------------------------------------------------------------
427 
428 ACG::Vec3d PlaneNode::yDirection() { return plane_.yDirection; }
429 
430 //----------------------------------------------------------------
431 
433 
434 //----------------------------------------------------------------
435 
437  plane_ = plane;
438  update();
439 }
440 
441 //----------------------------------------------------------------------------
442 
443 void PlaneNode::addSphereAt(ACG::Vec3d _pos, ACG::IRenderer* _renderer,
444  ACG::GLState& _state, ACG::RenderObject* _ro) {
445  // 1. Project point to screen
446  ACG::Vec3d projected = _state.project(_pos);
447 
448  // 2. Shift it by the requested point size
449  // glPointSize defines the diameter but we want the radius, so we divide it
450  // by two
451  ACG::Vec3d shifted = projected;
452  shifted[0] = shifted[0] + (double)_state.point_size() / 2.0;
453 
454  // 3. un-project into 3D
455  ACG::Vec3d unProjectedShifted = _state.unproject(shifted);
456 
457  // 4. The difference vector defines the radius in 3D for the sphere
458  ACG::Vec3d difference = unProjectedShifted - _pos;
459 
460  const double sphereSize = difference.norm();
461 
462  sphere_->addToRenderer(_renderer, _ro, sphereSize, ACG::Vec3f(_pos));
463 }
464 
466  // update the plane in the next renderstep
467  // if the old renderer is used, nothing to do here
468  // if the new, shader based renderer is used, we have to update the vbo
469  // this is done at the next render call
470 
471  // this method prevents, that the vbo is created, if we don't use a shader
472  // based renderer
473  vboNeedsUpdate_ = true;
474 }
475 
476 //----------------------------------------------------------------------------
477 
479  if (!vboNeedsUpdate_) return;
480 
481  if (!vbo_) {
482  glGenBuffers(1, &vbo_);
483  }
484 
485  const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
486  const ACG::Vec3d normal =
487  (plane_.xDirection % plane_.yDirection).normalized();
488 
489  // Array of coordinates for the plane ( duplicated due to front and back
490  // rendering ) Interleaved with normals 8 vertices with (3 float for position
491  // + 3 float for normal + 2 for uv)
492  const size_t vboSize = 8 * (3 + 3 + 2);
493  float vboData[vboSize] = {
494  // vertex A
495  0.0, 0.0, 0.0, (float)normal[0], (float)normal[1], (float)normal[2], 0.f,
496  0.f,
497  // vertex B
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,
501  // vertex C
502  (float)xy[0], (float)xy[1], (float)xy[2], (float)normal[0],
503  (float)normal[1], (float)normal[2], 1.f, 1.f,
504  // vertex D
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,
508  // backside vertex D
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,
512  // backside vertex C
513  (float)xy[0], (float)xy[1], (float)xy[2], (float)-normal[0],
514  (float)-normal[1], (float)-normal[2], 1.f, 1.f,
515  // backside vertex B
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,
519  // backside vertex A
520  0.0, 0.0, 0.0, (float)-normal[0], (float)-normal[1], (float)-normal[2],
521  0.f, 0.f};
522 
523  // Bind buffer
524  glBindBuffer(GL_ARRAY_BUFFER_ARB, vbo_);
525 
526  // Upload to buffer
527  glBufferData(GL_ARRAY_BUFFER_ARB, vboSize * sizeof(float), &vboData[0],
528  GL_STATIC_DRAW_ARB);
529 
530  // Unbind
531  ACG::GLState::bindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
532 
533  // VBO is updated for the new renderer
534  vboNeedsUpdate_ = false;
535 }
536 
538  ACG::IRenderer* _renderer, ACG::GLState& _state,
539  const ACG::SceneGraph::DrawModes::DrawMode& _drawMode,
540  const ACG::SceneGraph::Material* _mat) {
541 
542  // init base render object
544 
545  // _state.enable(GL_COLOR_MATERIAL);
546  // _state.disable(GL_LIGHTING);
547  ro.initFromState(&_state);
548 
549  // plane_.position represents the center of the plane.
550  // Compute the corner position
551  const ACG::Vec3d pos =
552  plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
553  const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
554 
555  // translate to corner position and store that in renderer
556  _state.push_modelview_matrix();
557  _state.translate(pos[0], pos[1], pos[2]);
558  ro.modelview = _state.modelview();
559  _state.pop_modelview_matrix();
560 
561  // Render with depth test enabled
562  ro.depthTest = true;
563 
564  updateVBO();
565 
566  // Set the buffers for rendering
567  ro.vertexBuffer = vbo_;
568  ro.vertexDecl = &vertexDecl_;
569 
570  for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i) {
571  ACG::SceneGraph::Material localMaterial = *_mat;
572 
574  _drawMode.getLayer(i);
575 
576  ro.setupShaderGenFromDrawmode(props);
577 
578  switch (props->primitive()) {
579  case ACG::SceneGraph::DrawModes::PRIMITIVE_POINT:
580 
581  ro.blending = false;
582 
583  //---------------------------------------------------
584  // No lighting!
585  // Therefore we need some emissive color
586  //---------------------------------------------------
587  localMaterial.baseColor(localMaterial.ambientColor());
588  ro.setMaterial(&localMaterial);
589 
590  //---------------------------------------------------
591  // Simulate glPointSize(12) with a sphere
592  //---------------------------------------------------
593 
594  ro.debugName = "Plane Sphere x";
595  addSphereAt(plane_.xDirection, _renderer, _state, &ro);
596 
597  ro.debugName = "Plane Sphere y";
598  addSphereAt(plane_.yDirection, _renderer, _state, &ro);
599 
600  ro.debugName = "Plane Sphere xy";
601  addSphereAt(xy, _renderer, _state, &ro);
602 
603  ro.debugName = "Plane Sphere 0";
604  addSphereAt(ACG::Vec3d(0.0, 0.0, 0.0), _renderer, _state, &ro);
605 
606  break;
607  default:
608 
609  ro.priority = 10;
610 
611  // Blending enabled, since we want some transparency
612  ro.blending = true;
613  ro.blendSrc = GL_SRC_ALPHA;
614  ro.blendDest = GL_ONE_MINUS_SRC_ALPHA;
615 
616  // Enable culling in order to avoid z-fighting artifacts
617  ro.culling = true;
618 
619  //---------------------------------------------------
620  // Just draw the quads here ( front )
621  //---------------------------------------------------
622  ro.debugName = "PlaneNode.plane_front ";
623  applyRenderObjectSettings(ACG::SceneGraph::DrawModes::PRIMITIVE_POLYGON, &ro);
624  if (ro.textures().size() != 0) {
625  localMaterial.ambientColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
626  localMaterial.diffuseColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
627  localMaterial.specularColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
628  } else {
629  localMaterial.ambientColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
630  localMaterial.diffuseColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
631  localMaterial.specularColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
632  }
633  ro.setMaterial(&localMaterial);
635  ro.glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
636  _renderer->addRenderObject(&ro);
637 
638  //---------------------------------------------------
639  // Just draw the quads here ( back )
640  //---------------------------------------------------
641  ro.debugName = "PlaneNode.plane_back";
642  applyRenderObjectSettings(ACG::SceneGraph::DrawModes::PRIMITIVE_POLYGON, &ro);
643  if (ro.textures().size() != 0) {
644  localMaterial.ambientColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
645  localMaterial.diffuseColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
646  localMaterial.specularColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
647  } else {
648  localMaterial.ambientColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
649  localMaterial.diffuseColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
650  localMaterial.specularColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
651  }
652 
653  ro.setMaterial(&localMaterial);
655  ro.glDrawArrays(GL_TRIANGLE_FAN, 4, 4);
656  _renderer->addRenderObject(&ro);
657 
658  break;
659  }
660  }
661 }
662 
663 //=============================================================================
void draw(ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode) override
draw Plane
Definition: PlaneNode.cc:194
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
Definition: GLState.cc:1507
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
Definition: RenderObject.cc:61
void pop_modelview_matrix()
pop modelview matrix
Definition: GLState.cc:1026
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const override
return available draw modes
Definition: PlaneNode.cc:112
float point_size() const
get point size
Definition: GLState.hh:995
void use()
Enables the program object for using.
Definition: GLSLShader.cc:345
picks faces (should be implemented for all nodes)
Definition: PickTarget.hh:78
ACG::Vec3d yDirection()
local y direction (multiplied with height)
Definition: PlaneNode.cc:428
void update()
updates the plane before the next render call
Definition: PlaneNode.cc:465
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
Definition: GLState.cc:640
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
Definition: PlaneNode.cc:80
void deactivateShaderPipeline(GLSL::Program *_prog) const
ACG::Vec3d xDirection()
local x direction (multiplied with width)
Definition: PlaneNode.cc:424
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:587
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
Definition: GLState.cc:1077
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
Definition: GLState.cc:1961
static bool isStateEnabled(GLenum _cap)
returns true, if a cpa state is enabled
Definition: GLState.cc:1562
void updateVBO()
create and update VBO
Definition: PlaneNode.cc:478
Plane & getPlane()
Get the currently rendered plane.
Definition: PlaneNode.cc:432
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
Definition: GLState.cc:651
void ambientColor(const Vec4f &_a)
set the ambient color.
void push_modelview_matrix()
push modelview matrix
Definition: GLState.cc:1010
void diffuseColor(const Vec4f &_d)
set the diffuse color.
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
Definition: GLState.cc:1527
GLSL program class.
Definition: GLSLShader.hh:211
void setPlane(Plane plane)
Set a new plane for rendering.
Definition: PlaneNode.cc:436
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
Definition: ShaderCache.cc:84
void addElement(const VertexElement *_pElement)
pick any of the prior targets (should be implemented for all nodes)
Definition: PickTarget.hh:84
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
Definition: GLState.cc:1584
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
Definition: GLState.cc:1051
DrawMode SOLID_TEXTURED
draw textured faces
Definition: DrawModes.cc:88
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)
Definition: PickTarget.hh:82
PlaneNode(Plane &_plane, BaseNode *_parent=0, std::string _name="<PlaneNode>")
Construct a plane rendering node.
Definition: PlaneNode.cc:60
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.
Definition: PlaneNode.cc:537
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
Definition: GLState.cc:1570
ACG::Vec3d position()
get center position of the plane
Definition: PlaneNode.cc:416
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:559
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
Definition: ShaderCache.cc:102
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
Definition: GLSLShader.cc:385
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
Definition: Vector11T.hh:433
void applyRenderObjectSettings(DrawModes::DrawModePrimitive _primitive, RenderObject *_obj) const
Set shaders, textures and uniforms as provided by user to a render-object.
Definition: BaseNode.cc:301
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
Definition: GLState.hh:307
~PlaneNode()
destructor
Definition: PlaneNode.cc:76
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:177
void set_color(const Vec4f &_col)
set color
Definition: GLState.cc:691
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
Definition: IRenderer.cc:104
int priority
Priority to allow sorting of objects.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:81
unsigned int vbo_
VBO used to render the plane.
Definition: PlaneNode.hh:149
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
Definition: GLState.cc:1061
void specularColor(const Vec4f &_s)
set the specular color
const GLMatrixd & modelview() const
get modelview matrix
Definition: GLState.hh:816
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
Definition: GLState.hh:579
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
Definition: GLState.hh:1060
void pick(ACG::GLState &_state, ACG::SceneGraph::PickTarget _target) override
draw Plane for object picking
Definition: PlaneNode.cc:222
void activateShaderPipeline(GLSL::Program *_prog) const
ACG::Vec3d normal()
get current normal
Definition: PlaneNode.cc:420
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
Definition: DrawModes.cc:527
const GLMatrixd & projection() const
get projection matrix
Definition: GLState.hh:811
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
size_t getNumLayers() const
returns the layer count
Definition: DrawModes.cc:523
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Definition: GLState.cc:533
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121
GLMatrixd modelview
Modelview transform.