コード例 #1
0
ファイル: OgreSetup.cpp プロジェクト: Tombana/NNYv3
int CUIMain::LoadWorld(void)
{
	Ogre::SceneNode* RootNode = mSceneMgr->getRootSceneNode();

	Ogre::Plane plane(Ogre::Vector3::UNIT_Y, -1); //1 unit under the ground
	Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
		2000,2000,20,20,true,1,5,5,Ogre::Vector3::UNIT_Z);
	Ogre::Entity *GroundEnt = mSceneMgr->createEntity("GroundEntity", "ground");
	GroundEnt->setQueryFlags(QUERY_MASK_MOUSE_MOVEMENT);
	GroundEnt->setMaterialName("Rockwall");
	RootNode->createChildSceneNode()->attachObject(GroundEnt);

	CharacterInfo local_player_info;
	mWorld.LocalPlayer = new CLocalPlayer(mWorld, RootNode->createChildSceneNode());
	AttachMeshes(mWorld.LocalPlayer, local_player_info);
	mWorld.LocalPlayer->SetMoveSpeed(100);
	mWorld.LocalPlayer->SetState(State_Idle);

	//Test:
	CreateNewPlayer(0, CharacterInfo());

	Ogre::SceneNode *DestMarkerNode = RootNode->createChildSceneNode();
	Ogre::Entity *DestMarker = mSceneMgr->createEntity("Ent-DestMarker", "arrow.mesh");
	DestMarker->setQueryFlags(0);
	DestMarkerNode->attachObject(DestMarker);
	DestMarkerNode->setVisible(false);
	mWorld.LocalPlayer->SetDestinationMarker(DestMarkerNode, DestMarker);

	mMoveDestinationIndicator = RootNode->createChildSceneNode();
	Ogre::Entity* MouseIndicatorEntity = mSceneMgr->createEntity("Ent-MouseIndicator", "arrow.mesh");
	MouseIndicatorEntity->setQueryFlags(0);
	MouseIndicatorEntity->setMaterialName("ArrowTransparent");
	mMoveDestinationIndicator->attachObject(MouseIndicatorEntity);
	mMoveDestinationIndicator->scale(0.8, 0.8, 0.8);

	mEntityHoveringIndicator = RootNode->createChildSceneNode();
	mEntitySelectionIndicator = RootNode->createChildSceneNode();
	Ogre::Entity* HoverIndicatorEntity = mSceneMgr->createEntity("Ent-HoveringIndicator", "arrows.mesh");
	Ogre::Entity* SelectionIndicatorEntity = mSceneMgr->createEntity("Ent-SelectionIndicator", "arrows.mesh");
	HoverIndicatorEntity->setQueryFlags(0);
	SelectionIndicatorEntity->setQueryFlags(0);
	HoverIndicatorEntity->setMaterialName("ArrowTransparent");
	mEntitySelectionIndicator->setInheritOrientation(false);
	mEntityHoveringIndicator->attachObject(HoverIndicatorEntity);
	mEntitySelectionIndicator->attachObject(SelectionIndicatorEntity);
	mEntityHoveringIndicator->setVisible(false);
	mEntitySelectionIndicator->setVisible(false);

	return 1;
}
コード例 #2
0
bool PlayerCamera::onGhostAdd(TNL::GhostConnection *theConnection)
{
	if(!Parent::onGhostAdd(theConnection))
		return false; //A parent had an error
	
#ifdef CLIENT_SIDE
	if(owner() == Player::myId())
	{
		qDebug() << "========= Got My Camera";
		return(true);
	}
	else
	{
		qDebug() << "========= Got user camera:" << owner();
		Ogre::Entity                   *entity;
		char entname[100];
		snprintf(entname, 100, "crateent%i", entnum);
		entity = Application::instance()->getScene()->createEntity(entname, "cube.mesh");
		entity->setQueryFlags(1 << 2);
		char entname2[100];
		snprintf(entname2, 100, "crateent%i", entnum);
		_node = Application::instance()->getScene()->getRootSceneNode()->createChildSceneNode(entname2);
		_node->attachObject(entity);
		entnum++;
	}
#endif
	return(true);
}
コード例 #3
0
ファイル: PlayersManager.cpp プロジェクト: jorge-d/zappy
void
PlayersManager::createPlayer(zappy::Player *player)
{
  Ogre::Entity *ent;
  Ogre::SceneNode *node;
  Ogre::AnimationState *anim;
  std::string id(NumberToString<unsigned int>(player->getId()));
  OPlayer *toAdd;

  ent = this->mSceneMgr->createEntity("Player" + id, "robot.mesh");
  node = this->mSceneMgr->getRootSceneNode()->
    createChildSceneNode(PLAYERNODENAME + id,
                         Ogre::Vector3(player->getX() * Constants::SquareSize,
                                       0,
                                       player->getY() * Constants::SquareSize));
  ent->setQueryFlags(Constants::PLAYER_MASK);
  anim = ent->getAnimationState("Idle");
  anim->setLoop(true);
  anim->setEnabled(true);
  node->attachObject(ent);
  player->setRendered(true);
  toAdd = new OPlayer(ent, node);
  toAdd->setSpell(this->mSceneMgr->createParticleSystem("Aureola" + id, "Examples/Aureola"));
  toAdd->setBroad(this->mSceneMgr->createParticleSystem("Purple" + id, "Examples/PurpleFountain"));
  this->mOPlayers.push_back(toAdd);
}
コード例 #4
0
AnimateableCharacter::AnimateableCharacter(Ogre::String name, Ogre::SceneManager *sceneMgr, OgreDetourCrowd* detourCrowd, bool debugDraw, Ogre::Vector3 position)
    : Character(name, sceneMgr, detourCrowd, position),
    mAnimState(NULL),
    mAnimSpeedScale(1),
    mDebugNode(NULL)
{
    mNode = sceneMgr->getRootSceneNode()->createChildSceneNode(name+"Node");
    mEnt = sceneMgr->createEntity(name, "Gamechar-male.mesh");

    // Assign random texture
    int i = (int)Ogre::Math::RangeRandom(0,14);
    if (i > 13)
        i = 13;
    mEnt->setMaterialName("GameChar_Male_Mat_"+Ogre::StringConverter::toString(i));

    mEnt->setQueryFlags(OgreRecastApplication::DEFAULT_MASK);   // Exclude from ray queries

    mNode->attachObject(mEnt);
    mNode->setPosition(position);

    // Assign animation
    mAnimState= mEnt->getAnimationState("Walk");
    mAnimState->setEnabled(true);
    mAnimState->setLoop(true);

    Ogre::Vector3 bBoxSize = mEnt->getBoundingBox().getSize();

    Ogre::Real agentRadius = mDetourCrowd->getAgentRadius();
    Ogre::Real agentHeight = mDetourCrowd->getAgentHeight();

    // Set Height to match that of agent
    //mNode->setScale((agentRadius*2)/bBoxSize.y, agentHeight/bBoxSize.y, (agentRadius*2)/bBoxSize.y);
    Ogre::Real scale = agentHeight/bBoxSize.y;
    mNode->setScale(scale, scale, scale);

    // Set animation speed scaling
    mAnimSpeedScale = 0.35*(scale*4);


    // Debug draw agent
    mDebugNode = mNode->createChildSceneNode(name+"AgentDebugNode");
    mDebugNode->setPosition(0, mDetourCrowd->m_recast->getNavmeshOffsetFromGround(), 0);
    Ogre::Entity* debugEnt = sceneMgr->createEntity(name+"AgentDebug", "Cylinder.mesh");
    debugEnt->setMaterialName("Cylinder/Wires/LightBlue");
    mDebugNode->attachObject(debugEnt);
    // Set marker scale to size of agent
    mDebugNode->setInheritScale(false);
    mDebugNode->setScale(agentRadius*2, agentHeight, agentRadius*2);
    debugEnt->setQueryFlags(OgreRecastApplication::DEFAULT_MASK);   // Exclude from ray queries
    mDebugNode->setVisible(debugDraw);
}
コード例 #5
0
ファイル: ManipulatorObject.cpp プロジェクト: mavaL/MiniCraft
Ogre::Entity* ManipulatorObject::AddEntity( const STRING& meshname, const POS& worldPos, bool bOp, const ORIENT& orient, const SCALE& scale )
{
	static int counter = 0;

	Ogre::String entName("Entity_");
	entName += Ogre::StringConverter::toString(counter++);

	Ogre::Entity* newEntity = RenderManager.m_pSceneMgr->createEntity(entName, meshname);
	if(!newEntity)
		return nullptr;

	Ogre::SceneNode* pNode = RenderManager.m_pSceneMgr->getRootSceneNode()->createChildSceneNode(worldPos, orient);
	pNode->setScale(scale);
	pNode->attachObject(newEntity);

	//每个Entity创建一个包围盒节点
	Ogre::WireBoundingBox* aabb = new Ogre::WireBoundingBox;
	aabb->setMaterial("BaseWhiteNoLighting");
	aabb->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
	Ogre::SceneNode* aabbNode = pNode->createChildSceneNode(entName);
	aabbNode->attachObject(aabb);
	aabbNode->setVisible(false);

	_UpdateAABBOfEntity(newEntity);

	//设置查询掩码
	newEntity->setQueryFlags(eQueryMask_Entity);

	SObjectInfo* objInfo = new SObjectInfo;
	objInfo->m_meshname = meshname;
	objInfo->m_pos = worldPos;
	objInfo->m_rot = orient;
	objInfo->m_scale = scale;

	m_objects.insert(std::make_pair(newEntity, objInfo));

	//可撤销操作
	if (bOp)
	{
		opObjectAddRemove* op = ManipulatorSystem.GetOperation().NewOperation<opObjectAddRemove>();
		opObjectAddRemove::SOpItem item;
		item.bAddOrRemove = true;
		item.ent = newEntity;
		item.objInfo = *objInfo;
		op->AddOp(item);
		ManipulatorSystem.GetOperation().Commit(op);
	}
	
	return newEntity;
}
コード例 #6
0
void SceneLoader::createWall( Ogre::Vector3 pos, Ogre::Real scale )
{
	Ogre::Entity* ent = mSceneMgr->createEntity("atd_cube.mesh");
//  	Ogre::MeshPtr mesh = ent->getMesh();
//  	mesh->freeEdgeList();
//  	mesh->buildEdgeList();

	ent->setCastShadows(true);
	ent->setQueryFlags(AugmentedTowerDefense::MASK_WALLS);
	Ogre::SceneNode* node = mSceneRootNode->createChildSceneNode("Wall_" + AugmentedTowerDefense::HelperClass::ToString(mWallCount));
	node->setPosition(pos);
	node->setScale(Ogre::Vector3::UNIT_SCALE*scale);
	node->attachObject(ent);
	
	mWallCount++;
}
コード例 #7
0
ファイル: ogrewidget.cpp プロジェクト: wpfhtl/octocopter
void OgreWidget::placeObjectOnTerrain(const QString meshName, const Ogre::Vector3 position, const float rotationY, const Ogre::Vector3 scale)
{
    Ogre::Quaternion rotation;
    QString name(meshName);
    name.replace(".mesh", "");

    Ogre::Entity* entity = mSceneManager->createEntity(name.toStdString(), meshName.toStdString());
    entity->setQueryFlags(0xFFFFFFFF);
    rotation.FromAngleAxis(Ogre::Degree(rotationY), Ogre::Vector3::UNIT_Y);
    Ogre::SceneNode* sceneNode = mSceneManager->getRootSceneNode()->createChildSceneNode(
                position + Ogre::Vector3(0, mTerrainGroup->getHeightAtWorldPosition(position) + mTerrainPos.y - 0.2, 0),
                rotation);
    sceneNode->setScale(scale);
    sceneNode->attachObject(entity);
    addMeshInformation(entity, sceneNode);
}
コード例 #8
0
ファイル: MyFrameListener.cpp プロジェクト: flush/CEDV-2015
/*
 * Create a fake Plane for Drag and Drop
 */   
