Exemplo n.º 1
0
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();
}
/* 
 * @Description: render scene to FBO texture
 * @param: none
 * @return: none
 */
void Base_ThreeD_ProjectApp::renderSceneToFBO()
{
	mScreenSpace1.bindFramebuffer();
    
	glClearColor( 0.5f, 0.5f, 0.5f, 1 );
	glClearDepth(1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	if (mLightingOn)
		glDisable(GL_LIGHTING);
	glColor3f( 1.0f, 1.0f, 0.1f );
	gl::drawFrustum( mLightRef->getShadowCamera() );
	glColor3f( 1.0f, 1.0f, 1.0f );
	if (mLightingOn)
		glEnable(GL_LIGHTING);
	
	mEye = mCam->getEyePoint();
	mEye.normalize();
	mEye = mEye * abs(mCameraDistance);
	mCam->lookAt( mEye, mCenter, mUp );
	gl::setMatrices( *mCam );
	mLight->update( *mCam );
	
	drawTestObjects();
	
	mScreenSpace1.unbindFramebuffer();
	
	glDisable(GL_LIGHTING);
}
Exemplo n.º 3
0
void MemExploreApp::draw()
{
  mTexture = gl::Texture(mDataPointer, GL_RGBA, mVolumeDim * mTilesDim, mVolumeDim * mTilesDim);
  mTexture.setWrap(GL_REPEAT, GL_REPEAT);
  mTexture.setMinFilter(GL_NEAREST);
  mTexture.setMagFilter(GL_NEAREST);
  
  float frustum[6];
  mCamera.getFrustum(&frustum[0], &frustum[1], &frustum[2], &frustum[3], &frustum[4], &frustum[5]);

  mFbo.bindFramebuffer();
  gl::setMatricesWindow(mFbo.getSize(), false);

  mProgram.bind();
  mProgram.uniform("uTexture", 0);
  mProgram.uniform("uVolumeDim", mVolumeDim);
  mProgram.uniform("uTilesDim", mTilesDim);
  mProgram.uniform("uTime", (float)getElapsedSeconds());
  mProgram.uniform("uEyePoint", mCamera.getEyePoint());
  mProgram.uniform("uXAxis", mCamera.getOrientation() * Vec3f::xAxis());
  mProgram.uniform("uYAxis", mCamera.getOrientation() * Vec3f::yAxis());
  mProgram.uniform("uViewDistance", mCamera.getAspectRatio() / abs(frustum[2] - frustum[0]) * mCamera.getNearClip());
  mProgram.uniform("uNegViewDir", -mCamera.getViewDirection().normalized());
  mProgram.uniform("uAspectRatio", mCamera.getAspectRatio());
  mTexture.enableAndBind();
  gl::drawSolidRect(mFbo.getBounds());
  mTexture.unbind();
  mProgram.unbind();
  
  mFbo.unbindFramebuffer();
  
  gl::setMatricesWindow(getWindowSize());
  gl::draw(mFbo.getTexture(), getWindowBounds());
}
Exemplo n.º 4
0
void Day41App::update()
{
    lightPos.x = (1.5f * cos(theta)) - 0.5;
    lightPos.y = 2+ 1.5f * sin(theta);
    lightPos.z = 1.5f;// * sin(theta*2);

    theta += 0.0523;

    eyePos = mCam.getEyePoint();

    mGlsl->uniform("light.position", vec3(mCam.getViewMatrix() * vec4(lightPos, 1.0f)));
    mGlsl->uniform("viewPos",  vec3(mCam.getViewMatrix() * vec4(eyePos, 1.0f)));

    vec3 lightColor = vec3(1.f);

    vec3 diffuseColor = lightColor * vec3(0.9f);
    vec3 ambientColor = diffuseColor * vec3(0.5f);

    mGlsl->uniform("light.diffuse", diffuseColor);
    mGlsl->uniform("light.specular", vec3(1.f));

    mGlsl->uniform("material.ambient", vec3(1.0f, 0.5f, 0.31f));
    mGlsl->uniform("material.diffuse", 0); //pass the diffuse map texture to shader
    mGlsl->uniform("material.specular", 1); //pass the specular map texture to the shader
    mGlsl->uniform("material.shininess", 32.f);


}
Exemplo n.º 5
0
void Choreo3DApp::updateRibbons()
{
    auto easing = 1.0f;
    int i = 0;
    for (auto &r:ribbons)
    {
        auto target = framePositions[i];
        const auto no_data_value = -123456;
        if (glm::all(glm::greaterThan(target, vec3(no_data_value))))
        {
            r._target = target;
        }
        
        auto &points = r._spine;
        for (auto i = points.size() - 1; i > 0; i -= 1)
        {
            auto &p1 = points.at(i);
            auto &p2 = points.at(i - 1);
            p1 += (p2 - p1) * easing;
        }
        auto &point = points.at(0);
        point += (r._target - point) * easing;
        i++;
    }
    
    for (auto &r: ribbons)
    {
        r._triangles = sansumbrella::createRibbon(20.0f, ci::EaseInOutQuad(), mCamera.getEyePoint(), r._spine);
    }
    
    //  _camera.lookAt(currentJointPosition(0));
}
Exemplo n.º 6
0
void MemExploreApp::update()
{
  Vec2f center = getWindowCenter();

  mCameraArcball.resetQuat();
  mCameraArcball.mouseDown(center);
  mCameraArcball.mouseDrag(getWindowSize() - mMousePos);
  mCamera.setOrientation(mCameraArcball.getQuat() * mCamera.getOrientation());

  // Reset mouse position to center of screen
  if(mIsFullscreen) {
    Vec2f center = getWindowCenter();
    CGSetLocalEventsSuppressionInterval(0.0);
    CGWarpMouseCursorPosition(CGPointMake(center.x, center.y));
    mMousePos = center;
  }

  float speed = 0.01f;
  Vec3f camX = mCamera.getOrientation() * Vec3f::xAxis() * speed;
  Vec3f camY = mCamera.getOrientation() * Vec3f::yAxis() * speed;
  Vec3f camZ = mCamera.getOrientation() * Vec3f::zAxis() * speed;
  
  if(mKeysDown.count('w')) mCameraAcc -= camZ;
  if(mKeysDown.count('a')) mCameraAcc -= camX;
  if(mKeysDown.count('s')) mCameraAcc += camZ;
  if(mKeysDown.count('d')) mCameraAcc += camX;
  if(mKeysDown.count('q')) mCameraAcc += camY;
  if(mKeysDown.count('e')) mCameraAcc -= camY;

  mCameraVel += mCameraAcc;
  mCamera.setEyePoint(mCamera.getEyePoint() + mCameraVel);
  mCameraVel *= 0.975f;
  mCameraAcc *= 0.8f;
}
Exemplo n.º 7
0
void PTWeekend::draw()
{
    /*
     * BEGIN - each frame part
     */
    
    /* Enqueue kernel for execution */
    
    glm::vec3 origin,lower_left, hor, ver;
    
    float theta = camera.getFov() * M_PI / 180.0f;
    float half_height = tan(theta / 2.0f);
    float half_width = camera.getAspectRatio() * half_height;
    
    origin = camera.getEyePoint();
    glm::vec3 u, v, w;
    
    w = -glm::normalize(camera.getViewDirection()); //odd...
    u = glm::normalize(glm::cross(glm::vec3(0,1,0), w));
    v = glm::cross(w, u);
    
    lower_left = origin - half_width * u - half_height * v - w;
    hor = 2.0f * half_width * u;
    ver = 2.0f * half_height * v;
    
    pt_assert(cl_set_pinhole_cam_arg(origin, lower_left, hor, ver, cam_buffer, cmd_queue), "Could not fill camera buffer");
    
    clStatus = cmd_queue.enqueueAcquireGLObjects(&img_buffer, NULL, NULL);
    pt_assert(clStatus, "Could not acquire gl objects");
    
    cl::Event profiling_evt;
    
    
    
    clStatus = cmd_queue.enqueueNDRangeKernel(kernel,
                                              cl::NDRange(0,0),
                                              cl::NDRange(img_width, img_height),
                                              cl::NDRange(local_width,local_height),
                                              NULL,
                                              &profiling_evt);
    profiling_evt.wait();
    
    pt_assert(clStatus, "Could not enqueue the kernel");
    clStatus = cmd_queue.enqueueReleaseGLObjects(&img_buffer, NULL, NULL);
    pt_assert(clStatus, "Could not release gl objects");
    cmd_queue.finish();
    
    cl_ulong time_start = profiling_evt.getProfilingInfo<CL_PROFILING_COMMAND_START>();
    cl_ulong time_end = profiling_evt.getProfilingInfo<CL_PROFILING_COMMAND_END>();
    cl_ulong total_time = time_end - time_start;
    std::cout << "Total time: " << total_time * 0.001 * 0.001 << " ms \n";
    
    /*
     * END - each frame part
     */
    
    gl::draw(imgTex, Rectf(0, 0, getWindowWidth(), getWindowHeight()));
}
Exemplo n.º 8
0
void Day62App::update()
{
    //INCREASE ANGLE OF ROTATION
    theta += 0.0523;
    
    //SORT THE WINDOWS BASED ON THEIR DISTANCE FROM THE CAMERA AND PLACE THEM INTO THE MAP, USING THE DISTANCE AS THE INDEX (WILL BE SORTED AUTOMATICALLY BASED ON SIZE)
    for (int i = 0; i < mPositions.size(); i++)
    {
        GLfloat distance = glm::length(mCam.getEyePoint() - mPositions[i]);
        sorted[distance] = mPositions[i];
    }
}
Exemplo n.º 9
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 AudioVisualizerApp::update()
{
	// update FMOD so it can notify us of events
	mFMODSystem->update();

	// handle signal: if audio has ended, play next file
	if(mIsAudioPlaying && signalChannelEnd)
		playAudio( nextAudio( mAudioPath ) );

	// reset FMOD signals
	signalChannelEnd= false;

	// get spectrum for left and right channels and copy it into our channels
	float* pDataLeft = mChannelLeft.getData() + kBands * mOffset;
	float* pDataRight = mChannelRight.getData() + kBands * mOffset;

	mFMODSystem->getSpectrum( pDataLeft, kBands, 0, FMOD_DSP_FFT_WINDOW_HANNING );	
	mFMODSystem->getSpectrum( pDataRight, kBands, 1, FMOD_DSP_FFT_WINDOW_HANNING );

	// increment texture offset
	mOffset = (mOffset+1) % kHistory;

	// clear the spectrum for this row to avoid old data from showing up
	pDataLeft = mChannelLeft.getData() + kBands * mOffset;
	pDataRight = mChannelRight.getData() + kBands * mOffset;
	memset( pDataLeft, 0, kBands * sizeof(float) );
	memset( pDataRight, 0, kBands * sizeof(float) );

	// animate camera if mouse has not been down for more than 30 seconds
	if(!mIsMouseDown && (getElapsedSeconds() - mMouseUpTime) > mMouseUpDelay)
	{
		float t = float( getElapsedSeconds() );
		float x = 0.5f + 0.5f * math<float>::cos( t * 0.07f );
		float y = 0.1f - 0.2f * math<float>::sin( t * 0.09f );
		float z = 0.25f * math<float>::sin( t * 0.05f ) - 0.25f;
		Vec3f eye = Vec3f(kWidth * x, kHeight * y, kHeight * z);

		x = 1.0f - x;
		y = -0.3f;
		z = 0.6f + 0.2f *  math<float>::sin( t * 0.12f );
		Vec3f interest = Vec3f(kWidth * x, kHeight * y, kHeight * z);

		// gradually move to eye position and center of interest
		mCamera.setEyePoint( eye.lerp(0.995f, mCamera.getEyePoint()) );
		mCamera.setCenterOfInterestPoint( interest.lerp(0.990f, mCamera.getCenterOfInterestPoint()) );
	}
}
Exemplo n.º 11
0
void GeometryApp::update()
{
	// If another primitive or quality was selected, reset the subdivision and recreate the primitive.
	if( mPrimitiveCurrent != mPrimitiveSelected || mQualitySelected != mQualityCurrent ) {
		mPrimitiveCurrent = mPrimitiveSelected;
		mQualityCurrent = mQualitySelected;
		createGeometry();
	}

	// After creating a new primitive, gradually move the camera to get a good view.
	if( mRecenterCamera ) {
		float distance = glm::distance( mCamera.getEyePoint(), mCameraLerpTarget );
		vec3 eye = mCameraLerpTarget - lerp( distance, 5.0f, 0.25f ) * mCameraViewDirection;
		mCameraTarget = lerp( mCameraTarget, mCameraLerpTarget, 0.25f );
		mCamera.lookAt( eye, mCameraTarget );
	}
}
Exemplo n.º 12
0
void GeometryApp::update()
{
	// If another primitive or quality was selected, reset the subdivision and recreate the primitive.
	if( mPrimitiveCurrent != mPrimitiveSelected || mQualitySelected != mQualityCurrent ) {
		mSubdivision = 1;
		mPrimitiveCurrent = mPrimitiveSelected;
		mQualityCurrent = mQualitySelected;
		createGeometry();
	}

	// After creating a new primitive, gradually move the camera to get a good view.
	if( mRecenterCamera ) {
		float distance = glm::distance( mCamera.getEyePoint(), mCameraCOI );
		mCamera.setEyePoint( mCameraCOI - lerp( distance, 5.0f, 0.1f ) * mCamera.getViewDirection() );
		mCamera.setCenterOfInterestPoint( lerp( mCamera.getCenterOfInterestPoint(), mCameraCOI, 0.25f) );
	}
}
Exemplo n.º 13
0
void Day44App::update()
{
    lightPos.x = 8.f * cos(theta);
    lightPos.y = 8.f * sin(theta);
    lightPos.z = 2.f * sin(theta * 2);
    
    theta += 0.0523;
    
    eyePos = mCam.getEyePoint();
    
    //VERY NB! CONVERT THE LIGHT'S POSITION TO VIEW SPACE BEFORE SENDING IT TO THE GPU, THIS IS BECAUSE ALL THE CALCULATIONS IN THE SHADERS ARE HAPPENING IN VIEW SPACE!
    
    mGlsl->uniform("uLightPos", vec3( mCam.getViewMatrix() * vec4( lightPos, 1 )));
    mGlsl->uniform("uConstant", 1.f);
    mGlsl->uniform("uLinear", 0.09f);
    mGlsl->uniform("uQuatratic", 0.01f);
    
    cout << lightPos << endl;
    
}
void EnvironmentTestApp::update() {
  getWindow()->setTitle(to_string((int)getAverageFps()));
  
  mDistance += (mDistanceTarget - mDistance) * 0.036f;
  
  mCamTarget = vec3(sin(mMousePos.x * 0.005), 0, cos(mMousePos.x * 0.005));
  mCamTarget *= mDistance;
  mCamTarget.y = mMousePos.y * 0.005;
  
  vec3 cameraPos = mCam.getEyePoint();
  cameraPos += (mCamTarget - cameraPos) * 0.036f;
#ifdef ENABLE_DOF
  cameraPos = normalize(cameraPos) * 2.0f;
#else
  cameraPos = normalize(cameraPos) * mDistance;
#endif
  mCam.lookAt(cameraPos, vec3(0));
  
#ifdef ENABLE_DOF
  mDOFFilter->setManualFocalDepth(mFocalDepth);
#endif
}
Exemplo n.º 15
0
CameraPersp	CameraPersp::getFrameSphere( const Sphere &worldSpaceSphere, int maxIterations ) const
{
	CameraPersp result = *this;
	result.setEyePoint( worldSpaceSphere.getCenter() - result.mViewDirection * getCenterOfInterest() );
	
	float minDistance = 0.01f, maxDistance = 100000.0f;
	float curDistance = getCenterOfInterest();
	for( int i = 0; i < maxIterations; ++i ) {
		float curRadius = result.getScreenRadius( worldSpaceSphere, 2.0f, 2.0f );
		if( curRadius < 1.0f ) { // we should get closer
			maxDistance = curDistance;
			curDistance = ( curDistance + minDistance ) * 0.5f;
		}
		else { // we should get farther
			minDistance = curDistance;
			curDistance = ( curDistance + maxDistance ) * 0.5f;			
		}
		result.setEyePoint( worldSpaceSphere.getCenter() - result.mViewDirection * curDistance );
	}
	
	result.setCenterOfInterest( result.getEyePoint().distance( worldSpaceSphere.getCenter() ) );
	return result;
}
Exemplo n.º 16
0
// dependent on a change in parameters, write new colors to the TriMesh
void GeoDeVisualizerApp::writeColors()
{
    mTriangles.getColorsRGB().clear();
    vector<Color> colors;
    colors.reserve(mTriangles.getNumTriangles());
    
    DisplayMode mode = (DisplayMode)mCurParams.displayMode;
    switch(mode) {
    case Geography:
        {
            colors = mWorld.mGeoColors;
            break;
        }
    case Colonies:
        {
            colors = mWorld.mGeoColors;
            // add sphere of influence and location
            Colony& colRef = mWorld.mColonies[mCurParams.displayColony];
            mCamVars.sceneRotation.set(getAverageVertex(colRef.mLocation), mCam.getEyePoint());
            for (set<u32>::iterator soiIt = colRef.mSphereInfluence.begin(); soiIt != colRef.mSphereInfluence.end(); ++soiIt) {
                colors[*soiIt] = Color(0.2, 0.2, 0.2);
            }
            colors[colRef.mLocation] = Color(1.0, 0.0, 0.0);
            break;
        }
    case Resources:
        {
            
            vector<u32> activeResIdxs;
            for (u32 i = 0; i < mCurParams.numResources; i++) {
                if (mCurParams.showResources[i]) {
                    activeResIdxs.push_back(i);
                }
            }
            if (activeResIdxs.size() > 0) {
                colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.0, 0.0, 0.0));
            } else {
                colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.2, 0.2, 0.2));
                break;
            }
            float numIndices = activeResIdxs.size();
            for(vector<u32>::iterator idxIt = activeResIdxs.begin(); idxIt != activeResIdxs.end(); ++idxIt) {
                vector<f32>& activeResVals = (mWorld.resources())[*idxIt].mVals;
                vector<Color>::iterator colIt = colors.begin();
                for (vector<f32>::iterator valIt = activeResVals.begin(); valIt != activeResVals.end(); ++valIt) {
                    *colIt += (resourceColors[*idxIt] * (*valIt)) / numIndices;
                    colIt++;
                }
            }
            break;
        }
    case Attributes:
        {
            colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.0, 0.0, 0.0));
            vector<u32> activeAttrIdxs;
            for (u32 i = 0; i < NUM_ATTRIBUTES; i++) {
                if (mCurParams.showAttributes[i]) {
                    activeAttrIdxs.push_back(i);
                }
            }
            if (activeAttrIdxs.size() == 0) {
                colors.clear();
                colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.1, 0.1, 0.1));
                break;
            }
            map<string, Color> attrMap;
            attrMap["wetness"] = Color(0.0, 0.0, 1.0);
            attrMap["temperature"] = Color(1.0, 0.0, 0.0);
            attrMap["elevation"] = Color(0.0, 1.0, 0);
            // iterate through all active indices
            for(vector<u32>::iterator idxIt = activeAttrIdxs.begin(); idxIt != activeAttrIdxs.end(); ++idxIt) {
                Color colorVal = attrMap[mWorld.mAttributes[*idxIt].mName];
                vector<Color>::iterator faceColorIt = colors.begin();
                // iterate through all attribute values
                for (vector<f32>::iterator attrIt = mWorld.mAttributes[*idxIt].mVals.begin(); attrIt != mWorld.mAttributes[*idxIt].mVals.end(); ++attrIt) {
                    *faceColorIt += (colorVal * (*attrIt));
                    faceColorIt++;
                }
            }
            break;
        }
    }
    // triple the colors vector so that triangles show up as solid triangles
    for (vector<Color>::iterator colIt = colors.begin(); colIt != colors.end(); ++colIt) {
        mTriangles.appendColorRgb(*colIt);
        mTriangles.appendColorRgb(*colIt);
        mTriangles.appendColorRgb(*colIt);
    }
    mFrame = mTriangles;
    mFrame.getColorsRGB().clear();
    vector<Color> frameColors(colors.size()*3, Color(0.1, 0.1, 0.1));
    mFrame.appendColorsRgb(frameColors.data(), frameColors.size());
}
Exemplo n.º 17
0
void ssaoApp::keyDown( KeyEvent event )
{
    
    switch ( event.getCode() )
    {
            //switch between render views
        case KeyEvent::KEY_0:
        {RENDER_MODE = DeferredRenderer::SHOW_FINAL_VIEW;}
            break;
        case KeyEvent::KEY_1:
        {RENDER_MODE = DeferredRenderer::SHOW_DIFFUSE_VIEW;}
            break;
        case KeyEvent::KEY_2:
        {RENDER_MODE = DeferredRenderer::SHOW_NORMALMAP_VIEW;}
            break;
        case KeyEvent::KEY_3:
        {RENDER_MODE = DeferredRenderer::SHOW_DEPTH_VIEW;}
            break;
        case KeyEvent::KEY_4:
        {RENDER_MODE = DeferredRenderer::SHOW_POSITION_VIEW;}
            break;
        case KeyEvent::KEY_5:
        {RENDER_MODE = DeferredRenderer::SHOW_ATTRIBUTE_VIEW;}
            break;
        case KeyEvent::KEY_6:
        {RENDER_MODE = DeferredRenderer::SHOW_SSAO_VIEW;}
            break;
        case KeyEvent::KEY_7:
        {RENDER_MODE = DeferredRenderer::SHOW_SSAO_BLURRED_VIEW;}
            break;
        case KeyEvent::KEY_8:
        {RENDER_MODE = DeferredRenderer::SHOW_LIGHT_VIEW;}
            break;
        case KeyEvent::KEY_9:
        {RENDER_MODE = DeferredRenderer::SHOW_SHADOWS_VIEW;}
            break;   
        case KeyEvent::KEY_a :
            mBunnyX-=0.5;
            break;
        case KeyEvent::KEY_w :
            mBunnyZ+=0.5;
            break;
        case KeyEvent::KEY_s :
            mBunnyZ-=0.5;
            break;
        case KeyEvent::KEY_d :
            mBunnyX+=0.5;
            break;
        case KeyEvent::KEY_UP :
        {
            Vec3f camPos = mCam.getEyePoint();
            mCam.setEyePoint(camPos + Vec3f(0,0.5,0));
            mMayaCam.setCurrentCam(mCam);
        }
            break;
        case KeyEvent::KEY_DOWN :
        {
            Vec3f camPos = mCam.getEyePoint();
            mCam.setEyePoint(camPos + Vec3f(0,-0.5,0));
            mMayaCam.setCurrentCam(mCam);
        }
            break;
        case KeyEvent::KEY_LEFT :
        {
            Vec3f camPos = mCam.getEyePoint();
            mCam.setEyePoint(camPos + Vec3f(-0.5,0,0));
            mMayaCam.setCurrentCam(mCam);
        }
            break;
        case KeyEvent::KEY_RIGHT :
        {
            Vec3f camPos = mCam.getEyePoint();
            mCam.setEyePoint(camPos + Vec3f(0.5,0,0));
            mMayaCam.setCurrentCam(mCam);
        }
            break;
            
        
        default:
            break;
    }
}
Exemplo n.º 18
0
void Day48App::update()
{
    mGlsl->uniform("uCamPosition", mCam.getViewMatrix() * vec4(mCam.getEyePoint(), 1.f));
    
//    cout << mCam.getViewMatrix() * vec4(mCam.getEyePoint(), 1.f) << endl;
    
    
     
    //MOVE THE POINT LIGHTS AROUND
    
    //WHITE
    mPointLights[0].x = -3 * cos(theta / 2);
    mPointLights[0].y = -3 * sin(theta / 2);
    mPointLights[0].z = -3 * cos(theta / 2);
    
    //RED
    mPointLights[1].x = 3 * sin(theta / 2 );
    mPointLights[1].y = 3 * cos(theta / 2 );
    mPointLights[1].z = 3 * cos(theta / 2 );
    
    //GREEN
    mPointLights[2].x = 3 * cos(theta / 2 );
    mPointLights[2].y = 3 * sin(theta / 2 );
    mPointLights[2].z = 3 * sin(theta / 2 );
    
    //BLUE
    mPointLights[3].x = 3 * cos( theta / 2 );
    mPointLights[3].y = 3 * cos( theta / 2);
    mPointLights[3].z = 3 * sin( theta / 2);
    
     
    
    //SET THE UNIFORMS FOR ALL THE LIGHTS
    
    mGlsl->uniform("dirLight.direction", vec3(-0., -1., 0.));
    mGlsl->uniform("dirLight.ambient", vec3(0.01f));
    mGlsl->uniform("dirLight.diffuse", vec3(0.25f));
    mGlsl->uniform("dirLight.specular", vec3(.8f));
    
    mGlsl->uniform("pointLights[0].position", vec3(mCam.getViewMatrix() * vec4(mPointLights[0], 1.f)));
    mGlsl->uniform("pointLights[0].ambient", vec3(0.01f,0.01f,0.01f));
    mGlsl->uniform("pointLights[0].diffuse", vec3(0.05f,0.05f,0.05f));
    mGlsl->uniform("pointLights[0].specular", vec3(0.05f,0.05f,0.05f));
    mGlsl->uniform("pointLights[0].constant", 1.f);
    mGlsl->uniform("pointLights[0].linear", 0.045f);
    mGlsl->uniform("pointLights[0].quadratic", 0.0075f);
    
    //RED LIGHT
    
    mGlsl->uniform("pointLights[1].position", vec3(mCam.getViewMatrix() * vec4(mPointLights[1], 1.f)));
    mGlsl->uniform("pointLights[1].ambient", vec3(0.05f,0.01f,0.01f));
    mGlsl->uniform("pointLights[1].diffuse", vec3(0.25f,0.05f,0.05f));
    mGlsl->uniform("pointLights[1].specular", vec3(0.25f,0.05f,0.05f));
    mGlsl->uniform("pointLights[1].constant", 1.f);
    mGlsl->uniform("pointLights[1].linear", 0.045f);
    mGlsl->uniform("pointLights[1].quadratic", 0.0075f);
    
    //GREEN LIGHT
    
    mGlsl->uniform("pointLights[2].position", vec3(mCam.getViewMatrix() * vec4(mPointLights[2], 1.f)));
    mGlsl->uniform("pointLights[2].ambient", vec3(0.01f,0.05f,0.01f));
    mGlsl->uniform("pointLights[2].diffuse", vec3(0.05f,0.25f,0.05f));
    mGlsl->uniform("pointLights[2].specular", vec3(0.05f,0.25f,0.05f));
    mGlsl->uniform("pointLights[2].constant", 1.f);
    mGlsl->uniform("pointLights[2].linear", 0.045f);
    mGlsl->uniform("pointLights[2].quadratic", 0.0075f);
    
    //BLUE LIGHT
    
    mGlsl->uniform("pointLights[3].position", vec3(mCam.getViewMatrix() * vec4(mPointLights[3], 1.f)));
    mGlsl->uniform("pointLights[3].ambient", vec3(0.01f,0.01f,0.05f));
    mGlsl->uniform("pointLights[3].diffuse", vec3(0.05f,0.05f,0.25f));
    mGlsl->uniform("pointLights[3].specular", vec3(0.05f,0.05f,0.25f));
    mGlsl->uniform("pointLights[3].constant", 1.f);
    mGlsl->uniform("pointLights[3].linear", 0.045f);
    mGlsl->uniform("pointLights[3].quadratic", 0.0075f);
    
    theta += 0.0523;
}
Exemplo n.º 19
0
void Day72App::update()
{
    mGlsl->uniform("uCamPos", vec3(mCam.getViewMatrix() * vec4(mCam.getEyePoint(),1.f)));
    theta += 0.0523;
}
void HeightfieldTerrainApp::update()
{
	// must update the world.
	mContext->update();
	mCam.setEyePoint( vec3(mCam.getEyePoint().x, mCamHeight, mCam.getEyePoint().z ) );
}
/* 
 * @Description: Listen for key presses
 * @param: KeyEvent
 * @return: none
 */
