void FModSoundManager::update(const Time& ElapsedTime)
{
    FMOD_RESULT result;

    //setup listener's position and orientation as camera's
    if(getCamera() != NULL)
    {
        Matrix camW2S;
        getCamera()->getViewing(camW2S, 1, 1);
        Pnt3f LisenerPosition(0, 0, 0);
        camW2S.mult(LisenerPosition,LisenerPosition);

        Vec3f up(0, 1, 0);
        camW2S.mult(up,up);

        Vec3f forward(0, 0, -1);
        camW2S.mult(forward,forward);
        FMOD_VECTOR f_pos, f_vel, f_up, f_forward;
        f_pos.x = LisenerPosition.x();
        f_pos.y = LisenerPosition.y();
        f_pos.z = LisenerPosition.z();
        f_up.x = up.x();
        f_up.y = up.y();
        f_up.z = up.z();
        f_forward.x = forward.x();
        f_forward.y = forward.y();
        f_forward.z = forward.z();

        //Calculate Velocity
        f_vel.x = 0;
        f_vel.y = 0;
        f_vel.z = 0;
        /*f_vel.x = ( _PreviousLisenerPosition.x() - LisenerPosition.x() ) / e.getElapsedTime();
        f_vel.y = ( _PreviousLisenerPosition.y() - LisenerPosition.y() ) / e.getElapsedTime();
        f_vel.z = ( _PreviousLisenerPosition.z() - LisenerPosition.z() ) / e.getElapsedTime();*/
        _PreviousLisenerPosition = LisenerPosition;

        result = _FModSystem->set3DListenerAttributes(0, &f_pos, &f_vel, &f_forward, &f_up);
        FMOD_ERRCHECK(result,"FModSoundManager: set3DListenerAttributes()");
    }
    //else
    //{
    //    SWARNING << "FModSoundManager: The Camera is not attached to the sound manager.  This is required to update the listeners position and velocity." << std::endl;
    //}

    //call FMOD's update
    result = _FModSystem->update();
    FMOD_ERRCHECK(result,"FModSoundManager: update()");

    //Update the number of channels statistic
    StatIntElem *NChannelsStatElem = StatCollector::getGlobalElem(SoundManager::statNChannels);
    if(NChannelsStatElem)
    {
        int channels;
        _FModSystem->getChannelsPlaying(&channels);
        FMOD_ERRCHECK(result,"FModSoundManager: getChannelsPlaying()");
        NChannelsStatElem->set(channels);
    }

}
Пример #2
0
/*!
 * \fn bool OSG::Animation::update(const Time& ElapsedTime)
 *
 * \brief Update the animation with the time since the last update
 *
 * The result of the animation will also be applied to the
 * object it is connected to.
 *
 * \param[in] ElapsedTime The time, in seconds, since the previous call to
 * update.
 */