void MyFrameListener::createBackGround() {
  Ogre::SceneManager* mSceneMgr = Ogre::Root::getSingleton().
                                  getSceneManager("mainSM");
  Ogre::Plane *mPlane = new Ogre::Plane(Ogre::Vector3::UNIT_Z, -2);

  Ogre::MeshManager::getSingleton().createPlane("backPlane",
                                                Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                *mPlane,800, 800, 20, 20, true, 1, 5, 5
                                                , Ogre::Vector3::UNIT_Y);
  Ogre::Entity* plane = mSceneMgr->createEntity("backPlane");
  plane->setQueryFlags(PLANE_DRAG_DROP);
  plane->setMaterialName("sheet");
  Ogre::Root::getSingleton().
      getSceneManager("mainSM")->getRootSceneNode()->
      attachObject(plane);
}
コード例 #9
0
// add a control point
Ogre::String CTrack::mAdd( ControlPoint tCP )
{
	Ogre::Entity *ent;
	char name[16];
	sprintf(name, "ControlPoint%d", mCount++);
	ent = mSm->createEntity(name, "point.mesh");
	ent->setQueryFlags(ObjectControl::CONTROL_POINT);

	Ogre::SceneNode *mCurrentObject = mSm->getRootSceneNode()->createChildSceneNode(std::string(name) + "Node", tCP.pos);
	mCurrentObject->attachObject(ent);
	mCurrentObject->setScale(0.05f, 0.05f, 0.05f);

	tCP.name = mCurrentObject->getName();

	CPs.push_back(tCP);

	return mCurrentObject->getName();
}
コード例 #10
0
ファイル: JunctionPoints.cpp プロジェクト: gitrider/wxsj2
    Ogre::SceneNode*
    JunctionPoints::allocNode(void)
    {
        Ogre::SceneNode* node;
        if (mFreeNodes.empty())
        {
            node = getIndicatorRootSceneNode()->createChildSceneNode();
            Ogre::Entity* entity = getSceneManager()->createEntity(node->getName(), mBaseMesh->getName());
            entity->setQueryFlags(0);
			//david-<<
            //entity->setNormaliseNormals(true);
			//david->>
            node->attachObject(entity);
        }
        else
        {
            node = mFreeNodes.back();
            mFreeNodes.pop_back();
            getIndicatorRootSceneNode()->addChild(node);
        }

        node->setScale(mScale, mScale, mScale);
        return node;
    }
