Commit 9b675c0f authored by Martin Schultz's avatar Martin Schultz
Browse files

Merge branch 'master' into feature_QOpenGLWidget

parents c3107993 edf2c337
......@@ -14,7 +14,12 @@ macro (acg_modify_project_dirs)
file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_BINDIR})
endif ()
elseif (APPLE)
set (MAC_OPENFLIPPER_BASEDIR "${OPENFLIPPER_PRODUCT_STRING}.app/Contents/Resources")
if(OPENFLIPPER_PRODUCT_STRING)
set (MAC_OPENFLIPPER_BASEDIR "${OPENFLIPPER_PRODUCT_STRING}.app/Contents/Resources")
else()
message(WARNING "OPENFLIPPER_PRODUCT_STRING is not set, using OpenFlipper as fallback")
set (MAC_OPENFLIPPER_BASEDIR "OpenFlipper.app/Contents/Resources")
endif()
set (ACG_PROJECT_DATADIR "${MAC_OPENFLIPPER_BASEDIR}")
set (ACG_PROJECT_PLUGINDIR "${MAC_OPENFLIPPER_BASEDIR}/Plugins")
set (ACG_PROJECT_LIBDIR "${MAC_OPENFLIPPER_BASEDIR}/../MacOS")
......
......@@ -52,7 +52,6 @@
#include "GLPrimitives.hh"
#include <ACG/GL/IRenderer.hh>
namespace ACG {
//========================================================================
......@@ -612,10 +611,9 @@ ACG::Vec3f GLCone::normalOnCone(int _sliceNumber, int _stackNumber)
double beta = ((2.0 * M_PI) / slices_) * _sliceNumber;
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 +1045,520 @@ 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);
}
}
//------------------------------------------------------------------------
GLTorus::GLTorus(GLdouble innerRadius,
GLdouble outerRadius,
GLint nsides, GLint rings):
rings_(rings),
nsides_(nsides),
innerRadius_(innerRadius),
outerRadius_(outerRadius)
{
updateVBO();
}
GLTorus::~GLTorus()
{
}
//------------------------------------------------------------------------
int GLTorus::getNumTriangles()
{
return rings_*nsides_*2;
}
//------------------------------------------------------------------------
void GLTorus::updateVBO()
{
// build the Torus in two steps.
// First build a unit Ring in XZ plane.
// Then copy and rotate the ring around z axis to form a torus.
//
// create faces and normals + texcoordinates.
// Inner seam is top/bottom of texture
std::vector<Vec3f> points;
std::vector<Vec3f> normals;
std::vector<Vec2f> texCoords;
std::vector<Vec3f> unitRing;
float ringSegmentAngle = 2 * M_PI / nsides_;
float torusSegmentAngle = 2 * M_PI / rings_;
// generate a unit ring with n sides
for (int i = 0 ; i < nsides_ ; ++i)
{
Vec3f ringPoint = Vec3f(cos(ringSegmentAngle * i),0.0f,sin(ringSegmentAngle *i));
unitRing.push_back(ringPoint);
////cosCache[i] = cos(angle);
}
for(int j = 0; j < rings_ ; ++j)
{
Vec3f torusPoint;
int side = 0;
for(Vec3f point : unitRing)
{
//scale the unit Ring
torusPoint = point * (1.f/innerRadius_);
//translate the unit Ring
torusPoint +=Vec3f(outerRadius_ + innerRadius_,0,0);
//rotate the translated ring around the z axis
Vec3f pointOnTorus = Vec3f(torusPoint[0] * cos(j*torusSegmentAngle) + torusPoint[1] * sin(j*torusSegmentAngle),
torusPoint[0] * -sin(j*torusSegmentAngle) + torusPoint[1] * cos(j*torusSegmentAngle),
torusPoint[2]);
points.push_back(pointOnTorus);
//the normal does not have to be translated or scaled
Vec3f normalOnTorus = Vec3f(point[0] * cos(j*torusSegmentAngle) + point[1] * sin(j*torusSegmentAngle),
point[0] * -sin(j*torusSegmentAngle) + point[1] * cos(j*torusSegmentAngle),
point[2]);
// probably not necessary as we are working with the unit circle
normalOnTorus.normalize();
normals.push_back(normalOnTorus);
// texcoords are a simple uv unwrap of the torus cut open.
// j/rings_ is directly the u component
// the ring segment gives us the v component
texCoords.push_back(Vec2f(j/rings_,side/nsides_));
++side;
}
}
// points are now stored one ring after the other in the points vector.
// creating a triangle is fairly easy adding nsides_ to the current index gives the same point on the next ring.
// create triangles as point on ring -> same point on next ring -> next point on next ring.
int end = rings_*nsides_;
int segmentOffset = nsides_;
int oddIndex = 0;
for(int i = 0 ; i < end ; ++i)
{
if((i+1) % nsides_ == 0)
{
segmentOffset = 0;
oddIndex = -nsides_;
}
else
{
segmentOffset = nsides_;
oddIndex = 0;
}
// first face (lower left triangle)
Vec3f p[3] = { points[i] , points[(i+nsides_)%end] , points[(i+segmentOffset+1)%end] };
Vec3f n[3] = { normals[i] , normals[(i+nsides_)%end] , normals[(i+segmentOffset+1)%end] };
Vec2f t[3] = { texCoords[i] , texCoords[(i+nsides_)%end] , texCoords[(i+segmentOffset+1)%end] };
addTriangleToVBO(p, n, t);
// second face (upper right triangle)
Vec3f p2[3] = { points[(i+1 + oddIndex)%end] , points[(i)%end] , points[(i+segmentOffset+1)%end] };
Vec3f n2[3] = { normals[(i+1 + oddIndex)%end] , normals[(i)%end] , normals[(i+segmentOffset+1)%end] };
Vec2f t2[3] = { texCoords[(i+1 + oddIndex)%end] , texCoords[(i)%end], texCoords[(i+segmentOffset+1)%end] };
addTriangleToVBO(p2, n2, t2);
}
}
//------------------------------------------------------------------------
}
......@@ -295,6 +295,93 @@ private:
//------------------------------------------------------------------------
// axis-aligned Dodecahedron centered at origin
class ACGDLLEXPORT GLDodecahedron: public GLPrimitive {
public:
GLDodecahedron();
~GLDodecahedron();
int getNumTriangles();
private:
void updateVBO();
};