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;
94 _bbMin.
minimize( pos0 + xDird + yDird);
98 _bbMax.
maximize( pos1 + xDird + yDird);
103 _bbMin.
minimize( pos1 + xDird + 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],
149 glDrawArrays(GL_LINE_STRIP,0,5);
164 glDrawArrays(GL_QUADS,0,4);
170 glDrawArrays(GL_QUADS,5,4);
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] };
202 glDrawArrays(GL_QUADS,0,4);
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]);
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 glGenBuffers(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 glBindBuffer(GL_ARRAY_BUFFER_ARB,
vbo_);
373 glBufferData(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);
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
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
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
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.
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.
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
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
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
ACG::Vec3d normal()
get current normal
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
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.