Commit 3e089065 authored by Martin Schultz's avatar Martin Schultz
Browse files

Fixed normal computation of cone primitive

Added some missing primitives that were rendered using glut (behavior
should be similar): Dodecahedron, Icosahedron, Octahedron and Tetrahedon

(except for Torus and Teapot htey are still todo)
parent adb0116d
......@@ -614,8 +614,8 @@ ACG::Vec3f GLCone::normalOnCone(int _sliceNumber, int _stackNumber)
double relativeHeight = _stackNumber / (double) stacks_;
double ringRadius = (1.0 - relativeHeight) * bottomRadius_ + relativeHeight * topRadius_;
normal[0] = sin(beta) * ringRadius;
normal[1] = cos(beta) * ringRadius;
normal[0] = sin(beta);
normal[1] = cos(beta);
normal[2] = (bottomRadius_ - topRadius_);
normal.normalize();
......@@ -1047,4 +1047,406 @@ void GLLineBox::updateVBO()
//------------------------------------------------------------------------
//------------------------------------------------------------------------
GLDodecahedron::GLDodecahedron()
{
updateVBO();
}
GLDodecahedron::~GLDodecahedron()
{
}
//------------------------------------------------------------------------
int GLDodecahedron::getNumTriangles()
{
return 36;
}
//------------------------------------------------------------------------
void GLDodecahedron::updateVBO()
{
static const Vec3f pos[20] =
{Vec3f( 1 , 1 , 1 ),
Vec3f( 1 , 1 , -1 ),
Vec3f( 1 , -1 , 1 ),
Vec3f( 1 , -1 , -1 ),
Vec3f( -1 , 1 , 1 ),
Vec3f( -1 , 1 , -1 ),
Vec3f( -1 , -1 , 1 ),
Vec3f( -1 , -1 , -1 ),
Vec3f( 0 , 0.618034 , 1.61803 ),
Vec3f( 0 , 0.618034 , -1.61803 ),
Vec3f( 0 , -0.618034 , 1.61803 ),
Vec3f( 0 , -0.618034 , -1.61803 ),
Vec3f( 0.618034 , 1.61803 , 0 ),
Vec3f( 0.618034 , -1.61803 , 0 ),
Vec3f( -0.618034 , 1.61803 , 0 ),
Vec3f( -0.618034 , -1.61803 , 0 ),
Vec3f( 1.61803 , 0 , 0.618034 ),
Vec3f( 1.61803 , 0 , -0.618034 ),
Vec3f( -1.61803 , 0 , 0.618034 ),
Vec3f( -1.61803 , 0 , -0.618034 )
};
static const Vec3f norm[20] =
{
Vec3f( 0.57735 , 0.57735 , 0.57735 ),
Vec3f( 0.57735 , 0.57735 , -0.57735 ),
Vec3f( 0.57735 , -0.57735 , 0.57735 ),
Vec3f( 0.57735 , -0.57735 , -0.57735 ),
Vec3f( -0.57735 , 0.57735 , 0.57735 ),
Vec3f( -0.57735 , 0.57735 , -0.57735 ),
Vec3f( -0.57735 , -0.57735 , 0.57735 ),
Vec3f( -0.57735 , -0.57735 , -0.57735 ),
Vec3f( 0 , 0.356822 , 0.934172 ),
Vec3f( 0 , 0.356822 , -0.934172 ),
Vec3f( 0 , -0.356822 , 0.934172 ),
Vec3f( 0 , -0.356822 , -0.934172 ),
Vec3f( 0.356822 , 0.934172 , 0 ),
Vec3f( 0.356822 , -0.934172 , 0 ),
Vec3f( -0.356822 , 0.934172 , 0 ),
Vec3f( -0.356822 , -0.934172 , 0 ),
Vec3f( 0.934172 , 0 , 0.356822 ),
Vec3f( 0.934172 , 0 , -0.356822 ),
Vec3f( -0.934172 , 0 , 0.356822 ),
Vec3f( -0.934172 , 0 , -0.356822 )
};
static const Vec2f texc[20] =
{
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1),
Vec2f( 1, 1)
};
// not the usual p,p,p ,n,n,n ,t,t,t
// i extracted those from an obj file so its:
// tri: p,t,n ,p,t,n ,p,t,n
static const int tris[36][9] =
{
{ 20,20,20, 19,19,19, 5,5,5 },
{ 12,12,12, 8,8,8, 20,20,20 },
{ 14,14,14, 3,3,3, 11,11,11 },
{ 17,17,17, 18,18,18, 2,2,2 },
{ 11,11,11, 3,3,3, 17,17,17 },
{ 14,14,14, 4,4,4, 18,18,18 },
{ 16,16,16, 8,8,8, 12,12,12 },
{ 7,7,7, 19,19,19, 20,20,20 },
{ 7,7,7, 11,11,11, 9,9,9 },
{ 1,1,1, 13,13,13, 15,15,15 },
{ 2,2,2, 10,10,10, 6,6,6 },
{ 18,18,18, 4,4,4, 12,12,12 },
{ 15,15,15, 6,6,6, 5,5,5 },
{ 6,6,6, 20,20,20, 5,5,5 },
{ 6,6,6, 10,10,10, 20,20,20 },
{ 10,10,10, 12,12,12, 20,20,20 },
{ 7,7,7, 16,16,16, 11,11,11 },
{ 16,16,16, 14,14,14, 11,11,11 },
{ 13,13,13, 1,1,1, 2,2,2 },
{ 1,1,1, 17,17,17, 2,2,2 },
{ 1,1,1, 9,9,9, 17,17,17 },
{ 9,9,9, 11,11,11, 17,17,17 },
{ 17,17,17, 3,3,3, 18,18,18 },
{ 3,3,3, 14,14,14, 18,18,18 },
{ 4,4,4, 14,14,14, 12,12,12 },
{ 14,14,14, 16,16,16, 12,12,12 },
{ 8,8,8, 16,16,16, 20,20,20 },
{ 16,16,16, 7,7,7, 20,20,20 },
{ 5,5,5, 19,19,19, 9,9,9 },
{ 19,19,19, 7,7,7, 9,9,9 },
{ 5,5,5, 9,9,9, 15,15,15 },
{ 9,9,9, 1,1,1, 15,15,15 },
{ 15,15,15, 13,13,13, 6,6,6 },
{ 13,13,13, 2,2,2, 6,6,6 },
{ 10,10,10, 2,2,2, 12,12,12 },
{ 2,2,2, 18,18,18, 12,12,12 }
};
//-1 since the objindices start at 1
for (int i = 0; i < 36; ++i)
{
Vec3f p[3] = { pos[tris[i][0]-1], pos[tris[i][3]-1], pos[tris[i][6]-1]};
Vec3f n[3] = { norm[tris[i][2]-1], norm[tris[i][5]-1], norm[tris[i][8]-1]};
Vec2f t[3] = { texc[tris[i][1]-1], texc[tris[i][4]-1], texc[tris[i][7]-1]};
addTriangleToVBO(p, n, t);
}
}
//------------------------------------------------------------------------
GLIcosahedron::GLIcosahedron()
{
updateVBO();
}
GLIcosahedron::~GLIcosahedron()
{
}
//------------------------------------------------------------------------
int GLIcosahedron::getNumTriangles()
{
return 20;
}
//------------------------------------------------------------------------
void GLIcosahedron::updateVBO()
{
static const Vec3f pos[12] =
{
Vec3f( 0 , -1 , -1.61803),
Vec3f( 0 , 1 , -1.61803),
Vec3f( 0 , 1 , 1.61803 ),
Vec3f( 0 , -1 , 1.61803 ),
Vec3f( -1 , -1.61803, 0 ),
Vec3f( 1 , -1.61803, 0 ),
Vec3f( 1 , 1.61803 , 0 ),
Vec3f( -1 , 1.61803 , 0 ),
Vec3f( -1.61803 , 0 , -1 ),
Vec3f( -1.61803 , 0 , 1 ),
Vec3f( 1.61803 , 0 , 1 ),
Vec3f( 1.61803 , 0 , -1 )
};
static const Vec3f norm[12] =
{
Vec3f( 0 , -0.525731 , -0.850651 ),
Vec3f( 2.79423e-17, 0.525731 , -0.850651 ),
Vec3f( 0 , 0.525731 , 0.850651 ),
Vec3f( 2.79423e-17, -0.525731 , 0.850651 ),
Vec3f( -0.525731 , -0.850651 , 0 ),
Vec3f( 0.525731 , -0.850651 , 2.79423e-17 ),
Vec3f( 0.525731 , 0.850651 , 0 ),
Vec3f( -0.525731 , 0.850651 , 0 ),
Vec3f( -0.850651 , 2.79423e-17, 0.525731 ),
Vec3f( 0.850651 , 0 , 0.525731 ),
Vec3f( -0.850651 , 0 , -0.525731 ),
Vec3f( 0.850651 , 2.79423e-17, -0.525731 )
};
static const Vec2f texc[12] =
{
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0)
};
// not the usual p,p,p ,n,n,n ,t,t,t
// i extracted those from an obj file so its:
// tri: p,t,n ,p,t,n ,p,t,n
static const int tris[20][9] =
{
{ 3,3,3, 7,7,7, 8,8,8, },
{ 8,8,8, 7,7,7, 2,2,2, },
{ 12,12,12, 1,1,1, 2,2,2, },
{ 1,1,1, 9,9,9, 2,2,2, },
{ 5,5,5, 10,10,10, 9,9,9, },
{ 9,9,9, 10,10,10, 8,8,8, },
{ 10,10,10, 4,4,4, 3,3,3, },
{ 11,11,1,3,3,3, 4,4,4, },
{ 6,6,6, 12,12,12, 11,11,1, },
{ 12,12,12, 7,7,7, 11,11,1, },
{ 1,1,1, 6,6,6, 5,5,5, },
{ 6,6,6, 4,4,4, 5,5,5, },
{ 7,7,7, 3,3,3, 11,11,1, },
{ 7,7,7, 12,12,12, 2,2,2, },
{ 2,2,2, 9,9,9, 8,8,8, },
{ 10,10,10, 3,3,3, 8,8,8, },
{ 4,4,4, 6,6,6, 11,11,1, },
{ 1,1,1, 12,12,12, 6,6,6, },
{ 4,4,4, 10,10,10, 5,5,5, },
{ 1,1,1, 5,5,5, 9,9,9, }
};
//-1 since the objindices start at 1
for (int i = 0; i < 20; ++i)
{
Vec3f p[3] = { pos[tris[i][0]-1], pos[tris[i][3]-1], pos[tris[i][6]-1]};
Vec3f n[3] = { norm[tris[i][2]-1], norm[tris[i][5]-1], norm[tris[i][8]-1]};
Vec2f t[3] = { texc[tris[i][1]-1], texc[tris[i][4]-1], texc[tris[i][7]-1]};
addTriangleToVBO(p, n, t);
}
}
//------------------------------------------------------------------------
GLOctahedron::GLOctahedron()
{
updateVBO();
}
GLOctahedron::~GLOctahedron()
{
}
//------------------------------------------------------------------------
int GLOctahedron::getNumTriangles()
{
return 8;
}
//------------------------------------------------------------------------
void GLOctahedron::updateVBO()
{
static const Vec3f pos[6] =
{
Vec3f( -1.41421 , 0 , 0 ),
Vec3f( 0 , -1.41421, 0 ),
Vec3f( 1.41421 , 0 , 0 ),
Vec3f( 0 , 1.41421 , 0 ),
Vec3f( 0 , 0 , 1.41421 ),
Vec3f( 0 , 0 , -1.41421)
};
static const Vec3f norm[6] =
{
Vec3f(-1, 0 , 0 ),
Vec3f(0 , -1, 0 ),
Vec3f(1 , 0 , 0 ),
Vec3f(0 , 1 , 0 ),
Vec3f(0 , 0 , 1 ),
Vec3f(0 , 0 , -1)
};
static const Vec2f texc[6] =
{
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0)
};
// not the usual p,p,p ,n,n,n ,t,t,t
// i extracted those from an obj file so its:
// tri: p,t,n ,p,t,n ,p,t,n
static const int tris[8][9] =
{
{ 1,1,1, 2,2,2, 5,5,5 },
{ 2,2,2, 3,3,3, 5,5,5 },
{ 3,3,3, 4,4,4, 5,5,5 },
{ 1,1,1, 5,5,5, 4,4,4 },
{ 6,6,6, 2,2,2, 1,1,1 },
{ 6,6,6, 3,3,3, 2,2,2 },
{ 6,6,6, 4,4,4, 3,3,3 },
{ 6,6,6, 1,1,1, 4,4,4 }
};
//-1 since the objindices start at 1
for (int i = 0; i < 8; ++i)
{
Vec3f p[3] = { pos[tris[i][0]-1], pos[tris[i][3]-1], pos[tris[i][6]-1]};
Vec3f n[3] = { norm[tris[i][2]-1], norm[tris[i][5]-1], norm[tris[i][8]-1]};
Vec2f t[3] = { texc[tris[i][1]-1], texc[tris[i][4]-1], texc[tris[i][7]-1]};
addTriangleToVBO(p, n, t);
}
}
//------------------------------------------------------------------------
GLTetrahedron::GLTetrahedron()
{
updateVBO();
}
GLTetrahedron::~GLTetrahedron()
{
}
//------------------------------------------------------------------------
int GLTetrahedron::getNumTriangles()
{
return 4;
}
//------------------------------------------------------------------------
void GLTetrahedron::updateVBO()
{
static const Vec3f pos[4] =
{
Vec3f( -1, -1, 1 ),
Vec3f( 1 , 1 , 1 ),
Vec3f( -1, 1 , -1 ),
Vec3f( 1 , -1, -1 )
};
static const Vec3f norm[4] =
{
Vec3f( -0.57735, -0.57735, 0.57735 ),
Vec3f( 0.57735 , 0.57735 , 0.57735 ),
Vec3f( -0.57735, 0.57735 , -0.57735 ),
Vec3f( 0.57735 , -0.57735, -0.57735 )
};
static const Vec2f texc[4] =
{
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0),
Vec2f( 0, 0)
};
// not the usual p,p,p ,n,n,n ,t,t,t
// i extracted those from an obj file so its:
// tri: p,t,n ,p,t,n ,p,t,n
static const int tris[4][9] =
{
{ 1, 1, 1, 2, 2, 2, 3, 3, 3 },
{ 1, 1, 1, 3, 3, 3, 4, 4, 4 },
{ 3, 3, 3, 2, 2, 2, 4, 4, 4 },
{ 4, 4, 4, 2, 2, 2, 1, 1, 1 }
};
//-1 since the objindices start at 1
for (int i = 0; i < 4; ++i)
{
Vec3f p[3] = { pos[tris[i][0]-1], pos[tris[i][3]-1], pos[tris[i][6]-1]};
Vec3f n[3] = { norm[tris[i][2]-1], norm[tris[i][5]-1], norm[tris[i][8]-1]};
Vec2f t[3] = { texc[tris[i][1]-1], texc[tris[i][4]-1], texc[tris[i][7]-1]};
addTriangleToVBO(p, n, t);
}
}
//------------------------------------------------------------------------
}
......@@ -295,6 +295,69 @@ private:
//------------------------------------------------------------------------
// axis-aligned Dodecahedron centered at origin
class ACGDLLEXPORT GLDodecahedron: public GLPrimitive {
public:
GLDodecahedron();
~GLDodecahedron();
int getNumTriangles();
private:
void updateVBO();
};
//------------------------------------------------------------------------
// axis-aligned Icosahedron centered at origin
class ACGDLLEXPORT GLIcosahedron: public GLPrimitive {
public:
GLIcosahedron();
~GLIcosahedron();
int getNumTriangles();
private:
void updateVBO();
};
//------------------------------------------------------------------------
// axis-aligned Icosahedron centered at origin
class ACGDLLEXPORT GLOctahedron: public GLPrimitive {
public:
GLOctahedron();
~GLOctahedron();
int getNumTriangles();
private:
void updateVBO();
};
//------------------------------------------------------------------------
// axis-aligned Icosahedron centered at origin
class ACGDLLEXPORT GLTetrahedron: public GLPrimitive {
public:
GLTetrahedron();
~GLTetrahedron();
int getNumTriangles();
private:
void updateVBO();
};
//------------------------------------------------------------------------
} // namespace ACG
......
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