void PhysicsJoint::changed(ConstFieldMaskArg whichField, 
                            UInt32            origin,
                            BitVector         details)
{
    Inherited::changed(whichField, origin, details);
    
    if(((whichField & FirstBodyFieldMask) || (whichField & WorldFieldMask)) ||
       ((whichField & SecondBodyFieldMask) || (whichField & WorldFieldMask)))
    {
        dBodyID First(NULL);
        dBodyID Second(NULL);
        if(getFirstBody() != NULL)
        {
            First = getFirstBody()->getBodyID();
        }
        if(getSecondBody() != NULL)
        {
            Second = getSecondBody()->getBodyID();
        }
        dJointAttach(_JointID, First, Second);
    }
}
Example #2
0
// update
int World::update( Ogre::Real t_step )
{
	int realUpdates = 0;

	/*
	// clean up all pending bodies for update
	for( BodyVectorVector::iterator it = m_bodyUpdateNodeRequests.begin(); it != m_bodyUpdateNodeRequests.end(); it++ )
	{
		for( BodyVector::iterator body = it->begin(); body != it->end(); body++ )
		{
			(*body)->setNodeUpdateNeeded (false);
		}

		it->clear();
	}
	*/


#ifdef _DEBUG
//	Ogre::LogManager::getSingleton().logMessage("   Newton Frame Listener... m_elapsed: "+Ogre::StringConverter::toString( t_step)+
//		"  m_update:"+Ogre::StringConverter::toString(m_update));
#endif

	// clamp the step if necessary
	if (t_step > (m_timestep * m_maxTicksPerFrames)) {
		t_step = m_timestep * m_maxTicksPerFrames;
	}

	// advance the accumulator;
	m_timeAcumulator += t_step;

	while (m_timeAcumulator >= m_timestep) {
		NewtonUpdate (m_world, m_timestep);
		m_timeAcumulator -= m_timestep;
		realUpdates++;
	}

#ifdef _DEBUG
//	Ogre::LogManager::getSingleton().logMessage("   Newton updates this loop: "+Ogre::StringConverter::toString(count));
#endif


	Ogre::Real param = m_timeAcumulator * m_invTimestep;
//param = 1.0f;

	/* Julio's version, does not really work as the body is only updated once per transform-callback
	for( BodyVectorVector::iterator it = m_bodyUpdateNodeRequests.begin(); it != m_bodyUpdateNodeRequests.end(); it++ )
	{
		for( BodyVector::iterator body = it->begin(); body != it->end(); body++ )
		{
			(*body)->updateNode(param);
		}
	}
	*/

	for( Body* body = getFirstBody(); body; body = body->getNext() )
    {
		body->updateNode(param);
    }

	return realUpdates;
}