bool Animation::update(const Time& ElapsedTime)
{
    if(!_IsPlaying || _IsPaused)
    {
        return false;
    }

    //Increment the updated animations statistic
    StatIntElem *NAnimationsStatElem = StatCollector::getGlobalElem(statNAnimations);
    if(NAnimationsStatElem) { NAnimationsStatElem->inc(); }

    //Start the  animation update time statistic
    StatTimeElem *AnimUpdateTimeStatElem = StatCollector::getGlobalElem(statAnimUpdateTime);
    if(AnimUpdateTimeStatElem) { AnimUpdateTimeStatElem->start(); }

    _CurrentTime += getScale()*ElapsedTime;
    UInt32 PreUpdateCycleCount(getCycles());
    if(getCycling() < 0 || PreUpdateCycleCount < getCycling())
    {
        Real32 CycleLength(getCycleLength() * getScale());

        //Check if the Animation Time is past the end
        if(_CurrentTime >= CycleLength)
        {
            //Update the number of cycles completed
            setCycles( (CycleLength <= 0.0f) ? (0): (static_cast<UInt32>( osgFloor( _CurrentTime / CycleLength ) )) );
            //commitChanges();
        }
        Real32 t(_CurrentTime);

        if(getCycling() > 0 && getCycles() >= getCycling())
        {
            if(getSpan() > 0.0f)
            {
                t = getSpan();
            }
            t -= 0.0001f;
        }
        else
        {
            if(getSpan() > 0.0f)
            {
                t -= osgFloor(_CurrentTime/getSpan())*getSpan();
            }
        }
        t += getOffset();

        //Internal Update
        internalUpdate(t, _PrevTime);


        //If the number of cycles has changed
        if(getCycles() != PreUpdateCycleCount)
        {
            if(getCycling() > 0 && getCycles() >= getCycling())
            {
                //Animation has reached the end
                //Remove the Animation from it's update producer
                _UpdateEventConnection.disconnect();
                _IsPlaying = false;

                //Produce the Ended event
                produceAnimationEnded();
            }
            else
            {
                //Animation hasn't finished yet
                //Produce the Cycled event
                produceAnimationCycled();
            }
        }
    }

    _PrevTime = _CurrentTime;

    //Stp[ the  animation update time statistic
    if(AnimUpdateTimeStatElem) { AnimUpdateTimeStatElem->stop(); }

    //Return true if the animation has completed its number of cycles, false otherwise
    return (getCycling() > 0 && getCycles() >= getCycling());
}
void PhysicsHandler::handleUpdate(EventDetails* const details)
{
    commitChanges();

    //Start the physics timing statistic
    StatTimeElem *PhysicsTimeStatElem = StatCollector::getGlobalElem(statPhysicsTime);
    if(PhysicsTimeStatElem) { PhysicsTimeStatElem->start(); }

    _TimeSinceLast += dynamic_cast<UpdateEventDetails* const>(details)->getElapsedTime();

    if(osgFloor(_TimeSinceLast/getStepSize()) > getMaxStepsPerUpdate())
    {
        SWARNING << "Physics Simulation slowing: dropping " << osgFloor(_TimeSinceLast/getStepSize())-getMaxStepsPerUpdate() << " steps" << std::endl;
        _TimeSinceLast = getMaxStepsPerUpdate()*getStepSize();
    }

    StatIntElem *NPhysicsStepsStatElem = StatCollector::getGlobalElem(statNPhysicsSteps);
    StatTimeElem *CollisionTimeStatElem = StatCollector::getGlobalElem(statCollisionTime);
    StatTimeElem *DynamicsTimeStatElem = StatCollector::getGlobalElem(statSimulationTime);
    while(_TimeSinceLast > getStepSize())
    {
        //Increment the steps statistic
        if(NPhysicsStepsStatElem) { NPhysicsStepsStatElem->inc(); }

        //*********** Collision Checks *************
        //Start the collision timing statistic
        if(CollisionTimeStatElem) { CollisionTimeStatElem->start(); }

        //Do collision checks
        for(UInt32 i(0) ; i<getMFSpaces()->size() ; ++i)
        {
            getSpaces(i)->Collide(getWorld());
        }

        //Stop the collision timing statistic
        if(CollisionTimeStatElem) { CollisionTimeStatElem->stop(); }


        //*********** Simulation step *************

        //Start the simulation timing statistic
        if(DynamicsTimeStatElem) { DynamicsTimeStatElem->start(); }

        //Step the dynamics simulation
        getWorld()->worldQuickStep(getStepSize());

        //Stop the simulation timing statistic
        if(DynamicsTimeStatElem) { DynamicsTimeStatElem->stop(); }

        //Decrease the time since last simulation step
        _TimeSinceLast -= getStepSize();
    }
    StatRealElem *NCollisionTestsStatElem = StatCollector::getGlobalElem(statNCollisionTests);
    if(NCollisionTestsStatElem) { NCollisionTestsStatElem->set(NCollisionTestsStatElem->get()/static_cast<Real32>(NPhysicsStepsStatElem->get())); }
    StatRealElem *NCollisionsStatElem = StatCollector::getGlobalElem(statNCollisions);
    if(NCollisionsStatElem) { NCollisionsStatElem->set(NCollisionsStatElem->get()/static_cast<Real32>(NPhysicsStepsStatElem->get())); }

    
    
    StatTimeElem *TransformUpdateTimeStatElem = StatCollector::getGlobalElem(statTransformUpdateTime);
    //Start the transform update timing statistic
    if(TransformUpdateTimeStatElem) { TransformUpdateTimeStatElem->start(); }
    //update matrices
    updateWorld(getUpdateNode());
    //Start the transform update timing statistic
    if(TransformUpdateTimeStatElem) { TransformUpdateTimeStatElem->stop(); }

    //Stop the physics timing statistic
    if(PhysicsTimeStatElem) { PhysicsTimeStatElem->stop(); }
}
Пример #4
0
	/// \brief Drawing the DynamicTerrain
	Action::ResultE DynamicTerrain::drawPrimitives( DrawActionBase* action )
	{
		// do frustum culling here.. extract frustum from the current camera:
		RenderAction* renderAction = dynamic_cast< RenderAction* >( action );

		if( needInitialize_ )
		{
			if( getHeightData() != NullFC )
			{
				if( getLevelSize() < 3 )
				{
					SWARNING << "DynamicTerrain: LevelSize is below minimum (using default)!" << std::endl;

					setLevelSize( 63 );
				}

				// todo: choose the correct height-/texturedata source:
				geoClipmaps_.initialize( getLevelSize(), &imageHeightSource_, getTextureSource() );
			}
			needInitialize_ = false;
		}

		if( !geoClipmaps_.isValid() )
		{
			// no valid data yet
			return Action::Continue;
		}

		// todo: get the viewport of the RenderAction, check if the camera already has a terrain attachment:
			// if not: create a new TerrainView and attach it to the camera

		// update/render the view
		if( renderAction )
		{
			// frustum culling
			const FrustumVolume& frustum = renderAction->getFrustum();

			// make an update right here:
			Matrix camera  = renderAction->getCameraToWorld();
			Matrix toworld = renderAction->top_matrix();			
			toworld.invert();
			camera.multLeft(toworld);
			Pnt3f eyePoint( camera[ 3 ][ 0 ], camera[ 3 ][ 1 ], camera[ 3 ][ 2 ] );

			// transform the eyePoint to the unscaled sample space:
			const WorldTransformation worldTransform = getWorldTransform();
			const Pnt3f worldOffset( worldTransform.offset[ 0 ], 0.0f, worldTransform.offset[ 1 ] );
			
			const Pnt3f localEyePoint = componentDivide( ( eyePoint - worldOffset ), worldTransform.sampleDistance );

			if( !getDisableUpdate() )
			{
				geoClipmaps_.update( localEyePoint );
			}			
			
			// and now draw what we have:
			ClipmapRenderParameters renderParams;
			
			renderParams.renderAction			= renderAction;
			renderParams.window					= renderAction->getWindow();
			renderParams.viewFrustum			= frustum;
			renderParams.enableFrustumCulling	= getEnableFrustumCulling();
			renderParams.showTransitionRegions	= getShowTransitionRegions();
			renderParams.useVboExtension		= getUseVboExtension();
			renderParams.globalTexture			= globalTexture_;
			renderParams.heightColorTexture		= getHeightColorTexture();
			
			renderParams.worldTransform			= worldTransform;

			ClipmapRenderStatistics renderStats;

			geoClipmaps_.render( renderParams, renderStats );

			if( getShowBoundingBoxes() )
			{
				//drawBox( 
			}

			// update stats:
			StatCollector* statCollector = action->getStatistics();
			
			if( statCollector ) 
			{
				StatIntElem* statTriangleCount = statCollector->getElem( Drawable::statNTriangles, false );
				StatIntElem* statVertexCount = statCollector->getElem( Drawable::statNVertices, false );

				if( statTriangleCount )
				{
					statTriangleCount->add( renderStats.drawnTriangleCount );
				}
				if( statVertexCount )
				{
					statVertexCount->add( renderStats.transformedVertexCount );
				}
			}
		}
		else
		{
			//todo: can this ever happen?!
			SLOG << "Test\n";
		}

		return Action::Continue;
	}