void CMonster3D::update(float timeSinceLastFrame, Ogre::SceneNode *pCameraNode) { // m_pMonster2D的work動作都在CScene內處理 if(m_pMonster2D->isChangeAction()) { CAction *pNewAction = m_pMonster2D->getCurAction(); setAnimation(pNewAction->getAnimationName() + "::" + m_pMonsterNode->getName()); } else playAnimation(timeSinceLastFrame); // 計算Y值, 要黏著3D地形 Ogre::Vector3 terrianPos(m_pMonster2D->getPosition().fX, 500, m_pMonster2D->getPosition().fY); Ogre::Vector3 dir(0, -1, 0); Ogre::Ray ray(terrianPos, dir); m_terrainHeight = Ogre::Vector3::ZERO; m_terrain.getRayPos(ray, m_terrainHeight); FPOS pos = m_pMonster2D->getPosition(); setPosition(pos.fX, m_terrainHeight.y, pos.fY); setDirection(m_pMonster2D->getDirection()); m_nameOverlay.setTitle(m_pMonster2D->getName()); m_nameOverlay.update(m_pMonsterNode, pCameraNode); }
void CNPC3D::setup() { CNPCInfo *pNPCInfo = CNPC::getInfo(m_pNPC2D->getID()); if(pNPCInfo != NULL) { m_pBodyEntity = m_pSceneManager->createEntity(pNPCInfo->getMeshName()); std::string meshName = pNPCInfo->getMeshName(); size_t idx = meshName.find(".mesh"); m_meshName = meshName.substr(0, idx); m_pNPCNode->attachObject(m_pBodyEntity); // 設定位置 const FPOS pos = m_pNPC2D->getPosition(); m_pNPCNode->setPosition(pos.fX, 0, pos.fY); // 設定方向 (臉朝向-Z軸與2D方向相同) m_pNPCNode->resetOrientation(); m_pNPCNode->yaw(Ogre::Radian(m_pNPC2D->getDirection())); // 載入相關動作 std::vector<std::string> vtAnimationName = m_pNPC2D->getAllAnimationName(); std::vector<std::string>::iterator it = vtAnimationName.begin(); while(it != vtAnimationName.end()) { if((*it).length() > 0) { std::string skeletonFile = (*it) + std::string(".skeleton"); setupSkeleton(skeletonFile); } it++; } // 設定動作 CAction *pNewAction = m_pNPC2D->getCurAction(); setAnimation(pNewAction->getAnimationName() + "::" + m_pNPCNode->getName()); m_nameOverlay.init(m_pBodyEntity, m_pRenderCore->getCamera(), "NCTaiwanFont", 20.0f); } }