Пример #1
0
// Ogre::Camera::getDirection() const
void camera_get_direction(CameraHandle handle, coiVector3* v3)
{
    Ogre::Camera* camera = static_cast<Ogre::Camera*>(handle);
    const Ogre::Vector3& v = camera->getDirection();
    v3->x = v.x;
    v3->y = v.y;
    v3->z = v.z;
}
Пример #2
0
void ActorSceneCanvas::OnKeyDown(wxKeyEvent& e)
{
	switch(e.GetKeyCode())
	{
	case 'w':
	case 'W':
		{
			Ogre::Camera* camera = GetSceneManipulator()->getCamera();
			assert (camera);

			Ogre::Vector3 oldPos = camera->getPosition();

			Ogre::Vector3 offsetPos = camera->getDirection() * GetSceneManipulator()->getMoveSpeed();

			Ogre::Vector3 newPos = oldPos;
            newPos.x += offsetPos.x;
            newPos.z += offsetPos.z;

			GetSceneManipulator()->setCameraPosition(newPos);
			e.Skip(false);
		}
		break;
	case 's':
	case 'S':
		{
			Ogre::Camera* camera = GetSceneManipulator()->getCamera();
			assert (camera);

			Ogre::Vector3 oldPos = camera->getPosition();

			Ogre::Vector3 offsetPos = camera->getDirection() * -(GetSceneManipulator()->getMoveSpeed());

			Ogre::Vector3 newPos = oldPos;
            newPos.x += offsetPos.x;
            newPos.z += offsetPos.z;

			GetSceneManipulator()->setCameraPosition(newPos);
			e.Skip(false);
		}
		break;
	case 'a':
	case 'A':
		{
			Ogre::Camera* camera = GetSceneManipulator()->getCamera();
			assert (camera);

			Ogre::Radian yawAngle( GetSceneManipulator()->getRotateSpeed() / 360.0f );

			camera->yaw(yawAngle);
			e.Skip(false);
		}
		break;
	case 'd':
	case 'D':
		{
			Ogre::Camera* camera = GetSceneManipulator()->getCamera();
			assert (camera);

			Ogre::Radian yawAngle( -(GetSceneManipulator()->getRotateSpeed() / 360.0f) );

			camera->yaw(yawAngle);
			e.Skip(false);
		}
		break;
	case 'h':
	case 'H':
		{
			mHideAxis = !mHideAxis;
			Fairy::CDataManipulator::m_baseNode->setVisible(!mHideAxis);
			Fairy::CDataManipulator::mAxisNode_x->setVisible(!mHideAxis);
			Fairy::CDataManipulator::mAxisNode_y->setVisible(!mHideAxis);
			Fairy::CDataManipulator::mAxisNode_z->setVisible(!mHideAxis);
		}
		break;
 	case 'b':
	case 'B':
		{
			GetDataManipulator()->switchBoundingBox(true);
		}
		break;
	case 't':
	case 'T':
		{
			GetSceneManipulator()->setTerrainVisible(!GetSceneManipulator()->getTerrainVisible());
		}
		break;
	case 'g':
	case 'G':
		{
			GetSceneManipulator()->setGridVisible(!GetSceneManipulator()->getGridVisible());
		}
		break;
	case 'r':
	case 'R':
		{
			mRotFirst = !mRotFirst;
		}
		break;
	//case 'C':
 //	case 'c':
 //		{
	//		Fairy::LogicModelManager::getSingleton().showModelBoundingBox(!Fairy::LogicModelManager::getSingleton().isShowBoundingBox()); 			
 //		}
 //		break;
// 
// 	case 'y':
// 	case 'Y':
// 		{
// 			mYax = !mYax;
// 			mXax = mZax = false;
// 		}
// 		break;
// 
// 	case 'z':
// 	case 'Z':
// 		{
// 			mZax = !mZax;
// 			mXax = mYax = false;
// 		}
		//break;
	//case 'z':
	//case 'Z':
 //       {
	//		GetSceneManipulator()->setActiveAction("ManipObjectAction");
 //           GetSceneManipulator()->setUseAxis(!GetSceneManipulator()->getUseAxis());
 //       }
 //       e.Skip(false);
 //       break;
	}
}
Пример #3
0
//!
//! Clones an Ogre::MovableObject.
//!
//! Is needed because OGRE does not provide clone functions for cameras and
//! lights.
//!
//! \param movableObject The object to clone.
//! \param name The name to use for the object.
//! \param sceneManager The scene manager to use for creating the object.
//! \return The cloned object.
//!
Ogre::MovableObject * OgreTools::cloneMovableObject ( Ogre::MovableObject *movableObject, const QString &name, Ogre::SceneManager *sceneManager /* =  0 */ )
{
    // make sure the given object is valid
    if (!movableObject) {
        Log::error("The given movable object is invalid.", "OgreTools::cloneMovableObject");
        return 0;
    }

    // make sure a valid scene manager is available
    if (!sceneManager)
        sceneManager = movableObject->_getManager();
    if (!sceneManager) {
        Log::error("No valid scene manager available.", "OgreTools::cloneMovableObject");
        return 0;
    }

    Ogre::MovableObject *result = 0;
    Ogre::String typeName = movableObject->getMovableType();
    if (typeName == "Entity") {
        // clone entity
        Ogre::Entity *entity = dynamic_cast<Ogre::Entity *>(movableObject);
        //movableObjectCopy = entity->clone(name.toStdString());
        Ogre::Entity *entityCopy = sceneManager->createEntity(name.toStdString(), entity->getMesh()->getName());
        Ogre::AnimationStateSet *animationStateSet = entity->getAllAnimationStates();
        Ogre::AnimationStateSet *animationStateSetCopy  = entityCopy->getAllAnimationStates();
        // set the same blend mode on entity copy
        if (entity && entityCopy) {
            if (entity->hasSkeleton() && entityCopy->hasSkeleton()) {
                Ogre::Skeleton *skeleton = entity->getSkeleton();
                Ogre::Skeleton *skeletonCopy = entityCopy->getSkeleton();
                skeletonCopy->setBlendMode(skeleton->getBlendMode());
            }
        }
        // copy all animation states
        if (animationStateSet && animationStateSetCopy) {
            Ogre::AnimationStateIterator animationStateIter = animationStateSet->getAnimationStateIterator();
            Ogre::AnimationStateIterator animationStateCopyIter = animationStateSetCopy->getAnimationStateIterator();
            while (animationStateIter.hasMoreElements()) {
                if (!animationStateCopyIter.hasMoreElements())
                    break;
                Ogre::AnimationState *animationState = animationStateIter.getNext();
                Ogre::AnimationState *animationStateCopy = animationStateCopyIter.getNext();
                animationStateCopy->setLoop(animationState->getLoop());
                //bool enabled = animationState->getEnabled();
                //animationStateCopy->setEnabled(animationState->getEnabled());
                animationStateCopy->setEnabled(true);
                animationStateCopy->setTimePosition(animationState->getTimePosition());
            }
        }

        // create a new container for the cloned entity
        OgreContainer *entityCopyContainer = new OgreContainer(entityCopy);
        entityCopy->setUserAny(Ogre::Any(entityCopyContainer));
        if (!entity->getUserAny().isEmpty()) {
            OgreContainer *entityContainer = Ogre::any_cast<OgreContainer *>(entity->getUserAny());
			if (entityContainer) {
                QObject::connect(entityContainer, SIGNAL(animationStateUpdated(const QString &, double)), entityCopyContainer, SLOT(updateAnimationState(const QString &, double)));
				QObject::connect(entityContainer, SIGNAL(boneTransformUpdated(const QString &, double, double, double, double, double, double)), entityCopyContainer, SLOT(updateBoneTransform(const QString &, double, double, double, double, double, double)));
			}
        }
        result = dynamic_cast<Ogre::MovableObject *>(entityCopy);
    } else if (typeName == "Light") {
        // clone light
        Ogre::Light *light = dynamic_cast<Ogre::Light *>(movableObject);
        Ogre::Light *lightCopy = sceneManager->createLight(name.toStdString());
        lightCopy->setType(light->getType());
        lightCopy->setDiffuseColour(light->getDiffuseColour());
        lightCopy->setSpecularColour(light->getSpecularColour());
        lightCopy->setAttenuation(light->getAttenuationRange(), light->getAttenuationConstant(), light->getAttenuationLinear(), light->getAttenuationQuadric());
        lightCopy->setPosition(light->getPosition());
        lightCopy->setDirection(light->getDirection());
        if (lightCopy->getType() == Ogre::Light::LT_SPOTLIGHT)
            lightCopy->setSpotlightRange(light->getSpotlightInnerAngle(), light->getSpotlightOuterAngle(), light->getSpotlightFalloff());
        lightCopy->setPowerScale(light->getPowerScale());
        lightCopy->setCastShadows(light->getCastShadows());

        // create a new container for the cloned light
        OgreContainer *lightCopyContainer = new OgreContainer(lightCopy);
        lightCopy->setUserAny(Ogre::Any(lightCopyContainer));
        if (!light->getUserAny().isEmpty()) {
            OgreContainer *lightContainer = Ogre::any_cast<OgreContainer *>(light->getUserAny());
            if (lightContainer)
                QObject::connect(lightContainer, SIGNAL(sceneNodeUpdated()), lightCopyContainer, SLOT(updateLight()));
        }
        result = dynamic_cast<Ogre::MovableObject *>(lightCopy);
    } else if (typeName == "Camera") {
        // clone camera
        Ogre::Camera *camera = dynamic_cast<Ogre::Camera *>(movableObject);
        Ogre::Camera *cameraCopy = sceneManager->createCamera(name.toStdString());
        //cameraCopy->setCustomParameter(0, camera->getCustomParameter(0));
        cameraCopy->setAspectRatio(camera->getAspectRatio());
        cameraCopy->setAutoAspectRatio(camera->getAutoAspectRatio());
        //cameraCopy->setAutoTracking(...);
        cameraCopy->setCastShadows(camera->getCastsShadows());
        //cameraCopy->setCullingFrustum(camera->getCullingFrustum());
        //cameraCopy->setCustomParameter(...);
        //cameraCopy->setCustomProjectionMatrix(..);
        //cameraCopy->setCustomViewMatrix(..);
        //cameraCopy->setDebugDisplayEnabled(...);
        //cameraCopy->setDefaultQueryFlags(...);
        //cameraCopy->setDefaultVisibilityFlags(...);
        cameraCopy->setDirection(camera->getDirection());
        //cameraCopy->setFixedYawAxis(...);
        cameraCopy->setFocalLength(camera->getFocalLength());
        cameraCopy->setFOVy(camera->getFOVy());

        //Ogre::Real left;
        //Ogre::Real right;
        //Ogre::Real top;
        //Ogre::Real bottom;
        //camera->getFrustumExtents(left, right, top, bottom);
        //cameraCopy->setFrustumExtents(left, right, top, bottom);
        //cameraCopy->setFrustumOffset(camera->getFrustumOffset());
        //cameraCopy->setListener(camera->getListener());
        cameraCopy->setLodBias(camera->getLodBias());
        //cameraCopy->setLodCamera(camera->getLodCamera());
        cameraCopy->setNearClipDistance(camera->getNearClipDistance());
        cameraCopy->setFarClipDistance(camera->getFarClipDistance());
        cameraCopy->setOrientation(camera->getOrientation());
        //cameraCopy->setOrthoWindow(...);
        //cameraCopy->setOrthoWindowHeight(...);
        //cameraCopy->setOrthoWindowWidth(...);
        cameraCopy->setPolygonMode(camera->getPolygonMode());
        cameraCopy->setPolygonModeOverrideable(camera->getPolygonModeOverrideable());
        cameraCopy->setPosition(camera->getPosition());
        cameraCopy->setProjectionType(camera->getProjectionType());
        cameraCopy->setQueryFlags(camera->getQueryFlags());
        cameraCopy->setRenderingDistance(camera->getRenderingDistance());
        cameraCopy->setRenderQueueGroup(camera->getRenderQueueGroup());
        //cameraCopy->setRenderSystemData(camera->getRenderSystemData());
        cameraCopy->setUseIdentityProjection(camera->getUseIdentityProjection());
        cameraCopy->setUseIdentityView(camera->getUseIdentityView());
        //cameraCopy->setUserAny(camera->getUserAny());
        cameraCopy->setUseRenderingDistance(camera->getUseRenderingDistance());
        //cameraCopy->setUserObject(camera->getUserObject());
        cameraCopy->setVisibilityFlags(camera->getVisibilityFlags());
        cameraCopy->setVisible(camera->getVisible());
        //cameraCopy->setWindow(...);

        if (!movableObject->getUserAny().isEmpty()) {
            CameraInfo *sourceCameraInfo = Ogre::any_cast<CameraInfo *>(movableObject->getUserAny());
            if (sourceCameraInfo) {
                CameraInfo *targetCameraInfo = new CameraInfo();
                targetCameraInfo->width = sourceCameraInfo->width;
                targetCameraInfo->height = sourceCameraInfo->height;
                dynamic_cast<Ogre::MovableObject *>(cameraCopy)->setUserAny(Ogre::Any(targetCameraInfo));
            }
        }

        //// Setup connections for instances
        //SceneNode *targetSceneNode = new SceneNode(cameraCopy);
        //((Ogre::MovableObject *)cameraCopy)->setUserAny(Ogre::Any(targetSceneNode));
        //if (!((Ogre::MovableObject *)camera)->getUserAny().isEmpty()) {
        //    SceneNode *sourceSceneNode = Ogre::any_cast<SceneNode *>(((Ogre::MovableObject *)camera)->getUserAny());
        //    if (sourceSceneNode) {
        //        QObject::connect(sourceSceneNode, SIGNAL(sceneNodeUpdated()), targetSceneNode, SLOT(updateSceneNode()));
        //    }
        //}

        result = dynamic_cast<Ogre::MovableObject *>(cameraCopy);
    }

    if (!result)
        Log::error(QString("Could not clone movable object \"%1\" of type \"%2\".").arg(movableObject->getName().c_str()).arg(typeName.c_str()), "OgreTools::cloneMovableObject");

    return result;
}
Пример #4
0
void SoundEditDialog::OnListBoxSoundItemDoubleClick( wxCommandEvent &event )
{
    _StopAllSounds();

    mPlaySoundInGame = false;

    int index = event.GetInt();

    if (index < (int)(mSoundItems.size()))
    {
        mWorkingSoundIndex = index;

        SoundItem* soundItem = mSoundItems[event.GetInt()];

        if (mSoundNameComboBox->IsEmpty())
            _FillSoundNameComboBox();

        SoundNames::iterator it = mSoundNames.find(soundItem->mSoundID);

        if (it != mSoundNames.end())
        {
            const Ogre::String& soundName = it->second;

            if (mSoundNameComboBox->FindString(soundName))
                mSoundNameComboBox->SetValue(soundName);
            else
                mSoundNameComboBox->SetSelection(0);

            mCurrentSoundHandle = _PlaySound(it->second, mCurrentSoundHandle, soundItem->mRepeatTime == 0);
        }
        else
        {
            mSoundNameComboBox->SetSelection(0);
        }

        mRadiusTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mRadius) );
        mXPosTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mXPos) );
        mZPosTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mZPos) );
        mRepeatTimeTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mRepeatTime) );
        mRepeatIntervalTimeTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mRepeatIntervalTime) );
        mNextRepeatTimeTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mNextRepeatTime) );
        mSoundIDText->SetLabel( Ogre::StringConverter::toString(soundItem->mSoundID) );

        mCurrentSoundItem = soundItem;

        mCurrentRepeatTime = 0;
        mCurrentRepeatIntervalTime = 0;
        mCurrentPlayIntervalTime = 0;

        Ogre::Camera* camera = mSceneManipulator->getCamera();

        Fairy::TerrainData* terrainData = mSceneManipulator->getTerrainData();

        std::pair<float, float> worldPos = terrainData->gridToWorld(soundItem->mXPos, soundItem->mZPos);
        float worldHeight = terrainData->getHeightAt(worldPos.first, worldPos.second);

        Ogre::Vector3 direction = camera->getDirection();
        float v = Ogre::Math::Sin(Ogre::Math::DegreesToRadians(89.9f));
        float s = Ogre::Math::Sqrt((direction.x*direction.x + direction.z*direction.z) / (1-v*v));
        direction.x /= s;
        direction.z /= s;
        direction.y = -v;
        camera->setDirection(direction);

        camera->setPosition(worldPos.first, worldHeight + 2750.0f, worldPos.second);

        Fairy::Action* action = mSceneManipulator->_getAction("SoundEditAction");

        action->setParameter("ShowRadiusEntity", Ogre::StringConverter::toString(worldPos.first) + " " +
            Ogre::StringConverter::toString(worldHeight) + " " +
            Ogre::StringConverter::toString(worldPos.second) + " " +
            Ogre::StringConverter::toString(soundItem->mRadius));
    }
}
void CSaveSceneView::SceneNodeExplore(Ogre::SceneNode *SceneNode)
{
	Ogre::Entity *Entity = NULL;
	Ogre::Camera *Camera = NULL;
	Ogre::Light *Light = NULL;
	Ogre::ParticleSystem *ParticleSystem = NULL;
	Ogre::ManualObject *ManualObject = NULL;
	Ogre::BillboardSet *BillboardSet = NULL;

	xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "SceneNode");
	
	Ogre::String SceneNodeName = SceneNode->getName();

	xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "SceneNodeName",
										BAD_CAST SceneNodeName.c_str());

	Ogre::SceneNode::ObjectIterator obji = SceneNode->getAttachedObjectIterator();

	while (obji.hasMoreElements())
	{
		Ogre::MovableObject* mobj = obji.getNext();
	
		Ogre::String Type = mobj->getMovableType();
	
		if (Type == "Entity")
		{
			Entity = (Ogre::Entity *)(mobj);
			Ogre::String EntityName = Entity->getName();
			xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Entity");
			xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "EntityName",
										BAD_CAST EntityName.c_str());

			Ogre::MeshPtr Mesh = Entity->getMesh();
			Ogre::String MeshName = Mesh->getName();
			xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "MeshName",
										BAD_CAST MeshName.c_str());
			xmlTextWriterEndElement(m_XmlWriter); 
		}
		
		if (Type == "Camera")
		{
			Camera = (Ogre::Camera *)(mobj);
			Ogre::String CameraName = Camera->getName();
			xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Camera");
			
			xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "CameraName",
										BAD_CAST CameraName.c_str());
			
			Ogre::Vector3 CameraPosition = Camera->getPosition();
			
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "XPosition",
										"%f",CameraPosition.x);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "YPosition",
										"%f",CameraPosition.y);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "ZPosition",
										"%f",CameraPosition.z);

			Ogre::Vector3 CameraDirection = Camera->getDirection();

			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "XDirection",
										"%f",CameraDirection.x);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "YDirection",
										"%f",CameraDirection.y);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "ZDirection",
										"%f",CameraDirection.z);

			xmlTextWriterEndElement(m_XmlWriter); 
		}

		if (Type == "Light")
		{
			Light = (Ogre::Light *)(mobj);
		}

		if (Type == "ParticleSystem")
		{
			ParticleSystem = (Ogre::ParticleSystem *)(mobj);
		}

		if (Type == "ManualObject")
		{
			ManualObject = (Ogre::ManualObject *)(mobj);
		}

		if (Type == "BillboardSet")
		{
			BillboardSet = (Ogre::BillboardSet *)(mobj);
		}

	}

	Ogre::Node::ChildNodeIterator nodei = SceneNode->getChildIterator();

	while (nodei.hasMoreElements())
	{
		Ogre::SceneNode* node = (Ogre::SceneNode*)(nodei.getNext());
			// Add this subnode and its children...
		SceneNodeExplore(node);
	}

	xmlTextWriterEndElement(m_XmlWriter); //end SceneNode
}