56 #include "GlutPrimitiveNode.hh" 58 #include <ACG/GL/IRenderer.hh> 69 GlutPrimitiveNode::GlutPrimitiveNode(
BaseNode* _parent,
70 const std::string & _name )
74 const int slices = 20;
75 const int stacks = 20;
82 GlutPrimitiveNode::GlutPrimitiveNode(GlutPrimitiveType _type,
84 const std::string & _name) :
88 const int slices = 20;
89 const int stacks = 20;
93 primitives_.push_back(p);
102 if (_idx > -1 && _idx < (
int)primitives_.size())
103 primitives_[_idx].position = _p;
112 if (_idx > -1 && _idx < (
int)primitives_.size())
113 return primitives_[_idx].position;
115 return Vec3d(-1,-1,-1);
124 if (_idx > -1 && _idx < (
int)primitives_.size())
125 primitives_[_idx].size = _s;
134 if (_idx > -1 && _idx < (
int)primitives_.size())
135 return primitives_[_idx].size;
145 for (
int i = 0; i < (int)primitives_.size(); ++i)
147 Vec3d sizeVec(primitives_[i].size, primitives_[i].size, primitives_[i].size);
148 _bbMax.
maximize(primitives_[i].position + sizeVec);
149 _bbMin.
minimize(primitives_[i].position - sizeVec);
173 Vec4f backupColorDiffuse;
174 Vec4f backupColorAmbient;
179 for (
size_t i = 0; i < primitives_.size(); ++i)
182 _state.
translate(primitives_[i].position[0], primitives_[i].position[1], primitives_[i].position[2]);
191 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
193 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
201 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
204 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
211 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
221 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
231 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
236 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
244 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
298 primitives_.push_back(p);
299 return primitives_.size() - 1;
305 GlutPrimitiveNode::draw_obj(
GLState& _state,
size_t _idx)
const 307 if ( _idx >= primitives_.size())
310 Vec3d axis = primitives_[_idx].axis;
311 double size = axis.
norm();
316 Vec3d direction = axis;
322 rot_angle = acos((z_axis | direction)) * 180 / M_PI;
323 rot_normal = ((z_axis % direction).normalize());
326 if (fabs(rot_angle) > 0.0001 && fabs(180 - rot_angle) > 0.0001)
328 _state.
rotate(rot_angle,rot_normal[0], rot_normal[1], rot_normal[2]);
332 _state.
rotate(rot_angle,1,0,0);
335 switch (primitives_[_idx].type)
338 ACG::GLCone(primitives_[_idx].slices, primitives_[_idx].stacks, primitives_[_idx].size, 0.0f,
true,
true).draw(_state, primitives_[_idx].innersize);
342 _state.
scale(primitives_[_idx].size);
359 ACG::GLSphere(primitives_[_idx].slices, primitives_[_idx].stacks).draw(_state,primitives_[_idx].size);
367 ACG::GLTorus(primitives_[_idx].innersize, primitives_[_idx].size, primitives_[_idx].slices, primitives_[_idx].stacks).draw_primitive();
384 std::cerr <<
"Strange pickSetMaximum failed for index " << primitives_.size() <<
" in GlutPrimitiveNode\n";
393 for (
size_t i = 0; i < primitives_.size(); ++i)
397 _state.
translate(primitives_[i].position[0], primitives_[i].position[1], primitives_[i].position[2]);
426 for (
int i = 0; i < (int)primitives_.size(); ++i)
431 _state.
translate(primitives_[i].position);
441 localMaterial.
baseColor(primitives_[i].color * .5f);
444 ro.setMaterial(&localMaterial);
447 switch (primitives_[i].type) {
451 ro.debugName = std::string(
"glutprimitive.sphere no ") + std::to_string(i) +
": " +
name();
453 sphere_->addToRenderer(_renderer, &ro, primitives_[i].size);
459 std::cerr <<
"Sorry, but the glut renderer objects are not available for this renderer yet!" << std::endl;
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
DrawMode WIREFRAME
draw wireframe
Namespace providing different geometric functions concerning angles.
void set_ambient_color(const Vec4f &_col)
set ambient color
pick any of the prior targets (should be implemented for all nodes)
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM >>().sqrnorm()))
compute euclidean norm
void set_diffuse_color(const Vec4f &_col)
set diffuse color
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
drawing the primitive
void push_modelview_matrix()
push modelview matrix
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
std::string name() const
Returns: name of node (needs not be unique)
double get_size(int _idx=0) const
get size
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
Add the objects to the given renderer.
void set_color(const Vec4f &_col)
set color
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.
void set_size(double _s, int _idx=0)
set size
GLMatrixd modelview
Modelview transform.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
const Vec4f & clear_color() const
get background color
void pick(GLState &_state, PickTarget _target)
picking
void diffuseColor(const Vec4f &_d)
set the diffuse color.
Interface class between scenegraph and renderer.
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) ) ...
VectorT< double, 3 > Vec3d
DrawModes::DrawMode availableDrawModes() const
return available draw modes
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
size_t add_primitive(GlutPrimitiveType _type, Vec3d _pos, Vec3d _axis, ACG::Vec4f _color)
const Vec4f & base_color() const
get base color (used when lighting is off)
const Vec3d get_position(int _idx=0) const
get position
const GLMatrixd & modelview() const
get modelview matrix
ShaderGenDesc shaderDesc
Drawmode and other shader params.
PickTarget
What target to use for picking.
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
GlutPrimitiveType
Lists all available primivites.
void pop_modelview_matrix()
pop modelview matrix
void scale(double _s)
scale by (_s, _s, _s)
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
picks faces (should be implemented for all nodes)
void set_position(const Vec3d &_p, int _idx=0)
set position
const Vec4f & diffuse_color() const
get diffuse color
const Vec4f & ambient_color() const
get ambient color
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 pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
int priority
Priority to allow sorting of objects.