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;
78 cone_ =
new ACG::GLCone(slices, stacks, 1.0, 0,
true,
false);
83 GlutPrimitiveNode::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);
104 if (_idx > -1 && _idx < (
int)primitives_.size())
105 primitives_[_idx].position = _p;
114 if (_idx > -1 && _idx < (
int)primitives_.size())
115 return primitives_[_idx].position;
117 return Vec3d(-1,-1,-1);
126 if (_idx > -1 && _idx < (
int)primitives_.size())
127 primitives_[_idx].size = _s;
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);
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]);
193 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
195 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
203 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
206 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
213 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
223 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
233 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
238 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
246 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
300 primitives_.push_back(p);
301 return primitives_.size() - 1;
307 GlutPrimitiveNode::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 i = 0; i < (int)primitives_.size(); ++i)
433 _state.
translate(primitives_[i].position);
443 localMaterial.
baseColor(primitives_[i].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())
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 initFromState(GLState *_glState)
Initializes a RenderObject instance.
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode) override
drawing the primitive
void pop_modelview_matrix()
pop modelview matrix
const Vec3d get_position(int _idx=0) const
get position
void set_diffuse_color(const Vec4f &_col)
set diffuse color
picks faces (should be implemented for all nodes)
Namespace providing different geometric functions concerning angles.
size_t add_primitive(GlutPrimitiveType _type, Vec3d _pos, Vec3d _axis, ACG::Vec4f _color)
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) ) ...
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
const Vec4f & base_color() const
get base color (used when lighting is off)
ShaderGenDesc shaderDesc
Drawmode and other shader params.
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
void scale(double _s)
scale by (_s, _s, _s)
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
const Vec4f & diffuse_color() const
get diffuse color
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
PickTarget
What target to use for picking.
void set_position(const Vec3d &_p, int _idx=0)
set position
void push_modelview_matrix()
push modelview matrix
void diffuseColor(const Vec4f &_d)
set the diffuse color.
pick any of the prior targets (should be implemented for all nodes)
void set_ambient_color(const Vec4f &_col)
set ambient color
GlutPrimitiveType
Lists all available primivites.
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
DrawModes::DrawMode availableDrawModes() const override
return available draw modes
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat) override
Add the objects to the given renderer.
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM >>().sqrnorm()))
compute euclidean norm
DrawMode POINTS
draw unlighted points using the default base 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
void set_color(const Vec4f &_col)
set color
int priority
Priority to allow sorting of objects.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
DrawMode WIREFRAME
draw wireframe
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
const GLMatrixd & modelview() const
get modelview matrix
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
double get_size(int _idx=0) const
get size
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
std::string name() const
Returns: name of node (needs not be unique)
void set_size(double _s, int _idx=0)
set size
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
Interface class between scenegraph and renderer.
size_t getNumLayers() const
returns the layer count
void pick(GLState &_state, PickTarget _target) override
picking
const Vec4f & clear_color() const
get background color
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
VectorT< double, 3 > Vec3d
const Vec4f & ambient_color() const
get ambient color
GLMatrixd modelview
Modelview transform.