Esempio n. 1
0
void
SoundUpdateCB::operator()( osg::Node* node, osg::NodeVisitor* nv )
{
    const osg::FrameStamp* fs( nv->getFrameStamp() );
	if( !m_sound_state.valid() || ( fs == NULL ) )
    {
		// Early exit.
		osg::notify(osg::DEBUG_INFO) << "SoundUpdateCB::operator()() No SoundState attached, or invalid FrameStamp." << std::endl;
		traverse( node, nv );
		return;
	}

	const double t( fs->getReferenceTime() );
	const double time( t - m_last_time );
	if(time >= m_sound_manager->getUpdateFrequency())
    {
		const osg::Matrix m( osg::computeLocalToWorld( nv->getNodePath() ) );
		const osg::Vec3 pos = m.getTrans();
		m_sound_state->setPosition(pos);

		//Calculate velocity
		osg::Vec3 velocity(0,0,0);
		if (m_first_run)
        {
			m_first_run = false;
			m_last_time = t;
			m_last_pos = pos;
		}
		else
        {
			velocity = pos - m_last_pos;
			m_last_pos = pos;
			m_last_time = t;
			velocity /= time;
		}

		if(m_sound_manager->getClampVelocity())
        {
			float max_vel = m_sound_manager->getMaxVelocity();
			float len = velocity.length();
			if ( len > max_vel)
            {
				velocity.normalize();
				velocity *= max_vel;
			}
		}
		m_sound_state->setVelocity(velocity);

		//Get new direction
        osg::Vec3 dir = osg::Vec3( 0., 1., 0. ) * m;
		dir.normalize();
		m_sound_state->setDirection(dir);      

		// Only do occlusion calculations if the sound is playing
		if (m_sound_state->getPlay() && m_occlude_callback.valid())
			m_occlude_callback->apply(m_sound_manager->getListenerMatrix(), pos, m_sound_state.get());
	} // if time to update

	traverse( node, nv );
}
Esempio n. 2
0
bool SceneUtils::getPlaneIntersection(opencover::coPlane *plane, osg::Matrix pointerMat, osg::Vec3 &point)
{
    osg::Vec3 pointerPos1, pointerPos2, pointerDir;
    pointerPos1 = pointerMat.getTrans();
    pointerDir[0] = pointerMat(1, 0);
    pointerDir[1] = pointerMat(1, 1);
    pointerDir[2] = pointerMat(1, 2);
    pointerPos2 = pointerPos1 + pointerDir;
    return plane->getLineIntersectionPoint(pointerPos1, pointerPos2, point);
}
	bool TransformFilterCallback::isTransOutlier(const osg::Matrix& matrix){
			// check if new matrix is likely to be an outlier by comparing translations
			osg::Vec3d new_trans = matrix.getTrans();				// new translation
			osg::Vec3d connect = m_storedTranslation - new_trans;	// connecting vector

			//std::cout << "trans_diff: " << connect.length() << std::endl;
			if (connect.length() > m_TransOutlierDistance)
			{
				//std::cout << "TransformFilterCallback::isTransOutlier:/ rejected translational outlier" << std::endl;
				return true;	
			}
		return false;
	}
Esempio n. 4
0
void PanoManipulator::setByMatrix(const osg::Matrix& matrix)
{
_eye = matrix.getTrans();
_rotation.set(matrix);
} // PanoManipulator::setByMatrix