69 namespace SceneGraph {
79 Vec3f bbMin(FLT_MAX,FLT_MAX,FLT_MAX);
80 Vec3f bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX);
82 for(
unsigned int i=0; i<vertices_.size(); ++i)
84 bbMin.minimize(vertices_[i]);
85 bbMax.maximize(vertices_[i]);
91 _bbMin.minimize(bbMind);
92 _bbMax.maximize(bbMaxd);
123 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
125 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
133 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
135 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
146 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
151 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
156 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
183 OBJNode::draw_obj()
const
185 glBegin(GL_TRIANGLES);
187 for(
unsigned int i=0; i<faces_.size(); ++i)
203 OBJNode::draw_obj_tex()
const
205 glBegin(GL_TRIANGLES);
207 for(
unsigned int i=0; i<faces_.size(); ++i)
210 if (faces_[i].t0 != -1)
268 FILE* in = fopen(_filename.c_str(),
"r");
269 if (!in)
return false;
283 while(!feof(in) && fgets(s, 200, in))
286 if (s[0] ==
'#')
continue;
290 else if (strncmp(s,
"v ", 2) == 0)
292 if (sscanf(s,
"v %30f %30f %30f", &x, &y, &z))
294 vertices_.push_back(
Vec3f(x,y,z));
300 else if (strncmp(s,
"vt ", 3) == 0)
302 if (sscanf(s,
"vt %40f %40f", &u, &v))
303 texCoords_.push_back(
Vec2f(u, v));
308 else if (strncmp(s,
"f ", 2) == 0)
310 std::vector<unsigned int> vIdx, tIdx;
311 int component(0), nV(0);
312 bool endOfVertex(
false);
326 while (*p1 !=
'/' && *p1 !=
'\r' && *p1 !=
'\n' &&
327 *p1 !=
' ' && *p1 !=
'\0')
331 if (*p1 !=
'/') endOfVertex =
true;
341 if (*p1 ==
'\0' || *p1 ==
'\n')
349 case 0: vIdx.push_back(atoi(p0)-1);
break;
350 case 1: tIdx.push_back(atoi(p0)-1);
break;
366 if (vIdx.size() >= 3)
369 if (vIdx.size() == tIdx.size())
371 for (
unsigned int i1=1, i2=2; i2 < vIdx.size(); ++i1, ++i2)
372 faces_.push_back(
Face(vIdx[0], vIdx[i1], vIdx[i2],
373 tIdx[0], tIdx[i1], tIdx[i2]));
379 for (
unsigned int i1=1, i2=2; i2 < vIdx.size(); ++i1, ++i2)
381 faces_.push_back(
Face(vIdx[0], vIdx[i1], vIdx[i2]));
407 normals_.reserve(faces_.size());
409 std::vector<Face>::const_iterator f_it(faces_.begin()), f_end(faces_.end());
410 for (; f_it!=f_end; ++f_it)
415 normals_.push_back(((v1-v0) % (v2-v0)).normalize());
VectorT< float, 2 > Vec2f
Namespace providing different geometric functions concerning angles.
static void enable(GLenum _cap)
replaces glEnable, but supports locking
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
void pick_set_name(unsigned int _idx)
sets the current name/color (like glLoadName(_idx))
PickTarget
What target to use for picking.
const Vec4f & clear_color() const
get background color
static void disable(GLenum _cap)
replaces glDisable, but supports locking
bool pick_set_maximum(unsigned int _idx)
Set the maximal number of primitives/components of your object.
Vec3f & vertex(unsigned int _i)
get i'th vertex
picks faces (should be implemented for all nodes)
pick any of the prior targets (should be implemented for all nodes)
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
VectorT< double, 3 > Vec3d
void glColor(const Vec3f &_v)
Wrapper: glColor for Vec3f.
picks verices (may not be implemented for all nodes)
picks edges (may not be implemented for all nodes)
void glTexCoord(const Vec2f &_t)
Wrapper: glTexCoord for Vec2f.
VectorT< float, 3 > Vec3f
DrawMode POINTS
draw unlighted points using the default base color
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
drawing the primitive
void glNormal(const Vec3f &_n)
Wrapper: glNormal for Vec3f.
DrawMode SOLID_TEXTURED
draw textured faces
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
void update_face_normals()
Update face normals. Call when geometry changes.
DrawMode WIREFRAME
draw wireframe
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
DrawModes::DrawMode availableDrawModes() const
return available draw modes
const Vec4f & base_color() const
get base color (used when lighting is off)
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
void pick(GLState &_state, PickTarget _target)
picking
bool read(const std::string &_filename)
Read from file. Implemented using OpenMesh loader and OBJNodeExporter.