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;
264 sphere_->draw(_state,sphereRadius);
269 _state.
rotate (-90, 0, 1, 0);
271 cylinder_->draw(_state,bodyLength);
273 cone_->draw(_state,arrowLength);
280 _state.
rotate (90, 1, 0, 0);
282 cylinder_->draw(_state,bodyLength);
284 cone_->draw(_state,arrowLength);
290 _state.
rotate (180, 0, 1, 0);
292 cylinder_->draw(_state,bodyLength);
294 cone_->draw(_state,arrowLength);
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.5;
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)
VectorT< float, 2 > Vec2f
Vec3f diffuse
material definitions
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
void setPosition(const Vec3f &_pos)
set position of the coordsys
void clearTextures()
disables texture support and removes all texture types
void push_projection_matrix()
push projection matrix
Draws the Coordsys at the upper right position on the screen.
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
add renderobjects for shader pipeline renderer
void pop_projection_matrix()
pop projection matrix
void setProjectionMode(const ProjectionMode _mode)
set mode to either ORTHOGRAPHIC_PROJECTION or PERSPECTIVE_PROJECTION
void translate(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with translation matrix (x,y,z)
bool overlay
Layer based rendering.
bool color_picking() const
Is color picking active?
ProjectionMode getProjectionMode() const
get current projection mode
void pick(GLState &_state, PickTarget _target)
draw Coordsys for object picking
void push_modelview_matrix()
push modelview matrix
void perspective(double _fovY, double _aspect, double _near_plane, double _far_plane)
perspective projection
int priority
Priority to allow sorting of objects.
Draws the Coordsys at the coordsys origin.
ProjectionMode
projection mode
void ortho(double _left, double _right, double _bottom, double _top, double _near_plane, double _far_plane)
orthographic projection
DrawMode POINTS
draw unlighted points using the default base color
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
PickTarget
What target to use for picking.
double aspect() const
get aspect ratio
GLMatrixd modelview
Modelview transform.
static void enable(GLenum _cap)
replaces glEnable, but supports locking
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
VectorT< float, 3 > Vec3f
const Vec4f & base_color() const
get base color (used when lighting is off)
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw Coordsys
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
bool pick_set_maximum(unsigned int _idx)
Set the maximal number of primitives/components of your object.
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
void set_modelview(const GLMatrixd &_m)
set modelview
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const
return available draw modes
const Scalar * get_raw_data() const
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
Namespace providing different geometric functions concerning angles.
void pop_modelview_matrix()
pop modelview matrix
void pick_set_name(unsigned int _idx)
sets the current name/color (like glLoadName(_idx))
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
void reset_projection()
reset projection matrix (load identity)
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
const GLMatrixd & projection() const
get projection matrix
const GLMatrixd & inverse_projection() const
get inverse projection matrix
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
const GLMatrixd & modelview() const
get modelview matrix
void setMode(const CoordsysMode _mode)
set mode to either POSITION or SCREENPOS
CoordsysNode(BaseNode *_parent=0, std::string _name="<TextNode>", CoordsysMode _mode=SCREENPOS, ProjectionMode _projectionMode=PERSPECTIVE_PROJECTION)
bool inZPrePass
Specify whether this object should be rendered in a z-prepass.
pick any of the prior targets (should be implemented for all nodes)
~CoordsysNode()
destructor
GLMatrixd proj
Projection transform.
Interface class between scenegraph and renderer.
CoordsysMode getMode() const
get current mode
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
ShaderGenDesc shaderDesc
Drawmode and other shader params.
void reset_modelview()
reset modelview matrix (load identity)
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
Scalar * data()
access to Scalar array
Vec2f depthRange
glDepthRange: (znear, zmax)
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active