コード例 #11
0
ファイル: EntityEditor.cpp プロジェクト: Laefy/ember
	/**
	 * @brief Ctor.
	 * @param entity The entity which the marker is attached to.
	 * @param sceneManager A scene manager used to create nodes and entities.
	 * @param terrainManager Provides height data.
	 * @param point The location which will be marked.
	 */
	EntityPointMarker(Eris::Entity& entity, Ogre::SceneManager& sceneManager, const IHeightProvider& heightProvider, const WFMath::Point<3>& point) :
			mEntity(entity), mMarkerEntity(0), mMarkerNode(0), mMarkerDirectionIndicator(0), mHeightProvider(heightProvider), mPoint(point)
	{
		mMarkerNode = sceneManager.getRootSceneNode()->createChildSceneNode();
		try {
			mMarkerEntity = sceneManager.createEntity("3d_objects/primitives/models/sphere.mesh");
			//start out with a normal material
			mMarkerEntity->setMaterialName("/global/authoring/point");
			//The material is made to ignore depth checks, so if we put it in a later queue we're
			//making sure that the marker is drawn on top of everything else, making it easier to interact with.
			mMarkerEntity->setRenderQueueGroup(Ogre::RENDER_QUEUE_9);
			mMarkerEntity->setRenderingDistance(300);
			mMarkerEntity->setQueryFlags(MousePicker::CM_NONPICKABLE);
			mMarkerNode->attachObject(mMarkerEntity);
		} catch (const std::exception& ex) {
			S_LOG_WARNING("Error when creating marker node." << ex);
			return;
		}
		mMarkerNode->setVisible(true);

		mMarkerDirectionIndicator = new ShapeVisual(*sceneManager.getRootSceneNode(), false);

		mEntity.Moved.connect(sigc::mem_fun(*this, &EntityPointMarker::entityMoved));
	}
