void AnimationSelector::OnBtn(wxCommandEvent & e) { if (e.GetId() == ID_BTN_PLAY) { if (!m_bPause) { return; } } else { if (m_bPause) { return; } } m_bPause = !m_bPause; m_btnPause->Enable(!m_bPause); m_btnPlay->Enable(m_bPause); Fairy::LogicModel* pObjModel = GetDataManipulator()->m_pObjTemplate; if ( pObjModel && !pObjModel->getCurrentAnimName().empty()) { pObjModel->setAnimEditing(m_bPause); } }
//重新设置效果物体 void SkillObjectEditor::ResetSkillObject() { Fairy::LogicModel* pDObject = m_Frame->GetActorSettingEditor()->GetActorObject(); if(!pDObject) return; //pDObject->execute(0.0f); try { pDObject->createSkill( mSkillTemplateName, m_Frame->GetGraphDialog()->GetLoop()); if(mSkill->getNumAnimationBulletFlows() > 0) { BulletFlowInfo* pInfo = new BulletFlowInfo; Fairy::AnimationBulletFlow* pAnimationFlow = mSkill->getAnimationBulletFlow(0); pInfo->attachPoint = pAnimationFlow->getAttachPoint(); pInfo->offsetPoistion = pAnimationFlow->getOffsetPos(); pInfo->offsetRotation = pAnimationFlow->getOffsetRotation(); pInfo->casterModel = m_Frame->GetActorSettingEditor()->GetCurrentObject(); pInfo->targetModel = m_Frame->GetActorSettingEditor()->GetTargetObject(); pInfo->targetPoint = "身体中心点"; pDObject->getCurrentSkill()->m_userData = pInfo; } } catch ( Ogre::Exception& e) { } //mSkill = Fairy::EffectManager::getSingleton().getSkill(mSkillTemplateName); m_Frame->GetGraphDialog()->InitSkillEditor(mSkill,mSkillTemplateName); }
tEntityNode* CEngineInterface::Find_HitFairyObject(INT nX, INT nY) { Ogre::Ray ray = m_pFairySystem->getWindowToViewportRay(Fairy::Point(nX, nY)); m_pRaySceneQuery->setRay(ray); // 按照逻辑优先级的查询队列 std::map< INT, tEntityNode* > mapRayQuery; const Ogre::RaySceneQueryResult& queryResult = m_pRaySceneQuery->execute(); for (Ogre::RaySceneQueryResult::const_iterator it = queryResult.begin(); it != queryResult.end(); ++it) { Ogre::MovableObject* pMovable = it->movable; Fairy::ObjectPtr object = Fairy::getObjectFromMovable(pMovable); if (object&&object->getData()) { tEntityNode* pEntityNode = (tEntityNode*)(object->getData()); // 不是游戏逻辑中动态生成的 if(!pEntityNode) continue; // 不再被关心 if(!(pEntityNode->GetRayQuery())) continue; if(pEntityNode->GetType() == tEntityNode::ETYPE_ACTOR) // object->getType() == "LogicModel") { Fairy::LogicModelObject* logicModelObject = static_cast<Fairy::LogicModelObject*>(object.get()); assert (logicModelObject); Fairy::LogicModel* model = logicModelObject->getLogicModel(); assert (model); // 不再自定义BoundingBox中 if (model->isUseExternalBoundingBox() && !(model->rayIntersect(ray))) { continue; } } // 如果已经有同级存在,按照摄像机远近排序 if(mapRayQuery.find(pEntityNode->RayQuery_GetLevel()) != mapRayQuery.end()) continue; // 放入查询队列 mapRayQuery.insert(std::make_pair(pEntityNode->RayQuery_GetLevel(), pEntityNode)); } } // 返回优先级最高的逻辑对象 if(!mapRayQuery.empty()) { return mapRayQuery.begin()->second; } return NULL; }
Fairy::Skill* SkillObjectEditor::getCurrentObjectSkill() { Fairy::LogicModel* pDObject = m_Frame->GetActorSettingEditor()->GetActorObject(); if(pDObject) { return pDObject->getCurrentSkill(); } return NULL; }
// 把一个物体放到指定得摄影机位置 void CFakeObjectEntityManager::CreateObject(LPCTSTR szObjName, CObjEntityActor* pNode, CObjEntityActor* pAttachNode, LPCTSTR szCameraName, int nTexWidth, int nTexHeight, LPCTSTR szBackgroundName) { // 先根据该fake object的名称来获取摆放位置 m_fvPosition = Ogre::Vector3(_GetFakeObjPos(szObjName), 10000.f, 0.f); //物体不存在,创建新的渲染环境 FakeObjectMap::iterator it = _GetFakeNode(szObjName, pNode, szCameraName, nTexWidth, nTexHeight, szBackgroundName); if(it == m_mapObject.end()) return; it->second.pEntityNode = pNode; it->second.pAttachEntityNode = pAttachNode; //将需要渲染的实体放入渲染环境中 // 如果骑在马上的,要设置马的位置,把人的位置复位 Fairy::LogicModel* modelImpl = pNode->GetActorImpl(); if (modelImpl->isAttached()) { Fairy::LogicModel* parentModel = modelImpl->getAttachModel(); KLAssert (parentModel); modelImpl->setPosition(Ogre::Vector3(0.0f, 0.0f, 0.0f)); parentModel->setPosition(Ogre::Vector3(m_fvPosition.x, m_fvPosition.y, m_fvPosition.z)); parentModel->setVisible(true); } else pNode->SetGfxPosition(fVector3(m_fvPosition.x, m_fvPosition.y, m_fvPosition.z)); //初始就显示,在运行过程中会一直保持visible为true的状态 pNode->SetVisible(TRUE); }
void SkillObjectEditor::InitSkillEditor(Fairy::Skill* pSkill,Ogre::String& templateName) { mSkillTemplateName = templateName; mSkill = pSkill; GetParentFrame()->GetEffectObjectProperty()->InitSkillEditor(mSkill,templateName); m_SkillObjectTree->DeleteAllItems(); m_SkillObjectTree->AddSkillToTree(mSkill); m_SkillObjectTree->SelectSkillSetting(); Fairy::LogicModel* pDObject = m_Frame->GetActorSettingEditor()->GetActorObject(); pDObject->setAnimEditing(false); m_Frame->GetGraphDialog()->InitSkillEditor(mSkill,mSkillTemplateName); m_Frame->GetGraphDialog()->InitAnimTimePosSlider(); try { pDObject->createSkill( mSkill->getSkillName(), m_Frame->GetGraphDialog()->GetLoop()); if(mSkill->getNumAnimationBulletFlows() > 0) { BulletFlowInfo* pInfo = new BulletFlowInfo; Fairy::AnimationBulletFlow* pAnimationFlow = mSkill->getAnimationBulletFlow(0); pInfo->attachPoint = pAnimationFlow->getAttachPoint(); pInfo->offsetPoistion = pAnimationFlow->getOffsetPos(); pInfo->offsetRotation = pAnimationFlow->getOffsetRotation(); pInfo->casterModel = m_Frame->GetActorSettingEditor()->GetCurrentObject(); pInfo->targetModel = m_Frame->GetActorSettingEditor()->GetTargetObject(); pInfo->targetPoint = "身体中心点"; pDObject->getCurrentSkill()->m_userData = pInfo; } } catch ( Ogre::Exception& e) { Ogre::String msg = "[Warning] Animation : " + mSkill->getSkillName() + "_getAnimationState Failed!"; wxLogMessage(msg.c_str()); } mDObject = pDObject; }
void AnimationSelector::OnSliderUpdate(wxCommandEvent & e) { if (!m_bPause) { return; } int pos = m_slider->GetValue(); Fairy::LogicModel* pObjModel = GetDataManipulator()->m_pObjTemplate; if ( pObjModel && !pObjModel->getCurrentAnimName().empty()) { Ogre::Real timeTotal = pObjModel->getAnimationLength(pObjModel->getCurrentAnimName()); Ogre::Real posValue = ((Ogre::Real)pos)/m_slider->GetMax(); pObjModel->setAnimTimePos(posValue); m_curTimeText->SetValue(Ogre::StringConverter::toString(posValue*timeTotal)); m_curFrameText->SetValue(Ogre::StringConverter::toString(posValue*timeTotal*STATIC_FPS)); } }
void AnimationSelector::pauseAnimation(bool bPause) { if (!GetDataManipulator()) { return; } Fairy::LogicModel* pObjModel = GetDataManipulator()->m_pObjTemplate; if ( !pObjModel || pObjModel->getCurrentAnimName().empty()) { return; } if (!bPause) { if (!m_bPause) { return; } } else { if (m_bPause) { return; } } m_bPause = !m_bPause; m_btnPause->Enable(!m_bPause); m_btnPlay->Enable(m_bPause); if ( pObjModel && !pObjModel->getCurrentAnimName().empty()) { pObjModel->setAnimEditing(m_bPause); } }
void AnimationSelector::OnAnimationListSelChanged(wxTreeEvent& e) { // reset the state resetState(); wxTreeItemId item = e.GetItem(); wxASSERT(item.IsOk()); wxTreeCtrl* tree = wxStaticCast(e.GetEventObject(), wxTreeCtrl); mActivedItem = e.GetItem(); wxArrayTreeItemIds selections; int nCount = tree->GetSelections(selections); if(nCount <= 0) return; if (mIsMeshAnim) { GetDataManipulator()->changeMeshAnimation(DoActiveItem(item)); return; } GetDataManipulator()->changeAnimation(DoActiveItem(item),0.0); Fairy::LogicModel* pObjModel = GetDataManipulator()->m_pObjTemplate; if ( pObjModel && !pObjModel->getCurrentAnimName().empty()) { m_btnPause->Enable(true); pObjModel->setAnimEditing(m_bPause); Ogre::String animationName = pObjModel->getCurrentAnimName(); bool bLoop = pObjModel->getAnimationLoop(); Ogre::Real timeTotal = pObjModel->getAnimationLength(animationName); m_endTimeText->SetValue(Ogre::StringConverter::toString(timeTotal)); m_endFrameText->SetValue(Ogre::StringConverter::toString(timeTotal*STATIC_FPS)); } }
void ActorSceneCanvas::OnMouseMove(wxMouseEvent& e) { ShowPos(e.GetX(), e.GetY()); if (!GetSceneManipulator()) return; if (m_pCameraManip) { wxASSERT(mDragButton != wxMOUSE_BTN_NONE); m_pCameraManip->onMotion(e.GetX(), e.GetY()); } if (mDragStarted && e.LeftIsDown()) { mDragCurrent =Ogre::Vector2(e.GetX(), e.GetY()) ; mDragDelta = mDragCurrent - mDragOrigin; mDragOrigin = mDragCurrent; if (Fairy::CDataManipulator::GetDataManipulator() && mCanManipulateAxis) { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Vector3 oldPos = camera->getPosition(); Fairy::LogicModel* pModel = GetDataManipulator()->m_pObjTemplate; if (pModel) { Ogre::Vector3 objPos = pModel->getPosition(); Ogre::Real distance = oldPos.distance(objPos); Ogre::Real factor = distance*0.1/150.0; Ogre::Vector3 pos=Fairy::CDataManipulator::m_baseNode->getPosition(); Ogre::Vector3 fdeltaxi = Ogre::Vector3::ZERO; Ogre::Quaternion qRot = Fairy::CDataManipulator::m_baseNode->getOrientation(); //david-<< if(mXax) fdeltaxi = /*qRot**/(mDragDelta.x*0.1*Ogre::Vector3::UNIT_X); if(mYax) fdeltaxi = /*qRot**/(mDragDelta.x*0.1*Ogre::Vector3::UNIT_Y); if(mZax) fdeltaxi = /*qRot**/(mDragDelta.x*0.1*Ogre::Vector3::UNIT_Z); //david->> Fairy::CDataManipulator::GetDataManipulator()->_updateCurLocatorTrans(fdeltaxi,Ogre::Quaternion::IDENTITY,true); } } } if(mDragRightStarted && e.RightIsDown()) { mDragCurrent =Ogre::Vector2(e.GetX(), e.GetY()) ; mDragDelta = mDragCurrent - mDragOrigin; mDragOrigin = mDragCurrent; // Ogre::Radian x = Ogre::Degree(mDragDelta.val[0]); // Ogre::Radian y = Ogre::Degree(mDragDelta.val[1]); // Fairy::CDataManipulator::m_axex->yaw(y); // Fairy::CDataManipulator::m_axex->pitch(x); if ( Fairy::CDataManipulator::GetDataManipulator() &&(mXax || mYax || mZax) && mCanManipulateAxis) { Ogre::Vector3 fBaseAxis = Ogre::Vector3::ZERO; Ogre::Quaternion fBaseRot = Fairy::CDataManipulator::m_baseNode->getOrientation(); if(mXax) fBaseAxis =/* fBaseRot**/Ogre::Vector3::UNIT_X; if(mYax) fBaseAxis =/* fBaseRot**/Ogre::Vector3::UNIT_Y; if(mZax) fBaseAxis =/* fBaseRot**/Ogre::Vector3::UNIT_Z; //david-<< Ogre::Radian angle = Ogre::Degree(mDragDelta.y); //david->> Ogre::Quaternion rot(angle, fBaseAxis); if(mRotFirst) { Fairy::CDataManipulator::GetDataManipulator()->_updateCurLocatorTrans(Ogre::Vector3::ZERO, rot, false); } else { Fairy::CDataManipulator::GetDataManipulator()->_updateCurLocatorRot(rot); } } } if (GetActiveAction()) { //GetActiveAction()->onMotion(e.GetX(), e.GetY()); if (e.ControlDown()) { GetActiveAction()->setParameter("FUNC_KEY", "CTRL"); } if(e.AltDown()) { GetActiveAction()->setParameter("FUNC_KEY", "ATL"); } if(e.ShiftDown()) { GetActiveAction()->setParameter("FUNC_KEY", "SHIFT"); } } else { //GetSceneManipulator()->getHitIndicator("IntersectPoint")->setHitPoint(e.GetX(), e.GetY()); } // 显示标准模型 //if ( GetSceneManipulator()->getShowStandardModel() ) // GetSceneManipulator()->getHitIndicator("StandardModelIndicator")->setHitPoint(0.5,0.5); //else // GetSceneManipulator()->getHitIndicator("StandardModelIndicator")->hide(); m_CurrentMousePos.x = e.GetX(); m_CurrentMousePos.y = e.GetY(); Ogre::Vector3 position; bool hit = GetSceneManipulator()->getTerrainIntersects(m_CurrentMousePos.x, m_CurrentMousePos.y, position); std::pair<int, int> gridCoord = GetSceneManipulator()->getTerrainData()->getGrid(position.x, position.z); if (hit) { mParentFrame->SetStatusText("World Coordinate : " + Ogre::StringConverter::toString((int)(position.x)) + " " + Ogre::StringConverter::toString((int)(position.y)) + " " + Ogre::StringConverter::toString((int)(position.z)), 0); mParentFrame->SetStatusText("Grid Coordinate : " + Ogre::StringConverter::toString(gridCoord.first) + " " + Ogre::StringConverter::toString(gridCoord.second), 1); } }
//销毁效果物体 void SkillObjectEditor::DestroySkillObject() { Fairy::LogicModel* pDObject = m_Frame->GetActorSettingEditor()->GetActorObject(); if(pDObject) pDObject->delCurrentSkill(); }
void AddEffectInfoDialog::OnInitDialog(wxInitDialogEvent &e) { wxDialog::OnInitDialog(e); wxSizer* sizer = new wxBoxSizer( wxVERTICAL ); wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 ); wxComboBox *item2 = new wxComboBox( this, feID_COMBOCTRL_EFFECT, wxT(""), wxDefaultPosition, wxSize(200,-1), 0, NULL, wxCB_DROPDOWN ); item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 ); wxComboBox *item3 = new wxComboBox( this, feID_COMBOCTRL_LOCATOR, wxT(""), wxDefaultPosition, wxSize(200,-1), 0, NULL, wxCB_DROPDOWN ); item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 ); sizer->Add( item1, 0, wxALIGN_CENTER|wxALL, 10 ); wxFlexGridSizer *item5 = new wxFlexGridSizer( 2, 0, 0 ); wxButton *item6 = new wxButton( this, wxID_OK, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0 ); item6->SetDefault(); item5->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 ); wxButton *item7 = new wxButton( this, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); item5->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 ); sizer->Add( item5, 0, wxALIGN_CENTER|wxALL, 10 ); this->SetSizer( sizer ); sizer->SetSizeHints( this ); Fairy::EffectManager::EffectTemplateIterator it = Fairy::EffectManager::getSingleton().getEffectTemplateIterator(); while ( it.hasMoreElements() ) { item2->AppendString(it.peekNextKey().c_str()); it.moveNext(); } item2->SetSelection(0); SkillObjectEditor* pEditor= static_cast<SkillObjectEditor*>(this->GetParent()); if(!pEditor) return; Fairy::LogicModel *pMbject = pEditor->GetParentFrame()->GetActorSettingEditor()->GetActorObject(); assert (pMbject); Ogre::StringVector boneNameList; for ( unsigned short i=0; i<pMbject->getNumBones(); ++i ) { boneNameList.push_back(pMbject->getBoneName(i)); } Ogre::StringVector locatorNames; pMbject->getLocatorNames(locatorNames); for ( size_t i=0; i<locatorNames.size(); ++i ) { Fairy::LogicModel::LocatorValue value; if(pMbject->getLocatorInfo(locatorNames[i], value)) { if(value.mBoneName != "" ) { for ( int index=0; index<(int)boneNameList.size(); ++index ) { if (boneNameList[index] == value.mBoneName) { // info of the locator is valid item3->Append(locatorNames[i].c_str()); break; } } } } } item3->SetSelection(0); }
void AddSkillDialog::OnInitDialog(wxInitDialogEvent &e) { wxDialog::OnInitDialog(e); wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 ); wxStaticText *item2 = new wxStaticText( this, wxID_ANY, /*_("Animation")*/ wxT("动作"), wxDefaultPosition, wxDefaultSize, 0 ); item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 ); wxString *strs3 = (wxString*) NULL; wxComboBox *item3 = new wxComboBox( this, ID_COMBO_ANIMATION, wxT(""), wxDefaultPosition, wxSize(200,-1), 0, strs3, wxCB_DROPDOWN ); item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 ); wxStaticText *item4 = new wxStaticText( this, wxID_ANY, /*_("Skill Name")*/wxT("技能名称"), wxDefaultPosition, wxDefaultSize, 0 ); item1->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 ); wxTextCtrl *item5 = new wxTextCtrl( this, ID_TEXTCTRL_SKILL, wxT(""), wxDefaultPosition, wxSize(200,-1), 0 ); item1->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 ); wxButton *item6 = new wxButton( this, wxID_OK, /*_("OK")*/wxT("确认[&O]"), wxDefaultPosition, wxDefaultSize, 0 ); item1->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 ); wxButton *item7 = new wxButton( this, wxID_CANCEL, /*_("Cancel")*/wxT("取消[&C]"), wxDefaultPosition, wxDefaultSize, 0 ); item1->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 ); item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 ); this->SetSizer( item0 ); item0->SetSizeHints( this ); SkillObjectEditor* pSkillEditor = dynamic_cast<SkillObjectEditor*>(m_parent); assert(pSkillEditor); ActorAnimationSettingEditor *parentDialog = pSkillEditor->GetParentFrame()->GetActorSettingEditor(); assert (parentDialog); Fairy::LogicModel *object = parentDialog->GetCurrentObject(); for ( unsigned short i = 0; i < object->getSkeletonAnimationCount(); ++i ) { Ogre::Animation *anim = object->getSkeletonAnimation(i); if ( anim ) { wxString nameStr(anim->getName().c_str()); item3->AppendString(nameStr); } } // 加入obj中定义的动作名称 Fairy::LogicModelManager::AnimationSkeletonLinksIterator asmIt = Fairy::LogicModelManager::getSingleton().getAnimationSkeletonLinksIterator(object->getName()); while ( asmIt.hasMoreElements() ) { wxString animName(asmIt.peekNextKey().c_str()); if ( wxNOT_FOUND == item3->FindString(animName) ) { wxString nameStr(animName.c_str()); item3->AppendString(nameStr); } asmIt.moveNext(); } item3->SetSelection(0); mAnimComboBox = item3; mSkillNameTextCtrl = item5; }
//----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; }