Пример #1
0
    /** Default constructor. */
    GravityAffector(Ogre::ParticleSystem *psys)
      : ParticleAffector(psys)
      , mForce(0.0f)
      , mForceType(Type_Wind)
      , mPosition(0.0f)
      , mDirection(0.0f)
    {
        std::vector<Ogre::Bone*> bones = Ogre::any_cast<NiNodeHolder>(psys->getUserObjectBindings().getUserAny()).mBones;
        assert (!bones.empty());
        mEmitterBone = bones[0];
        Ogre::TagPoint* tag = static_cast<Ogre::TagPoint*>(mParent->getParentNode());
        mParticleBone = static_cast<Ogre::Bone*>(tag->getParent());

        mType = "Gravity";

        // Init parameters
        if(createParamDictionary("GravityAffector"))
        {
            Ogre::ParamDictionary *dict = getParamDictionary();

            Ogre::String force_title("force");
            Ogre::String force_descr("Amount of force applied to particles.");
            Ogre::String force_type_title("force_type");
            Ogre::String force_type_descr("Type of force applied to particles (point or wind).");
            Ogre::String direction_title("direction");
            Ogre::String direction_descr("Direction of wind forces.");
            Ogre::String position_title("position");
            Ogre::String position_descr("Position of point forces.");

            dict->addParameter(Ogre::ParameterDef(force_title, force_descr, Ogre::PT_REAL), &msForceCmd);
            dict->addParameter(Ogre::ParameterDef(force_type_title, force_type_descr, Ogre::PT_STRING), &msForceTypeCmd);
            dict->addParameter(Ogre::ParameterDef(direction_title, direction_descr, Ogre::PT_VECTOR3), &msDirectionCmd);
            dict->addParameter(Ogre::ParameterDef(position_title, position_descr, Ogre::PT_VECTOR3), &msPositionCmd);
        }
    }
Пример #2
0
 NifEmitter(Ogre::ParticleSystem *psys)
   : Ogre::ParticleEmitter(psys)
 {
     mEmitterBone = Ogre::any_cast<Ogre::Bone*>(psys->getUserObjectBindings().getUserAny());
     Ogre::TagPoint* tag = static_cast<Ogre::TagPoint*>(mParent->getParentNode());
     mParticleBone = static_cast<Ogre::Bone*>(tag->getParent());
     initDefaults("Nif");
 }
Пример #3
0
 NifEmitter(Ogre::ParticleSystem *psys)
   : Ogre::ParticleEmitter(psys)
   , mEmitterBones(Ogre::any_cast<NiNodeHolder>(psys->getUserObjectBindings().getUserAny()).mBones)
 {
     assert (!mEmitterBones.empty());
     Ogre::TagPoint* tag = static_cast<Ogre::TagPoint*>(mParent->getParentNode());
     mParticleBone = static_cast<Ogre::Bone*>(tag->getParent());
     initDefaults("Nif");
 }
 /**
  * Attaches an empty object to the owner. This has no effect if the owner is a node since
  * there's no notion of an "empty" object for nodes. For entities, an "empty" object corresponds
  * to a tag point that has no attachment
  */
 void AttachEmpty(const Ogre::String& name = Ogre::StringUtil::BLANK) const
 {
     if (this->entity != 0 && !this->boneName.empty())
     {
         Ogre::SkeletonInstance* skeleton = this->entity->getSkeleton();
         Ogre::Bone* bone = skeleton->getBone(this->boneName);
         //TODO: Modify Ogre to accept name when creating TagPoint
         Ogre::TagPoint* tagPoint = skeleton->createTagPointOnBone(bone);
         tagPoint->setPosition(this->attachPosition);
         tagPoint->setScale(this->attachScale);
         tagPoint->setOrientation(this->attachRotation);
     }
 }
 /** Attaches the movable object to the owner */
 void Attach(Ogre::MovableObject* object) const
 {
     if (this->node != 0)
         this->node->attachObject(object);
     else if (this->entity != 0 && !this->boneName.empty())
     {
         //TODO: Modify Ogre to accept object->getName() when creating TagPoint
         Ogre::TagPoint* tagPoint = this->entity->attachObjectToBone(this->boneName, object);
         tagPoint->setPosition(this->attachPosition);
         tagPoint->setScale(this->attachScale);
         tagPoint->setOrientation(this->attachRotation);
     }
 }
Пример #6
0
void SkeletonDebug::SetSkeletonDebug(
    Ogre::Entity* entity,
    Ogre::SceneManager* sceneManager,
    const bool enable,
    Ogre::Real boneSize,
    Ogre::Real axisSize)
{
    if (!HasSkeletonDebug(entity))
    {
        GetAxesMaterial();
        GetBoneMaterial();
        GetAxesMesh();
        GetBoneMesh(boneSize);

        const int numBones = entity->getSkeleton()->getNumBones();

        for(unsigned short int iBone = 0; iBone < numBones; ++iBone)
        {
            Ogre::Bone* pBone = entity->getSkeleton()->getBone(iBone);
            if ( !pBone )
            {
                assert(false);
                continue;
            }

            Ogre::Entity *ent;
            Ogre::TagPoint *tp;

            // Absolutely HAVE to create bone representations first. Otherwise we
            // would get the wrong child count because an attached object counts as
            // a child would be nice to have a function that only gets the children
            // that are bones...
            unsigned short numChildren = pBone->numChildren();
            if (numChildren == 0)
            {
                // There are no children, but we should still represent the bone
                // Creates a bone of length 1 for leaf bones (bones without children)
                ent = sceneManager->createEntity(boneName);
                ent->setCastShadows(false);
                tp = entity->attachObjectToBone(
                    pBone->getName(),
                    (Ogre::MovableObject*)ent,
                    Ogre::Quaternion(Ogre::Degree(270.0f), Ogre::Vector3::UNIT_Z));

                const Ogre::Real modBoneSize =
                    boneSize + boneSize * boneSize * 15.0f;

                tp->setScale(modBoneSize, boneSize, modBoneSize);
            }
            else
            {
                for(unsigned short i = 0; i < numChildren; ++i)
                {
                    if (dynamic_cast<Ogre::Bone*>(pBone->getChild(i)))
                    {
                        Ogre::Vector3 childPosition = pBone->getChild(i)->getPosition();
                        // If the length is zero, no point in creating the bone representation
                        float length = childPosition.length();
                        if(length < 0.00001f)
                            continue;

                        Ogre::Quaternion rotation = Ogre::Vector3::UNIT_Y.getRotationTo(
                            childPosition);

                        ent = sceneManager->createEntity(boneName);
                        ent->setCastShadows(false);
                        tp = entity->attachObjectToBone(
                            pBone->getName(),
                            (Ogre::MovableObject*)ent,
                            rotation);

                        const Ogre::Real modBoneSize =
                            boneSize + boneSize * length * 15.0f;

                        tp->setScale(modBoneSize, length, modBoneSize);
                    }
                }
            }

            ent = sceneManager->createEntity(axesName);
            ent->setCastShadows(false);
            tp = entity->attachObjectToBone(pBone->getName(), (Ogre::MovableObject*)ent);
            // Make sure we don't wind up with tiny/giant axes and that one axis doesnt get squashed
            tp->setScale(
                (axisSize/entity->getParentSceneNode()->getScale().x),
                (axisSize/entity->getParentSceneNode()->getScale().y),
                (axisSize/entity->getParentSceneNode()->getScale().z));
        }
    }

    if (enable)
    {
        ShowSkeletonDebug(entity);
    }
    else
    {
        HideSkeletonDebug(entity);
    }
}