STDMETHODIMP CAtlBase::LoadDoodadModel(BSTR fileName) { if (FAILED(g_pEngineManager->NewKG3DRepresentObject(REPRESENTOBJECT_DEFAULT, 0, 0, &g_DoodadRepresentObject))) { return E_FAIL; } if (g_pLastDoodadModel) { g_pLastDoodadModel->Release(); } // 自动恢复镜头,不然误操作的话就没办法了 IKG3DCamera* pCamera = g_pDoodadScene->GetCurrentCamera(); D3DXVECTOR3 vCameraPos(0.f, 250.f, -500.f); pCamera->SetPosition(vCameraPos); g_DoodadRepresentObject->SetModel(0, BSTR_TO_STRING(fileName), NULL, NULL, TRUE); IKG3DModel *pModel = NULL; g_DoodadRepresentObject->GetModel(pModel, 0); g_pLastNpcModel = dynamic_cast<IEKG3DModel*>(pModel); IEKG3DSceneModelEditor* pModelEditor = NULL; g_pDoodadScene->GetSceneModelEditor(&pModelEditor); _ASSERTE(pModelEditor); pModelEditor->OpenModel((IEKG3DModel*)pModel, FALSE); return S_OK; }
STDMETHODIMP CAtlBase::LoadDoodadScene(LONG hwndOutput) { g_pEngineManager->NewOneScene(SCENETYPE_MODELEDITOR, (IKG3DScene**)&g_pDoodadScene); if(!g_pDoodadScene) { MessageBox(NULL, "创建场景失败", "失败", 0); return FALSE; } if (FAILED(g_pDoodadScene->LoadFromFile("", 0, 0))) { SAFE_RELEASE(g_pDoodadScene); MessageBox(NULL, "创建场景失败", "失败", 0); return FALSE; } g_pEngineManager->SetFocusScene(g_pDoodadScene); g_pDoodadScene->AddOutputWindow("SceneMain", (HWND)hwndOutput, OUTPUTWND_MODELEDITOR_MAIN, 0, &g_pDoodadSceneWindowID); ASSERT(g_pDoodadScene->GetCurrentCamera()); IKG3DCamera* pCamera = g_pDoodadScene->GetCurrentCamera(); D3DXVECTOR3 vCameraPos(0.f, 250.f, -500.f); pCamera->SetPosition(vCameraPos); IEKG3DSceneOutputWnd *piSceneCurOutputWnd = NULL; g_pDoodadScene->GetCurOutputWnd(&piSceneCurOutputWnd); if (piSceneCurOutputWnd) { piSceneCurOutputWnd->InitCameraStation("Config.ini"); } g_pDoodadScene->SetCurrentOutputWindow(g_pDoodadSceneWindowID); IEKG3DSceneModelEditor* pModelEditor = NULL; g_pDoodadScene->GetSceneModelEditor(&pModelEditor); _ASSERTE(pModelEditor); if (!pModelEditor) { return E_FAIL; } IEKG3DSceneEditorBase* pBase = NULL; g_pDoodadScene->GetSceneEditorBase(&pBase); _ASSERTE(pBase); if (!pBase) { return E_FAIL; } g_DoodadInputProxy = new CInputProxy(); _ASSERTE(g_DoodadInputProxy); static PROXYKEYMAP KEYMAP[] = { // C S A L M R ? Trigger ID Prev Ig Exclusive {VK_RBUTTON, 0, 0, 0, 0, 0, 1, 0, WM_MOUSEMOVE, 1, 0, 0, 0}, // 鼠标右键, 旋转摄像机镜头 {VK_LBUTTON, 0, 0, 0, 1, 0, 0, 0, WM_MOUSEMOVE, 2, 0, 0, 0}, // 鼠标左键, 快速缩放视角 {VK_MBUTTON, 0, 0, 0, 0, 1, 0, 0, WM_MOUSEMOVE, 3, 0, 0, 0}, // 鼠标中键, PAN 视图 {0 , 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0}, // 结束 }; g_DoodadInputProxy->Init(pBase, CWnd::FromHandle((HWND)hwndOutput), KEYMAP); g_pLastDoodadModel = NULL; return S_OK; }
void VsSimulationWindow::SetCameraPositionAndLookAt(CStdFPoint oCameraPos, CStdFPoint oTarget) { osg::Vec3d vCameraPos(oCameraPos.x, oCameraPos.y, oCameraPos.z); osg::Vec3d vTargetPos(oTarget.x, oTarget.y, oTarget.z); SetCameraPositionAndLookAt(vCameraPos, vTargetPos); }