コード例 #12
0
ObjectEditHandler::ObjectEditHandler(SceneDoc *Owner)
{
	mOwner = Owner;
	mMode = OEM_NONE;
	mAxisMode = AM_NONE;
	mTarget = NULL;
	mObjectEditNode = mOwner->getSceneManager()->getRootSceneNode()->createChildSceneNode();
	mRayQuery = mOwner->getSceneManager()->createRayQuery(Ogre::Ray());

	mMaterials[0] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/RedMat");
	mMaterials[1] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/GreenMat");
	mMaterials[2] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/BlueMat");
	mMaterials[3] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/ObjectIndicatorWhiteMat");
	mMaterials[4] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/ObjectIndicatorYellowMat");

	//////////////////////////////////////////////////
	// 碰撞检测
	//////////////////////////////////////////////////

	mCollisionManager = new OgreOpcode::CollisionManager(Owner->getSceneManager());
	mCollisionManager->addCollClass("Object");
	mCollisionManager->addCollType("Object", "Object", OgreOpcode::COLLTYPE_IGNORE);
	mCollisionContext = mCollisionManager->createContext("SceneObject");

	Ogre::MovableObjectFactory* Factory = 
		Ogre::Root::getSingleton().getMovableObjectFactory(Ogre::EntityFactory::FACTORY_TYPE_NAME);
	Ogre::NameValuePairList Params;

	//////////////////////////////////////////////////
	// 平移放缩指示器
	//////////////////////////////////////////////////

	mIndicatorContext = mCollisionManager->createContext("TransScale");

	mTransScaleNode = mObjectEditNode->createChildSceneNode("TransScaleIndicator");
	mTransScaleNode->setScale(200.0f, 200.0f, 200.0f);

	// x
	Ogre::SceneNode *SubNode = mTransScaleNode->createChildSceneNode();
	SubNode->roll(Ogre::Degree(-90.0f));

	Ogre::Entity *Entity = Owner->getSceneManager()->createEntity("TransScaleXLine", "MoveArrowLineVisible.mesh");
	//Entity->setQueryFlags(0); // 参与查询
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[0]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_TRANS_SCALE_X] = Entity;

	Entity = Owner->getSceneManager()->createEntity("TransScaleXCone", "MoveArrowConeVisible.mesh");
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[0]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);

	Params["mesh"] = "MoveArrowCollision.mesh";
	Entity = (Ogre::Entity*)Factory->createInstance("TransScaleXCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	OgreOpcode::CollisionObject *CollisionObject = 
		AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_X;

	// y
	SubNode = mTransScaleNode;

	Entity = Owner->getSceneManager()->createEntity("TransScaleYLine", "MoveArrowLineVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[1]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_TRANS_SCALE_Y] = Entity;

	Entity = Owner->getSceneManager()->createEntity("TransScaleYCone", "MoveArrowConeVisible.mesh");
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[1]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);

	Params["mesh"] = "MoveArrowCollision.mesh";
	Entity = (Ogre::Entity*)Factory->createInstance("TransScaleYCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_Y;

	// z
	SubNode = mTransScaleNode->createChildSceneNode();
	SubNode->pitch(Ogre::Degree(90));

	Entity = Owner->getSceneManager()->createEntity("TransScaleZLine", "MoveArrowLineVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[2]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_TRANS_SCALE_Z] = Entity;

	Entity = Owner->getSceneManager()->createEntity("TransScaleZCone", "MoveArrowConeVisible.mesh");
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[2]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);

	Params["mesh"] = "MoveArrowCollision.mesh";
	Entity = (Ogre::Entity*)Factory->createInstance("TransScaleZCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_Z;

	// box
	SubNode = mTransScaleNode;

	Params["mesh"] = "Box1m.mesh";
	Entity =(Ogre::Entity*)Factory->createInstance("TransScaleAll", Owner->getSceneManager(), &Params);
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[3]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_TRANS_SCALE_ALL] = Entity;

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_ALL;

	mIndicatorContext->reset();
	mObjectEditNode->removeChild(mTransScaleNode);

	//////////////////////////////////////////////////
	// 旋转指示器
	//////////////////////////////////////////////////

	mIndicatorContext = mCollisionManager->createContext("Rotate");

	mRotateNode = mObjectEditNode->createChildSceneNode("RotateIndicator");
	mRotateNode->setScale(200.0f, 200.0f, 200.0f);

	// x
	SubNode = mRotateNode->createChildSceneNode();
	SubNode->roll(Ogre::Degree(90));

	Entity = Owner->getSceneManager()->createEntity("RotateX", "RotationRingVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[0]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_ROTATE_X] = Entity;

	Params["mesh"] = "RotationRingCollision.mesh";
	Entity =(Ogre::Entity*)Factory->createInstance("RotateXCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_ROTATE_X;

	// y
	SubNode = mRotateNode;
	Entity = Owner->getSceneManager()->createEntity("RotateY", "RotationRingVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[1]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_ROTATE_Y] = Entity;

	Params["mesh"] = "RotationRingCollision.mesh";
	Entity =(Ogre::Entity*)Factory->createInstance("RotateYCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);
	
	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_ROTATE_Y;

	// z
	SubNode = mRotateNode->createChildSceneNode();
	SubNode->pitch(Ogre::Degree(90.0f));

	Entity = Owner->getSceneManager()->createEntity("RotateZ", "RotationRingVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[2]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_ROTATE_Z] = Entity;

	Params["mesh"] = "RotationRingCollision.mesh";
	Entity =(Ogre::Entity*)Factory->createInstance("RotateZCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_ROTATE_Z;

	mIndicatorContext->reset();
	mObjectEditNode->removeChild(mRotateNode);
}
コード例 #13
0
//这个函数会在初始化调用
void FCScene::doEnable(void)
{
	
	_map->active();
	using namespace Ogre;
	//从系统中得到Ogre的场景管理器
	SceneManager * sm = OgreGraphicsManager::getSingleton().getSceneManager();

	//把其场景清空
	sm->clearScene();
	
	
	Plane plane;
	plane.normal = Vector3::UNIT_Y;
	plane.d = 100;
	FCKnowledge::getSingleton().mapInfo().setGround(-plane.d);
	FCKnowledge::getSingleton().mapInfo().enable();
	MeshManager::getSingleton().createPlane("Myplane",
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
		512, 512,20,20,true,1,60,60,Vector3::UNIT_Z);
	Ogre::Entity* pPlaneEnt = sm->createEntity( "plane", "Myplane" );
	pPlaneEnt->setMaterialName("Examples/Rockwall");
	pPlaneEnt->setQueryFlags(0);
	sm->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);

	//设置环境光
	sm->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

	//创建天空盒
	//sm->setSkyBox(true, "Examples/SpaceSkyBox", 50 );

	// 创建一个光源
	Light* l = sm->createLight("MainLight");

	//设置光源位置
	l->setPosition(20,80,50);


	//下面代码随机 放置砖块
	NameValueList par;
	for(int i = 1; i< 16 *16; ++i)
	{
		if(rand()%2 == 0)
		{
			par["pos"] = i;
			ActorPtr wall = Orz::GameFactories::getInstance().createActor("FCWall",IDManager::BLANK, &par );
			getWorld()->comeIn(wall);
			_walls.push_back(wall);
		}
	}

	//在这里我们通过XML文件FighteingClub.xml 得到两个格斗者的名字,然后创建他们 并给他们位置和ID
	XMLFighterLoader loader;
	if(loader.load("FighteingClub.xml"))
	{
		{
			par["pos"] = 10;
			par["id"] = 0;
			ActorPtr fighter = Orz::GameFactories::getInstance().createActor(loader.getFighter1(),IDManager::BLANK, &par );
			getWorld()->comeIn(fighter);
			_enemies.push_back(fighter);
			
		}
		{
			par["pos"] = 20;
			
			par["id"] = 1;
			ActorPtr fighter = Orz::GameFactories::getInstance().createActor(loader.getFighter2(),IDManager::BLANK, &par );
			getWorld()->comeIn(fighter);
		_enemies.push_back(fighter);
		}
	}
	else//如果XML读取失败 那么就采用默认的 "FCFighter"
	{
		for(int i =0; i<2; ++i)
		{
			
			par["id"] = i;
			par["pos"] = i*10;
			ActorPtr fighter = Orz::GameFactories::getInstance().createActor("FCFighter",IDManager::BLANK, &par );
			getWorld()->comeIn(fighter);
			_enemies.push_back(fighter);
		}
	}
}
コード例 #14
0
void ObjectNode::createEntities(Ogre::SceneNode *target_node, Ogre::SceneManager *scene_manager, LibGens::ModelLibrary *model_library, LibGens::MaterialLibrary *material_library, LibGens::ObjectProduction *object_production, string slot_id_name) {
	string model_name=object->queryEditorModel(slot_id_name, OBJECT_NODE_UNKNOWN_MESH);
	string skeleton_name=object->queryEditorSkeleton(slot_id_name, "");
	string animation_name=object->queryEditorAnimation(slot_id_name, "");

	string preview_box_x=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_X, "");
	string preview_box_y=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_Y, "");
	string preview_box_z=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_Z, "");

	string preview_box_x_scale=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_X_SCALE, "");
	string preview_box_y_scale=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_Y_SCALE, "");
	string preview_box_z_scale=object->queryExtraName(OBJECT_NODE_EXTRA_PREVIEW_BOX_Z_SCALE, "");

	if ((preview_box_x.size()) || (preview_box_y.size()) || (preview_box_z.size())) {
		LibGens::ObjectElementFloat *p_x = (LibGens::ObjectElementFloat *) object->getElement(preview_box_x);
		LibGens::ObjectElementFloat *p_y = (LibGens::ObjectElementFloat *) object->getElement(preview_box_y);
		LibGens::ObjectElementFloat *p_z = (LibGens::ObjectElementFloat *) object->getElement(preview_box_z);

		Ogre::Vector3 new_scale = preview_box_node->getScale();
		float scale_f=0.0f;

		float scale_x = 1.0f;
		float scale_y = 1.0f;
		float scale_z = 1.0f;

		if (preview_box_x_scale.size()) FromString<float>(scale_x, preview_box_x_scale, std::dec);
		if (preview_box_y_scale.size()) FromString<float>(scale_y, preview_box_y_scale, std::dec);
		if (preview_box_z_scale.size()) FromString<float>(scale_z, preview_box_z_scale, std::dec);

		// Check if elements were found. If not, try reading the float value from the string
		if (p_x) new_scale.x = p_x->value;
		else {
			FromString<float>(scale_f, preview_box_x, std::dec);
			new_scale.x = scale_f;
		}

		if (p_y) new_scale.y = p_y->value;
		else {
			FromString<float>(scale_f, preview_box_y, std::dec);
			new_scale.y = scale_f;
		}

		if (p_z) new_scale.z = p_z->value;
		else {
			FromString<float>(scale_f, preview_box_z, std::dec);
			new_scale.z = scale_f;
		}

		new_scale.x = new_scale.x * scale_x;
		new_scale.y = new_scale.y * scale_y;
		new_scale.z = new_scale.z * scale_z;

		// Check for valid scaling values
		if (new_scale.x <= 0.0) new_scale.x = 0.1;
		if (new_scale.y <= 0.0) new_scale.y = 0.1;
		if (new_scale.z <= 0.0) new_scale.z = 0.1;

		preview_box_node->setScale(new_scale);
	}

	if ((object->getName() == OBJECT_NODE_OBJECT_PHYSICS) && object_production) {
		bool found_model=false;

		LibGens::ObjectElement *element=object->getElement(OBJECT_NODE_OBJECT_PHYSICS_ELEMENT_TYPE);
		if (element) {
			string type_name=static_cast<LibGens::ObjectElementString *>(element)->value;

			if (type_name != current_type_name) {
				current_type_name = type_name;
				destroyAllAttachedMovableObjects(target_node);
			}
			else {
				return;
			}

			LibGens::ObjectPhysics *object_physics = object_production->getObjectPhysics(type_name);
			if (object_physics) {
				vector<string> models=object_physics->getModels();
				vector<string> motions=object_physics->getMotions();
				vector<string> motion_skeletons=object_physics->getMotionSkeletons();

				for (size_t i=0; i<models.size(); i++) {
					string model_id=models[i];
					string skeleton_id = "";
					string animation_id = "";

					LibGens::Model *model=model_library->getModel(model_id);
					if (i < motions.size()) {
						animation_id = motions[i];
					}

					if (i < motion_skeletons.size()) {
						skeleton_id = motion_skeletons[i];
					}

					if (model) {
						prepareSkeletonAndAnimation(skeleton_id, animation_id);
						buildModel(target_node, model, model->getName(), skeleton_id, scene_manager, material_library, EDITOR_NODE_QUERY_OBJECT, GENERAL_MESH_GROUP, false);
						createAnimationState(animation_id);
						found_model = true;
					}
				}
			}
		}

		if (found_model) {
			return;
		}
		else {
			current_model_name = "";
		}
	}

	if ((model_name != current_model_name) || (skeleton_name != current_skeleton_name) || (animation_name != current_animation_name)) {
		current_model_name = model_name;
		current_skeleton_name = skeleton_name;
		current_animation_name = animation_name;

		destroyAllAttachedMovableObjects(target_node);
	}
	else {
		return;
	}

	string model_id=model_name;
	model_id.resize(model_id.size() - ((string)OBJECT_NODE_MODEL_EXTENSION).size());

	string skeleton_id="";
	if (skeleton_name.size()) {
		skeleton_id=skeleton_name;
		skeleton_id.resize(skeleton_id.size() - ((string)OBJECT_NODE_SKELETON_EXTENSION).size());
	}

	string animation_id="";
	if (animation_name.size()) {
		animation_id=animation_name;
		animation_id.resize(animation_id.size() - ((string)OBJECT_NODE_ANIMATION_EXTENSION).size());
	}

	if (model_name.find(OBJECT_NODE_MODEL_EXTENSION) != string::npos) {
		LibGens::Model *model=model_library->getModel(model_id);

		if (model) {
			prepareSkeletonAndAnimation(skeleton_id, animation_id);
			buildModel(target_node, model, model->getName(), skeleton_id, scene_manager, material_library, EDITOR_NODE_QUERY_OBJECT, GENERAL_MESH_GROUP, false);
		}
		else {
			Ogre::Entity *entity = scene_manager->createEntity(OBJECT_NODE_UNKNOWN_MESH);
			entity->setQueryFlags(EDITOR_NODE_QUERY_OBJECT);
			target_node->attachObject(entity);
		}
	}
	else if (model_name.find(OBJECT_NODE_MESH_EXTENSION) != string::npos) {
		Ogre::Entity *entity = scene_manager->createEntity(model_name);
		entity->setQueryFlags(EDITOR_NODE_QUERY_OBJECT);
		target_node->attachObject(entity);
	}

	createAnimationState(animation_id);

	// Create PreviewBox if necessary
	if ((preview_box_x.size()) || (preview_box_y.size()) || (preview_box_z.size())) {
		preview_box_entity = scene_manager->createEntity("preview_box.mesh");
		preview_box_entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAX);
		preview_box_entity->setQueryFlags(EDITOR_NODE_QUERY_PREVIEW_BOX);
		preview_box_node->attachObject(preview_box_entity);
	}
}
コード例 #15
0
void GameRenderer::initialize(){
	
	DEBUG("GameRenderer::initialize");
	
	Client::getInstance().getOgreManager().getRoot()->addFrameListener(this);
	
	// Tray manager, hacky fix for intel graphics
	mTrayMgr = new OgreBites::SdkTrayManager(
		"InterfaceName", 
		Client::getInstance().getOgreManager().getWindow(), 
		Client::getInstance().getOISManager().getMouse(), 
		this);
	mTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
	mTrayMgr->toggleAdvancedFrameStats();
	mTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
	mTrayMgr->hideCursor();
	
	//cameraMan = new OgreBites::SdkCameraMan(Client::getInstance().getOgreManager().getCamera());
	Client::getInstance().getOISManager().addMouseListener(this);
	Client::getInstance().getOISManager().addKeyListener(this);
	
	Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
	
	Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
	
	Ogre::Entity* entGround = 
		Client::getInstance()
			.getOgreManager()
			.getSceneManager()
			->createEntity("GroundEntity", "ground");

	Ogre::SceneNode* groundNode = Client::getInstance().getOgreManager().getSceneManager()->getRootSceneNode()->createChildSceneNode();
	groundNode->attachObject(entGround);
	groundNode->scale(.1, .1, .1);
	
	entGround->setMaterialName("Examples/Rockwall");
	entGround->setCastShadows(false);
	entGround->setQueryFlags(0);
	
	//point light
	Ogre::Light* pointLight = Client::getInstance().getOgreManager().getSceneManager()->createLight("pointLight");
	pointLight->setType(Ogre::Light::LT_POINT);
	pointLight->setPosition(Ogre::Vector3(0, 10, 10));
	pointLight->setDiffuseColour(1.0, 1.0, 1.0);
	pointLight->setSpecularColour(1.0, 1.0, 1.0);
	
	Client::getInstance()
		.getOgreManager()
		.getSceneManager()
		->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
	
	orb = new OgreOrb(Client::getInstance().getOgreManager().getSceneManager());
	felhound = new OgreFelhound(Client::getInstance().getOgreManager().getSceneManager(),0);
	
	//TODO: magic strings
	cameraStyles["TOCameraMan"] = new TOCameraManStyle();
	cameraStyles["WC3Style"] = new WC3CameraStyle();
	//TODO: configurable default
	setCameraStyle("WC3Style");
	
	DEBUG("GameRenderer::initialize done");
}
コード例 #16
0
void WalkabilityMap::init(TWalkabilityMapParameters tWalkabilityMapParameters,Ogre::SceneManager * pSceneManager,Ogre::SceneNode * pDebugObjects)
{
		unsigned int i,j;

		mDebugObjects=pDebugObjects;
		mSceneManager=pSceneManager;

		mName=tWalkabilityMapParameters.name;

		mDebugObjects->createChildSceneNode("walkability#"+tWalkabilityMapParameters.name);

		myLines.clear();
		myNodes.clear();
		mDisplays.clear();

		//init node numbers
		mNodeNumbers.clear();
		for(i=0;i<tWalkabilityMapParameters.walkabilityNodes.size();i++)
		{
			mNodeNumbers[tWalkabilityMapParameters.walkabilityNodes[i].nodeName]=i;
		}

		//init graph
		mGraph.clear();
		mGraph = Graph(mNodeNumbers.size());

		Ogre::SceneNode * pSceneNode;
		Ogre::Entity * pEntity;
		Ogre::SceneNode * pEntityDebugNode;
		ObjectTextDisplay* pDisplay;
		//create graph nodes
		for(i=0;i<tWalkabilityMapParameters.walkabilityNodes.size();i++)
		{
			//Logger::getInstance()->log("Adding node "+tWalkabilityMapParameters.walkabilityNodes[i].nodeName);

			if(pSceneManager->hasSceneNode(tWalkabilityMapParameters.walkabilityNodes[i].nodeName))
			{
				pSceneNode=pSceneManager->getSceneNode(tWalkabilityMapParameters.walkabilityNodes[i].nodeName);
			}
			else
			{
				pSceneNode=pSceneManager->getRootSceneNode()->createChildSceneNode(tWalkabilityMapParameters.walkabilityNodes[i].nodeName);
				pSceneNode->setPosition(tWalkabilityMapParameters.walkabilityNodes[i].position);
				pSceneNode->setOrientation(tWalkabilityMapParameters.walkabilityNodes[i].orientation);
			}

			mGraph[getNodeNumber(tWalkabilityMapParameters.walkabilityNodes[i].nodeName)].mSceneNode=pSceneNode;

			//create graphics debug objects
			std::string debugName="walkability#"+tWalkabilityMapParameters.name+"#"+tWalkabilityMapParameters.walkabilityNodes[i].nodeName;
			pEntityDebugNode=mDebugObjects->createChildSceneNode(debugName);
			pEntityDebugNode->setPosition(pSceneNode->getPosition());
			pEntityDebugNode->setVisible(mVisible);
			pEntity=pSceneManager->createEntity(debugName,"node.mesh");
			pEntity->setMaterialName("red");
			pEntity->setVisible(mVisible);
			pEntity->setCastShadows(false);
			pEntity->setQueryFlags(OUAN::QUERYFLAGS_NONE);
			pEntityDebugNode->attachObject(pEntity);
			myNodes.push_back(pEntity);
			pDisplay = new ObjectTextDisplay(pEntity,Application::getInstance()->getCameraManager()->getCamera());
			pDisplay->setText(tWalkabilityMapParameters.walkabilityNodes[i].nodeName);
			pDisplay->enable(mVisible);

			mDisplays.push_back(pDisplay);
		}

		//add graph edges
		for(i=0;i<tWalkabilityMapParameters.walkabilityNodes.size();i++)
		{
			for(j=0;j<tWalkabilityMapParameters.walkabilityNodes[i].neighbors.size();j++)
			{
				//Logger::getInstance()->log("Adding edge "+tWalkabilityMapParameters.walkabilityNodes[i].nodeName+"-"
				//	+tWalkabilityMapParameters.walkabilityNodes[i].neighbors[j]);

				if(hasNode(tWalkabilityMapParameters.walkabilityNodes[i].neighbors[j]))
				{
					add_edge(getNodeNumber(tWalkabilityMapParameters.walkabilityNodes[i].nodeName.c_str()),
						getNodeNumber(tWalkabilityMapParameters.walkabilityNodes[i].neighbors[j].c_str()),
						mGraph);
				}
			}
		}

		//set graph edges properties
		Graph::vertex_descriptor v1,v2;
		Ogre::SceneNode * pSceneNode1;
		Ogre::SceneNode * pSceneNode2;

		Graph::edge_descriptor e;

		boost::graph_traits<Graph>::edge_iterator eit,eend;

		boost::property_map<Graph, edge_weight_t>::type weightmap = get(edge_weight, mGraph);
		i=0;

		Line3D *myLine; 

		for (tie(eit, eend) = edges(mGraph); eit != eend; ++eit) 
		{
			Graph::edge_descriptor e = *eit;

			v1=source(e, mGraph);
			v2=target(e, mGraph);
			pSceneNode1=mGraph[v1].mSceneNode;
			pSceneNode2=mGraph[v2].mSceneNode;

			weightmap[e]=pSceneNode1->getPosition().distance(pSceneNode2->getPosition());

			//create graphics debug objects
			myLine = new Line3D();
			myLine->addPoint(pSceneNode1->getPosition());
			myLine->addPoint(pSceneNode2->getPosition());
			myLine->setMaterial("black");
			myLine->setCastShadows(false);
			myLine->drawLines();
			mDebugObjects->attachObject(myLine);
			mDebugObjects->setVisible(mVisible);
			myLines.push_back(myLine);
		}

		//print graph information
		Logger::getInstance()->log("[TrajectoryManager] Walkability map vertices");
		boost::graph_traits<Graph>::vertex_iterator vit,vend;
		for (tie(vit, vend) = vertices(mGraph); vit != vend; ++vit) 
		{
			Logger::getInstance()->log("Vertex "+mGraph[*vit].mSceneNode->getName());
		}

		Logger::getInstance()->log("[TrajectoryManager] Walkability map edges");
		for (tie(eit, eend) = edges(mGraph); eit != eend; ++eit) 
		{
			v1=source(*eit, mGraph);
			v2=target(*eit, mGraph);

			Logger::getInstance()->log("Edge "+mGraph[v1].mSceneNode->getName()+"-"+mGraph[v2].mSceneNode->getName()+
				" distance:"+Ogre::StringConverter::toString(Ogre::Real(weightmap[*eit])));
		}
}