void DOFTransform::traverse(osg::NodeVisitor& nv) { if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR) { // ensure that we do not operate on this node more than // once during this traversal. This is an issue since node // can be shared between multiple parents. if ((nv.getTraversalNumber()!=_previousTraversalNumber) && nv.getFrameStamp()) { double newTime = nv.getFrameStamp()->getSimulationTime(); animate((float)(newTime-_previousTime)); _previousTraversalNumber = nv.getTraversalNumber(); _previousTime = newTime; } } Transform::traverse(nv); }
void OcclusionQueryNode::traverseQuery( const osg::Camera* camera, osg::NodeVisitor& nv ) { bool issueQuery; { const int curFrame = nv.getTraversalNumber(); OpenThreads::ScopedLock<OpenThreads::Mutex> lock( _frameCountMutex ); int& lastQueryFrame = _frameCountMap[ camera ]; if ( issueQuery = (curFrame - lastQueryFrame >= _queryFrameCount) ) lastQueryFrame = curFrame; } if (issueQuery) _queryGeode->accept( nv ); }
void SoundNode::traverse(osg::NodeVisitor &nv) { // continue only if the visitor actually is a cull visitor if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR) { // Make sure we only execute this once during this frame. // There could be two or more culls for stereo/multipipe... if (!m_sound_state.valid()) { // call the inherited method osg::notify(osg::DEBUG_INFO) << "SoundNode::traverse() No soundstate attached to soundnode" << std::endl; Node::traverse(nv); return; } if ( m_sound_state.valid() && nv.getTraversalNumber() != m_last_traversal_number && nv.getFrameStamp()) { m_last_traversal_number = nv.getTraversalNumber(); // retrieve the current time double t = nv.getFrameStamp()->getReferenceTime(); double time = t - m_last_time; if(time >= m_sound_manager->getUpdateFrequency()) { osg::Matrix m; m = osg::computeLocalToWorld(nv.getNodePath()); 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(0,1,0); dir = dir * 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 } } // if cullvisitor // call the inherited method Node::traverse(nv); }