56#include "GlutPrimitiveNode.hh"
58#include <ACG/GL/IRenderer.hh>
69GlutPrimitiveNode::GlutPrimitiveNode(
BaseNode* _parent,
70 const std::string & _name )
74 const int slices = 20;
75 const int stacks = 20;
78 cone_ =
new ACG::GLCone(slices, stacks, 1.0, 0,
true,
false);
83GlutPrimitiveNode::GlutPrimitiveNode(GlutPrimitiveType _type,
85 const std::string & _name) :
89 const int slices = 20;
90 const int stacks = 20;
94 primitives_.push_back(p);
97 cone_ =
new ACG::GLCone(slices, stacks, 1.0, 0,
true,
false);
102set_position(
const Vec3d& _p,
int _idx)
104 if (_idx > -1 && _idx < (
int)primitives_.size())
105 primitives_[_idx].position = _p;
112get_position(
int _idx)
const
114 if (_idx > -1 && _idx < (
int)primitives_.size())
115 return primitives_[_idx].position;
117 return Vec3d(-1,-1,-1);
124set_size(
double _s,
int _idx)
126 if (_idx > -1 && _idx < (
int)primitives_.size())
127 primitives_[_idx].size = _s;
134get_size(
int _idx)
const
136 if (_idx > -1 && _idx < (
int)primitives_.size())
137 return primitives_[_idx].size;
147 for (
int i = 0; i < (int)primitives_.size(); ++i)
149 Vec3d sizeVec(primitives_[i].size, primitives_[i].size, primitives_[i].size);
150 _bbMax.
maximize(primitives_[i].position + sizeVec);
151 _bbMin.
minimize(primitives_[i].position - sizeVec);
159availableDrawModes()
const
161 return ( DrawModes::POINTS |
162 DrawModes::WIREFRAME |
163 DrawModes::HIDDENLINE |
164 DrawModes::SOLID_FLAT_SHADED |
165 DrawModes::SOLID_SMOOTH_SHADED |
166 DrawModes::SOLID_FACES_COLORED );
175 Vec4f backupColorDiffuse;
176 Vec4f backupColorAmbient;
181 for (
size_t i = 0; i < primitives_.size(); ++i)
184 _state.
translate(primitives_[i].position[0], primitives_[i].position[1], primitives_[i].position[2]);
187 if (_drawMode & DrawModes::POINTS)
193 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
195 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
199 if (_drawMode & DrawModes::WIREFRAME)
203 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
206 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
209 if (_drawMode & DrawModes::SOLID_FACES_COLORED)
213 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
223 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
226 if (_drawMode & DrawModes::HIDDENLINE)
233 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
238 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
246 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
250 if (_drawMode & DrawModes::SOLID_FLAT_SHADED)
266 if (_drawMode & DrawModes::SOLID_SMOOTH_SHADED)
300 primitives_.push_back(p);
301 return primitives_.size() - 1;
307GlutPrimitiveNode::draw_obj(
GLState& _state,
size_t _idx)
const
309 if ( _idx >= primitives_.size())
312 Vec3d axis = primitives_[_idx].axis;
313 double size = axis.
norm();
318 Vec3d direction = axis;
324 rot_angle = acos((z_axis | direction)) * 180 / M_PI;
325 rot_normal = ((z_axis % direction).normalize());
328 if (fabs(rot_angle) > 0.0001 && fabs(180 - rot_angle) > 0.0001)
330 _state.
rotate(rot_angle,rot_normal[0], rot_normal[1], rot_normal[2]);
334 _state.
rotate(rot_angle,1,0,0);
337 switch (primitives_[_idx].type)
340 ACG::GLCone(primitives_[_idx].slices, primitives_[_idx].stacks, primitives_[_idx].size, 0.0f,
true,
true).draw(_state, primitives_[_idx].innersize);
344 _state.
scale(primitives_[_idx].size);
361 ACG::GLSphere(primitives_[_idx].slices, primitives_[_idx].stacks).draw(_state,primitives_[_idx].size);
369 ACG::GLTorus(primitives_[_idx].innersize, primitives_[_idx].size, primitives_[_idx].slices, primitives_[_idx].stacks).draw_primitive();
386 std::cerr <<
"Strange pickSetMaximum failed for index " << primitives_.size() <<
" in GlutPrimitiveNode\n";
395 for (
size_t i = 0; i < primitives_.size(); ++i)
399 _state.
translate(primitives_[i].position[0], primitives_[i].position[1], primitives_[i].position[2]);
428 for (
int j = 0; j < (int)primitives_.size(); ++j)
433 _state.
translate(primitives_[j].position);
443 localMaterial.
baseColor(primitives_[j].color * .5f);
446 ro.setMaterial(&localMaterial);
448 for (
size_t i = 0; i < n_layers; ++i)
450 const auto layer = _drawMode.
getLayer(i);
452 switch (layer->lightStage())
454 case DrawModes::LIGHTSTAGE_SMOOTH:
457 case DrawModes::LIGHTSTAGE_PHONG:
460 case DrawModes::LIGHTSTAGE_UNLIT:
465 switch (primitives_[i].type)
470 ro.debugName = std::string(
"glutprimitive.sphere no ") + std::to_string(i) +
": " + name();
472 sphere_->addToRenderer(_renderer, &ro, primitives_[i].size);
477 ro.debugName = std::string(
"glutprimitive.cone no ") + std::to_string(i) +
": " + name();
478 cone_->addToRenderer(_renderer, &ro, primitives_[i].innersize);
483 std::cerr <<
"Sorry, but the glut renderer objects are not available for this renderer yet!" << std::endl;
void set_ambient_color(const Vec4f &_col)
set ambient color
void pop_modelview_matrix()
pop modelview matrix
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
const GLMatrixd & modelview() const
get modelview matrix
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)
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
void scale(double _s)
scale by (_s, _s, _s)
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
void set_color(const Vec4f &_col)
set color
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
const Vec4f & ambient_color() const
get ambient color
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
const Vec4f & clear_color() const
get background color
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
const Vec4f & diffuse_color() const
get diffuse color
void push_modelview_matrix()
push modelview matrix
void set_diffuse_color(const Vec4f &_col)
set diffuse color
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
size_t getNumLayers() const
returns the layer count
GlutPrimitiveType
Lists all available primivites.
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) )
void diffuseColor(const Vec4f &_d)
set the diffuse color.
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM > >().norm())
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM > >().sqrnorm()))
compute euclidean norm
PickTarget
What target to use for picking.
@ PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
@ PICK_FACE
picks faces (should be implemented for all nodes)
Namespace providing different geometric functions concerning angles.
Interface class between scenegraph and renderer.
ShaderGenDesc shaderDesc
Drawmode and other shader params.
int priority
Priority to allow sorting of objects.
GLMatrixd modelview
Modelview transform.
void initFromState(GLState *_glState)
Initializes a RenderObject instance.