void GeometryApp::loadGeomSource( const geom::Source &source )
{
	// The purpose of the TriMesh is to capture a bounding box; without that need we could just instantiate the Batch directly using primitive
	TriMesh::Format fmt = TriMesh::Format().positions().normals().texCoords();
	if( mShowColors && source.getAvailableAttribs().count( geom::COLOR ) > 0 )
		fmt.colors();

	TriMesh mesh( source, fmt );
	AxisAlignedBox3f bbox = mesh.calcBoundingBox();
	mCameraCOI = mesh.calcBoundingBox().getCenter();
	mRecenterCamera = true;

	if( mSubdivision > 1 )
		mesh.subdivide( mSubdivision );

	if( mPhongShader )
		mPrimitive = gl::Batch::create( mesh, mPhongShader );

	if( mWireframeShader )
		mPrimitiveWireframe = gl::Batch::create( mesh, mWireframeShader );

	vec3 size = bbox.getMax() - bbox.getMin();
	float scale = std::max( std::max( size.x, size.y ), size.z ) / 25.0f;
	mPrimitiveNormalLines = gl::Batch::create( geom::VertexNormalLines( mesh, scale ), gl::getStockShader( gl::ShaderDef().color() ) );

	getWindow()->setTitle( "Geometry - " + to_string( mesh.getNumVertices() ) + " vertices" );
}
Exemple #2
0
void ColorCubePoints::draw()
{
    // Unit cube with wireframe outline
    gl::enableAlphaBlending();
    gl::color(0.0f, 0.0f, 0.0f, 0.5f);
    gl::drawCube(Vec3f(0.5f, 0.5f, 0.5f), Vec3f(1.0f, 1.0f, 1.0f));
    gl::color(0.4f, 0.4f, 0.7f);
    gl::drawStrokedCube(Vec3f(0.5f, 0.5f, 0.5f), Vec3f(1.0f, 1.0f, 1.0f));

    // Scaled RGB color coordinate system    
    AxisAlignedBox3f range = getRangeRGB();
    gl::pushModelView();
    gl::scale(Vec3f(1.0f, 1.0f, 1.0f) / range.getSize());
    gl::translate(-range.getMin());

    // Point history
    gl::enableAdditiveBlending();
    glPointSize(3.0f);
    glBegin(GL_POINTS);
    for (unsigned i = 0; i < mPoints.size(); i++) {
        drawColorPoint(range, mPoints[i]);
    }
    glEnd();

    // Local coordinates for latest point
    Vec4f local = mLineSolver.worldToLocal * Vec4f(getCurrentPoint(), 1.0f);

    // Local coordinates for arbitrary endpoints on the Z axis
    Vec4f zMin(0.0f, 0.0f, range.getMin().z, 1.0f);
    Vec4f zMax(0.0f, 0.0f, range.getMax().z, 1.0f);

    // Convert to world coords and clamp to the AABB to keep the chart tidy
    Ray ray((mLineSolver.localToWorld * zMin).xyz(),
            (mLineSolver.localToWorld * (zMax - zMin)).xyz());
    float intersections[2];
    range.intersect(ray, intersections);

    // Draw a triangle between the Z axis and current point
    gl::color(1.0f, 1.0f, 1.0f);
    gl::drawLine(ray.calcPosition(intersections[0]),
                 ray.calcPosition(intersections[1]));
    gl::color(1.0f, 0.0f, 0.0f);
    gl::drawLine(ray.calcPosition(intersections[0]),
                 (mLineSolver.localToWorld * local).xyz());
    gl::color(0.0f, 1.0f, 0.0f);
    gl::drawLine(ray.calcPosition(intersections[1]),
                 (mLineSolver.localToWorld * local).xyz());

    gl::popModelView();
}
Exemple #3
0
void AxisAlignedBox3f::include( const AxisAlignedBox3f &rhs )
{
	Vec3f minB = rhs.getMin();
	if(minB.x < mExtents[0].x) mExtents[0].x = minB.x;
	if(minB.y < mExtents[0].y) mExtents[0].y = minB.y;
	if(minB.z < mExtents[0].z) mExtents[0].z = minB.z;

	Vec3f maxB = rhs.getMax();
	if(maxB.x > mExtents[1].x) mExtents[1].x = maxB.x;
	if(maxB.y > mExtents[1].y) mExtents[1].y = maxB.y;
	if(maxB.z > mExtents[1].z) mExtents[1].z = maxB.z;

	// update vertices
	Vec3f extent( mExtents[1].x - mExtents[0].x, mExtents[1].y - mExtents[0].y, mExtents[1].z - mExtents[0].z );
	Vec3f mid( ( mExtents[0].x + mExtents[1].x ) / 2.0f, ( mExtents[0].y + mExtents[1].y ) / 2.0f, ( mExtents[0].z + mExtents[1].z ) / 2.0f );
	mVerts[0] = Vec3f( -0.5f, -0.5f, 0.5f ) * extent +  mid;
	mVerts[1] = Vec3f( 0.5f, -0.5f, 0.5f ) * extent + mid;
	mVerts[2] = Vec3f( -0.5f, 0.5f, 0.5f ) * extent + mid;
	mVerts[3] = Vec3f( 0.5f, 0.5f, 0.5f ) * extent + mid;
	mVerts[4] = Vec3f( -0.5f, 0.5f, -0.5f ) * extent + mid;
	mVerts[5] = Vec3f( 0.5f, 0.5f, -0.5f ) * extent + mid;
	mVerts[6] = Vec3f( -0.5f, -0.5f, -0.5f ) * extent + mid;
	mVerts[7] = Vec3f( 0.5f, -0.5f, -0.5f ) * extent + mid;
}