void AssimpApp::draw() { gl::clear( Color::black() ); gl::setMatrices( mMayaCam.getCamera() ); gl::enableDepthWrite(); gl::enableDepthRead(); gl::color( Color::white() ); if ( mEnableWireframe ) gl::enableWireframe(); gl::Light light( gl::Light::DIRECTIONAL, 0 ); light.setAmbient( Color::white() ); light.setDiffuse( Color::white() ); light.setSpecular( Color::white() ); light.lookAt( Vec3f( 0, 5, -20 ), Vec3f( 0, 5, 0 ) ); light.update( mMayaCam.getCamera() ); light.enable(); gl::enable( GL_LIGHTING ); gl::enable( GL_NORMALIZE ); mAssimpLoader.draw(); gl::disable( GL_LIGHTING ); if ( mEnableWireframe ) gl::disableWireframe(); if ( mDrawBBox ) gl::drawStrokedCube( mAssimpLoader.getBoundingBox() ); params::InterfaceGl::draw(); }
void StereoscopicRenderingApp::mouseDrag( MouseEvent event ) { // handle camera mMayaCam.mouseDrag( event.getPos(), event.isLeftDown(), event.isMiddleDown(), event.isRightDown() ); // update stereoscopic camera mCamera.setEyePoint( mMayaCam.getCamera().getEyePoint() ); mCamera.setCenterOfInterestPoint( mMayaCam.getCamera().getCenterOfInterestPoint() ); }
void cApp::draw(){ mExp.begin( camUi.getCamera() );{ gl::clear(); gl::enableAlphaBlending(); gl::pushMatrices(); if( !mExp.bRender && !mExp.bSnap ){ glLineWidth( 3 ); mt::drawCoordinate(100); } if( mDg.mDot ){ glPointSize( 1 ); gl::draw( mDg.mDot ); } gl::popMatrices(); }mExp.end(); if( bDrawLine ){ mExp2.begin( camUi.getCamera() );{ gl::clear(); gl::enableAlphaBlending(); gl::pushMatrices(); if( mDg.mLine ){ glLineWidth( 1 ); gl::draw( mDg.mLine ); } gl::popMatrices(); }mExp2.end(); } //gl::enableAdditiveBlending(); gl::clear( ColorA(0,0,0,1) ); gl::color( Color::white() ); mExp.draw(); if( bDrawLine ) mExp2.draw(); gl::drawString("Frame: " + to_string(frame), Vec2f(50, 50) ); gl::drawString("simDirNum: " + to_string(simDirNum), Vec2f(50, 75) ); gl::drawString("numParticle: " + to_string(numParticle), Vec2f(50, 100) ); #ifdef RENDER frame+=1; #else frame+=1; #endif }
void gpuPSApp::computeAttractorPosition() { // The attractor is positioned at the intersection of a ray // from the mouse to a plane perpendicular to the camera. float t = 0; Vec3f right, up; mMayaCam.getCamera().getBillboardVectors(&right, &up); CameraPersp cam = mMayaCam.getCamera(); float u = mMousePos.x / (float) getWindowWidth(); float v = mMousePos.y / (float) getWindowHeight(); Ray ray = cam.generateRay(u , 1.0f - v, cam.getAspectRatio() ); if (ray.calcPlaneIntersection(Vec3f(0.0f,0.0f,0.0f), right.cross(up), &t)) { mAttractor.set(ray.calcPosition(t)); } }
void FastTrailsApp::resize( ResizeEvent event ) { // adjust aspect ratio CameraPersp cam = mCamera.getCamera(); cam.setAspectRatio( event.getAspectRatio() ); mCamera.setCurrentCam( cam ); }
void FastTrailsApp::draw() { // clear window gl::clear(); // set render states gl::enableWireframe(); gl::enableAlphaBlending(); gl::enableDepthRead(); gl::enableDepthWrite(); // enable 3D camera gl::pushMatrices(); gl::setMatrices( mCamera.getCamera() ); // draw VBO mesh using texture mTexture.enableAndBind(); gl::drawRange( mVboMesh, 0, mTrail.size(), 0, mTrail.size()-1 ); mTexture.unbind(); // restore camera and render states gl::popMatrices(); gl::disableDepthWrite(); gl::disableDepthRead(); gl::disableAlphaBlending(); gl::disableWireframe(); }
void FadeCandyClientApp::resize() { // adjust aspect ratio CameraPersp cam = mMayaCam.getCamera(); cam.setAspectRatio( getWindowAspectRatio() ); mMayaCam.setCurrentCam( cam ); }
void TessellationSampleApp::resize() { // adjust aspect ratio CameraPersp cam = mMayaCam.getCamera(); cam.setAspectRatio( getWindowAspectRatio() ); mMayaCam.setCurrentCam( cam ); }
void wellingtonModelApp::frameCurrentObject() { Sphere boundingSphere = Sphere::calculateBoundingSphere( mMesh.getVertices() ); mMayaCam.setCurrentCam( mMayaCam.getCamera().getFrameSphere( boundingSphere, 100 ) ); }
void LookAroundYouApp::draw() { // clear out the window with black gl::clear( Color( 0, 0, 0 ) ); // set up the camera gl::pushMatrices(); gl::setMatrices( mMayaCam.getCamera() ); for(int i=0; i<mBoids.size(); i++) { mBoids[i]->draw(); } gl::drawCoordinateFrame( 6.0f ); gl::popMatrices(); // Draw the interface mParams.draw(); float pos = music->getPlayheadNorm(); Rectf bar(0, 0, app::getWindowWidth()*pos, 10); gl::drawSolidRect(bar); }
void PhysicallyBasedShadingApp::update() { // animate the light if( mAnimateLight ){ mLightPosition = vec3( cos( mTime * 0.5f ) * 8.0f, 8.0f + sin( mTime * 0.25f ) * 3.5f, sin( mTime * 0.5f ) * 8.0f ); mTime += 0.025f; } // check for camera properties change CameraPersp cam = mMayaCam.getCamera(); float sensorHeight = mSensorSize / getWindowAspectRatio(); float fov = 180.0f / M_PI * 2.0f * math<float>::atan( 0.5f * sensorHeight / mFocalLength ); if( mFocalLengthPreset != 0 && mFocalLengthPreset != mPrevFocalLengthPreset ){ mFocalLength = sFocalPresetsValues[ mFocalLengthPreset ]; } if( mSensorSizePreset != 0 && mSensorSizePreset != mPrevSensorSizePreset ){ mSensorSize = sSensorPresetsValues[ mSensorSizePreset ]; } if( mFStopPreset != 0 && mFStopPreset != mPrevFStopPreset ){ mFStop = sFStopPresetsValues[ mFStopPreset ]; } mPrevFocalLengthPreset = mFocalLengthPreset; mPrevSensorSizePreset = mSensorSizePreset; mPrevFStopPreset = mFStopPreset; // update the fov if necessary if( cam.getFov() != fov ){ cam.setFov( fov ); mMayaCam.setCurrentCam( cam ); } }
void MarionetteZooApp::mouseDown( MouseEvent event ) { if ( mCameraLock ) mBulletWorld->mouseDown( event, mMayaCam.getCamera() ); else mMayaCam.mouseDown( event.getPos() ); }
void ProceduralAnimApp::update() { mLightPos.x = mRotationRadius * math<float>::sin( float( app::getElapsedSeconds() ) ); mLightPos.z = mRotationRadius * math<float>::cos( float( app::getElapsedSeconds() ) ); mFlapAngle += 0.01f * mFlapIncrement; float h = mAmplitude * 0.5f * math<float>::sin( mFlapAngle ); float t = mAmplitude * 0.5f * math<float>::sin( mFlapAngle - M_PI / 2 ); SkeletonRef skeleton = mSkinnedVboBird->getSkeleton(); NodeRef midL = skeleton->getBone("Gannet_Lwing_mid"); NodeRef midR = skeleton->getBone("Gannet_Rwing_mid"); NodeRef tipL = skeleton->getBone("Gannet_Lwing_tip"); NodeRef tipR = skeleton->getBone("Gannet_Rwing_tip"); midL->setRelativeRotation( midL->getInitialRelativeRotation() * Quatf( Vec3f::xAxis(), t ) * Quatf( Vec3f::zAxis(), mShoulderAngle ) ); midR->setRelativeRotation( midR->getInitialRelativeRotation() * Quatf( Vec3f::xAxis(), t ) * Quatf( Vec3f::zAxis(), mShoulderAngle ) ); tipL->setRelativeRotation( Quatf( Vec3f::yAxis(), h ) ); tipR->setRelativeRotation( Quatf( Vec3f::yAxis(), h ) ); NodeRef head = skeleton->getBone("Gannet_head"); head->setRelativeRotation( head->getInitialRelativeRotation().slerp(0.5f, mMayaCam.getCamera().getOrientation() ) ); skeleton->getBone("Gannet_body")->setRelativePosition( Vec3f(0, -t, 0) ); /* The mesh isn't automatically updated when the skeleton it contained is modified, so * an update call is necessary (for now). This may change since I don't find it very * intuitive... */ mSkinnedVboBird->update(); for( auto& d : mDust ) { d.z -= 0.75f; d.z = ( d.z < -SCENE_SIZE/2 ) ? SCENE_SIZE/2 : d.z; } }
void HexagonMirrorApp::resize( ResizeEvent event ) { // adjust the camera aspect ratio CameraPersp cam = mCamera.getCamera(); cam.setAspectRatio( event.getAspectRatio() ); mCamera.setCurrentCam( cam ); }
void rayMarcherApp::draw() { glClearColor( 0, 0, 0, 0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glDepthMask( GL_TRUE ); glDisable( GL_TEXTURE_2D ); gl::setMatrices( mMayaCam.getCamera() ); mMarcher.renderSceneGL(); gl::setMatricesWindow( getWindowSize() ); // draw as much of the texture as we've rendered glDisable( GL_LIGHTING ); glDepthMask( GL_TRUE ); glDisable( GL_DEPTH_TEST ); glColor3f( 1, 1, 1 ); mImageTexture.enableAndBind(); glBegin( GL_QUADS ); glTexCoord2f( mImageTexture.getLeft(), mImageTexture.getTop() ); glVertex2f( 0, 0 ); glTexCoord2f( mImageTexture.getLeft(), mImageTexture.getBottom() * mCurrentLine / mImageTexture.getHeight() ); glVertex2f( 0, mCurrentLine ); glTexCoord2f( mImageTexture.getRight(), mImageTexture.getBottom() * mCurrentLine / mImageTexture.getHeight() ); glVertex2f( mImageTexture.getWidth(), mCurrentLine ); glTexCoord2f( mImageTexture.getRight(), mImageTexture.getTop() ); glVertex2f( mImageTexture.getWidth(), 0 ); glEnd(); }
void HexagonMirrorApp::resize() { // adjust the camera aspect ratio CameraPersp cam = mCamera.getCamera(); cam.setAspectRatio( getWindowAspectRatio() ); mCamera.setCurrentCam( cam ); }
void MarionetteZooApp::update() { mFps = getAverageFps(); CameraPersp cam = mMayaCam.getCamera(); if ( cam.getFov() != mCameraFov ) { cam.setPerspective( mCameraFov, getWindowAspectRatio(), 0.1f, 1000.0f ); mMayaCam.setCurrentCam( cam ); } if( mCameraLock ) { if( mCameraEyePoint != cam.getEyePoint() ) { cam.setEyePoint( mCameraEyePoint ); mMayaCam.setCurrentCam( cam ); } if( mCameraCenterOfInterestPoint != cam.getCenterOfInterestPoint() ) { cam.setCenterOfInterestPoint( mCameraCenterOfInterestPoint ); mMayaCam.setCurrentCam( cam ); } } else { mCameraEyePoint = cam.getEyePoint(); mCameraCenterOfInterestPoint = cam.getCenterOfInterestPoint(); } // mLight->setDirection( mLightDirection * Vec3f( 1.f, 1.f, -1.f ) ); // mLight->update( cam ); mBulletWorld->update(); mModelManager->update(); }
void MarionetteZooApp::mouseDrag( MouseEvent event ) { if ( mCameraLock ) mBulletWorld->mouseDrag( event, mMayaCam.getCamera() ); else mMayaCam.mouseDrag( event.getPos(), event.isLeftDown(), event.isMiddleDown(), event.isRightDown() ); }
void WaterSimulationApp::draw(){ gl::clear( Color( 0.11f, 0.13f, 0.1f ) ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mParams->draw(); gl::setMatrices(mMayaCam.getCamera()); if(mDrawBox){ glColor4f(0.2, 0.4, 0.5, 1);//orange gl::drawStrokedCube(boxCenter,boxDimension); } if(mDrawGravity){ glColor4f(1.0f,0.3f,0.0f,0.5f);//red if(mDrawGravity)glColor4f(0.0f,1.0f,0.5f,1);//green gl::drawVector(boxCenter,(boxCenter-gravity),3.0f,1.0f); } //draw random force if(mDrawForce){ if(randomForce.lengthSquared()!=0){ glColor4f(1.0f,0.0f,0.0f,1); gl::drawVector(randomForceX,randomForce+randomForceX,1.0f,0.5f); } } fluidsys->draw(); }
void reflection_animationApp::resize( ResizeEvent event ) { // reset camera on resize CameraPersp cam = m_mayaCam.getCamera(); cam.setAspectRatio( getWindowAspectRatio() ); m_mayaCam.setCurrentCam( cam ); }
void _TBOX_PREFIX_App::resize() { console() << getWindowBounds(); CameraPersp cam = mMayaCam.getCamera(); cam.setAspectRatio( getWindowAspectRatio() ); mMayaCam.setCurrentCam( cam ); gl::enableDepthRead(); }
void CameraLensShiftTestApp::resize() { mCamera.setAspectRatio( event.getAspectRatio() * 0.5f ); CameraPersp cam( mOverview.getCamera() ); cam.setAspectRatio( event.getAspectRatio() * 0.5f ); mOverview.setCurrentCam( cam ); }
void HexagonMirrorApp::draw() { // clear the window gl::clear(); // activate our camera gl::pushMatrices(); gl::setMatrices( mCamera.getCamera() ); // set render states gl::enable( GL_CULL_FACE ); gl::enableDepthRead(); gl::enableDepthWrite(); gl::color( Color::white() ); if( mVboMesh && mShaderInstanced && mBuffer ) { // bind webcam image if( mWebcamTexture ) mWebcamTexture.bind(0); // bind the shader, which will do all the hard work for us mShaderInstanced.bind(); mShaderInstanced.uniform( "texture", 0 ); mShaderInstanced.uniform( "scale", Vec2f( 1.0f / (3.0f * INSTANCES_PER_ROW), 1.0f / (3.0f * INSTANCES_PER_ROW) ) ); // bind the buffer containing the model matrix for each instance, // this will allow us to pass this information as a vertex shader attribute. // See: initializeBuffer() glBindVertexArray(mVAO); // we do all positioning in the shader, and therefor we only need // a single draw call to render all instances. drawInstanced( mVboMesh, NUM_INSTANCES ); // make sure our VBO is no longer bound mVboMesh.unbindBuffers(); // unbind vertex array object containing our buffer glBindVertexArray(0); // unbind shader mShaderInstanced.unbind(); if( mWebcamTexture ) mWebcamTexture.unbind(); } // reset render states gl::disableDepthWrite(); gl::disableDepthRead(); gl::disable( GL_CULL_FACE ); // restore 2D drawing gl::popMatrices(); }
void CameraLensShiftTestApp::draw() { gl::clear(); gl::enableDepthRead(); gl::enableDepthWrite(); // draw the overview of the scene in the left half of the window glPushAttrib( GL_VIEWPORT_BIT ); gl::setViewport( Area( getWindowWidth() * 0.0f, 0, getWindowWidth() * 0.5f, getWindowHeight() ) ); gl::pushMatrices(); gl::setMatrices( mOverview.getCamera() ); render(); gl::color( Color(0, 1, 1) ); gl::drawFrustum( mCamera ); gl::popMatrices(); glPopAttrib(); // draw what the camera sees in the right half of the window glPushAttrib( GL_VIEWPORT_BIT ); gl::setViewport( Area( getWindowWidth() * 0.5f, 0, getWindowWidth() * 1.0f, getWindowHeight() ) ); gl::pushMatrices(); gl::setMatrices( mCamera ); render(); gl::popMatrices(); glPopAttrib(); // gl::disableDepthWrite(); gl::disableDepthRead(); // draw separator gl::color( Color(0.25f, 0.25f, 0.25f) ); gl::drawLine( Vec2f( getWindowWidth() * 0.5f, 0.0f ), Vec2f( getWindowWidth() * 0.5f, getWindowHeight() ) ); // draw info gl::enableAlphaBlending(); gl::drawString( (boost::format("Lens Shift X: %02.2f\nLens Shift Y: %02.2f\n\nUse cursor keys to adjust lens shift,\nuse mouse to control overview camera") % mCamera.getLensShiftHorizontal() % mCamera.getLensShiftVertical() ).str(), Vec2f( 10, 10 ), Color::white(), mFont ); gl::drawString( "Overview of the scene", Vec2f( 10, getWindowHeight() - 28 ), Color::white(), mFont ); gl::drawString( "View from the camera", Vec2f( 0.5f * getWindowWidth() + 10, getWindowHeight() - 28 ), Color::white(), mFont ); gl::disableAlphaBlending(); }
void rayMarcherApp::resize( int width, int height ) { mImageSurface = shared_ptr<Surface8u>( new Surface8u( getWindowWidth(), getWindowHeight(), false ) ); mImageTexture = gl::Texture( *mImageSurface ); mCurrentLine = 0; CameraPersp cam = mMayaCam.getCamera(); cam.setPerspective( 45, getWindowWidth() / (float)getWindowHeight(), 0.1f, 100.0f ); mMayaCam.setCurrentCam( cam ); }
void GizmoSampleApp::keyDown( KeyEvent event ){ if( event.getChar() == '1' ) mGizmo->setMode( Gizmo::TRANSLATE ); else if( event.getChar() == '2' ) mGizmo->setMode( Gizmo::ROTATE ); else if( event.getChar() == '3' ) mGizmo->setMode( Gizmo::SCALE ); else if( event.getChar() == 'o' ) { CameraPersp centered = mCamUI.getCamera(); centered.setCenterOfInterestPoint( mGizmo->getTranslate() ); mCamUI.setCurrentCam( centered ); } }
void AudioObjApp::draw() { gl::clear( Color( 0, 0, 0 ) ); gl::enableAlphaBlending(); gl::enableDepthRead(); gl::enableDepthWrite(); gl::pushMatrices(); gl::setMatrices( mMayaCam.getCamera() ); if ( mFeature && mFeatureTex ) { mShader->bind(); mFeatureTex.enableAndBind(); mShader->uniform( "dataTex", 0 ); mShader->uniform( "texWidth", (float)mFeatureTex.getWidth() ); mShader->uniform( "texHeight", (float)mFeatureTex.getHeight() ); mShader->uniform( "soundDataSize", (float)mFeature->getSize() ); mShader->uniform( "spread", mFeatureSpread ); mShader->uniform( "spreadOffset", mFeatureSpreadOffset ); mShader->uniform( "time", (float)getElapsedSeconds() ); mShader->uniform( "tintColor", mObjColor ); } if ( mRenderWireframe ) gl::enableWireframe(); gl::color( Color(1.0f, 0.0f, 0.0f ) ); if ( mVbo ) gl::draw( mVbo ); if ( mRenderWireframe ) gl::disableWireframe(); mShader->unbind(); mFeatureTex.unbind(); gl::color( Color::white() ); // gl::drawCoordinateFrame(); gl::popMatrices(); gl::disableDepthRead(); gl::disableDepthWrite(); gl::setMatricesWindow( getWindowSize() ); ciXtractReceiver::drawData( mFeature, Rectf( 15, getWindowHeight() - 150, 255, getWindowHeight() - 35 ) ); gl::draw( mFeatureSurf ); mParams->draw(); }
void MarionetteZooApp::draw() { // clear out the window with black gl::clear( Colorf( 0.392, 0.392, 0.784 ) ); gl::setViewport( getWindowBounds() ); gl::setMatrices( mMayaCam.getCamera() ); gl::enableDepthRead(); gl::enableDepthWrite(); ci::gl::pushMatrices(); mBulletWorld->draw(); ci::gl::popMatrices(); mModelManager->draw( mMayaCam.getCamera() ); ci::gl::drawCoordinateFrame( 5.f ); mParams.draw(); }
void HiKinectApp::draw3D() { gl::setMatrices( mCamUI.getCamera() ); if (mWireframe) gl::enableWireframe(); else gl::disableWireframe(); if (mLighting) { glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); } // GLfloat light_position[] = { mMousePos.x, mMousePos.y, -275.0f, 0.0f }; GLfloat light_position[] = { 0, 0, 1.0f, 0.0f }; glLightfv( GL_LIGHT0, GL_POSITION, light_position ); if( DIFFUSE ){ ci::ColorA color( CM_RGB, 1.0f, 1.0f, 1.0f, 1.0f ); glMaterialfv( GL_FRONT, GL_DIFFUSE, color ); } else { glMaterialfv( GL_FRONT, GL_DIFFUSE, no_mat ); } if( AMBIENT ) glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient ); else glMaterialfv( GL_FRONT, GL_AMBIENT, no_mat ); if( SPECULAR ){ glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular ); glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess ); } else { glMaterialfv( GL_FRONT, GL_SPECULAR, no_mat ); glMaterialfv( GL_FRONT, GL_SHININESS, no_shininess ); } if( EMISSIVE ) glMaterialfv( GL_FRONT, GL_EMISSION, mat_emission ); else glMaterialfv( GL_FRONT, GL_EMISSION, no_mat ); if (mDepthTexture) mDepthTexture.bind(0); mFbo.bindTexture(1); if (mColorTexture) mColorTexture.bind(2); mGridMesh.draw( lmap(mMousePos.x, 0.0f, (float)getWindowWidth(), 0.0f, 1.0f) ); if (mLighting) { glDisable( GL_LIGHTING ); glDisable( GL_LIGHT0 ); } gl::disableWireframe(); }
void godComplexApp::draw() { gl::enableDepthRead(); gl::enableDepthWrite(); gl::enableAlphaBlending(); // clear out the window with black gl::clear( Color( 0, 0, 0 ) ); gl::setMatrices( mMayaCam.getCamera()); if(drawWater == true){ if(mWaterModule != NULL){ gl::pushMatrices(); mWaterModule->draw(0); gl::popMatrices(); } } if(drawMesh == true){ gl::pushMatrices(); myImage.enableAndBind(); // gl::rotate( mArcball.getQuat() ); //NOTE: for debugging gl::scale(Vec3f(0.035,0.035,0.035)); glLineWidth(0.2f); gl::enableWireframe(); gl::translate(Vec3f(280.0, 0.0, -180.0)); gl::rotate(Vec3f(-10.0, -10.0, 0.0)); gl::draw(mVbo); gl::disableWireframe(); myImage.unbind(); gl::popMatrices(); } gl::pushMatrices(); mFlowField->draw(); gl::popMatrices(); /* glPushMatrix(); glColor4f(1.0, 0.0, 0.0, 1.0); gl::drawSphere(Vec3f(userIncr1, userIncr2, userIncr3), 30.0, 12.0); glPopMatrix(); */ }