50 #include <ACG/GL/acg_glew.hh>
52 #include "PlaneNode.hh"
61 vboNeedsUpdate_(true),
75 glDeleteBuffers(1,&
vbo_);
82 ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
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);
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);
128 const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
131 float vboData_[9 * 3 ] = { 0.0,0.0,0.0,
132 (float)plane_.xDirection[0],(
float)plane_.xDirection[1],(float)plane_.xDirection[2],
133 (
float)xy[0],(float)xy[1],(
float)xy[2],
134 (
float)plane_.
yDirection[0],(
float)plane_.yDirection[1],(
float)plane_.yDirection[2],
136 (
float)plane_.yDirection[0],(
float)plane_.yDirection[1],(
float)plane_.yDirection[2],
137 (
float)xy[0],(
float)xy[1],(
float)xy[2],
138 (
float)plane_.
xDirection[0],(
float)plane_.xDirection[1],(
float)plane_.xDirection[2],
142 _state.enableClientState(GL_VERTEX_ARRAY);
143 _state.vertexPointer(3,GL_FLOAT,0,&vboData_[0]);
146 _state.set_color(
ACG::
Vec4f(1.0, 1.0, 1.0 , 1.0) );
149 glDrawArrays(GL_LINE_STRIP,0,5);
154 bool blending = _state.blending();
155 bool culling = _state.isStateEnabled(GL_CULL_FACE);
158 ACG::GLState::enable (GL_BLEND);
159 ACG::GLState::blendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
161 ACG::GLState::enable (GL_CULL_FACE);
163 _state.set_color(
ACG::Vec4f( 0.6f, 0.15f, 0.2f, 0.5f));
164 glDrawArrays(GL_QUADS,0,4);
168 _state.set_color(
ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f ));
170 glDrawArrays(GL_QUADS,5,4);
173 ACG::GLState::disable(GL_BLEND);
176 ACG::GLState::disable(GL_CULL_FACE);
179 _state.disableClientState(GL_VERTEX_ARRAY);
187 _state.pick_set_maximum(1);
188 _state.pick_set_name(0);
190 const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
193 float vboData_[4* 3 ] = { 0.0,0.0,0.0,
194 (float)plane_.xDirection[0],(
float)plane_.xDirection[1],(float)plane_.xDirection[2],
195 (
float)xy[0],(float)xy[1],(
float)xy[2],
196 (
float)plane_.yDirection[0],(
float)plane_.yDirection[1],(
float)plane_.yDirection[2] };
199 _state.enableClientState(GL_VERTEX_ARRAY);
200 _state.vertexPointer(3,GL_FLOAT,0,&vboData_[0]);
202 glDrawArrays(GL_QUADS,0,4);
205 _state.disableClientState(GL_VERTEX_ARRAY);
214 _state.push_modelview_matrix();
215 glPushAttrib(GL_COLOR_BUFFER_BIT);
216 glPushAttrib(GL_LIGHTING_BIT);
218 glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
223 ACG::Vec3d pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
226 _state.translate(pos[0], pos[1], pos[2]);
233 _state.pop_modelview_matrix();
246 ACG::Vec3d pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
248 _state.
translate(pos[0], pos[1], pos[2]);
250 drawPlanePick(_state);
260 return plane_.position;
267 return plane_.normal;
274 return plane_.xDirection;
281 return plane_.yDirection;
310 shifted[0] = shifted[0] + (double)_state.
point_size() / 2.0 ;
316 ACG::Vec3d difference = unProjectedShifted - _pos ;
318 const double sphereSize = difference.norm();
320 sphere_->addToRenderer(_renderer, _ro, sphereSize,
ACG::Vec3f(_pos));
330 vboNeedsUpdate_ =
true;
337 if (!vboNeedsUpdate_)
341 glGenBuffersARB(1, &
vbo_);
344 const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
345 const ACG::Vec3d normal = (plane_.xDirection % plane_.yDirection).normalized();
350 const size_t vboSize = 8 * (3+3);
351 float vboData[vboSize] = { 0.0,0.0,0.0,
352 (float)normal[0],(
float)normal[1],(float)normal[2],
353 (
float)plane_.xDirection[0],(float)plane_.xDirection[1],(
float)plane_.xDirection[2],
354 (float)normal[0],(
float)normal[1],(float)normal[2],
355 (
float)xy[0],(float)xy[1],(
float)xy[2],
356 (float)normal[0],(
float)normal[1],(float)normal[2],
357 (
float)plane_.yDirection[0],(float)plane_.yDirection[1],(
float)plane_.yDirection[2],
358 (float)normal[0],(
float)normal[1],(float)normal[2],
359 (
float)plane_.yDirection[0],(float)plane_.yDirection[1],(
float)plane_.yDirection[2],
360 (float)-normal[0],(
float)-normal[1],(float)-normal[2],
361 (
float)xy[0],(float)xy[1],(
float)xy[2],
362 (float)-normal[0],(
float)-normal[1],(float)-normal[2],
363 (
float)plane_.xDirection[0],(float)plane_.xDirection[1],(
float)plane_.xDirection[2],
364 (float)-normal[0],(
float)-normal[1],(float)-normal[2],
366 (
float)-normal[0],(float)-normal[1],(
float)-normal[2]};
370 glBindBufferARB(GL_ARRAY_BUFFER_ARB,
vbo_);
373 glBufferDataARB(GL_ARRAY_BUFFER_ARB, vboSize *
sizeof(
float), &vboData[0], GL_STATIC_DRAW_ARB);
379 vboNeedsUpdate_ =
false;
389 _state.
enable(GL_COLOR_MATERIAL);
395 const ACG::Vec3d pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
396 const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
400 _state.
translate(pos[0], pos[1], pos[2]);
414 for (
unsigned int i = 0; i < _drawMode.
getNumLayers(); ++i)
423 switch (props->primitive()) {
425 case ACG::SceneGraph::DrawModes::PRIMITIVE_POINT:
434 ro.setMaterial(&localMaterial);
440 ro.debugName =
"Plane Sphere x";
441 addSphereAt(plane_.xDirection,_renderer,_state,&ro);
443 ro.debugName =
"Plane Sphere y";
444 addSphereAt(plane_.yDirection,_renderer,_state,&ro);
446 ro.debugName =
"Plane Sphere xy";
447 addSphereAt(xy,_renderer,_state,&ro);
449 ro.debugName =
"Plane Sphere 0";
450 addSphereAt(
ACG::Vec3d(0.0,0.0,0.0),_renderer,_state,&ro);
460 ro.blendSrc = GL_SRC_ALPHA;
469 ro.debugName =
"PlaneNode.plane_front ";
473 ro.setMaterial(&localMaterial);
474 ro.glDrawArrays(GL_QUADS, 0, 4);
480 ro.debugName =
"PlaneNode.plane_back";
484 ro.setMaterial(&localMaterial);
485 ro.glDrawArrays(GL_QUADS, 4, 4);
ACG::Vec3d position()
get center position of the plane
static void enable(GLenum _cap)
replaces glEnable, but supports locking
Namespace providing different geometric functions concerning angles.
void specularColor(const Vec4f &_s)
set the specular color
PickTarget
What target to use for picking.
void getRenderObjects(ACG::IRenderer *_renderer, ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
Add the objects to the given renderer.
pick any of the prior targets (should be implemented for all nodes)
Interface class between scenegraph and renderer.
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
void setPlane(Plane plane)
Set a new plane for rendering.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const
return available draw modes
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
VectorT< double, 3 > Vec3d
const GLMatrixd & modelview() const
get modelview matrix
void draw(ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode)
draw Plane
void diffuseColor(const Vec4f &_d)
set the diffuse color.
void push_modelview_matrix()
push modelview matrix
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
size_t getNumLayers() const
returns the layer count
void update()
updates the plane before the next render call
DrawModeProperties stores a set of properties that defines, how to render an object.
unsigned int vbo_
VBO used to render the plane.
ACG::Vec3d xDirection()
local x direction (multiplied with width)
float point_size() const
get point size
DrawMode POINTS
draw unlighted points using the default base color
void boundingBox(ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax)
update bounding box
void ambientColor(const Vec4f &_a)
set the ambient color.
void pop_modelview_matrix()
pop modelview matrix
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
void baseColor(const Vec4f &_c)
set the base color
void updateVBO()
create and update VBO
ACG::Vec3d normal()
get current normal
static void disable(GLenum _cap)
replaces glDisable, but supports locking
void pick(ACG::GLState &_state, ACG::SceneGraph::PickTarget _target)
draw Plane for object picking
GLMatrixd modelview
Modelview transform.
PlaneNode(Plane &_plane, BaseNode *_parent=0, std::string _name="<PlaneNode>")
Construct a plane rendering node.
ACG::Vec3d yDirection()
local y direction (multiplied with height)
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
int priority
Priority to allow sorting of objects.
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void addElement(const VertexElement *_pElement)
Plane & getPlane()
Get the currently rendered plane.