virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) { { Ogre::SceneNode *Node = static_cast<Ogre::SceneNode *>(colObj0->getUserPointer()); if(Node) Node->setVisible(false); } { Ogre::SceneNode *Node = static_cast<Ogre::SceneNode *>(colObj1->getUserPointer()); if(Node) Node->setVisible(false); } //testVal = true; return 0; }
void Replicator::update(float value) { //logFile << getFrequentcyRange() << " :\t " << value << "\n"; Ogre::Vector3 currentScale = getScale(); this->setThreshold(0.7*this->getThreshold() + 0.4*value); float result = value / this->getThreshold(); int numOfChildrenToGenerate = result > 1.0 ? (result - value) * 2 : 0; //logFile << value / this->getThreashold() << "\t" << (result - value) * 10 << "\t" << numOfChildrenToGenerate << "\n"; for ( int i = 0; i < numOfChildrenToGenerate; i++ ) { createChildren(numOfChildrenToGenerate); } for(std::vector<Ogre::Entity*>::size_type i = 0; i < children.size(); ) { Ogre::SceneNode* childNode = children[i]->getParentSceneNode(); Ogre::Real res = childNode->getScale().length(); if ( res < 0.1 ) { children[i]->setVisible(false); childNode->setVisible(false); childNode->detachObject(children[i]->getName()); _sceneManager->destroyEntity(children[i]->getName()); // entity is now destroyed, don't try to use the pointer anymore! // optionally destroy node _sceneManager->destroySceneNode(childNode->getName()); children.erase( children.begin() + i ); } else { Ogre::Vector3 currScale = childNode->getScale(); childNode->setScale(Ogre::Vector3(currScale.x - currScale.x/3, currScale.y - currScale.y/3, currScale.z - currScale.z/3)); i++; } } }
void ManipulatorObject::ShowEntityGizmo(Ogre::Entity* pEntity, bool bShow, eEditMode mode, bool bDrift/* = false*/) { if(!pEntity) return; assert(mode != eEditMode_None); if (mode == eEditMode_Select) { Ogre::SceneNode* aabbNode = dynamic_cast<Ogre::SceneNode*>(pEntity->getParentSceneNode()->getChild(pEntity->getName())); aabbNode->setVisible(bShow); if (bShow) { //显示包围盒 Ogre::WireBoundingBox* pAABB = GetEntityAABBGizmo(pEntity); if(bDrift) //显示为红色 pAABB->setMaterial("RedEmissive_ZCheck"); else //显示为绿色 pAABB->setMaterial("GreenEmissive_ZCheck"); } } else { //显示坐标轴 m_pGizmoAixs->Show(bShow, mode == eEditMode_Move || mode == eEditMode_Scale); if (bShow) m_pGizmoAixs->Attach(pEntity->getParentSceneNode()); } }
//----------------------------------------------------------------------- void EntityRenderer::_updateRenderQueue(Ogre::RenderQueue* queue, ParticlePool* pool) { // Always perform this one ParticleRenderer::_updateRenderQueue(queue, pool); if (!mVisible) return; // Fast check to determine whether there are visual particles if (pool->isEmpty(Particle::PT_VISUAL)) return; VisualParticle* particle = static_cast<VisualParticle*>(pool->getFirst(Particle::PT_VISUAL)); while (!pool->end(Particle::PT_VISUAL)) { if (particle) { if (!particle->visualData && !mVisualData.empty()) { particle->visualData = mVisualData.back(); mVisualData.pop_back(); } if (particle->visualData) { Ogre::SceneNode* node = (static_cast<EntityRendererVisualData*>(particle->visualData))->node; if (node) { node->_setDerivedPosition(particle->position); if (mEntityOrientationType == ENT_ORIENTED_SHAPE) { // Use the orientation of the particle itself node->setOrientation(particle->orientation); } else if (mEntityOrientationType == ENT_ORIENTED_SELF) { // Rotate towards the direction node->setOrientation(Vector3::UNIT_X.getRotationTo(particle->direction)); } else if (mEntityOrientationType == ENT_ORIENTED_SELF_MIRRORED) { // Rotate towards the negative direction node->setOrientation(Vector3::UNIT_X.getRotationTo(-particle->direction)); } node->setVisible(true); node->setScale(particle->width / mBoxWidth, particle->height / mBoxHeight, particle->depth / mBoxDepth); if (mZRotated) { _rotateTexture(particle, static_cast<Ogre::Entity*>(node->getAttachedObject(0))); // We know for sure there is only one and it is an Entity* } } } } particle = static_cast<VisualParticle*>(pool->getNext(Particle::PT_VISUAL)); } }
// This is a helper function to create a new flag in the Ogre scene and save its scene node in a list. void FlagTool3D::makeFlag( const Ogre::Vector3& position ) { Ogre::SceneNode* node = scene_manager_->getRootSceneNode()->createChildSceneNode(); Ogre::Entity* entity = scene_manager_->createEntity( flag_resource_ ); node->attachObject( entity ); node->setVisible( true ); node->setPosition( position ); flag_nodes_.push_back( node ); }
// TO DO: finish listener thread to get keyboard input from client!! DWORD WINAPI Listener(LPVOID lpParam) { UDPReceive receiver = UDPReceive(); receiver.init(5001); // set to port specified in client Ogre::SceneManager* mSceneMgr = (Ogre::SceneManager*)lpParam; Ogre::SceneNode* penguin = mSceneMgr->getSceneNode("PlayerNode"); char* data = (char*) malloc(128); double* ptime = new double(1); std::string cInput; int counter; while(true) { counter = receiver.receive(data,strlen(data),ptime); (*ptime)++; cInput.assign(data,0,counter); // make sure variables are set the same as in client! if ((cInput.find("KEY_YELLOW",0)!=std::string::npos)) { penguin->setVisible( true ); penguin->setPosition(0,20,0); } if ((cInput.find("KEY_RED",0)!=std::string::npos)) { penguin->setVisible( true ); penguin->setPosition(65,20,0); } if ((cInput.find("KEY_BLUE",0)!=std::string::npos)) { penguin->setVisible( true ); penguin->setPosition(0,20,65); } if ((cInput.find("KEY_GREEN",0)!=std::string::npos)) { penguin->setVisible( true ); penguin->setPosition(65,20,65); } } return 0; }
bool CGrassSticks::buildGrassSticks(Ogre::SceneManager* sceneMgr, btDynamicsWorld* dynamicsWorld, btSoftBodyWorldInfo &softBodyWorldInfo) { // create our grass mesh, and create a grass entity from it if (!sceneMgr->hasEntity(GRASS_MESH_NAME)) { createGrassMesh(); } // End if const int n=16; const int sg=4; const btScalar sz=16; const btScalar hg=4; const btScalar in=1/(btScalar)(n-1); int index = 0; for(int y=0;y<n;++y) { for(int x=0;x<n;++x) { const btVector3 org(-sz+sz*2*x*in, 1, -sz+sz*2*y*in); btSoftBody* psb=btSoftBodyHelpers::CreateRope(softBodyWorldInfo, org, org+btVector3(hg*0.001f,hg,0), sg, 1); psb->m_cfg.kDP = 0.005f; psb->m_cfg.kCHR = 0.1f; for(int i=0;i<3;++i) { psb->generateBendingConstraints(2+i); } psb->setMass(1,0); psb->setTotalMass(0.01f); static_cast<btSoftRigidDynamicsWorld*>(dynamicsWorld)->addSoftBody(psb); const Ogre::String& strIndex = Ogre::StringConverter::toString(index++); Ogre::Entity* grass = sceneMgr->createEntity("Grass" + strIndex, GRASS_MESH_NAME); Ogre::SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode("node_grass_" + strIndex ,Ogre::Vector3(org.getX(), org.getY(), org.getZ()) ,Ogre::Quaternion(Ogre::Degree(0), Vector3::UNIT_Y)); node->attachObject(grass); node->scale(1.0f, Ogre::Math::RangeRandom(0.85f, 1.15f), 1.0f); node->setVisible(true); psb->setUserPointer((void*)(grass->getSubEntity(0))); } // End for } // End for dynamicsWorld->setInternalTickCallback(&CGrassSticks::simulationTickCallback); return true; }
void GraphicsController::_initBackgroundHdr() { Ogre::Rectangle2D* rect = new Ogre::Rectangle2D(false); rect->setCorners(-1.0f, 1.0f, 1.0f, -1.0f); rect->setMaterial("PRJZ/HDRBackground"); rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND + 1); rect->setBoundingBox(Ogre::AxisAlignedBox(-100000.0*Ogre::Vector3::UNIT_SCALE, 100000.0*Ogre::Vector3::UNIT_SCALE)); rect->setCastShadows(false); rect->setVisibilityFlags(0xf00000); Ogre::SceneNode* node = _scnMgr->getRootSceneNode()->createChildSceneNode("HdrBackground"); node->attachObject(rect); node->setVisible(true); }
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; }
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; }
void DatuPointEditAction::setParameter(const String& name, const String& value) { if (name == "ShowDatuPointItem") { mShowSoundEntity = value == "true"; if (mSoundNode) { mSoundNode->setVisible(mShowSoundEntity); } } else if (name == "CreatePointEntity") { Ogre::StringVector values = Ogre::StringUtil::split(value); _createPointEntity(Ogre::StringConverter::parseInt(values[0]), Ogre::StringConverter::parseInt(values[1])); } else if (name == "ClearPointEntity") { _clearAllPointEntities(); } else if (name == "DeleteDatuPointItem") { _deletePointEntity( Ogre::StringConverter::parseInt(value) ); } else if (name == "ShowRadiusEntity") { Ogre::StringVector valueVector = Ogre::StringUtil::split(value); if (mDatuPointRadiusEntity) { Ogre::SceneNode* node = mDatuPointRadiusEntity->getParentSceneNode(); node->setVisible(true); node->setPosition( Ogre::StringConverter::parseReal(valueVector[0]), Ogre::StringConverter::parseReal(valueVector[1]), Ogre::StringConverter::parseReal(valueVector[2]) ); float scale = Ogre::StringConverter::parseReal(valueVector[3]) * 100.0f; node->setScale( scale, 1, scale ); } } else { Action::setParameter(name, value); } }
SnapToMovement::SnapToMovement(Eris::Entity& entity, Ogre::Node& node, float snapThreshold, Ogre::SceneManager& sceneManager, bool showDebugOverlay) : mEntity(entity), mNode(node), mSnapThreshold(snapThreshold), mSceneManager(sceneManager) { if (showDebugOverlay) { for (int i = 0; i < 30; ++i) { Ogre::SceneNode* node = mSceneManager.getRootSceneNode()->createChildSceneNode(); Ogre::Entity* sphereEntity = mSceneManager.createEntity(node->getName() + "_entity", "3d_objects/primitives/models/sphere.mesh"); //start out with a normal material sphereEntity->setMaterialName("/global/authoring/point"); sphereEntity->setRenderingDistance(300); // entity.setQueryFlags(MousePicker::CM_UNDEFINED); node->setScale(0.25, 0.25, 0.25); node->attachObject(sphereEntity); node->setVisible(false); mDebugNodes.push_back(node); } } }
Ring::Ring(Ogre::String name, RingFlier* flier):flier(flier) { check=true; ringName=name; position.x=(rand()%5000); position.z=(rand()%5000); position.y=(rand()%700)+flier->getTerrainHeightAt(position.x,position.z)+100.0f; Ogre::SceneNode* sn = flier->getSceneManager()->getRootSceneNode()->createChildSceneNode("sn"+name); Ogre::Entity* ring = flier->getSceneManager()->createEntity(name,"Torus.mesh"); sn->attachObject(ring); sn->scale(Ogre::Vector3(015.10f,015.10f,015.10f)); sn->setPosition(position); sn->setVisible(true); sn->setOrientation(Ogre::Quaternion(Ogre::Radian(30.0f), Ogre::Vector3::UNIT_Z)); sn->setDirection(rand()%10,rand()%10,rand()%10,Ogre::Node::TransformSpace::TS_LOCAL,Ogre::Vector3::NEGATIVE_UNIT_Z); Ogre::ParticleSystem* pSysRing = flier->getSceneManager()->createParticleSystem(ringName+'p',"PEExamples/ringShimmer"); flier->getSceneManager()->getSceneNode("sn"+ringName)->attachObject(pSysRing); }
void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_) { Ogre::SceneNode* root = mMwRoot; Ogre::SceneNode* cellnode; if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end()) { //Create the scenenode and put it in the map cellnode = root->createChildSceneNode(); mCellSceneNodes[ptr.getCell()] = cellnode; } else { cellnode = mCellSceneNodes[ptr.getCell()]; } Ogre::SceneNode* insert = cellnode->createChildSceneNode(); const float *f = ptr.getRefData().getPosition().pos; insert->setPosition(f[0], f[1], f[2]); insert->setScale(ptr.getCellRef().scale, ptr.getCellRef().scale, ptr.getCellRef().scale); // Convert MW rotation to a quaternion: f = ptr.getCellRef().pos.rot; // Rotate around X axis Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X); // Rotate around Y axis Ogre::Quaternion yr(Ogre::Radian(-f[1]), Ogre::Vector3::UNIT_Y); // Rotate around Z axis Ogre::Quaternion zr(Ogre::Radian(-f[2]), Ogre::Vector3::UNIT_Z); // Rotates first around z, then y, then x insert->setOrientation(xr*yr*zr); if (!enabled) insert->setVisible (false); ptr.getRefData().setBaseNode(insert); mIsStatic = static_; }
/** * @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)); }
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]))); } }
CombatSetupWnd::CombatSetupWnd( const std::vector<CombatSetupGroup>& setup_groups, CombatWnd* combat_wnd, const CombatData* combat_data, Ogre::SceneManager* scene_manager, boost::function<std::pair<bool, Ogre::Vector3> (const GG::Pt& pt)> intersect_mouse_with_ecliptic, boost::function<const Ogre::MaterialPtr& (const Ship&)> get_ship_material, boost::function<void (int, Ogre::SceneNode*, Ogre::Entity*, const Ogre::MaterialPtr&)> add_ship_node_to_combat_wnd, boost::function<Ogre::MovableObject* (const GG::Pt&)> get_object_under_pt, boost::function<void (int, const Ogre::Vector3&, const Ogre::Quaternion&)> reposition_ship_node, boost::function<void (int)> remove_ship, boost::function<void (const Ogre::Vector3&)> look_at, GG::Flags<GG::WndFlag> flags/* = GG::INTERACTIVE | GG::DRAGABLE*/) : CUIWnd("Ships", GG::X(PAD), GG::GUI::GetGUI()->AppHeight() - SETUP_WND_HEIGHT - GG::Y(PAD), GG::X(500), SETUP_WND_HEIGHT, flags), m_setup_groups(setup_groups), m_current_setup_group(m_setup_groups.size()), m_setup_finished_waiting_for_server(false), m_dragging_placed_ship(false), m_button_press_on_placed_ship(INVALID_PRESS_POS), m_button_press_placed_ship_node(0), m_mouse_dragged(false), m_listbox(new CUIListBox(GG::X0, GG::Y0, GG::X1, GG::Y1)), m_redo_placements_button(new CUIButton(GG::X0, GG::Y1, GG::X1, UserString("REDO_PLACEMENTS"))), m_auto_place_button(new CUIButton(GG::X0, GG::Y(2), GG::X1, UserString("AUTO_PLACE_SHIPS"))), m_done_button(new CUIButton(GG::X0, GG::Y(3), GG::X1, UserString("DONE"))), m_selected_placeable_ship(0), m_placeable_ship_node(0), m_scene_manager(scene_manager), m_combat_universe(combat_data->m_combat_universe), m_intersect_mouse_with_ecliptic(intersect_mouse_with_ecliptic), m_get_ship_material(get_ship_material), m_add_ship_node_to_combat_wnd(add_ship_node_to_combat_wnd), m_get_object_under_pt(get_object_under_pt), m_reposition_ship_node(reposition_ship_node), m_remove_ship(remove_ship), m_look_at(look_at) { m_listbox->SetStyle(m_listbox->Style() | GG::LIST_SINGLESEL); Connect(m_redo_placements_button->ClickedSignal, &CombatSetupWnd::RedoPlacementsButtonClicked, this); Connect(m_auto_place_button->ClickedSignal, &CombatSetupWnd::AutoPlaceButtonClicked, this); Connect(m_done_button->ClickedSignal, &CombatSetupWnd::DoneButtonClicked, this); GG::Y original_button_height = m_done_button->Height(); GG::Y original_all_buttons_height = original_button_height * 3; AttachChild(m_listbox); AttachChild(m_redo_placements_button); AttachChild(m_auto_place_button); AttachChild(m_done_button); VerticalLayout(); GetLayout()->SetRowStretch(0, Value(Height() - original_all_buttons_height)); GetLayout()->SetRowStretch(1, Value(original_button_height)); GetLayout()->SetRowStretch(2, Value(original_button_height)); GetLayout()->SetRowStretch(3, Value(original_button_height)); GetLayout()->SetCellMargin(2); const GG::Pt row_size = ListRowSize(); for (PathingEngine::const_iterator it = combat_data->m_pathing_engine.begin(); it != combat_data->m_pathing_engine.end(); ++it) { if (CombatShipPtr combat_ship = boost::dynamic_pointer_cast<CombatShip>(*it)) { // create scene node Ship& ship = combat_ship->GetShip(); // TODO: Temporary! Serialization of CombatData currently sends // everything to everyone. Fix this. if (!ship.OwnedBy(HumanClientApp::GetApp()->EmpireID())) continue; Ogre::SceneNode* node = GetShipNode(ship); if (combat_ship->position() == OpenSteer::Vec3(0.0, 0.0, 0.0)) { UniverseObject* o = m_combat_universe[ship.FleetID()]; Fleet* fleet = boost::polymorphic_downcast<Fleet*>(o); ShipRow* row = new ShipRow(&ship, fleet, row_size.x, row_size.y); m_listbox->Insert(row); } else { node->setPosition(ToOgre(combat_ship->position())); node->setOrientation(Ogre::Quaternion(ToOgre(combat_ship->side()), ToOgre(combat_ship->forward()), ToOgre(combat_ship->up()))); PlaceShip(&ship, node); node->setVisible(true); } } } m_redo_placements_button->Disable(m_placed_nodes.empty()); m_auto_place_button->Disable(m_listbox->Empty()); m_done_button->Disable(!m_listbox->Empty()); GG::Connect(m_listbox->SelChangedSignal, &CombatSetupWnd::PlaceableShipSelected_, this); combat_wnd->InstallEventFilter(this); }
//----------------------------------------------------------------------- void ParticlePool::_increaseParticleSystemPool(size_t size, Particle::ParticleBehaviourList& behaviours, ParticleTechnique* technique) { size_t oldSize = mSystems.size(); if (size < oldSize) return; // Run through all emitters in the technique and check which one emits a particle system size_t numberOfEmitters = technique->getNumEmitters(); if (numberOfEmitters == 0) return; ParticleSystem* system = 0; ParticleSystem* clonedSystem = 0; ParticleEmitter* emitter = 0; size_t numberOfEmittedSystems = 0; size_t systemCount = 0; // First determine the number of emitted particle systems. for (systemCount = 0; systemCount < numberOfEmitters; systemCount++) { emitter = technique->getEmitter(systemCount); if (emitter->getEmitsType() == Particle::PT_SYSTEM) { numberOfEmittedSystems++; } } if (numberOfEmittedSystems == 0) return; // Distribute size equally size_t increment = (size-oldSize) / numberOfEmittedSystems; // Fill the pool for (systemCount = 0; systemCount < numberOfEmitters; systemCount++) { emitter = technique->getEmitter(systemCount); if (emitter->getEmitsType() == Particle::PT_SYSTEM) { system = ParticleSystemManager::getSingletonPtr()->getParticleSystemTemplate(emitter->getEmitsName()); if (system) { // Create 'increment' ParticleSystems and add to the pool std::stringstream ss; ss << this; for (size_t i = 0; i < increment; i++) { clonedSystem = ParticleSystemManager::getSingletonPtr()->createParticleSystem( emitter->getEmitsName()+ ss.str() + StringConverter::toString(i), emitter->getEmitsName(), technique->getParentSystem()->getSceneManager()); clonedSystem->_setMarkedForEmission(true); mParticleSystemPool.addElement(emitter->getEmitsName(), clonedSystem); mSystems.push_back(clonedSystem->getName()); // Attach the Particle System to a SceneNode Ogre::SceneNode* parentNode = technique->getParentSystem()->getParentSceneNode(); Ogre::SceneNode* node = parentNode->createChildSceneNode(); node->attachObject(clonedSystem); node->setVisible(false); } } } } }
bool SnapToMovement::testSnapTo(const WFMath::Point<3>& position, const WFMath::Quaternion& orientation, WFMath::Vector<3>& adjustment, EmberEntity* snappedToEntity) { try { for (std::vector<Ogre::SceneNode*>::iterator I = mDebugNodes.begin(); I != mDebugNodes.end(); ++I) { Ogre::SceneNode* node = *I; node->setVisible(false); Ogre::Entity* sphereEntity = static_cast<Ogre::Entity*> (node->getAttachedObject(0)); sphereEntity->setMaterialName("/global/authoring/point"); } } catch (const std::exception& ex) { S_LOG_WARNING("Error when setting up debug nodes for snapping." << ex); } std::vector<Ogre::SceneNode*>::iterator nodeIterator = mDebugNodes.begin(); //Use an auto pointer to allow both for undefined values and automatic cleanup when exiting the method. std::auto_ptr<SnapPointCandidate> closestSnapping(0); WFMath::AxisBox<3> currentBbox = mEntity.getBBox(); //Translate the bbox into a rotbox WFMath::RotBox<3> currentRotbox; currentRotbox.size() = currentBbox.highCorner() - currentBbox.lowCorner(); currentRotbox.corner0() = currentBbox.lowCorner(); currentRotbox.orientation().identity(); currentRotbox.rotatePoint(orientation, WFMath::Point<3>(0, 0, 0)); currentRotbox.shift(WFMath::Vector<3>(position)); //See if we should visualize debug nodes for the moved entity for (size_t j = 0; j < currentRotbox.numCorners(); ++j) { WFMath::Point<3> currentPoint = currentRotbox.getCorner(j); if (currentPoint.isValid() && nodeIterator != mDebugNodes.end()) { Ogre::SceneNode* node = *nodeIterator; node->setPosition(Convert::toOgre(currentPoint)); node->setVisible(true); nodeIterator++; } } //First find all entities which are close enough //Then try to do a snap movement based on the points of the eris bounding boxes. I.e. we only provide support for snapping one corner of a bounding box to another corner (for now). WFMath::Ball<3> boundingSphere = mEntity.getBBox().boundingSphere(); Ogre::Sphere sphere(mNode._getDerivedPosition(), boundingSphere.radius() * 2); Ogre::SphereSceneQuery* query = mSceneManager.createSphereQuery(sphere); Ogre::SceneQueryResult& result = query->execute(); for (Ogre::SceneQueryResultMovableList::const_iterator I = result.movables.begin(); I != result.movables.end(); ++I) { Ogre::MovableObject* movable = *I; if (movable->getUserAny().getType() == typeid(EmberEntityUserObject::SharedPtr)) { EmberEntityUserObject* anUserObject = Ogre::any_cast<EmberEntityUserObject::SharedPtr>(movable->getUserAny()).get(); EmberEntity& entity = anUserObject->getEmberEntity(); if (&entity != &mEntity && entity.hasBBox()) { //Ok, we have an entity which is close to our entity. Now check if any of the points of the bounding box is close. WFMath::AxisBox<3> bbox = entity.getBBox(); if (bbox.isValid()) { WFMath::RotBox<3> rotbox; rotbox.size() = bbox.highCorner() - bbox.lowCorner(); rotbox.corner0() = bbox.lowCorner(); rotbox.orientation().identity(); rotbox.rotatePoint(entity.getViewOrientation(), WFMath::Point<3>(0, 0, 0)); rotbox.shift(WFMath::Vector<3>(entity.getViewPosition())); for (size_t i = 0; i < rotbox.numCorners(); ++i) { WFMath::Point<3> point = rotbox.getCorner(i); Ogre::SceneNode* currentNode(0); //If there is any unclaimed debug node left we'll use it to visualize the corner if (nodeIterator != mDebugNodes.end()) { currentNode = *nodeIterator; currentNode->setPosition(Convert::toOgre(point)); currentNode->setVisible(true); nodeIterator++; } point.z() = 0; for (size_t j = 0; j < currentRotbox.numCorners(); ++j) { WFMath::Point<3> currentPoint = currentRotbox.getCorner(j); currentPoint.z() = 0; WFMath::CoordType distance = WFMath::Distance(currentPoint, point); if (distance <= mSnapThreshold) { if (currentNode) { Ogre::Entity* sphereEntity = static_cast<Ogre::Entity*> (currentNode->getAttachedObject(0)); if (sphereEntity) { try { sphereEntity->setMaterialName("/global/authoring/point/moved"); } catch (const std::exception& ex) { S_LOG_WARNING("Error when setting material for point." << ex); } } } if (!closestSnapping.get()) { closestSnapping = std::auto_ptr<SnapPointCandidate>(new SnapPointCandidate()); closestSnapping->entity = &entity; closestSnapping->distance = distance; closestSnapping->adjustment = point - currentPoint; } else if (distance < closestSnapping->distance) { closestSnapping->entity = &entity; closestSnapping->distance = distance; closestSnapping->adjustment = point - currentPoint; } } } } } } } } mSceneManager.destroyQuery(query); if (closestSnapping.get()) { adjustment = closestSnapping->adjustment; snappedToEntity = closestSnapping->entity; return true; } return false; }
Room::Room(Ogre::SceneManager *mSceneMgr, Simulator *gameSimulator, int numPlayers) { roomSimulator = gameSimulator; active = false; rSceneMgr = mSceneMgr; char tileNameBuffer[100]; char hTileNameBuffer[100]; char gapBufferNode[35]; char gapBufferPlane[35]; char gapBufferEntity[35]; int roomID = 2; if (numPlayers > 2) roomID = 4; playerRoomSpaces = vector<RoomSpace*>(numPlayers, NULL); numberOfPlayers = numPlayers; mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", false); /* Room Dimensions */ width = 30.0f; // along x-axis height = 60.0f; // along z-axis heightScalingFactor = 3.0f/4.0f; gapSize = 10.0f; /* NOTE: gapSize, width, and height must be divisible by the tileSize */ Ogre::Real fnSideWidth = Ogre::Math::Sqrt(Ogre::Math::Sqr(width/3) + Ogre::Math::Sqr(width/3)); if (numberOfPlayers > 2) { width *= 2; height *= 2; heightScalingFactor *= 2.0f/3.0f; /* Will f**k up the room */ fnSideWidth = Ogre::Math::Sqrt(Ogre::Math::Sqr(width/3) + Ogre::Math::Sqr(width/3)); } /* Tile Attributes */ tileSize = 5.0f; tilesPerRow = width/tileSize; tilesPerCol = ((height/2.0f) + (width/3.0f) - (gapSize/2.0f))/tileSize; if (numberOfPlayers > 2) tilesPerRow = ((width/2.0f) - (gapSize/2.0f))/tileSize; tilesPerPlayer = tilesPerRow * tilesPerCol; printf("\n\n\n\nTiles Per Row = %f\n", tilesPerRow); printf("Tiles Per Col = %f\n\n\n\n", tilesPerCol); /* Plane Creation */ Ogre::Plane plane; plane.d = 0; Ogre::Vector3 position; /* Create Gap Planes for each Player */ Ogre::SceneNode* clientGapNode; Ogre::Real hGapX = 0.0f; Ogre::Real hGapZ = gapSize/2.0f; Ogre::Real vGapX = gapSize/2.0f; Ogre::Real vGapZ = height/2.0f + width/3.0f + gapSize/2.0f; Ogre::Vector3 hGapPosition; Ogre::Vector3 vGapPosition; Ogre::Entity* gapEnt; Ogre::Real hPlaneWidth = width; Ogre::Real vPlaneWidth; if (numberOfPlayers > 2) { Ogre::Real vPlaneWidth = (height/2.0f + width/3.0f - gapSize/2.0f); hGapX = (width/2.0f + gapSize/2.0f)/2.0f; hPlaneWidth = (width/2.0f - gapSize/2.0f); } for (int player = 1; player <= numberOfPlayers; player++) { RoomSpace *gp = new RoomSpace; gp->active = false; if (player == 1 || player == 2) { hGapPosition = Ogre::Vector3(-hGapX, 0.0f, hGapZ); vGapPosition = Ogre::Vector3(-vGapX, 0.0f, vGapZ); } else { hGapPosition = Ogre::Vector3(hGapX, 0.0f, hGapZ); vGapPosition = Ogre::Vector3(vGapX, 0.0f, vGapZ); } if (player == 2 || player == 4) { hGapPosition = Ogre::Vector3(hGapPosition.x, 0.0f, -hGapZ); vGapPosition = Ogre::Vector3(vGapPosition.x, 0.0f, -vGapZ); } /************** Horizontal Gap **************/ sprintf(gapBufferNode, "%d_HGap_%d", roomID, player); sprintf(gapBufferPlane, "%s%s", gapBufferNode, "_Plane"); sprintf(gapBufferEntity, "%s%s", gapBufferNode, "_Entity"); if (player == 2 || player == 4) plane.normal = Ogre::Vector3::NEGATIVE_UNIT_Z; else plane.normal = Ogre::Vector3::UNIT_Z; Ogre::MeshManager::getSingleton().createPlane(gapBufferPlane, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, hPlaneWidth, width*heightScalingFactor, 20, 20, true, 1, width/4, height/4, Ogre::Vector3::UNIT_Y); clientGapNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(gapBufferNode); gapEnt = mSceneMgr->createEntity(gapBufferEntity, gapBufferPlane); clientGapNode->attachObject(gapEnt); gapEnt->setMaterialName("Examples/SpaceSkyPlane"); gapEnt->setCastShadows(false); clientGapNode->setPosition(hGapPosition); clientGapNode->setVisible(false); gp->horizontalGap = clientGapNode; if (numberOfPlayers > 2) { /************** Vertical Gap **************/ sprintf(gapBufferNode, "%d_VGap_%d", roomID, player); sprintf(gapBufferPlane, "%s%s", gapBufferNode, "_Plane"); sprintf(gapBufferEntity, "%s%s", gapBufferNode, "_Entity"); if (player == 1 || player == 3) plane.normal = Ogre::Vector3::NEGATIVE_UNIT_X; else plane.normal = Ogre::Vector3::UNIT_X; Ogre::MeshManager::getSingleton().createPlane(gapBufferPlane, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, vPlaneWidth, width*heightScalingFactor, 20, 20, true, 1, width/4, height/4, Ogre::Vector3::UNIT_Y); clientGapNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(gapBufferNode); gapEnt = mSceneMgr->createEntity(gapBufferEntity, gapBufferPlane); clientGapNode->attachObject(gapEnt); gapEnt->setMaterialName("Examples/SpaceSkyPlane"); gapEnt->setCastShadows(false); clientGapNode->setPosition(vGapPosition); clientGapNode->setVisible(false); gp->verticalGap = clientGapNode; } playerRoomSpaces[player - 1] = gp; } /* Tile Placement */ Ogre::Real tilePosX = -width/2.0f + tileSize/2.0f; Ogre::Real tilePosY = -(width*heightScalingFactor)/2.0f; Ogre::Real tilePosZ = height/2.0f + width/3.0f - tileSize/2.0f; Ogre::Real nTilePosZ = (-height/2.0f - width/3.0f) + tileSize/2.0f; Ogre::Vector3 tilePosition = Ogre::Vector3(tilePosX, tilePosY, tilePosZ); Ogre::Vector3 nTilePosition = Ogre::Vector3(tilePosX, tilePosY, nTilePosZ); floorPositionY = tilePosY; Tile* localTile; Ogre::Vector3 localPosition; /***************** TILES OF FLOOR *****************/ for (int row = 0; row < tilesPerCol; row++) // change the Z { for (int col = 0; col < tilesPerRow; col++) // change the X { for (int player = 1; player <= numberOfPlayers; player++) { if (player == 2 || player == 4) localPosition = nTilePosition; else localPosition = tilePosition; if (player == 3 || player == 4) localPosition = Ogre::Vector3(localPosition.x + (width/2.0f + gapSize/2.0f), tilePosY, localPosition.z); sprintf(tileNameBuffer, "%d_client%d_%d%d", roomID, player, col, row); localTile = new Tile(tileNameBuffer, mSceneMgr, gameSimulator, localPosition, tileSize, (row*tilesPerRow + col), player); playerRoomSpaces[player - 1]->tileList.push_back(localTile); } tilePosition = Ogre::Vector3(tilePosition.x + tileSize, tilePosY, tilePosition.z); nTilePosition = Ogre::Vector3(nTilePosition.x + tileSize, tilePosY, nTilePosition.z); } tilePosition = Ogre::Vector3(tilePosX, tilePosY, tilePosition.z - tileSize); nTilePosition = Ogre::Vector3(tilePosX, tilePosY, nTilePosition.z + tileSize); } char wallCBuffer[100]; char wallCPlaneBuffer[100]; sprintf(wallCBuffer, "%d%s", roomID, "_Ceiling"); sprintf(wallCPlaneBuffer, "%d%s", roomID, "__Ceiling_Plane"); /* Plane for Ceiling */ plane.normal = Ogre::Vector3::NEGATIVE_UNIT_Y; position = Ogre::Vector3(0.0f, (width*heightScalingFactor)/2.0f, 0.0f); Ogre::MeshManager::getSingleton().createPlane(wallCPlaneBuffer, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, width, height + width, 20, 20, true, 1, width/4, (height*heightScalingFactor)/4, Ogre::Vector3::UNIT_Z); wallList.push_back(new Wall(wallCBuffer, wallCPlaneBuffer, mSceneMgr, gameSimulator, Ogre::Vector3::NEGATIVE_UNIT_Y, position, Ogre::Vector3(width, 0.01f, height + width))); char wallLBuffer[100]; char wallLPlaneBuffer[100]; sprintf(wallLBuffer, "%d%s", roomID, "_LeftWall"); sprintf(wallLPlaneBuffer, "%d%s", roomID, "_LeftWall_Plane"); /* Plane for LeftWall */ plane.normal = Ogre::Vector3::UNIT_X; position = Ogre::Vector3(-width/2.0f, 0.0f, 0.0f); Ogre::MeshManager::getSingleton().createPlane(wallLPlaneBuffer, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, height, width*heightScalingFactor, 20, 20, true, 1, (height*heightScalingFactor)/4, width/4, Ogre::Vector3::UNIT_Y); wallList.push_back(new Wall(wallLBuffer, wallLPlaneBuffer, mSceneMgr, gameSimulator, Ogre::Vector3::UNIT_X, position, Ogre::Vector3(0.01f, width*heightScalingFactor, height))); char wallRBuffer[100]; char wallRPlaneBuffer[100]; sprintf(wallRBuffer, "%d%s", roomID, "_RightWall"); sprintf(wallRPlaneBuffer, "%d%s", roomID, "_RightWall_Plane"); /* Plane for RightWall */ plane.normal = Ogre::Vector3::NEGATIVE_UNIT_X; position = Ogre::Vector3(width/2.0f, 0.0f, 0.0f); Ogre::MeshManager::getSingleton().createPlane(wallRPlaneBuffer, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, height, width*heightScalingFactor, 20, 20, true, 1, (height*heightScalingFactor)/4, width/4, Ogre::Vector3::UNIT_Y); wallList.push_back(new Wall(wallRBuffer, wallRPlaneBuffer, mSceneMgr, gameSimulator, Ogre::Vector3::NEGATIVE_UNIT_X, position, Ogre::Vector3(0.01f, width*heightScalingFactor, height))); // Front and Back Divisions char wallFBuffer[100]; char wallFPlaneBuffer[100]; sprintf(wallFBuffer, "%d%s", roomID, "_FarWall"); sprintf(wallFPlaneBuffer, "%d%s", roomID, "_FarWall_Plane"); /* Plane for FarWall */ plane.normal = Ogre::Vector3::UNIT_Z; position = Ogre::Vector3(0.0f, 0.0f, -height/2.0f - width/3.0f); Ogre::MeshManager::getSingleton().createPlane(wallFPlaneBuffer, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, width/3, width*heightScalingFactor, 20, 20, true, 1, (height*heightScalingFactor)/4, width/4, Ogre::Vector3::UNIT_Y); wallList.push_back(new Wall(wallFBuffer, wallFPlaneBuffer, mSceneMgr, gameSimulator, Ogre::Vector3::UNIT_Z, position, Ogre::Vector3(width/3, width*heightScalingFactor, 0.01f))); char wallNBuffer[100]; char wallNPlaneBuffer[100]; sprintf(wallNBuffer, "%d%s", roomID, "_NearWall"); sprintf(wallNPlaneBuffer, "%d%s", roomID, "_NearWall_Plane"); /* Plane for NearWall */ plane.normal = Ogre::Vector3::NEGATIVE_UNIT_Z; position = Ogre::Vector3(0.0f, 0.0f, height/2.0f + width/3.0f); Ogre::MeshManager::getSingleton().createPlane(wallNPlaneBuffer, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, width/3, width*heightScalingFactor, 20, 20, true, 1, (height*heightScalingFactor)/4, width/4, Ogre::Vector3::UNIT_Y); wallList.push_back(new Wall(wallNBuffer, wallNPlaneBuffer, mSceneMgr, gameSimulator, Ogre::Vector3::NEGATIVE_UNIT_Z, position, Ogre::Vector3(width/3, width*heightScalingFactor, 0.01f))); char wallFLBuffer[100]; char wallFLPlaneBuffer[100]; sprintf(wallFLBuffer, "%d%s", roomID, "_FarLeftWall"); sprintf(wallFLPlaneBuffer, "%d%s", roomID, "_FarLeftWall_Plane"); // Plane for FarLeftWall plane.normal = Ogre::Vector3::UNIT_Z; position = Ogre::Vector3(-width/3.0f, 0.0f, -height/2.0f - width/6.0f); Ogre::MeshManager::getSingleton().createPlane(wallFLPlaneBuffer, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, fnSideWidth, width*heightScalingFactor, 20, 20, true, 1, (height*heightScalingFactor)/4, width/4, Ogre::Vector3::UNIT_Y); wallList.push_back(new Wall(wallFLBuffer, wallFLPlaneBuffer, mSceneMgr, gameSimulator, Ogre::Vector3(-1.0f, 0.0f, 1.0f), position, Ogre::Vector3(fnSideWidth, width*heightScalingFactor, 0.01f))); char wallFRBuffer[100]; char wallFRPlaneBuffer[100]; sprintf(wallFRBuffer, "%d%s", roomID, "_FarRightWall"); sprintf(wallFRPlaneBuffer, "%d%s", roomID, "_FarRightWall_Plane"); // Plane for FarRightWall plane.normal = Ogre::Vector3::UNIT_Z; position = Ogre::Vector3(width/3.0f, 0.0f, -height/2.0f - width/6.0f); Ogre::MeshManager::getSingleton().createPlane(wallFRPlaneBuffer, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, fnSideWidth, width*heightScalingFactor, 20, 20, true, 1, (height*heightScalingFactor)/4, width/4, Ogre::Vector3::UNIT_Y); wallList.push_back(new Wall(wallFRBuffer, wallFRPlaneBuffer, mSceneMgr, gameSimulator, Ogre::Vector3(1.0f, 0.0f, 1.0f), position, Ogre::Vector3(fnSideWidth, width*heightScalingFactor, 0.01f))); char wallNLBuffer[100]; char wallNLPlaneBuffer[100]; sprintf(wallNLBuffer, "%d%s", roomID, "_NearLeftWall"); sprintf(wallNLPlaneBuffer, "%d%s", roomID, "_NearLeftWall_Plane"); // Plane for NearLeftWall plane.normal = Ogre::Vector3::NEGATIVE_UNIT_Z; position = Ogre::Vector3(-width/3.0f, 0.0f, height/2.0f + width/6.0f); Ogre::MeshManager::getSingleton().createPlane(wallNLPlaneBuffer, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, fnSideWidth, width*heightScalingFactor, 20, 20, true, 1, (height*heightScalingFactor)/4, width/4, Ogre::Vector3::UNIT_Y); wallList.push_back(new Wall(wallNLBuffer, wallNLPlaneBuffer, mSceneMgr, gameSimulator, Ogre::Vector3(1.0f, 0.0f, -1.0f), position, Ogre::Vector3(fnSideWidth, width*heightScalingFactor, 0.01f))); char wallNRBuffer[100]; char wallNRPlaneBuffer[100]; sprintf(wallNRBuffer, "%d%s", roomID, "_NearRightWall"); sprintf(wallNRPlaneBuffer, "%d%s", roomID, "_NearRightWall_Plane"); // Plane for NearRightWall plane.normal = Ogre::Vector3::NEGATIVE_UNIT_Z; position = Ogre::Vector3(width/3.0f, 0.0f, height/2.0f + width/6.0f); Ogre::MeshManager::getSingleton().createPlane(wallNRPlaneBuffer, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, fnSideWidth, width*heightScalingFactor, 20, 20, true, 1, (height*heightScalingFactor)/4, width/4, Ogre::Vector3::UNIT_Y); wallList.push_back(new Wall(wallNRBuffer, wallNRPlaneBuffer, mSceneMgr, gameSimulator, Ogre::Vector3(-1.0f, 0.0f, -1.0f), position, Ogre::Vector3(fnSideWidth, width*heightScalingFactor, 0.01f))); for (int i = 0; i < wallList.size(); i++) wallList[i]->getSceneNode()->setVisible(false); }
void RoR::GfxEnvmap::SetupEnvMap() { m_rtt_texture = Ogre::TextureManager::getSingleton().getByName("EnvironmentTexture"); for (int face = 0; face < NUM_FACES; face++) { m_render_targets[face] = m_rtt_texture->getBuffer(face)->getRenderTarget(); m_cameras[face] = gEnv->sceneManager->createCamera("EnvironmentCamera-" + TOSTRING(face)); m_cameras[face]->setAspectRatio(1.0); m_cameras[face]->setProjectionType(Ogre::PT_PERSPECTIVE); m_cameras[face]->setFixedYawAxis(false); m_cameras[face]->setFOVy(Ogre::Degree(90)); m_cameras[face]->setNearClipDistance(0.1f); m_cameras[face]->setFarClipDistance(gEnv->mainCamera->getFarClipDistance()); Ogre::Viewport* v = m_render_targets[face]->addViewport(m_cameras[face]); v->setOverlaysEnabled(false); v->setClearEveryFrame(true); v->setBackgroundColour(gEnv->mainCamera->getViewport()->getBackgroundColour()); m_render_targets[face]->setAutoUpdated(false); } m_cameras[0]->setDirection(+Ogre::Vector3::UNIT_X); m_cameras[1]->setDirection(-Ogre::Vector3::UNIT_X); m_cameras[2]->setDirection(+Ogre::Vector3::UNIT_Y); m_cameras[3]->setDirection(-Ogre::Vector3::UNIT_Y); m_cameras[4]->setDirection(-Ogre::Vector3::UNIT_Z); m_cameras[5]->setDirection(+Ogre::Vector3::UNIT_Z); if (App::diag_envmap.GetActive()) { // create fancy mesh for debugging the envmap Ogre::Overlay* overlay = Ogre::OverlayManager::getSingleton().create("EnvMapDebugOverlay"); if (overlay) { Ogre::Vector3 position = Ogre::Vector3::ZERO; float scale = 1.0f; Ogre::MeshPtr mesh = Ogre::MeshManager::getSingletonPtr()->createManual("cubeMapDebug", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); // create sub mesh Ogre::SubMesh* sub = mesh->createSubMesh(); // Initialize render operation sub->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST; // sub->useSharedVertices = true; mesh->sharedVertexData = new Ogre::VertexData; sub->indexData = new Ogre::IndexData; // Create vertex declaration size_t offset = 0; mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION); offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3); mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_TEXTURE_COORDINATES); // Create and bind vertex buffer mesh->sharedVertexData->vertexCount = 14; Ogre::HardwareVertexBufferSharedPtr vertexBuffer = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer( mesh->sharedVertexData->vertexDeclaration->getVertexSize(0), mesh->sharedVertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY); mesh->sharedVertexData->vertexBufferBinding->setBinding(0, vertexBuffer); // Vertex data static const float vertexData[] = { // Position Texture coordinates // Index 0.0, 2.0, -1.0, 1.0, 1.0, // 0 0.0, 1.0, -1.0, -1.0, 1.0, // 1 1.0, 2.0, -1.0, 1.0, -1.0, // 2 1.0, 1.0, -1.0, -1.0, -1.0, // 3 2.0, 2.0, 1.0, 1.0, -1.0, // 4 2.0, 1.0, 1.0, -1.0, -1.0, // 5 3.0, 2.0, 1.0, 1.0, 1.0, // 6 3.0, 1.0, 1.0, -1.0, 1.0, // 7 4.0, 2.0, -1.0, 1.0, 1.0, // 8 4.0, 1.0, -1.0, -1.0, 1.0, // 9 1.0, 3.0, -1.0, 1.0, 1.0, // 10 2.0, 3.0, 1.0, 1.0, 1.0, // 11 1.0, 0.0, -1.0, -1.0, 1.0, // 12 2.0, 0.0, 1.0, -1.0, 1.0, // 13 }; // Fill vertex buffer float* pData = static_cast<float*>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD)); for (size_t vertex = 0, i = 0; vertex < mesh->sharedVertexData->vertexCount; vertex++) { // Position *pData++ = position.x + scale * vertexData[i++]; *pData++ = position.y + scale * vertexData[i++]; *pData++ = 0.0; // Texture coordinates *pData++ = vertexData[i++]; *pData++ = vertexData[i++]; *pData++ = vertexData[i++]; } vertexBuffer->unlock(); // Create index buffer sub->indexData->indexCount = 36; Ogre::HardwareIndexBufferSharedPtr indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer( Ogre::HardwareIndexBuffer::IT_16BIT, sub->indexData->indexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY); sub->indexData->indexBuffer = indexBuffer; // Index data static const Ogre::uint16 indexData[] = { // Indices // Face 0, 1, 2, // 0 2, 1, 3, // 1 2, 3, 4, // 2 4, 3, 5, // 3 4, 5, 6, // 4 6, 5, 7, // 5 6, 7, 8, // 6 8, 7, 9, // 7 10, 2, 11, // 8 11, 2, 4, // 9 3, 12, 5, // 10 5, 12, 13, // 11 }; // Fill index buffer indexBuffer->writeData(0, indexBuffer->getSizeInBytes(), indexData, true); mesh->_setBounds(Ogre::AxisAlignedBox::BOX_INFINITE); mesh->_setBoundingSphereRadius(10); mesh->load(); Ogre::Entity* e = gEnv->sceneManager->createEntity(mesh->getName()); e->setCastShadows(false); e->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1); e->setVisible(true); e->setMaterialName("tracks/EnvMapDebug"); Ogre::SceneNode* mDebugSceneNode = new Ogre::SceneNode(gEnv->sceneManager); mDebugSceneNode->attachObject(e); mDebugSceneNode->setPosition(Ogre::Vector3(0, 0, -5)); mDebugSceneNode->setFixedYawAxis(true, Ogre::Vector3::UNIT_Y); mDebugSceneNode->setVisible(true); mDebugSceneNode->_update(true, true); mDebugSceneNode->_updateBounds(); overlay->add3D(mDebugSceneNode); overlay->show(); } } }
//----laim void CEngineInterface::SetShowObjectByType( LPCTSTR szName) { static bool blogic=TRUE; static bool bstaticentity = TRUE; static bool bliquid = TRUE; static bool effect = TRUE; static bool pareticle = TRUE; static long lshowType = ENUM_OBJ_TYPE::ALL_TYPE;; Ogre::String currentName = szName; if (currentName == "lm") { lshowType =lshowType ^ ( blogic << 5); } if (currentName == "se"){ lshowType =lshowType ^ bstaticentity; // bstaticentity =!bstaticentity; } if (currentName == "sl"){ lshowType = lshowType ^ (bliquid <<2);//ENUM_OBJ_TYPE::TERRAINLIQUIDOBJ_TYPE; //bliquid =!bliquid; } if (currentName == "ef"){ lshowType = lshowType ^ (effect <<3); //effect =!effect; } if (currentName == "ps"){ lshowType = lshowType ^ (effect <<1); // pareticle =!pareticle; } if (currentName == "all"){ lshowType = ENUM_OBJ_TYPE::ALL_TYPE; } //obj Fairy::LogicModelManager::LogicModelMap logicmap = Fairy::LogicModelManager::getSingleton().getModelMap(); for ( Fairy::LogicModelManager::LogicModelMap::iterator i = logicmap.begin(); i != logicmap.end(); ++i ) { Fairy::LogicModel* model = i->second; model->setVisible(lshowType & ENUM_OBJ_TYPE::LOGICMODEL_TYPE); } Fairy::Scene::Objects objs = CEngineInterface::GetMe()->GetFairySystem()->getSceneInfo()->getObjects(); Fairy::Scene::Objects::const_iterator it = objs.begin(); for ( ; it != objs.end(); it++) { const Fairy::ObjectPtr& object = *it; if ( object->getType()== "StaticEntity" ) { Fairy::StaticEntityObject* entity = static_cast<Fairy::StaticEntityObject*>(object.get()); Ogre::SceneNode* parentNode = entity->getSceneNode(); if(parentNode) parentNode->setVisible( lshowType & ENUM_OBJ_TYPE::STATICENTITY_TYPE ); } if( object->getType()== "TerrainLiquid") { Fairy::TerrainLiquidObject* liquid = static_cast< Fairy::TerrainLiquidObject *>(object.get()); Fairy::TerrainLiquid * parentNode = liquid->getTerrainLiquid(); if(parentNode) parentNode->setVisible(lshowType & ENUM_OBJ_TYPE::TERRAINLIQUIDOBJ_TYPE); } if( object->getType()== "Effect") { Fairy::EffectObject* effect = static_cast<Fairy::EffectObject*>(object.get()); Ogre::SceneNode* parentNode = effect->getSceneNode(); if(parentNode) parentNode->setVisible(lshowType & ENUM_OBJ_TYPE::EFFECTOBJ_TYPE); } if(object->getType()== "ParticleSystem") { Fairy::ParticleSystemObject* particle = static_cast<Fairy::ParticleSystemObject*>(object.get()); Ogre::SceneNode* parentNode = particle->getSceneNode(); if(parentNode) parentNode->setVisible( lshowType & ENUM_OBJ_TYPE::PARTICLE_TYPE); } } return; }