void Base_ThreeD_ProjectApp::keyDown( KeyEvent event ) 
{
	//printf("%i \n", event.getCode());
	
	switch ( event.getCode() ) 
	{
		case KeyEvent::KEY_1:
		{
			RENDER_MODE = 0;
		}
			break;
		case KeyEvent::KEY_2:
		{
			RENDER_MODE = 1;
		}
			break;
		case KeyEvent::KEY_3:
		{
			RENDER_MODE = 2;
		}
			break;
		case KeyEvent::KEY_4:
		{
			RENDER_MODE = 3;
		}
			break;		
			
		case KeyEvent::KEY_UP:
		{
			Vec3f lightPos = mLight->getPosition();
			if ( lightPos.y > 0 )
				lightPos.y *= -1;
			lightPos = lightPos + Vec3f(0, 0.0, 0.1);		
			mLight->lookAt( lightPos, Vec3f::zero() );
			//mLight->update( *mCam );
			
			lightPos = mLightRef->getPosition() + Vec3f(0, 0.0, 0.1);
			mLightRef->lookAt( lightPos, Vec3f::zero() );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_DOWN:
		{
			Vec3f lightPos = mLight->getPosition();
			if ( lightPos.y > 0 )
				lightPos.y *= -1;
			lightPos = lightPos + Vec3f(0, 0.0, -0.1);		
			mLight->lookAt( lightPos, Vec3f::zero() );
			//mLight->update( *mCam );
			
			lightPos = mLightRef->getPosition() + Vec3f(0, 0.0, -0.1);	
			mLightRef->lookAt( lightPos, Vec3f::zero() );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_LEFT:
		{
			Vec3f lightPos = mLight->getPosition();
			if ( lightPos.y > 0 )
				lightPos.y *= -1;
			lightPos = lightPos + Vec3f(0.1, 0, 0);		
			mLight->lookAt( lightPos, Vec3f::zero() );
			//mLight->update( *mCam );
			
			lightPos = mLightRef->getPosition() + Vec3f(0.1, 0, 0);
			mLightRef->lookAt( lightPos, Vec3f::zero() );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_RIGHT:
		{
			Vec3f lightPos = mLight->getPosition();
			if ( lightPos.y > 0 )
				lightPos.y *= -1;
			lightPos = lightPos + Vec3f(-0.1, 0, 0);		
			mLight->lookAt( lightPos, Vec3f::zero() );
			//mLight->update( *mCam );
			
			lightPos = mLightRef->getPosition() + Vec3f(-0.1, 0, 0);	
			mLightRef->lookAt( lightPos, Vec3f::zero() );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_w:
		{
			mEye = mCam->getEyePoint();
			mEye = Quatf( Vec3f(1, 0, 0), -0.03f ) * mEye;
			mCam->lookAt( mEye, Vec3f::zero() );
			//mLight->update( *mCam );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_a:
		{
			mEye = mCam->getEyePoint();
			mEye = Quatf( Vec3f(0, 1, 0), 0.03f ) * mEye;
			mCam->lookAt( mEye, Vec3f::zero() );
			//mLight->update( *mCam );
			mLightRef->update( *mCam );
		}
			break;	
		case KeyEvent::KEY_s:
		{
			mEye = mCam->getEyePoint();
			mEye = Quatf( Vec3f(1, 0, 0), 0.03f ) * mEye;
			mCam->lookAt( mEye, Vec3f::zero() );
			//mLight->update( *mCam );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_d:
		{
			mEye = mCam->getEyePoint();
			mEye = Quatf( Vec3f(0, 1, 0), -0.03f ) * mEye;
			mCam->lookAt( mEye, Vec3f::zero() );
			//mLight->update( *mCam );
			mLightRef->update( *mCam );
		}
			break;
		default:
			break;
	}
}