void MaterialApp::setup(){ font = Font(loadAsset("player1up.ttf"), 20); rotate = Vec3f::zero(); eye = Vec3f(0, 0, 700); target = Vec3f::zero(); camera = CameraPersp(getWindowWidth(), getWindowWidth(), 35.0f, 0.5f, 800.f); camera.lookAt(eye, target); light = std::make_unique<gl::Light>(gl::Light::DIRECTIONAL, 0); light->setAmbient(Color(0.6f, 0.6f, 0.6f)); light->setDiffuse(Color(1.f, 1.f, 1.f)); light->setDirection(Vec3f::zAxis()); material.setAmbient(Color(0.3f, 0.3f, 0.3f)); material.setDiffuse(Color(0.6f, 0.6f, 0.6f)); material.setShininess(60); material.setEmission(Color(0.f, 0.f, 0.f)); //gl::enable(GL_LIGHTING); gl::enable(GL_CULL_FACE); gl::enableDepthRead(); gl::enableDepthWrite(); }
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( ); }
void TerrainApp::update() { static float height = 0; static float noiseScale = 0; if ( ( height != mHeight ) || ( noiseScale != mNoiseScale ) ) { generateTerrain(); height = mHeight; noiseScale = mNoiseScale; } mMaterial.setAmbient( mAmbient ); mMaterial.setDiffuse( mDiffuse ); mMaterial.setSpecular( mSpecular ); mMaterial.setShininess( mShininess ); mMaterial.setEmission( mEmission ); mLight->setDirection( mLightDirection ); mLight->update( mMayaCam.getCamera() ); mFps = getAverageFps(); }
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(); }
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(); }
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 BrainbowApp::scene1(){ if (!musicOn && getElapsedSeconds() > 1){ mAudio.playTraz("drone"); } // //addspheres if (lightFade >= 0.45f && ballTimer.getSeconds() > 0.5f && mCloud.getNumber() < 20){ mCloud.addSphere(); mAudio.playTraz("bubble"); ballTimer = 0; ballTimer.start(); } //into diamond if (gongTimer.getSeconds()>1 && scaledZ < 290 && scaledZ > 100 && !gong && getElapsedSeconds() > 30){ mAudio.playTraz("activate"); gong = true; gongTimer.stop(); gongTimer.start(); } if (gong && zshift < 500 ){ // zshift = 1; zshift++; scaledZ += zshift; } if (mCloud.getNumber() < 300 && ballTimer.getSeconds() > 0.1f && gong && zshift > 0){ mCloud.addSphere(); // mAudio.playTraz("bubble"); ballTimer = 0; ballTimer.start(); } // cout << "x: " << scaledX << endl; // cout << "y: " << scaledY << endl; // cout << "z: " << scaledZ << endl; if ((mCloud.getHexClear() || shift2) && getElapsedSeconds() > 10 && zshift < 750 && gong){ // if (getElapsedSeconds() > 10 && zshift < 720){ shift2 = true; zshift++; scaledZ += zshift; discMaterial.setSpecular( ColorA(colorSat, colorSat, colorSat, .4f + discOp ) ); discMaterial.setDiffuse( ColorA(colorSat, colorSat, colorSat, .4f + discOp) ); discMaterial.setAmbient( ColorA(colorSat, colorSat, colorSat, .05f ) ); discMaterial.setShininess( 600.0f ); discMaterial.setEmission(ColorA(1, 1, 1, 1 )); mDisc.setMaterial( discMaterial ); discOp += .01; if (zshift > 680){ diamondFade += .005; sphereMaterial.setSpecular( ColorA(colorSat-0.3f, colorSat, colorSat, .4f-diamondFade ) ); sphereMaterial.setDiffuse( ColorA(colorSat-0.3f, colorSat, colorSat, .4f-diamondFade ) ); sphereMaterial.setAmbient( ColorA(colorSat-0.3f, colorSat, colorSat, .05f-diamondFade ) ); mDiamond.setMaterial( sphereMaterial ); // drawDiamond = false; } if (!musicOn){ mAudio.playTraz("activate2"); musicOn = true; } } if (zshift >= 750 && scaledZ > 700 && scaledY < 450 && scaledY > 320 && scaledX <685 && scaledX > 590){ sceneOne = false; sceneTwo = true; zshift = 0; } }
void BrainbowApp::setup() { // LOAD AUDIO mAudio = AudioCont(); mAudio.setUp(); // START SCENE 1 sceneOne = true; sceneTwo = false; // Set up OpenGL gl::enableAlphaBlending(); gl::enableDepthRead(); gl::enableDepthWrite(); gongTimer.start(); ballTimer.start(); // LIGHTING //here glPolygonOffset( 1.0f, 1.0f ); glEnable( GL_LIGHTING ); glEnable( GL_DEPTH_TEST ); mLight = new gl::Light( gl::Light::POINT, 0 ); mLight->lookAt( Vec3f( 1, 5, 1 ), Vec3f (getWindowWidth(), getWindowHeight() * 0.5f, 0.0f )); mLight->setAmbient( Color( 0.3f, 0.3f, 0.3f ) ); mLight->setDiffuse( Color( 1.0f, 1.0f, 1.0f ) ); mLight->setSpecular( Color( 1.0f, 1.0f, 1.0f ) ); mLight->setShadowParams( 60.0f, 0.5f, 8.0f ); // mLight->update( *mCamera ); mLight->enable(); //LOAD SHAPES colorSat = 1.0f; sphereMaterial.setSpecular( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) ); sphereMaterial.setDiffuse( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) ); sphereMaterial.setAmbient( ColorA(colorSat-0.3f, colorSat, colorSat, .05f ) ); sphereMaterial.setShininess( 1.0f ); sphereMaterial.setEmission(ColorA(1, 1, 1, 1 )); gl::Material cylMaterial; cylMaterial.setSpecular( ColorA(0, 1.0f, 1.0f, .2f )); cylMaterial.setDiffuse( ColorA(0, 1.0f, 1.0f, .2f ) ); cylMaterial.setAmbient( ColorA(0, 1.0f, 1.0f, .2f ) ); cylMaterial.setShininess( 600.0f ); cylMaterial.setEmission(ColorA(1, 1, 1, 1 )); gl::Material curMaterial; curMaterial.setSpecular( ColorA(1, .5, 0, .5f )); curMaterial.setDiffuse( ColorA(1, .5, 0, .5f ) ); curMaterial.setAmbient( ColorA(1, 1.0f, 1.0f, .05f ) ); curMaterial.setShininess( 600.0f ); curMaterial.setEmission(ColorA(1, 1, 1, 1 )); discMaterial.setSpecular( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) ); discMaterial.setDiffuse( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) ); discMaterial.setAmbient( ColorA(colorSat-0.3f, colorSat, colorSat, .05f ) ); discMaterial.setShininess( 600.0f ); discMaterial.setEmission(ColorA(1, 1, 1, 1 )); initShadowMap(); mCloud = SphereCloud(0, 70); mDiamond = gl::DisplayList( GL_COMPILE ); mDiamond.newList(); gl::drawSphere(Vec3f(0, 0, 0), 300, 4); mDiamond.endList(); mDiamond.setMaterial( sphereMaterial ); mCyl = gl::DisplayList( GL_COMPILE ); mCyl.newList(); // gl::drawCylinder(200, 200, 200); gl::drawColorCube(Vec3f(0, 0, 0), Vec3f(300, 300, 300)); mCyl.endList(); mCyl.setMaterial(cylMaterial); mCur = gl::DisplayList( GL_COMPILE ); mCur.newList(); gl::drawSphere(Vec3f(0, 0, 0), 5); mCur.endList(); mCur.setMaterial(curMaterial); mDisc = gl::DisplayList( GL_COMPILE ); mDisc.newList(); gl::drawSolidCircle(Vec2f(0, 0), 60, 6); mDisc.endList(); mDisc.setMaterial( discMaterial ); // START LEAP mLeap = LeapSdk::Device::create(); mCallbackId = mLeap->addCallback( &BrainbowApp::onFrame, this ); mShader = gl::GlslProg( loadResource( RES_SHADOWMAP_VERT ), loadResource( RES_SHADOWMAP_FRAG ) ); mShader.bind(); mShader.uniform( "depthTexture", 0 ); }
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"); }
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(); }