55 #include "CoordsysNode.hh" 56 #include <ACG/GL/IRenderer.hh> 57 #include <ACG/GL/ShaderCache.hh> 71 projectionMode_(_projectionMode)
73 const double bodyRadius = 0.004;
74 const double topRadius = 0.01;
75 const int slices = 10;
76 const int stacks = 10;
79 cylinder_ =
new ACG::GLCylinder(slices, stacks, bodyRadius,
false,
false);
80 cone_ =
new ACG::GLCone(slices, stacks, 0, topRadius ,
false,
true);
81 disk_ =
new ACG::GLDisk(slices, 10, 0.0f, bodyRadius);
123 drawCoordsys(
GLState& _state) {
125 const double arrowLength = 0.03;
126 const double bodyLength = 0.06;
127 const double sphereRadius = 0.01;
133 glColor4f(0.5, 0.5, 0.5 , 1.0);
134 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (matCol * 0.5f).data());
135 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matCol.
data());
136 sphere_->draw(_state,sphereRadius);
139 glColor4f(1.0, 0.0, 0.0, 1.0);
140 matCol[0] = 1.0f; matCol[1] = 0.0f; matCol[2] = 0.0f;
141 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (matCol * 0.5f).data());
142 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matCol.
data());
144 _state.
rotate (-90, 0, 1, 0);
146 cylinder_->draw(_state,bodyLength);
148 cone_->draw(_state,arrowLength);
152 glColor4f(0.0, 1.0, 0.0, 1.0);
153 matCol[0] = 0.0f; matCol[1] = 1.0f; matCol[2] = 0.0f;
154 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (matCol * 0.2f).data());
155 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matCol.
data());
157 _state.
rotate (90, 1, 0, 0);
159 cylinder_->draw(_state,bodyLength);
161 cone_->draw(_state,arrowLength);
165 glColor4f(0.0, 0.0, 1.0, 1.0);
166 matCol[0] = 0.0f; matCol[1] = 0.0f; matCol[2] = 1.0f;
167 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (matCol * 0.5f).data());
168 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matCol.
data());
170 _state.
rotate (180, 0, 1, 0);
172 cylinder_->draw(_state,bodyLength);
174 cone_->draw(_state,arrowLength);
185 const double arrowLength = 0.03;
186 const double bodyLength = 0.06;
187 const double sphereRadius = 0.01;
191 _baseRO->debugName =
"coordsys.sphere";
192 _baseRO->emissive =
Vec3f(0.4f, 0.4f, 0.4f);
194 _baseRO->specular =
Vec3f(0.2f, 0.2f, 0.2f);
195 _baseRO->ambient =
Vec3f(0.1f, 0.1f, 0.1f);
196 sphere_->addToRenderer(_renderer, _baseRO, sphereRadius);
200 _baseRO->debugName =
"coordsys.x.axis";
201 _baseRO->emissive =
Vec3f(0.5f, 0.0f, 0.0f);
203 _baseRO->specular =
Vec3f(0.1f, 0.0f, 0.0f);
204 _baseRO->ambient =
Vec3f(0.1f, 0.0f, 0.0f);
208 cylinder_->addToRenderer(_renderer, _baseRO, bodyLength);
210 _baseRO->debugName =
"coordsys.x.head";
212 cone_->addToRenderer(_renderer, _baseRO, arrowLength);
216 _baseRO->debugName =
"coordsys.y.axis";
217 _baseRO->emissive =
Vec3f(0.0f, 0.5f, 0.0f);
219 _baseRO->specular =
Vec3f(0.0f, 0.1f, 0.0f);
220 _baseRO->ambient =
Vec3f(0.0f, 0.1f, 0.0f);
224 cylinder_->addToRenderer(_renderer, _baseRO, bodyLength);
226 _baseRO->debugName =
"coordsys.y.head";
228 cone_->addToRenderer(_renderer, _baseRO, arrowLength);
232 _baseRO->debugName =
"coordsys.z.axis";
233 _baseRO->emissive =
Vec3f(0.0f, 0.0f, 0.5f);
235 _baseRO->specular =
Vec3f(0.0f, 0.0f, 0.1f);
236 _baseRO->ambient =
Vec3f(0.0f, 0.0f, 0.1f);
240 cylinder_->addToRenderer(_renderer, _baseRO, bodyLength);
242 _baseRO->debugName =
"coordsys.z.head";
244 cone_->addToRenderer(_renderer, _baseRO, arrowLength);
252 const double arrowLength = 0.03;
253 const double bodyLength = 0.06;
254 const double sphereRadius = 0.01;
262 mWVP.
scale(sphereRadius, sphereRadius, sphereRadius);
264 sphere_->draw_primitive(_pickShader);
269 sphere_->draw(_state,sphereRadius);
278 _state.
rotate (-90, 0, 1, 0);
281 _state.
scale(1.0, 1.0, bodyLength);
287 cylinder_->draw_primitive(_pickShader);
290 cylinder_->draw_primitive();
293 _state.
scale(1.0, 1.0, arrowLength);
299 cone_->draw_primitive(_pickShader);
302 cone_->draw_primitive();
312 _state.
rotate (90, 1, 0, 0);
315 _state.
scale(1.0, 1.0, bodyLength);
321 cylinder_->draw_primitive(_pickShader);
324 cylinder_->draw_primitive();
327 _state.
scale(1.0, 1.0, arrowLength);
333 cone_->draw_primitive(_pickShader);
336 cone_->draw_primitive();
345 _state.
rotate (180, 0, 1, 0);
348 _state.
scale(1.0, 1.0, bodyLength);
354 cylinder_->draw_primitive(_pickShader);
357 cylinder_->draw_primitive();
360 _state.
scale(1.0, 1.0, arrowLength);
366 cone_->draw_primitive(_pickShader);
369 cone_->draw_primitive();
384 GLboolean colorMask[4];
385 glGetBooleanv (GL_COLOR_WRITEMASK, colorMask);
392 glPushAttrib( GL_LIGHTING_BIT );
394 glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
398 GLfloat zeroVec[4] = {0.0f};
399 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zeroVec);
400 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, zeroVec);
403 Vec3d pos3D(0.0,0.0,0.0);
407 int left, bottom, width, height;
408 double aspect = _state.
aspect();
419 _state.
ortho(-0.65*aspect, 0.65*aspect, -0.65, 0.65, 0.8, 20.0);
424 float rel_size = 50.0;
425 float projdist = sqrt ( (width*height) / rel_size );
427 float posx = left + width - projdist ;
428 float posy = bottom + height - projdist ;
438 modelview(0,3) = 0.0;
439 modelview(1,3) = 0.0;
440 modelview(2,3) = 0.0;
443 _state.
translate (pos3D[0], pos3D[1], pos3D[2], MULT_FROM_LEFT);
450 drawCoordsys(_state);
456 drawCoordsys(_state);
461 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
464 drawCoordsys(_state);
468 glColorMask (colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
478 modelview(0,3) = 0.0;
479 modelview(1,3) = 0.0;
480 modelview(2,3) = 0.0;
489 drawCoordsys(_state);
496 drawCoordsys(_state);
501 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
504 drawCoordsys(_state);
509 glColorMask (colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
514 glColor4fv(lastBaseColor.
data());
528 Vec3d pos3D(0.0,0.0,0.0);
536 ro.setMaterial(_mat);
540 ro.depthWrite =
true;
546 int left, bottom, width, height;
547 double aspect = _state.
aspect();
558 _state.
ortho(-0.65*aspect, 0.65*aspect, -0.65, 0.65, 0.8, 20.0);
563 float rel_size = 50.0;
564 float projdist = sqrt ( (width*height) / rel_size );
566 float posx = left + width - projdist ;
567 float posy = bottom + height - projdist ;
577 modelview(0,3) = 0.0;
578 modelview(1,3) = 0.0;
579 modelview(2,3) = 0.0;
582 _state.
translate (pos3D[0], pos3D[1], pos3D[2], MULT_FROM_LEFT);
604 drawCoordsys(_renderer, &ro);
614 modelview(0,3) = 0.0;
615 modelview(1,3) = 0.0;
616 modelview(2,3) = 0.0;
625 drawCoordsys(_renderer, &ro);
632 drawCoordsys(_renderer, &ro);
637 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
640 drawCoordsys(_renderer, &ro);
660 projectionMode_ = _mode;
681 return projectionMode_;
688 const bool fixedFunctionGL = _state.compatibilityProfile();
692 if (!fixedFunctionGL)
695 desc.fragmentTemplateFile =
"Picking/single_color_fs.glsl";
696 desc.vertexTemplateFile =
"Picking/vertex.glsl";
716 Vec3d pos3D(0.0,0.0,0.0);
720 int left, bottom, width, height;
721 double aspect = _state.
aspect();
732 _state.
ortho(-0.65*aspect, 0.65*aspect, -0.65, 0.65, 0.8, 20.0);
737 float rel_size = 50.0;
738 float projdist = sqrt ( (width*height) / rel_size );
740 float posx = left + width - projdist ;
741 float posy = bottom + height - projdist ;
750 modelview(0,3) = 0.0;
751 modelview(1,3) = 0.0;
752 modelview(2,3) = 0.0;
755 _state.
translate (pos3D[0], pos3D[1], pos3D[2], MULT_FROM_LEFT);
762 clearPickArea(_state,
true, 1.0, pickShader);
765 drawCoordsysPick(_state, pickShader);
768 clearPickArea(_state,
false, 0.0, pickShader);
777 drawCoordsys(_state);
784 drawCoordsys(_state);
789 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
792 drawCoordsys(_state);
797 glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
809 if (_state.compatibilityProfile())
812 glMatrixMode(GL_PROJECTION);
817 glGetDoublev(GL_PROJECTION_MATRIX, mat);
823 glMatrixMode(GL_MODELVIEW);
827 modelview(0,3) = 0.0;
828 modelview(1,3) = 0.0;
829 modelview(2,3) = 0.0;
841 clearPickArea(_state,
true, 1.0, pickShader);
844 drawCoordsysPick(_state, pickShader);
847 clearPickArea(_state,
false, 0.0, pickShader);
856 drawCoordsys(_state);
863 drawCoordsys(_state);
868 glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
871 drawCoordsys(_state);
876 glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
890 void CoordsysNode::clearPickArea(
GLState& _state,
bool _draw, GLfloat _depth,
GLSL::Program* _pickShader)
894 std::vector<Vec2f> points;
898 int left, bottom, width, height;
901 GLboolean colorMask[4];
902 glGetBooleanv (GL_COLOR_WRITEMASK, colorMask);
906 points.push_back (
Vec2f (proj[0], proj[1]));
909 points.push_back (
Vec2f (proj[0], proj[1]));
912 points.push_back (
Vec2f (proj[0], proj[1]));
915 points.push_back (
Vec2f (proj[0], proj[1]));
919 boundingCircle(points, center, radius);
924 _state.
ortho (left, left + width, bottom, bottom + height, 0.0, 1.0);
930 _state.
translate (center[0], center[1], -0.5);
940 glColorMask(
false,
false,
false,
false);
949 disk_->setInnerRadius(0.0f);
950 disk_->setOuterRadius(radius * 1.1f);
951 disk_->draw_primitive(_pickShader);
955 disk_->setInnerRadius(0.0f);
956 disk_->setOuterRadius(radius * 1.1f);
957 disk_->draw_primitive();
968 glColorMask (colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
973 void CoordsysNode::boundingCircle(std::vector<Vec2f> &_in,
Vec2f &_center,
float &_radius)
986 for (
unsigned int i = 0; i < _in.size () - 1; i++)
987 for (
unsigned int j = i + 1; j < _in.size (); j++)
989 Vec2f cen = (_in[i] + _in[j]) * 0.5f;
990 float rad = (_in[i] - cen).length ();
993 for (
unsigned int k = 0; k < _in.size (); k++)
994 if (k != i && k != j && (_in[k] - cen).length () > rad)
1023 for (
unsigned int i = 0; i < _in.size () - 2; i++)
1024 for (
unsigned int j = i + 1; j < _in.size () - 1; j++)
1025 for (
unsigned int k = j + 1; k < _in.size (); k++)
1027 float v = ((_in[k][0]-_in[j][0])*((_in[i][0]*_in[i][0])+(_in[i][1]*_in[i][1]))) +
1028 ((_in[i][0]-_in[k][0])*((_in[j][0]*_in[j][0])+(_in[j][1]*_in[j][1]))) +
1029 ((_in[j][0]-_in[i][0])*((_in[k][0]*_in[k][0])+(_in[k][1]*_in[k][1])));
1030 float u = ((_in[j][1]-_in[k][1])*((_in[i][0]*_in[i][0])+(_in[i][1]*_in[i][1]))) +
1031 ((_in[k][1]-_in[i][1])*((_in[j][0]*_in[j][0])+(_in[j][1]*_in[j][1]))) +
1032 ((_in[i][1]-_in[j][1])*((_in[k][0]*_in[k][0])+(_in[k][1]*_in[k][1])));
1033 float d = (_in[i][0]*_in[j][1])+(_in[j][0]*_in[k][1])+(_in[k][0]*_in[i][1]) -
1034 (_in[i][0]*_in[k][1])-(_in[j][0]*_in[i][1])-(_in[k][0]*_in[j][1]);
1035 Vec2f cen(0.5 * (u/d), 0.5 * (v/d));
1036 float rad = (_in[i] - cen).length ();
1039 for (
unsigned int l = 0; l < _in.size (); l++)
1040 if (l != i && l != j && l != k && (_in[l] - cen).length () > rad)
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
Namespace providing different geometric functions concerning angles.
void clearTextures()
disables texture support and removes all texture types
GLMatrixd proj
Projection transform.
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
bool inZPrePass
Specify whether this object should be rendered in a z-prepass.
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
bool color_picking() const
Is color picking active?
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw Coordsys
pick any of the prior targets (should be implemented for all nodes)
void setProjectionMode(const ProjectionMode _mode)
set mode to either ORTHOGRAPHIC_PROJECTION or PERSPECTIVE_PROJECTION
CoordsysMode getMode() const
get current mode
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
void push_modelview_matrix()
push modelview matrix
VectorT< float, 3 > Vec3f
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
const GLMatrixd & projection() const
get projection matrix
void reset_modelview()
reset modelview matrix (load identity)
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
GLMatrixd modelview
Modelview transform.
Draws the Coordsys at the coordsys origin.
CoordsysNode(BaseNode *_parent=0, std::string _name="<TextNode>", CoordsysMode _mode=SCREENPOS, ProjectionMode _projectionMode=PERSPECTIVE_PROJECTION)
void disable()
Resets to standard rendering pipeline.
Scalar * data()
access to Scalar array
void push_projection_matrix()
push projection matrix
Vec2f depthRange
glDepthRange: (znear, zmax)
Interface class between scenegraph and renderer.
Vec3f diffuse
material definitions
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
void perspective(double _fovY, double _aspect, double _near_plane, double _far_plane)
perspective projection
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
Draws the Coordsys at the upper right position on the screen.
void ortho(double _left, double _right, double _bottom, double _top, double _near_plane, double _far_plane)
orthographic projection
ProjectionMode getProjectionMode() const
get current projection mode
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
VectorT< float, 2 > Vec2f
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
void setMode(const CoordsysMode _mode)
set mode to either POSITION or SCREENPOS
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void scale(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with scaling matrix (x,y,z)
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
const Vec4f & base_color() const
get base color (used when lighting is off)
void pick(GLState &_state, PickTarget _target)
draw Coordsys for object picking
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
ProjectionMode
projection mode
double aspect() const
get aspect ratio
const Scalar * get_raw_data() const
bool overlay
Layer based rendering.
void reset_projection()
reset projection matrix (load identity)
const GLMatrixd & modelview() const
get modelview matrix
ShaderGenDesc shaderDesc
Drawmode and other shader params.
PickTarget
What target to use for picking.
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 pop_modelview_matrix()
pop modelview matrix
void pop_projection_matrix()
pop projection matrix
void scale(double _s)
scale by (_s, _s, _s)
void set_modelview(const GLMatrixd &_m)
set modelview
~CoordsysNode()
destructor
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
add renderobjects for shader pipeline renderer
const GLMatrixd & inverse_projection() const
get inverse projection matrix
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
void translate(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with translation matrix (x,y,z)
DrawMode POINTS
draw unlighted points using the default base color
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
void setPosition(const Vec3f &_pos)
set position of the coordsys
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const
return available draw modes
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
int priority
Priority to allow sorting of objects.
void use()
Enables the program object for using.