Exemplo n.º 1
0
    bool CreateObjectAction::updateInstance(const Point& pt)
    {
        if (mObjectType.empty())
        {
            hide();
            return false;
        }

        Ogre::Vector3 position, normal;
        if (!getSceneManipulator()->getTerrainIntersects(pt, position, &normal, true))
        {
            hide();
            return false;
        }

        if (!mObject)
        {
            mObject = ObjectFactoryManager::getSingleton().createInstance(mObjectType);
            mObject->setPropertyList(mParameters);
            mObject->createRenderInstance(getSceneManipulator());		
        }
        else
        {
            mObject->setPropertyList(mParameters);
        }

        Ogre::Vector3 groundingPoint(Ogre::Vector3::ZERO);
        if (mObject->hasProperty("grounding point"))
        {
            // Adjust position by grounding point
            groundingPoint = VariantCast<Ogre::Vector3>(mObject->getProperty("grounding point"));
            position -= groundingPoint;
        }
        position = getSceneManipulator()->_alignPosition(position);
        position.y = getTerrainData()->getHeightAt(position.x, position.z) - groundingPoint.y;
        position = getSceneManipulator()->_alignPosition(position);
		if(!mHasPosition)
			mObject->setProperty("position", position);

		mRangeSphereNode->setVisible(false);
		Ogre::String type = mObject->getType();
		if ( type == "Light")
		{
			LightObject *lightObject = static_cast<LightObject *> (mObject.get());
			if (mObject->getPropertyAsString("type") == "point")
			{
				mRangeSphereNode->setPosition(position);
				mRangeSphereNode->setVisible(true);
			}
		}

        return true;
    }
	bool CreateComplexObjectAction::updateInstance(const Point& pt)
	{
		if (mObjectType.empty())
		{
			hide();
			return false;
		}

		Ogre::Vector3 position, normal;
		if (!getSceneManipulator()->getTerrainIntersects(pt, position, &normal, true))
		{
			hide();
			return false;
		}

		if (!mObject)
		{
			mObject = ObjectFactoryManager::getSingleton().createInstance(mObjectType);
			mObject->setPropertyList(mParameters);

			// 设置物体的位置
			Ogre::Vector3 groundingPoint(Ogre::Vector3::ZERO);
			if (mObject->hasProperty("grounding point"))
			{
				// Adjust position by grounding point
				groundingPoint = VariantCast<Ogre::Vector3>(mObject->getProperty("grounding point"));
				position -= groundingPoint;
			}
			position = getSceneManipulator()->_alignPosition(position);
			position.y = getTerrainData()->getHeightAt(position.x, position.z) - groundingPoint.y;
			position = getSceneManipulator()->_alignPosition(position);
			mObject->setProperty("position", position);

			mObject->createRenderInstance(getSceneManipulator());
		}
		else
		{
			mObject->setPropertyList(mParameters);
		}
		
		return true;
	}