Beispiel #1
0
void triMeshApp::setup(){
	// cam, lights material
	mCam = new CameraPersp(getWindowWidth(), getWindowHeight(), 45.0f);
	mCam->lookAt( Vec3f(300, 700, -600), Vec3f(0,0,0) );
	mCam->setPerspective( 60.0f, getWindowAspectRatio(), 0.1f, 5000.0f );
	yrot = 0;
	
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_LIGHTING);
	glEnable(GL_NORMALIZE);

	mLight = new gl::Light(gl::Light::DIRECTIONAL, 0);
	mLight->setDirection( Vec3f(0,0.1,0.3).normalized());
	mLight->setAmbient( Color( 0.2f, 0.2f, 0.2f ) );
	mLight->setDiffuse( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->update( *mCam );
	mLight->enable();
	
	mMaterial1.setSpecular( Color(0.5,0.5,0.5) );
	mMaterial1.setDiffuse( Color( 0.0f, 1.0f, 0.0f ) );
	mMaterial1.setAmbient( Color( 0.1f, 0.1f, 0.1f ) );
	mMaterial1.setShininess( 20.0f );
	mMaterial1.apply();
	
	mMaterial2.setSpecular( Color(0,0,0) );
	mMaterial2.setDiffuse( Color(1,0,0) );
	mMaterial2.setAmbient( Color( 0.4f, 0.0f, 0.0f ) );
	mMaterial2.setEmission(Color(1,0,0));
	
	initPhysics();
	
	
	ObjLoader loader( loadResource( RES_LOSPHERE )->createStream() );
	loader.load( &mConvex );
	mVBO = gl::VboMesh( mConvex );
	
	ObjLoader loader2( loadResource( RES_TORUS )->createStream() );
	loader2.load( &mConcave );
	mVBOTerrain = gl::VboMesh( mConcave );

	btConvexHullShape* shape = bullet::createConvexHullShape(mConvex, Vec3f(CONVEX_SCALE, CONVEX_SCALE, CONVEX_SCALE));
	m_convexRigidBody = bullet::createConvexHullBody(m_dynamicsWorld, shape, Vec3f(0,500,0), 10000);
	
	btBvhTriangleMeshShape* concaveShape = bullet::createStaticConcaveMeshShape(mConcave, Vec3f(CONCAVE_SCALE, CONCAVE_SCALE, CONCAVE_SCALE), 5.0f);
	m_concaveRigidBody = bullet::createStaticRigidBody(m_dynamicsWorld, concaveShape, Vec3f(0,255,0));
	
	m_hfImage = loadImage(loadResource(RES_HEIGHTMAP));
	m_hfChannel = new Channel32f(m_hfImage);
	// note that HF_HEIGHTSCALE is ignored since we are using float data. we adjust the y-scale with the local scaling parameter only!
	btHeightfieldTerrainShape* hfShape = bullet::createHeightfieldTerrainShape(m_hfChannel, 64, 64, HF_HEIGHTSCALE, -500, 500, 1, Vec3f(HF_SCALE,HF_SCALEY,HF_SCALE));
	m_hfRigidBody = bullet::createStaticRigidBody(m_dynamicsWorld, hfShape, Vec3f(0,0,0));
	
	gl::VboMesh::Layout layout;
	layout.setDynamicColorsRGB();
	layout.setDynamicPositions();
	mVBOHeightfield = gl::VboMesh( m_hfImage.getWidth() * m_hfImage.getHeight(), 0, layout, GL_POINTS );
	
	updateData( );		
}
Beispiel #2
0
void winBodiesApp::draw()
{

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	
	for(int i = 0; i < mObjects.size(); i++) {
		mMaterial1.apply();
		Matrix44f tf = bullet::getWorldTransform(mObjects[i]->body);
		
		glPushMatrix();
			glMultMatrixf(tf.m);
			mObjects[i]->draw();
		glPopMatrix();
		
		glPolygonOffset(1.0f, 1.0f);
		mMaterial2.apply();
		glPolygonMode(GL_FRONT, GL_LINE);
		
		glPushMatrix();
			glMultMatrixf(tf.m);
			mObjects[i]->draw();
		glPopMatrix();
		
		glPolygonMode(GL_FRONT, GL_FILL);
		mMaterial1.apply();
		
	}
	
	mMaterialG.apply();
	glPushMatrix();
	gl::drawCube( Vec3f::zero(), Vec3f(1000, 0.1f, 1000) );
	glPopMatrix();
	
}
Beispiel #3
0
void TerrainApp::draw()
{
	gl::clear( Color::black() );

	gl::setMatrices( mMayaCam.getCamera() );
	gl::enable( GL_LIGHTING );

	gl::enableDepthRead();
	gl::enableDepthWrite();

	mMaterial.apply();
	gl::draw( mTriMesh );

	gl::disable( GL_LIGHTING );

	params::InterfaceGl::draw();
}
Beispiel #4
0
void winBodiesApp::setup(){
	// cam, lights material
	mCam = new CameraPersp(getWindowWidth(), getWindowHeight(), 45.0f);
	mCam->lookAt( Vec3f(100, 400, -400), Vec3f(0,0,0) );
	mCam->setPerspective( 60.0f, getWindowAspectRatio(), 0.1f, 5000.0f );
	
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_LIGHTING);

	mLight = new gl::Light(gl::Light::DIRECTIONAL, 0);
	mLight->setDirection( Vec3f(0,0.1,0.3));
	mLight->setAmbient( Color( 0.2f, 0.2f, 0.2f ) );
	mLight->setDiffuse( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->update( *mCam );
	mLight->enable();
	
	mMaterial1.setSpecular( Color(0.5,0.5,0.5) );
	mMaterial1.setDiffuse( Color( 0.33f, 0.24f, 1.0f ) );
	mMaterial1.setAmbient( Color( 0.1f, 0.1f, 0.1f ) );
	mMaterial1.setShininess( 20.0f );
	mMaterial1.apply();
	
	mMaterial2.setSpecular( Color(0,0,0) );
	mMaterial2.setDiffuse( Color(1,0,0) );
	mMaterial2.setAmbient( Color( 0.4f, 0.0f, 0.0f ) );
	mMaterial2.setEmission(Color(1,0,0));
	
	mMaterialG.setSpecular(Color(0,0,0));
	mMaterialG.setDiffuse(Color(0,0,0.03));
	mMaterialG.setAmbient(Color(0.1,0.1,0.1));
	
	initPhysics();
	
	lastTime = getElapsedSeconds();
}
Beispiel #5
0
void triMeshApp::draw()
{
	glPushMatrix();
	glRotated(yrot, 0, 1, 0);
	
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	// convex mesh
	glPushMatrix();

	Matrix44f tf = bullet::getWorldTransform(m_convexRigidBody);
	glMultMatrixf(tf.m);
	gl::scale(Vec3f(CONVEX_SCALE, CONVEX_SCALE, CONVEX_SCALE));
	mMaterial1.apply();
	gl::draw(mVBO);
	/*
	glPolygonOffset(1.0f, 1.0f);
	mMaterial2.apply();
	glPolygonMode(GL_FRONT, GL_LINE);
	gl::draw(mVBO);
	glPolygonMode(GL_FRONT, GL_FILL);
	 */
	
	glPopMatrix();
	
	//concave mesh
	glPushMatrix();
	
	Matrix44f tf2 = bullet::getWorldTransform(m_concaveRigidBody);
	glMultMatrixf(tf2.m);
	gl::scale(Vec3f(CONCAVE_SCALE, CONCAVE_SCALE, CONCAVE_SCALE));
	mMaterial1.apply();
	gl::draw(mVBOTerrain);
	/*
	glPolygonOffset(1.0f, 1.0f);
	mMaterial2.apply();
	glPolygonMode(GL_FRONT, GL_LINE);
	gl::draw(mVBOTerrain);
	glPolygonMode(GL_FRONT, GL_FILL);
	 */
	
	glPopMatrix();
	
	// heightfield
	mMaterial2.apply();
	glPushMatrix();
	Matrix44f tf3 = bullet::getWorldTransform(m_hfRigidBody);
	glMultMatrixf(tf3.m);
	gl::draw( mVBOHeightfield );
    glPopMatrix();
	
	
	// falling bodies
	for(int i = 0; i < mObjects.size(); i++) {
		mMaterial1.apply();
		Matrix44f tf = bullet::getWorldTransform(mObjects[i]->body);
		
		glPushMatrix();
		glMultMatrixf(tf.m);
		mObjects[i]->draw();
		glPopMatrix();
		/*
		glPolygonOffset(1.0f, 1.0f);
		mMaterial2.apply();
		glPolygonMode(GL_FRONT, GL_LINE);
		
		glPushMatrix();
		glMultMatrixf(tf.m);
		mObjects[i]->draw();
		glPopMatrix();
		
		glPolygonMode(GL_FRONT, GL_FILL);
		mMaterial1.apply();
		 */
		
	}
	
	glPopMatrix();
	
}
void RodSoundApp::draw() {
  while (running &&
//         app::getElapsedSeconds() - tAtLastDraw < 1.0/app::getFrameRate() &&
         fe.nextTimestep(c) > 1.0 / (real) SampleRate) {
    update();
  }
  tAtLastDraw = app::getElapsedSeconds();
  
  PROFILER_START("Draw");
  
	// Clear out the window with grey
	gl::clear(Color(0.45, 0.45, 0.5));
  
  // Enable alpha blending and depth testing
  gl::enableAlphaBlending();
	gl::enableDepthRead(true);
	gl::enableDepthWrite(true);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
  // Draw framerate counter
  gl::setMatricesWindow(getWindowSize());
  std::stringstream ss;
  ss << getAverageFps();
  gl::drawStringRight(ss.str(),
                      Vec2c(getWindowWidth()-toPixels(10), getWindowHeight()-toPixels(20)),
                      Color(0.0, 0.0, 0.0),
                      Font("Arial", toPixels(12)));
  
  // Set projection/modelview matrices
  gl::setMatrices(cam);
  
  // Draw the rod and the normal of the bishop frame
  for(int i=0; i<r->numEdges(); i++) {
    Vec3c p0 = EtoC(r->cur().POS(i));
    Vec3c p1 = EtoC(r->cur().POS(i+1));
    gl::drawLine(p0, p1);
    gl::color(1.0, 1.0, 0.0);
    gl::lineWidth(1.0);
    Vec3c u = EtoC(r->cur().u[i]);
    gl::drawLine((p0+p1)/2.0, (p0+p1)/2.0+u*(p1-p0).length()*2.0);
  }
  
  m.apply();
  
  l->setDiffuse(Color::white());
  l->setAmbient(Color::white());
  l->setPosition(Vec3c(0.0, 50.0, 0.0));
  l->enable();
  
  diffuseProg.bind();
  for (int i=0; i<r->numCPs(); i++) {
    gl::pushModelView();
    gl::translate(EtoC(r->cur().POS(i)));
    spheredl->draw();
    gl::popModelView();
  }
  diffuseProg.unbind();
  
  rodProg.bind();

  floorTex.enableAndBind();
  gl::draw(floor);
  floorTex.disable();
  
  rodProg.unbind();
  
  // Draw rod edges
  rodProg.bind();
  rodTex.enableAndBind();
  for (int i=0; i<r->numEdges(); i++) {
    gl::pushModelView();
    Vec3c v = EtoC(r->cur().edge(i).normalized());
    
    gl::translate(EtoC(r->cur().POS(i)));
    Quaternion<real> q(Vec3c(0.0, 1.0, 0.0), v);
    real angle = acos(std::max((real)-1.0, std::min((real)1.0, (q*Vec3c(-1.0, 0.0, 0.0)).dot(EtoC(r->cur().u[i])))));
    if ((q*Vec3c(-1.0, 0.0, 0.0)).dot(EtoC(r->cur().v(i))) > 0.0) angle = -angle;
    gl::rotate(Quaternion<real>(v, angle));
    gl::rotate(q);
    gl::rotate(Vec3c(0.0, r->cur().rot(i)*180.0/constants::pi, 0.0));
    gl::scale(1.0, r->cur().edgeLength(i), 1.0);
    cylinderdl->draw();
    gl::popModelView();
  }
  rodTex.unbind();
  rodProg.unbind();

  for (RodEnergy* e : energies) {
    e->draw(c.timestep());
  }
  integrator->draw();
 
  fe.record(c);
  
  PROFILER_STOP("Draw");
}