void STAGEObjectMotionModel::OnScale(osg::Vec3 delta)
{
   for (int subIndex = 0; subIndex < GetNumTargets(); subIndex++)
   {
      dtDAL::TransformableActorProxy* targetProxy = GetTarget(subIndex);

      if (targetProxy)
      {
         dtDAL::ActorProperty* prop = targetProxy->GetProperty("Scale");
         dtDAL::Vec3ActorProperty* scaleProp = dynamic_cast<dtDAL::Vec3ActorProperty*>(prop);

         if (scaleProp)
         {
            osg::Vec3 oldScale = scaleProp->GetValue();
            osg::Vec3 newScale = oldScale + delta;

            // It causes problems when the scale is negative.
            if (newScale.x() < 0.01f)
            {
               newScale.x() = 0.01f;
            }
            if (newScale.y() < 0.01f)
            {
               newScale.y() = 0.01f;
            }
            if (newScale.z() < 0.01f)
            {
               newScale.z() = 0.01f;
            }

            scaleProp->SetValue(newScale);
         }
      }
   }
}
void STAGEObjectMotionModel::RemoveTarget(dtDAL::TransformableActorProxy* target)
{
   for (int subIndex = 0; subIndex < GetNumTargets(); subIndex++)
   {
      dtDAL::TransformableActorProxy* targetProxy = GetTarget(subIndex);

      // Once we find the target, remove it.
      if (target == targetProxy)
      {
         mTargets.erase(mTargets.begin() + subIndex);
         break;
      }
   }

   // Make sure our primary target it set to the first target.
   if (mTargets.size() > 0)
   {
      dtDAL::TransformableActorProxy* targetProxy = GetTarget(0);

      if (targetProxy)
      {
         dtCore::Transformable* target = NULL;
         targetProxy->GetActor(target);
         ObjectMotionModel::SetTarget(target);
      }
   }
   else
   {
      ObjectMotionModel::SetTarget(NULL);
   }
}
Example #3
0
//
// Send SDL sendState msg to object's plAGMasterSDLModifier
//
bool plAGMasterMod::DirtySynchState(const plString& SDLStateName, uint32_t synchFlags)
{
    if(GetNumTargets() > 0 && (!fIsGrouped || fIsGroupMaster))
    {
        plSceneObject *sObj = GetTarget(0);
        if(sObj) 
            return sObj->DirtySynchState(SDLStateName, synchFlags);
    }
    return false;
}
SvGraphNodeReference OrientConstRotation::SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags)
{
	SvGraphNodeReference nodeRef = Control::SvTraverseAnimGraph( gom, owner, id, flags );

	if( nodeRef.stat == SVT_PROCEED ) {
		for( int i=0; i<GetNumTargets(); i++ ) {
			gom->AddRelationship( nodeRef.gNode, GetNode(i), i, RELTYPE_CONSTRAINT );
		}
	}

	return nodeRef;
}
void STAGEObjectMotionModel::OnTranslate(osg::Vec3 delta)
{
   for (int subIndex = 0; subIndex < GetNumTargets(); subIndex++)
   {
      dtDAL::TransformableActorProxy* targetProxy = GetTarget(subIndex);

      if (targetProxy)
      {
         osg::Vec3 pos = targetProxy->GetTranslation();
         pos += delta;
         targetProxy->SetTranslation(pos);
      }
   }
}
bool OrientConstRotation::SvDetachRel(IGraphObjectManager *gom, IGraphNode *gNodeTarget, int id, IGraphNode *gNodeMaker)
{
	if(GetLocked()==false)
	{
		for( int i=0; i<GetNumTargets(); i++ ) {
			if( GetNode(i) == gNodeTarget->GetAnim() ) {
				DeleteTarget(i);
				return true;
			}
		}
	}
	return false;

}
void STAGEObjectMotionModel::OnRotate(float delta, osg::Vec3 axis)
{
   osg::Vec3 center;
   dtCore::Transformable* target = ObjectMotionModel::GetTarget();
   if (target)
   {
      dtCore::Transform transform;
      target->GetTransform(transform);
      center = transform.GetTranslation();
   }

   for (int subIndex = 0; subIndex < GetNumTargets(); subIndex++)
   {
      dtDAL::TransformableActorProxy* targetProxy = GetTarget(subIndex);

      if (targetProxy)
      {
         dtCore::Transformable* target = NULL;
         targetProxy->GetActor(target);

         if (target)
         {
            osg::Matrix rotation;
            osg::Matrix matrix;
            dtCore::Transform transform;
            target->GetTransform(transform);
            transform.GetRotation(matrix);
            osg::Vec3 targetCenter = transform.GetTranslation();
            osg::Vec3 offset = targetCenter - center;

            rotation = matrix.rotate(delta, axis);
            matrix *= rotation;
            osg::Vec3 newPos = (offset * rotation) + center;

            targetProxy->SetRotationFromMatrix(matrix);
            targetProxy->SetTranslation(newPos);
         }
      }
   }
}
void STAGEObjectMotionModel::AddTarget(dtDAL::TransformableActorProxy* target)
{
   // Skip if there is no target to add.
   if (!target)
   {
      return;
   }

   for (int subIndex = 0; subIndex < GetNumTargets(); subIndex++)
   {
      dtDAL::TransformableActorProxy* targetProxy = GetTarget(subIndex);

      // Skip if the target is already added.
      if (target == targetProxy)
      {
         return;
      }
   }

   mTargets.push_back(target);

   // Make sure our primary target it set to the first target.
   if (mTargets.size() > 0)
   {
      dtDAL::TransformableActorProxy* targetProxy = GetTarget(0);

      if (targetProxy)
      {
         dtCore::Transformable* target = NULL;
         targetProxy->GetActor(target);
         ObjectMotionModel::SetTarget(target);
      }
   }
   else
   {
      ObjectMotionModel::SetTarget(NULL);
   }
}
Example #9
0
bool plInterestingModifier::IEval(double secs, float del, uint32_t dirty)
{
    for (int i=0; i < GetNumTargets(); i++)
    {
        if( GetTarget(i) && GetTarget(i)->GetDrawInterface() )
        {
            const hsBounds3Ext& targBnd = GetTarget(i)->GetDrawInterface()->GetWorldBounds();
            if( targBnd.GetType() == kBoundsNormal )
            {
                plInterestingModMsg* pMsg = new plInterestingModMsg;
                pMsg->fPos= GetTarget(i)->GetDrawInterface()->GetWorldBounds().GetCenter();
                pMsg->fSize = GetTarget(i)->GetDrawInterface()->GetWorldBounds().GetMaxDim();
                pMsg->fRadius = fInterestRadius;
                pMsg->fWeight = fInterestWeight;
                pMsg->fObj = GetTarget(i)->GetKey();
                pMsg->fType = GetType();
                pMsg->SetBCastFlag( plMessage::kPropagateToModifiers );
                plgDispatch::MsgSend( pMsg );
            }
        }
    }
    return true;
}