InstancedStereoApp::InstancedStereoApp()
: mLightWorldPosition( vec4( 1, 1, 1, 1 ) )
{
	CameraPersp host;
	host.setEyePoint( vec3( 0, 0, 1 ) );
	host.lookAt( vec3( 0 ) );
	mRift = hmd::OculusRift::create( hmd::OculusRift::Params().hostCamera( host ).screenPercentage( 1.25f ) );

	try {
		mShader = gl::GlslProg::create( gl::GlslProg::Format().vertex( loadAsset( "phong.vert" ) ).fragment( loadAsset( "phong.frag" ) ) );
	}
	catch( const std::exception& e ) {
		console() << e.what() << std::endl;
		quit();
	}
	mTeapot = gl::Batch::create( geom::Teapot().subdivisions( 12 ), mShader );

	gl::enableVerticalSync( false );
	gl::disableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();
	gl::enable( GL_CLIP_DISTANCE0, true );
}
Beispiel #2
0
void CubeApp::setup()
{
    mRenderDescriptor = mtl::RenderPassDescriptor::create();

    mCam.lookAt( vec3( 3, 2, 4 ), vec3( 0 ) );

    mTexture = mtl::TextureBuffer::create(loadImage(getAssetPath("texture.jpg")),
                                          mtl::TextureBuffer::Format().mipmapLevel(3).flipVertically());

    mDepthEnabled = mtl::DepthState::create( mtl::DepthState::Format().depthWriteEnabled() );

    mPipeline = mtl::RenderPipelineState::create("batch_vertex", "cube_fragment");
    mBatchCube = mtl::Batch::create(geom::Cube(), mPipeline);
}
Beispiel #3
0
void MemExploreApp::updateLayout()
{
  int pixelSize = 4;
  mFbo = gl::Fbo(getWindowWidth() / pixelSize, getWindowHeight() / pixelSize);
  
  mCamera.setPerspective(60.0f, getWindowAspectRatio(), 0.01f, 100.0f);
  
  mCameraArcball.setCenter(getWindowCenter());
  mCameraArcball.setRadius(mIsFullscreen ? 500.0f
                                         : Vec2f(getWindowSize()).length() * 10.0f);
  
  if(mIsFullscreen) hideCursor();
  else showCursor();
}
Beispiel #4
0
void Day57App::update()
{
    if (mLowerThresh > mHigherThresh) mHigherThresh = mLowerThresh;
    
    //mParticleController.applyForceToPredators(mZoneRadius, 0.4f, 0.7f);
    mParticleController.applyForceToParticles(mZoneRadius, mLowerThresh, mHigherThresh, mAttractStrength, mRepelStrength, mOrientStrength);
    if (mCentralGravity) mParticleController.pullToCenter(mCenter);
    mParticleController.update(mFlatten);
    
    mEye = vec3(0.0f, 0.0f, mCameraDistance);
    mCam.lookAt(mEye, mCenter, mUp);
    gl::setMatrices(mCam);
    gl::rotate(mSceneRotation);
}
Beispiel #5
0
void Day44App::setup()
{
    mCam.lookAt(vec3(0,0,5), vec3(0));
    mCam.setPerspective(45.f, getWindowAspectRatio(), 1.f, 1000.f);
    
    lightPos = vec3(0.f);
    
    theta = 0.0;
    
    setupGlsl();
    
    mCamUi = CameraUi(&mCam, getWindow());
    
    auto cube = geom::Icosahedron();
    
    auto s = geom::Sphere().subdivisions(128);
    auto scal = geom::Scale(0.3,0.3,0.3);
    
    mBatchB = gl::Batch::create(s, mGlsl);
    
    mBatch = gl::Batch::create(cube >> scal, mGlsl);
    
    auto sphere = geom::Sphere();
    auto scale = geom::Scale(0.1f,0.1f,0.1f);
    auto shader = gl::ShaderDef().color();
    auto rotate = geom::Rotate(angleAxis(2.1f, vec3(1.0,0.,0.f)));
    mLight = gl::Batch::create(sphere >> scale >> rotate, gl::getStockShader(shader));
    
    gl::enableDepthRead();
    gl::enableDepthWrite();
    
    for (int i=0; i < NUM_OBJS; i++)
    {
        mPositions.push_back(vec3(randFloat(-10.,10),randFloat(-10.,10),randFloat(-10.,10)));
    }
    setFrameRate(60);
}
void Corrdinate_spacesApp::setup()
{
    vector<Vec3f> positions;
    vector<uint32_t> indices;
    
    positions.push_back( Vec3f( -1,  1, 0) ); //0
    positions.push_back( Vec3f( -1, -1, 0) ); //1
    positions.push_back( Vec3f(  1, -1, 0) ); //2
    positions.push_back( Vec3f(  1,  1, 0) ); //3
    
    indices.push_back(1);
    indices.push_back(3);
    indices.push_back(0);
    
    indices.push_back(1);
    indices.push_back(2);
    indices.push_back(3);

//    mMesh.appendVertices(positions.data(), positions.size());
//    mMesh.appendIndices(indices.data(), indices.size());
    
    gl::VboMesh::Layout layout;
    layout.setStaticPositions();
    layout.setStaticIndices();
    
    mVboMesh = gl::VboMesh::create( 4, 6, layout, GL_TRIANGLES );
    
    mVboMesh->bufferPositions(positions);
    mVboMesh->bufferIndices(indices);
    
    mVboMesh->unbindBuffers();
    
    mCam.setPerspective(60, getWindowAspectRatio(), .1, 10000);
    mCam.lookAt( Vec3f(0,0,5), Vec3f(0,0,0), Vec3f::yAxis() );
    
    
}
Beispiel #7
0
void Day61App::setup()
{
    mCam.lookAt(vec3(0,15,15), vec3(0));
    mCam.setPerspective( 35.0f, 1.0f, 1.f, 1000.0f );
    
    setupGlsl();
    
    mUi = CameraUi(&mCam, getWindow());
    
    setFrameRate(30);
    
    auto scale = geom::Scale(2.,2.,2.);
    auto sphere = geom::Sphere().subdivisions(64);
    
    auto rot = geom::Rotate(angleAxis(toRadians(90.f),vec3(1.,0.,0.)));
    
    mBatch = gl::Batch::create(sphere >> geom::Scale(0.7,0.7,0.7), mGlsl);
    
    //CREATE A BATCH WITH A DEFAULT SHADER THAT WILL ACT AS THE DESTINATION COLOUR
    auto phong = gl::ShaderDef().lambert().color();
    auto shader = gl::getStockShader(phong);
    mSolidSphere = gl::Batch::create(sphere, shader);
    
    loadImage();
    
    mPointLights = {
        vec3( 3.0f,  0.f,   .0f),
        vec3( -3.f,  0.f,  3.0f),
        vec3( 0.f ,  1.f,    2.),
        vec3( 0.0f,  -3.0f,  0.f)
    };
    
    

    mPos = vec3(0.);
}
Beispiel #8
0
void ParamsBasicApp::setup()
{
    
    ObjLoader loader( (DataSourceRef)loadResource( "Final_sculpture3.obj" ) );
	loader.load( &mMesh );
    a = 1;
    e = 1;
    c = 1;
	mVBO = gl::VboMesh( mMesh );
    mMesh.recalculateNormals();
        mCameraDistance = 25;
    receiver.setup(3000);
	mObjSize = 4;
    mEye = Vec3f(-1,0.8f,1);
	mLightDirection = Vec3f( -0.54f, -0.27f, -1.07f );
	mColor = ColorA( 0.25f, 0.5f, 1.0f, 1.0f );
    mCam.setPerspective( 60.0f, getWindowAspectRatio(), 0.1f, 30000.0f );
	// setup our default camera, looking down the z-axis
	mCam.lookAt( mEye, Vec3f(0,0,0) );
    
	// Setup the parameters
	mParams = params::InterfaceGl::create( getWindow(), "App parameters", toPixels( Vec2i( 200, 400 ) ) );
	mParams->addParam( "Cube Size", &mObjSize, "min=0.1 max=20.5 step=0.5 keyIncr=z keyDecr=Z" );
	mParams->addParam( "Cube Rotation", &mObjOrientation );
	//mParams->addParam( "Cube Color", &mColor, "" );
	mParams->addSeparator();
	mParams->addParam( "Light Direction", &mLightDirection, "" );
	mParams->addButton( "Button!", std::bind( &ParamsBasicApp::button, this ) );
	mParams->addText( "text", "label=`This is a label without a parameter.`" );
	mParams->addParam( "String ", &mString, "" );
    mParams->addParam( "Eye Distance", &mCameraDistance, "min=1.0 max=100.0 step=1.0 keyIncr=s keyDecr=w" );
    
    
    
    
}
Beispiel #9
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();
}
void MarionetteZooApp::setupParams()
{
	mndl::params::PInterfaceGl::load( "params.xml" );

	mParams = mndl::params::PInterfaceGl( "Parameters", Vec2i( 230, 550 ), Vec2i( 50, 50 ) );
	mParams.addPersistentSizeAndPosition();

	mFps = 0;
	mParams.addParam( "Fps", &mFps, "", true );
	mParams.addSeparator();
	mParams.addText( "Camera" );
	mParams.addPersistentParam( "Lock camera (l)", &mCameraLock, false );
	mParams.addPersistentParam( "Fov", &mCameraFov, 45.f, "min=20 max=180 step=.1" );
	mParams.addPersistentParam( "Eye", &mCameraEyePoint, Vec3f( 0.0f, -20.0f, 0.0f ) );
	mParams.addPersistentParam( "Center of Interest", &mCameraCenterOfInterestPoint, Vec3f( 0.0f, 0.0f, 0.1f ) );
	mParams.addButton( "Reset camera", [ & ]()
			{
				mCameraCenterOfInterestPoint = Vec3f( 0.0f, 0.0f, 0.1f );
				mCameraFov = 45.f;
				mCameraEyePoint = Vec3f( 0.0f, -20.0f, 0.0f );

				CameraPersp cam = mMayaCam.getCamera();
				cam.setPerspective( mCameraFov, getWindowAspectRatio(), 0.1f, 1000.0f );
				cam.setEyePoint( mCameraEyePoint );
				cam.setCenterOfInterestPoint( mCameraCenterOfInterestPoint );
				mMayaCam.setCurrentCam( cam );
			} );
	mParams.addSeparator();

	mModelTypes = ModelFileManager::getSingleton().getModelTypes();
	mParams.addPersistentParam( "Model", mModelTypes, &mModelTypeId, 0 );
	if ( mModelTypeId > mModelTypes.size() )
		mModelTypeId = 0;

	mParams.addButton( "Test model", std::bind( &MarionetteZooApp::testModel, this ) );
}
Beispiel #11
0
void Day37bApp::update()
{
    lightPos.x = 1.f * cos(theta);
    lightPos.y = 1.f * sin(theta);
     lightPos.z = 1.f * cos(sin(theta)*2.f);
    
    theta += 0.0523;
    
    eyePos = mCam.getEyePoint();
    
    mGlsl->uniform("uLightPos", vec3( gl::getModelView() * lightPos));
    
    cout << lightPos << endl;
    
}
void kinectPointCloudApp::update()
{
	if( mKinect.checkNewDepthFrame() )
		mDepthTexture = mKinect.getDepthImage();
	
	// This sample does not use the color data
	//if( mKinect.checkNewVideoFrame() )
	//	mColorTexture = mKinect.getVideoImage();

	if( mKinectTilt != mKinect.getTilt() )
		mKinect.setTilt( mKinectTilt );
		
	mEye = Vec3f( 0.0f, 0.0f, mCameraDistance );
	mCam.lookAt( mEye, mCenter, mUp );
	gl::setMatrices( mCam );
}
void RodSoundApp::mouseDrag(MouseEvent event)
{
  if (!running) return;
  Vec2i mouse = event.getPos();
  Vec2i windowSize = getWindowSize();
  
  Ray r = cam.generateRay((real)mouse.x/windowSize.x,
                          1.0 - (real)mouse.y/windowSize.y,
                          getWindowAspectRatio());
  
  float t;
  if(!r.calcPlaneIntersection(targetPos, targetPos-eyePos, &t)) {
    std::cerr << "Mouse ray did not intersect plane!\n";
  }
  mousePosition = r.calcPosition(t);
}
void MatrixStudyApp::setup()
{
    // SETUP CAMERA
	mCameraDistance = 1200.0f;
	mEye			= Vec3f( 0.0f, 0.0f, mCameraDistance );
	mCenter			= Vec3f( 0.0f, 0.0f, 0.0f );
	mUp				= Vec3f::yAxis();
	mCam.setPerspective( 75.0f, getWindowAspectRatio(), 5.0f, 3000.0f );
    
    // CAMERA ROTATION
    xAngle = 0.0f;
    yAngle = 0.0f;
    zAngle = 0.0f;
    
    //PARAMS
    mParams = params::InterfaceGl( "Control Panel", Vec2i( 200, 160 ) );
    mParams.addParam( "Scene Rotation", &mSceneRotation );
    mParams.addParam( "Eye Distance", &mCameraDistance, "min=50.0 max=1500.0 step=50.0 keyIncr=s keyDecr=w" );
    mParams.addParam( "X Angle", &xAngle, "min=0.0 max=360.0 step=5.0 keyIncr=r keyDecr=f" );
    mParams.addParam( "Y Angle", &yAngle, "min=0.0 max=360.0 step=5.0 keyIncr=t keyDecr=g" );
    mParams.addParam( "Z Angle", &zAngle, "min=0.0 max=360.0 step=5.0 keyIncr=y keyDecr=h" );

    
    mDirectional = 1.0f;
    
    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
	
	gl::enableDepthWrite();
	gl::enableDepthRead();
	gl::enableAlphaBlending();
    
    glDisable( GL_TEXTURE_2D );
    
    
    // Set up coordinates
    
    mLocalStartPosition.set(100.0f, 100.0f, 0.0f);
    mLocalBasisRotation.set(20.0f, 30.0f, 45.0f);
    mLocalObjectRotation.set(0.0f, 30.0f, 60.0f);
    mLocalEndPosition.set( 0.0f, 300.0f, 0.0f); //I know what the local end position is because I'm drawing a cylinder of length 300. 
    
    mWorldEndPosition = getWorldEndPosition( mLocalStartPosition, mLocalBasisRotation, mLocalObjectRotation, mLocalEndPosition );
  
    mShowCube = true;
    
}
Beispiel #15
0
void TweakBarApp::setup()
{
	mObjSize = 4;
	mLightDirection = Vec3f( 0, 0, -1 );
	mColor = ColorA( 0.25f, 0.5f, 1.0f, 1.0f );

	// setup our default camera, looking down the z-axis
	mCam.lookAt( Vec3f( -20, 0, 0 ), Vec3f::zero() );

	// Setup the parameters
	mParams = params::InterfaceGl( "Parameters", Vec2i( 200, 400 ) );
	mParams.addParam( "Cube Size", &mObjSize, "min=0.1 max=20.5 step=0.5 keyIncr=z keyDecr=Z" );
	mParams.addParam( "Cube Rotation", &mObjOrientation );
	mParams.addParam( "Cube Color", &mColor, "" );	
	mParams.addSeparator();	
	mParams.addParam( "Light Direction", &mLightDirection, "" );
}
Beispiel #16
0
void ArcballTestApp::draw()
{
	CameraPersp &cam = ( mUsingCameraUi ) ? mDebugCam : mCam;
	gl::clear( Color( 0, 0.0f, 0.15f ) );
	gl::setMatrices( cam );

	// draw the earth
	gl::enableDepthRead();
	gl::enableDepthWrite();
	gl::translate( mEarthSphere.getCenter() );
	gl::rotate( mArcball.getQuat() );
	mEarthTex->bind();
	mEarth->draw();

	// draw constraint axis
	if( mArcball.isUsingConstraint() ) {
		gl::setMatrices( cam );
		gl::color( 1, 1, 0 );
		gl::translate( mEarthSphere.getCenter() );
		gl::rotate( glm::rotation( vec3( 0, 1, 0 ), mArcball.getConstraintAxis() ) );
		mConstraintAxis->draw();
	}

	gl::disableDepthRead();

	// draw from vector marker
	gl::setMatrices( cam );
	gl::color( 0, 1, 0.25f );
	gl::translate( mEarthSphere.getCenter() + mArcball.getFromVector() * mEarthSphere.getRadius() );
	mMarker->draw();

	// draw to vector marker
	gl::setMatrices( cam );
	gl::color( 1, 0.5f, 0.25f );
	gl::translate( mEarthSphere.getCenter() + mArcball.getToVector() * mEarthSphere.getRadius() );
	mMarker->draw();

	// draw the elliptical axes
	gl::setMatricesWindow( getWindowSize() );
	gl::color( 1, 0, 0 );
	vec2 center, axisA, axisB;
	mCam.calcScreenProjection( mEarthSphere, getWindowSize(), &center, &axisA, &axisB );
	gl::drawLine( center - axisA, center + axisA );
	gl::drawLine( center - axisB, center + axisB );
}
void TutorialApp::update()
{

    // Stop repulsing for now.
	//mParticleController.repulseParticles();

    // UPDATE CAMERA
	mEye = Vec3f( 0.0f, 0.0f, mCameraDistance );
	mCam.lookAt( mEye, mCenter, mUp );
	gl::setMatrices( mCam );
	gl::rotate( mSceneRotation );
	
	// UPDATE PARTICLE CONTROLLER
    mParticleController.applyForce( mZoneRadius * mZoneRadius, mThresh );    
	if( mCentralGravity ) mParticleController.pullToCenter( mCenter );
    
	mParticleController.update( mFlatten );
}
Beispiel #18
0
void TextureTestApp::setup()
{
  // assetフォルダから画像を読み込む
  // 幅と高さは2のべき乗でなくてもよい
  image = loadImage(loadAsset("imagesFH4XK5GD.jpg"));

  // 平行光源を1つ用意
  light = std::unique_ptr<gl::Light>(new gl::Light(gl::Light::DIRECTIONAL, 0));
  light->setAmbient(Color(0.0, 0.0, 0.0));
  light->setDiffuse(Color(1.0, 1.0, 1.0));
  light->setDirection(Vec3f(0.0, 0.0, 1.0));

  // カメラの準備
  camera = CameraPersp(getWindowWidth(), getWindowHeight(),
                       35.0, 0.5, 1000.0);

  camera.lookAt(Vec3f(0.0, 0.0, 700.0),
                Vec3f(0.0, 0.0, 0.0));

 
  // テクスチャON
  gl::enable(GL_TEXTURE_2D);
 
  // カリングON
  gl::enable(GL_CULL_FACE);

  // gl::color or 頂点カラーを対象にしてライティングの計算を行う
  gl::enable(GL_COLOR_MATERIAL);
  
  // ライティングON
  gl::enable(GL_LIGHTING);
  // 法線を正規化する
  gl::enable(GL_NORMALIZE);

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


  // ブレンディングゆうこう
  gl::enableAlphaBlending(true);


  rx = ry = rz = 0.0;
}
Beispiel #19
0
void cApp::setup(){
    
    setWindowPos( 0, 0 );
    setWindowSize( mW*0.5, mH*0.5 );
    mExp.setup( mW*mScale, mH*mScale,0, 2999, GL_RGB, mt::getRenderPath() );
    
    mPln.setOctaves(4);
    mPln.setSeed(1332);

    randSeed( mt::getSeed() );
    
    int count = 0;
    for( int i=0; i<100; i++){
        StrangeAgent sa;
        sa.setRandom();
        mSAs.push_back( sa );

        for(int j=0; j<sa.points.size(); j++){
            mPlnPts.push_back( Vec3f(count*scale,0,0) );
            count++;
        }
    }
    
    total = count;
    
    if( 1 ){
        CameraPersp cam;
        cam.setNearClip(0.1);
        cam.setFarClip(1000000);
        cam.setFov(60);
        cam.setEyePoint( Vec3f(0,0,-30 ) );
        cam.setCenterOfInterestPoint( Vec3f(0,0,0) );
        cam.setAspectRatio( (float)mW/mH );
        mCamUi.setCurrentCam(cam);
    }else{
        ortho.setNearClip(0.1);
        ortho.setFarClip(1000000);
        ortho.setEyePoint( Vec3f(0,0,-7 ) );
        ortho.setCenterOfInterestPoint( Vec3f(0,0,0) );
        ortho.setAspectRatio( (float)mW/mH );
    }
    
#ifdef RENDER
    mExp.startRender();
#endif
}
Beispiel #20
0
void FlockingApp::setup()
{	
	Rand::randomize();
	
	mCenter			= Vec3f( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, 0.0f );
	mCentralGravity = true;
	mFlatten		= false;
	mSaveFrames		= false;
	mIsRenderingPrint = false;
	mZoneRadius		= 80.0f;
	mLowerThresh	= 0.5f;
	mHigherThresh	= 0.8f;
	mAttractStrength	= 0.004f;
	mRepelStrength		= 0.01f;
	mOrientStrength		= 0.01f;
	
	// SETUP CAMERA
	mCameraDistance = 350.0f;
	mEye			= Vec3f( 0.0f, 0.0f, mCameraDistance );
	mCenter			= Vec3f::zero();
	mUp				= Vec3f::yAxis();
	mCam.setPerspective( 75.0f, getWindowAspectRatio(), 5.0f, 5000.0f );

	// SETUP PARAMS
	mParams = params::InterfaceGl( "Flocking", Vec2i( 200, 310 ) );
	mParams.addParam( "Scene Rotation", &mSceneRotation, "opened=1" );
	mParams.addSeparator();
	mParams.addParam( "Eye Distance", &mCameraDistance, "min=100.0 max=2000.0 step=50.0 keyIncr=s keyDecr=w" );
	mParams.addParam( "Center Gravity", &mCentralGravity, "keyIncr=g" );
	mParams.addParam( "Flatten", &mFlatten, "keyIncr=f" );
	mParams.addSeparator();
	mParams.addParam( "Zone Radius", &mZoneRadius, "min=10.0 max=100.0 step=1.0 keyIncr=z keyDecr=Z" );
	mParams.addParam( "Lower Thresh", &mLowerThresh, "min=0.025 max=1.0 step=0.025 keyIncr=l keyDecr=L" );
	mParams.addParam( "Higher Thresh", &mHigherThresh, "min=0.025 max=1.0 step=0.025 keyIncr=h keyDecr=H" );
	mParams.addSeparator();
	mParams.addParam( "Attract Strength", &mAttractStrength, "min=0.001 max=0.1 step=0.001 keyIncr=a keyDecr=A" );
	mParams.addParam( "Repel Strength", &mRepelStrength, "min=0.001 max=0.1 step=0.001 keyIncr=r keyDecr=R" );
	mParams.addParam( "Orient Strength", &mOrientStrength, "min=0.001 max=0.1 step=0.001 keyIncr=o keyDecr=O" );
	
	// CREATE PARTICLE CONTROLLER
	mParticleController.addParticles( NUM_INITIAL_PARTICLES );
	mParticleController.addPredators( NUM_INITIAL_PREDATORS );
}
Beispiel #21
0
void ObjLoaderApp::setup()
{
#if defined( CINDER_GL_ES )
    mGlsl = gl::GlslProg::create( loadAsset( "shader_es2.vert" ), loadAsset( "shader_es2.frag" ) );
#else
    mGlsl = gl::GlslProg::create( loadAsset( "shader.vert" ), loadAsset( "shader.frag" ) );
#endif
    mGlsl->uniform( "uTex0", 0 );

    mCam.setPerspective( 45.0f, getWindowAspectRatio(), 0.1, 10000 );
    mCamUi = CameraUi( &mCam );

    mCheckerTexture = gl::Texture::create( ip::checkerboard( 512, 512, 32 ) );
    mCheckerTexture->bind( 0 );

    loadObj( loadResource( RES_8LBS_OBJ ) );

    mArcball = Arcball( &mCam, mBoundingSphere );
}
void PostProcessingAAApp::resize()
{
	gl::Texture2d::Format tfmt;
	tfmt.setMinFilter( GL_NEAREST );
	tfmt.setMagFilter( GL_NEAREST );
	tfmt.setInternalFormat( GL_RGBA8 );

	gl::Fbo::Format fmt;
	fmt.setColorTextureFormat( tfmt );

	mFboScene = gl::Fbo::create( getWindowWidth() / mPixelSize, getWindowHeight() / mPixelSize, fmt );
	mFboFinal = gl::Fbo::create( getWindowWidth() / mPixelSize, getWindowHeight() / mPixelSize, fmt );

	// Update the camera's aspect ratio.
	mCamera.setAspectRatio( getWindowAspectRatio() );

	// Resize the divider.
	mDividerWidth = getWindowWidth() / 4;
}
void DeferredRenderingApp::drawOverlay() const
{
    Vec3f camUp, camRight;
    mCam.getBillboardVectors(&camRight, &camUp);
    
    //create text labels
    TextLayout layout1;
	layout1.clear( ColorA( 1.0f, 1.0f, 1.0f, 0.0f ) );
	layout1.setFont( Font( "Arial", 34 ) );
	layout1.setColor( ColorA( 255.0f/255.0f, 255.0f/255.0f, 8.0f/255.0f, 1.0f ) );
	layout1.addLine( to_string(getAverageFps()) ); //to_string is a c++11 function for conversions
	Surface8u rendered1 = layout1.render( true, false );
    gl::Texture fontTexture_FR = gl::Texture( rendered1 );
    
    //draw framerate
    fontTexture_FR.bind();
    gl::drawBillboard(Vec3f(-3.0f, 7.0f, 20.0f), Vec2f(fontTexture_FR.getWidth()/20.0f , fontTexture_FR.getHeight()/20.0f), 0, camRight, camUp);
    fontTexture_FR.unbind();
}
void InstancedTeapotsApp::setup()
{
	mCam.lookAt( vec3( 0, CAMERA_Y_RANGE.first, 0 ), vec3( 0 ) );
	
	mTexture = gl::Texture::create( loadImage( loadAsset( "texture.jpg" ) ), gl::Texture::Format().mipmap() );
#if ! defined( CINDER_GL_ES )
	mGlsl = gl::GlslProg::create( loadAsset( "shader.vert" ), loadAsset( "shader.frag" ) );
#elif defined( CINDER_GL_ES_3 )
	mGlsl = gl::GlslProg::create(loadAsset("shader_es3.vert"), loadAsset("shader_es3.frag"));
#else
	mGlsl = gl::GlslProg::create( loadAsset( "shader_es2.vert" ), loadAsset( "shader_es2.frag" ) );
#endif

	gl::VboMeshRef mesh = gl::VboMesh::create( geom::Teapot().subdivisions( 4 ) );

	// create an array of initial per-instance positions laid out in a 2D grid
	std::vector<vec3> positions;
	for( size_t potX = 0; potX < NUM_INSTANCES_X; ++potX ) {
		for( size_t potY = 0; potY < NUM_INSTANCES_Y; ++potY ) {
			float instanceX = potX / (float)NUM_INSTANCES_X - 0.5f;
			float instanceY = potY / (float)NUM_INSTANCES_Y - 0.5f;
			positions.push_back( vec3( instanceX * vec3( DRAW_SCALE, 0, 0 ) + instanceY * vec3( 0, 0, DRAW_SCALE ) ) );
		}
	}
	
	// create the VBO which will contain per-instance (rather than per-vertex) data
	mInstanceDataVbo = gl::Vbo::create( GL_ARRAY_BUFFER, positions.size() * sizeof(vec3), positions.data(), GL_DYNAMIC_DRAW );

	// we need a geom::BufferLayout to describe this data as mapping to the CUSTOM_0 semantic, and the 1 (rather than 0) as the last param indicates per-instance (rather than per-vertex)
	geom::BufferLayout instanceDataLayout;
	instanceDataLayout.append( geom::Attrib::CUSTOM_0, 3, 0, 0, 1 /* per instance */ );
	
	// now add it to the VboMesh we already made of the Teapot
	mesh->appendVbo( instanceDataLayout, mInstanceDataVbo );

	// and finally, build our batch, mapping our CUSTOM_0 attribute to the "vInstancePosition" GLSL vertex attribute
	mBatch = gl::Batch::create( mesh, mGlsl, { { geom::Attrib::CUSTOM_0, "vInstancePosition" } } );

	gl::enableDepthWrite();
	gl::enableDepthRead();
	
	mTexture->bind();	
}
void GeoDeVisualizerApp::setup()
{
    // read the initial world
    json initJSON;
    if (!debug) {
        string JSONBuff;
        if (mServer.open(DEFAULT_PORT, "localhost")) {
            while (!mServer.isReady(JSONBuff)) {};
        }
        initJSON = json::parse(JSONBuff);
    } else {
        ifstream inputFile( "../../../resources/test_data.json" );
        assert( inputFile.good() );
        string JSONBuff(( istreambuf_iterator<char>( inputFile )), ( istreambuf_iterator<char>() ));
        initJSON = json::parse(JSONBuff);
    }
    
    if (!(isInitialJSON(initJSON) and validateInitialJSON(initJSON))) {
        cerr << "Initial JSON was not valid" << endl;
        exit(1);
    }
    
    // WRITE VERTICES AND FACES TO THE TRIMESH
    writeMesh(initJSON);
    mWorld.initialize(initJSON);
    setupColoniesList();
    resourceColors = ResourceColorPicker().getColors(mWorld.numResources());
    

    // SETUP CAMERA
    setupCamVars(mCamVars);
    mCam.setPerspective(75.0f, getWindowAspectRatio(), 0.5f, 2000.0f );
    
    // SETUP PARAMS
    setupParamVars(mCurParams, mPrevParams, mWorld.numResources());
    mParams = params::InterfaceGl::create("GeoDe", Vec2i(200, 400));
    mParams->addParam("scene rotation", &mCamVars.sceneRotation, "opened=1");
    mParams->addParam("eye distance", &mCamVars.cameraDistance, "min=1.0 max=1500.0 step=0.1 keyIncr=s keyDecr=k keyIncr=j");
    mParams->addSeparator();
    mParams->addParam("time", &mCurParams.timeStep);
    mParams->addParam("state", mDisplayModes, &mCurParams.displayMode);
    mParams->addSeparator();
}
Beispiel #26
0
void SplatTestApp::update() {
  if (spaceNav) {
    spaceNav->update();
  }

  {
    const auto &ori = cameraBody.orientation;
    cameraBody.impulse = glm::rotate(ori, cameraTranslation * vec3(1, 1, -1)) * 0.000005f;
    cameraBody.angularImpulse = quat(cameraRotation * vec3(1, 1, -1) * 0.00000333f);
  }

  cameraBody.step();
  cameraBody.applyTransform(camera);

  particleSys->update(getElapsedSeconds(), getElapsedFrames(), cameraBody.position,
                      cameraBody.position - cameraBody.positionPrev, camera.getViewDirection());

  updateGui();
}
Beispiel #27
0
void Day5App::setup()
{
    auto lambert = gl::ShaderDef().lambert().color();
    gl::GlslProgRef shader = gl::getStockShader(lambert);
    
    for (int i = 0; i < NUM_SLICES; i++)
    {
        float rel = i / (float)NUM_SLICES;
        float sliceWidth = 2.0f / NUM_SLICES;
        
        auto slice = geom::Cube().size(sliceWidth,1,1);
        auto trans = geom::Translate(rel,0,0);
        auto color = geom::Constant(geom::COLOR, Color(CM_HSV, 0, 0, 1 ));
        mSlices[i] = gl::Batch::create( slice >> trans >> color, shader);
    }
    
    mCam.lookAt( vec3(2,3,2), vec3(0, 0, 0));
    
    setFrameRate(30);
}
void InstancedTeapotsApp::update()
{
	// move the camera up and down on Y
	mCam.lookAt( vec3( 0, CAMERA_Y_RANGE.first + abs(sin( getElapsedSeconds() / 4)) * (CAMERA_Y_RANGE.second - CAMERA_Y_RANGE.first), 0 ), vec3( 0 ) );
	
	// update our instance positions; map our instance data VBO, write new positions, unmap
	vec3 *positions = (vec3*)mInstanceDataVbo->mapWriteOnly( true );
	for( size_t potX = 0; potX < NUM_INSTANCES_X; ++potX ) {
		for( size_t potY = 0; potY < NUM_INSTANCES_Y; ++potY ) {
			float instanceX = potX / (float)NUM_INSTANCES_X - 0.5f;
			float instanceY = potY / (float)NUM_INSTANCES_Y - 0.5f;
			// just some nonsense math to move the teapots in a wave
			vec3 newPos(	instanceX * vec3( DRAW_SCALE, 0, 0 ) +
							instanceY * vec3( 0, 0, DRAW_SCALE ) +
							vec3( 0, 30, 0 ) * sinf( getElapsedSeconds() * 3 + instanceX * 3 + instanceY * 3 ) );
			*positions++ = newPos;
		}
	}
	mInstanceDataVbo->unmap();
}
void TutorialApp::setup()
{	

	mCentralGravity = true;
    mFlatten        = true; //makes it easy to see the effects in 2D...while we are experimenting
	mZoneRadius		= 65.0f;
    mThresh         = 0.65f;
    
    //define the camera
    mCameraDistance = 500.0f;
    mEye    = Vec3f( 0.0f, 0.0f, mCameraDistance ); //position of the camera
    mCenter = Vec3f::zero(); //the location in 3D space that the camera points at
    mUp     = Vec3f::yAxis(); //the camera's up direction

    // Takes four parameters:
    // (1) foV : the smaller the number the tighter the fustrum (usually between 60.0 and 90.0)
    // (2) aspect ratio of the application window
    // (3) near clipping plane
    // (4) far clipping plane
    mCam.setPerspective( 75.0f, getWindowAspectRatio(), 50.0f, 2000.0f ); 
    
    
    // Initialize the Params object
    mParams = params::InterfaceGl( "Flocking", Vec2i( 200, 240 ) );
    // We tell Params that we want it control the mSceneRotation variable...during runtime!
    // It expects the addr in memory of the variable...that's what & is.
    // So, it will include an arc-ball in the scene.
    mParams.addParam( "Scene Rotation", &mSceneRotation, "opened=1" );
    mParams.addSeparator();
    mParams.addParam( "Eye Distance", &mCameraDistance, "min=50.0 max=1500.0 step=50.0 keyIncr=s keyDecr=w" );
    mParams.addParam( "Center Gravity", &mCentralGravity, "keyIncr=g" );
	mParams.addParam( "Flatten", &mFlatten, "keyIncr=f" );
	mParams.addSeparator();
	mParams.addParam( "Zone Radius", &mZoneRadius, "min=10.0 max=100.0 step=1.0 keyIncr=z keyDecr=Z" );
	mParams.addParam( "Thresh", &mThresh, "min=0.025 max=1.0 step=0.025 keyIncr=t keyDecr=T" );    
    
    // CREATE PARTICLE CONTROLLER
	mParticleController.addParticles( NUM_INITIAL_PARTICLES );

    
}
Beispiel #30
0
void VboSampleApp::setup()
{
    mCamera.setAspectRatio(getWindowAspectRatio());

    mTexture = bluegin::getTextureAsset("cinder_logo.png");
    mTexture.setMinFilter(GL_LINEAR);
    mTexture.setMagFilter(GL_LINEAR);

	gl::VboMesh::Layout layout;
	layout.setStaticIndices();
	layout.setStaticPositions();
    layout.setStaticTexCoords2d();

    const int vertexCount = 4;
    const int indexCount  = 6;

	mVboMesh = gl::VboMesh( vertexCount, indexCount, layout, GL_TRIANGLES );

    vector<Vec3f> positions;
    positions.push_back(Vec3f(-1.0f, 1.0f, 0));
    positions.push_back(Vec3f(-1.0f, -1.0f, 0));
    positions.push_back(Vec3f(1.0f, -1.0f, 0));
    positions.push_back(Vec3f(1.0f, 1.0f, 0));
    mVboMesh.bufferPositions(positions);

    vector<Vec2f> texcoords;
    texcoords.push_back(Vec2f(0, 0));
    texcoords.push_back(Vec2f(0, 1.0f));
    texcoords.push_back(Vec2f(1.0f, 1.0f));
    texcoords.push_back(Vec2f(1.0f, 0));
    mVboMesh.bufferTexCoords2d(0, texcoords);

    vector<index_t> indices;
    indices.push_back(index_t(0));
    indices.push_back(index_t(1));
    indices.push_back(index_t(2));
    indices.push_back(index_t(2));
    indices.push_back(index_t(3));
    indices.push_back(index_t(0));
    mVboMesh.bufferIndices(indices);
}