61 #include "CoordsysNode.hh"
62 #include <ACG/GL/IRenderer.hh>
77 projectionMode_(_projectionMode)
79 const double bodyRadius = 0.004;
80 const double topRadius = 0.01;
81 const int slices = 10;
82 const int stacks = 10;
85 cylinder_ =
new ACG::GLCylinder(slices, stacks, bodyRadius,
false,
false);
86 cone_ =
new ACG::GLCone(slices, stacks, 0, topRadius ,
false,
true);
87 disk_ =
new ACG::GLDisk(slices, 10, 0.0f, bodyRadius);
129 drawCoordsys(
GLState& _state) {
131 const double arrowLength = 0.03;
132 const double bodyLength = 0.06;
133 const double sphereRadius = 0.01;
139 glColor4f(0.5, 0.5, 0.5 , 1.0);
140 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (matCol * 0.5f).data());
141 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matCol.data());
142 sphere_->draw(_state,sphereRadius);
145 glColor4f(1.0, 0.0, 0.0, 1.0);
146 matCol[0] = 1.0f; matCol[1] = 0.0f; matCol[2] = 0.0f;
147 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (matCol * 0.5f).data());
148 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matCol.data());
150 _state.
rotate (-90, 0, 1, 0);
152 cylinder_->draw(_state,bodyLength);
154 cone_->draw(_state,arrowLength);
158 glColor4f(0.0, 1.0, 0.0, 1.0);
159 matCol[0] = 0.0f; matCol[1] = 1.0f; matCol[2] = 0.0f;
160 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (matCol * 0.2f).data());
161 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matCol.data());
163 _state.
rotate (90, 1, 0, 0);
165 cylinder_->draw(_state,bodyLength);
167 cone_->draw(_state,arrowLength);
171 glColor4f(0.0, 0.0, 1.0, 1.0);
172 matCol[0] = 0.0f; matCol[1] = 0.0f; matCol[2] = 1.0f;
173 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (matCol * 0.5f).data());
174 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matCol.data());
176 _state.
rotate (180, 0, 1, 0);
178 cylinder_->draw(_state,bodyLength);
180 cone_->draw(_state,arrowLength);
191 const double arrowLength = 0.03;
192 const double bodyLength = 0.06;
193 const double sphereRadius = 0.01;
197 _baseRO->debugName =
"coordsys.sphere";
198 _baseRO->emissive =
Vec3f(0.4f, 0.4f, 0.4f);
200 _baseRO->specular =
Vec3f(0.2f, 0.2f, 0.2f);
201 _baseRO->ambient =
Vec3f(0.1f, 0.1f, 0.1f);
202 sphere_->addToRenderer(_renderer, _baseRO, sphereRadius);
206 _baseRO->debugName =
"coordsys.x.axis";
207 _baseRO->emissive =
Vec3f(0.5f, 0.0f, 0.0f);
209 _baseRO->specular =
Vec3f(0.1f, 0.0f, 0.0f);
210 _baseRO->ambient =
Vec3f(0.1f, 0.0f, 0.0f);
214 cylinder_->addToRenderer(_renderer, _baseRO, bodyLength);
216 _baseRO->debugName =
"coordsys.x.head";
218 cone_->addToRenderer(_renderer, _baseRO, arrowLength);
222 _baseRO->debugName =
"coordsys.y.axis";
223 _baseRO->emissive =
Vec3f(0.0f, 0.5f, 0.0f);
225 _baseRO->specular =
Vec3f(0.0f, 0.1f, 0.0f);
226 _baseRO->ambient =
Vec3f(0.0f, 0.1f, 0.0f);
230 cylinder_->addToRenderer(_renderer, _baseRO, bodyLength);
232 _baseRO->debugName =
"coordsys.y.head";
234 cone_->addToRenderer(_renderer, _baseRO, arrowLength);
238 _baseRO->debugName =
"coordsys.z.axis";
239 _baseRO->emissive =
Vec3f(0.0f, 0.0f, 0.5f);
241 _baseRO->specular =
Vec3f(0.0f, 0.0f, 0.1f);
242 _baseRO->ambient =
Vec3f(0.0f, 0.0f, 0.1f);
246 cylinder_->addToRenderer(_renderer, _baseRO, bodyLength);
248 _baseRO->debugName =
"coordsys.z.head";
250 cone_->addToRenderer(_renderer, _baseRO, arrowLength);
256 CoordsysNode::drawCoordsysPick( GLState& _state) {
258 const double arrowLength = 0.03;
259 const double bodyLength = 0.06;
260 const double sphereRadius = 0.01;
263 _state.pick_set_name (1);
264 sphere_->draw(_state,sphereRadius);
267 _state.pick_set_name (2);
268 _state.push_modelview_matrix ();
269 _state.rotate (-90, 0, 1, 0);
270 _state.translate ( 0, 0, -bodyLength );
271 cylinder_->draw(_state,bodyLength);
272 _state.translate ( 0, 0, -arrowLength );
273 cone_->draw(_state,arrowLength);
274 _state.pop_modelview_matrix ();
278 _state.pick_set_name (3);
279 _state.push_modelview_matrix ();
280 _state.rotate (90, 1, 0, 0);
281 _state.translate ( 0, 0, -bodyLength );
282 cylinder_->draw(_state,bodyLength);
283 _state.translate ( 0, 0, -arrowLength );
284 cone_->draw(_state,arrowLength);
285 _state.pop_modelview_matrix ();
288 _state.pick_set_name (4);
289 _state.push_modelview_matrix ();
290 _state.rotate (180, 0, 1, 0);
291 _state.translate ( 0, 0, -bodyLength );
292 cylinder_->draw(_state,bodyLength);
293 _state.translate ( 0, 0, -arrowLength );
294 cone_->draw(_state,arrowLength);
295 _state.pop_modelview_matrix ();
309 GLboolean colorMask[4];
310 glGetBooleanv (GL_COLOR_WRITEMASK, colorMask);
317 glPushAttrib( GL_LIGHTING_BIT );
319 glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
323 GLfloat zeroVec[4] = {0.0f};
324 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zeroVec);
325 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, zeroVec);
328 Vec3d pos3D(0.0,0.0,0.0);
332 int left, bottom, width, height;
333 double aspect = _state.
aspect();
344 _state.
ortho(-0.65*aspect, 0.65*aspect, -0.65, 0.65, 0.8, 20.0);
349 float rel_size = 50.0;
350 float projdist = sqrt ( (width*height) / rel_size );
352 float posx = left + width - projdist ;
353 float posy = bottom + height - projdist ;
363 modelview(0,3) = 0.0;
364 modelview(1,3) = 0.0;
365 modelview(2,3) = 0.0;
368 _state.
translate (pos3D[0], pos3D[1], pos3D[2], MULT_FROM_LEFT);
375 drawCoordsys(_state);
381 drawCoordsys(_state);
386 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
389 drawCoordsys(_state);
393 glColorMask (colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
403 modelview(0,3) = 0.0;
404 modelview(1,3) = 0.0;
405 modelview(2,3) = 0.0;
414 drawCoordsys(_state);
421 drawCoordsys(_state);
426 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
429 drawCoordsys(_state);
434 glColorMask (colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
439 glColor4fv(lastBaseColor.data());
453 Vec3d pos3D(0.0,0.0,0.0);
461 ro.setMaterial(_mat);
465 ro.depthWrite =
true;
471 int left, bottom, width, height;
472 double aspect = _state.
aspect();
483 _state.
ortho(-0.65*aspect, 0.65*aspect, -0.65, 0.65, 0.8, 20.0);
488 float rel_size = 50.0;
489 float projdist = sqrt ( (width*height) / rel_size );
491 float posx = left + width - projdist ;
492 float posy = bottom + height - projdist ;
502 modelview(0,3) = 0.0;
503 modelview(1,3) = 0.0;
504 modelview(2,3) = 0.0;
507 _state.
translate (pos3D[0], pos3D[1], pos3D[2], MULT_FROM_LEFT);
529 drawCoordsys(_renderer, &ro);
539 modelview(0,3) = 0.0;
540 modelview(1,3) = 0.0;
541 modelview(2,3) = 0.0;
550 drawCoordsys(_renderer, &ro);
557 drawCoordsys(_renderer, &ro);
562 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
565 drawCoordsys(_renderer, &ro);
585 projectionMode_ = _mode;
606 return projectionMode_;
624 Vec3d pos3D(0.0,0.0,0.0);
628 int left, bottom, width, height;
629 double aspect = _state.
aspect();
640 _state.
ortho(-0.65*aspect, 0.65*aspect, -0.65, 0.65, 0.8, 20.0);
645 float rel_size = 50.0;
646 float projdist = sqrt ( (width*height) / rel_size );
648 float posx = left + width - projdist ;
649 float posy = bottom + height - projdist ;
658 modelview(0,3) = 0.0;
659 modelview(1,3) = 0.0;
660 modelview(2,3) = 0.0;
663 _state.
translate (pos3D[0], pos3D[1], pos3D[2], MULT_FROM_LEFT);
670 clearPickArea(_state,
true, 1.0);
673 drawCoordsysPick(_state);
676 clearPickArea(_state,
false, 0.0);
685 drawCoordsys(_state);
692 drawCoordsys(_state);
697 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
700 drawCoordsys(_state);
705 glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
716 glMatrixMode(GL_PROJECTION);
721 glGetDoublev(GL_PROJECTION_MATRIX, mat);
727 glMatrixMode(GL_MODELVIEW);
731 modelview(0,3) = 0.0;
732 modelview(1,3) = 0.0;
733 modelview(2,3) = 0.0;
740 clearPickArea(_state,
true, 1.0);
743 drawCoordsysPick(_state);
746 clearPickArea(_state,
false, 0.0);
755 drawCoordsys(_state);
762 drawCoordsys(_state);
767 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
770 drawCoordsys(_state);
775 glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
786 void CoordsysNode::clearPickArea(
GLState& _state,
bool _draw, GLfloat _depth)
790 std::vector<Vec2f> points;
794 int left, bottom, width, height;
797 GLboolean colorMask[4];
798 glGetBooleanv (GL_COLOR_WRITEMASK, colorMask);
802 points.push_back (
Vec2f (proj[0], proj[1]));
805 points.push_back (
Vec2f (proj[0], proj[1]));
808 points.push_back (
Vec2f (proj[0], proj[1]));
811 points.push_back (
Vec2f (proj[0], proj[1]));
815 boundingCircle(points, center, radius);
820 _state.
ortho (left, left + width, bottom, bottom + height, 0.0, 1.0);
826 _state.
translate (center[0], center[1], -0.5);
831 glColorMask(
false,
false,
false,
false);
834 disk_->setInnerRadius(0.0f);
835 disk_->setOuterRadius(radius * 1.1f);
845 glColorMask (colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
850 void CoordsysNode::boundingCircle(std::vector<Vec2f> &_in,
Vec2f &_center,
float &_radius)
863 for (
unsigned int i = 0; i < _in.size () - 1; i++)
864 for (
unsigned int j = i + 1; j < _in.size (); j++)
866 Vec2f cen = (_in[i] + _in[j]) * 0.5f;
867 float rad = (_in[i] - cen).length ();
870 for (
unsigned int k = 0; k < _in.size (); k++)
871 if (k != i && k != j && (_in[k] - cen).length () > rad)
900 for (
unsigned int i = 0; i < _in.size () - 2; i++)
901 for (
unsigned int j = i + 1; j < _in.size () - 1; j++)
902 for (
unsigned int k = j + 1; k < _in.size (); k++)
904 float v = ((_in[k][0]-_in[j][0])*((_in[i][0]*_in[i][0])+(_in[i][1]*_in[i][1]))) +
905 ((_in[i][0]-_in[k][0])*((_in[j][0]*_in[j][0])+(_in[j][1]*_in[j][1]))) +
906 ((_in[j][0]-_in[i][0])*((_in[k][0]*_in[k][0])+(_in[k][1]*_in[k][1])));
907 float u = ((_in[j][1]-_in[k][1])*((_in[i][0]*_in[i][0])+(_in[i][1]*_in[i][1]))) +
908 ((_in[k][1]-_in[i][1])*((_in[j][0]*_in[j][0])+(_in[j][1]*_in[j][1]))) +
909 ((_in[i][1]-_in[j][1])*((_in[k][0]*_in[k][0])+(_in[k][1]*_in[k][1])));
910 float d = (_in[i][0]*_in[j][1])+(_in[j][0]*_in[k][1])+(_in[k][0]*_in[i][1]) -
911 (_in[i][0]*_in[k][1])-(_in[j][0]*_in[i][1])-(_in[k][0]*_in[j][1]);
912 Vec2f cen(0.5 * (u/d), 0.5 * (v/d));
913 float rad = (_in[i] - cen).length ();
916 for (
unsigned int l = 0; l < _in.size (); l++)
917 if (l != i && l != j && l != k && (_in[l] - cen).length () > rad)
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
ProjectionMode
projection mode
const GLMatrixd & projection() const
get projection matrix
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
void setMode(const CoordsysMode _mode)
set mode to either POSITION or SCREENPOS
void pop_modelview_matrix()
pop modelview matrix
void push_modelview_matrix()
push modelview matrix
void set_modelview(const GLMatrixd &_m)
set modelview
~CoordsysNode()
destructor
void translate(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with translation matrix (x,y,z)
Namespace providing different geometric functions concerning angles.
static void enable(GLenum _cap)
replaces glEnable, but supports locking
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const
return available draw modes
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
DrawMode POINTS
draw unlighted points using the default base color
ProjectionMode getProjectionMode() const
get current projection mode
pick any of the prior targets (should be implemented for all nodes)
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
bool inZPrePass
Specify whether this object should be rendered in a z-prepass.
void clearTextures()
disables texture support and removes all texture types
CoordsysNode(BaseNode *_parent=0, std::string _name="<TextNode>", CoordsysMode _mode=SCREENPOS, ProjectionMode _projectionMode=PERSPECTIVE_PROJECTION)
Draws the Coordsys at the upper right position on the screen.
bool color_picking() const
Is color picking active?
void setProjectionMode(const ProjectionMode _mode)
set mode to either ORTHOGRAPHIC_PROJECTION or PERSPECTIVE_PROJECTION
GLMatrixd proj
Projection transform.
Vec3f diffuse
material definitions
void reset_projection()
reset projection matrix (load identity)
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
VectorT< float, 3 > Vec3f
void pick(GLState &_state, PickTarget _target)
draw Coordsys for object picking
const Scalar * get_raw_data() const
const GLMatrixd & inverse_projection() const
get inverse projection matrix
GLMatrixd modelview
Modelview transform.
VectorT< float, 2 > Vec2f
void ortho(double _left, double _right, double _bottom, double _top, double _near_plane, double _far_plane)
orthographic projection
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Vec2f depthRange
glDepthRange: (znear, zmax)
Draws the Coordsys at the coordsys origin.
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw Coordsys
void reset_modelview()
reset modelview matrix (load identity)
void pop_projection_matrix()
pop projection matrix
void setPosition(const Vec3f &_pos)
set position of the coordsys
int priority
Priority to allow sorting of objects.
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
const GLMatrixd & modelview() const
get modelview matrix
void perspective(double _fovY, double _aspect, double _near_plane, double _far_plane)
perspective projection
void push_projection_matrix()
push projection matrix
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
PickTarget
What target to use for picking.
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
add renderobjects for shader pipeline renderer
Interface class between scenegraph and renderer.
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
const Vec4f & base_color() const
get base color (used when lighting is off)
double aspect() const
get aspect ratio
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
bool overlay
Layer based rendering.
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
CoordsysMode getMode() const
get current mode
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
ShaderGenDesc shaderDesc
Drawmode and other shader params.