Commit 17f4ff16 authored by Ellen Dekkers's avatar Ellen Dekkers
Browse files

ACG/Scenegraph: GlutPrimitiveNode. rotate each primitve according to its axis

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8911 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4db21a9c
......@@ -111,21 +111,12 @@ void
GlutPrimitiveNode::
boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
{
Vec3d bbMin(FLT_MAX,FLT_MAX,FLT_MAX);
Vec3d bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX);
for (int i = 0; i < (int)primitives_.size(); ++i)
{
Vec3d sizeVec(primitives_[i].size, primitives_[i].size, primitives_[i].size);
bbMax.maximize(primitives_[i].position + sizeVec);
bbMin.minimize(primitives_[i].position - sizeVec);
_bbMax.maximize(primitives_[i].position + sizeVec);
_bbMin.minimize(primitives_[i].position - sizeVec);
}
Vec3d bbMind = ACG::Vec3d(bbMin);
Vec3d bbMaxd = ACG::Vec3d(bbMax);
_bbMin.minimize(bbMind);
_bbMax.maximize(bbMaxd);
}
//----------------------------------------------------------------------------
......@@ -245,45 +236,71 @@ GlutPrimitiveNode::draw_obj(int _idx) const
{
if (_idx < 0 || _idx >= (int)primitives_.size()) // range check
return;
switch (primitives_[_idx].type)
Vec3d axis = primitives_[_idx].axis;
double size = axis.norm();
if (size > 1e-10)
{
case CONE:
glutSolidCone(primitives_[_idx].size, primitives_[_idx].innersize, primitives_[_idx].slices, primitives_[_idx].stacks);
break;
glPushMatrix();
case CUBE:
glutSolidCube(primitives_[_idx].size);
break;
case DODECAHEDRON:
glutSolidDodecahedron();
break;
case ICOSAHEDRON:
glutSolidIcosahedron();
break;
Vec3d direction = axis;
Vec3d z_axis(0,0,1);
Vec3d rot_normal;
double rot_angle;
case OCTAHEDRON:
glutSolidOctahedron();
break;
direction.normalize();
rot_angle = acos((z_axis | direction)) * 180 / M_PI;
rot_normal = ((z_axis % direction).normalize());
case SPHERE:
glutSolidSphere(primitives_[_idx].size, primitives_[_idx].slices, primitives_[_idx].stacks);
break;
case TEAPOT:
glutSolidTeapot(primitives_[_idx].size);
break;
if (fabs(rot_angle) > 0.0001 && fabs(180 - rot_angle) > 0.0001)
glRotatef(rot_angle,rot_normal[0], rot_normal[1], rot_normal[2]);
else
glRotatef(rot_angle,1,0,0);
case TETRAHEDRON:
glutSolidTetrahedron();
break;
switch (primitives_[_idx].type)
{
case CONE:
glutSolidCone(primitives_[_idx].size, primitives_[_idx].innersize, primitives_[_idx].slices, primitives_[_idx].stacks);
break;
case TORUS:
glutSolidTorus(primitives_[_idx].innersize, primitives_[_idx].size, primitives_[_idx].slices, primitives_[_idx].stacks);
break;
};
case CUBE:
glutSolidCube(primitives_[_idx].size);
break;
case DODECAHEDRON:
glutSolidDodecahedron();
break;
case ICOSAHEDRON:
glutSolidIcosahedron();
break;
case OCTAHEDRON:
glutSolidOctahedron();
break;
case SPHERE:
glutSolidSphere(primitives_[_idx].size, primitives_[_idx].slices, primitives_[_idx].stacks);
break;
case TEAPOT:
glutSolidTeapot(primitives_[_idx].size);
break;
case TETRAHEDRON:
glutSolidTetrahedron();
break;
case TORUS:
glutSolidTorus(primitives_[_idx].innersize, primitives_[_idx].size, primitives_[_idx].slices, primitives_[_idx].stacks);
break;
}
glPopMatrix();
}
}
//----------------------------------------------------------------------------
......
......@@ -113,23 +113,26 @@ public:
// Constructor
Primitive()
{
// default axis is negative z
axis = Vec3d(0,0,1);
// set default resolution
size = 1.0;
innersize = 0.5;
innersize = 1.0;
slices = 20;
stacks = 20;
}
Primitive(GlutPrimitiveType _t, Vec3d _p, Vec3d _v, ACG::Vec3uc _c)
Primitive(GlutPrimitiveType _t, Vec3d _p, Vec3d _a, ACG::Vec3uc _c)
{
type = _t;
position = _p;
axis = _v;
axis = _a;
color = _c;
// set default resolution
size = 1.0;
innersize = 0.5;
innersize = 1.0;
slices = 20;
stacks = 20;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment