diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index 13266473e9..01164366a8 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -93,7 +93,7 @@ void CSVRender::Object::update() Ogre::Quaternion zr (Ogre::Radian (-reference.mPos.rot[2]), Ogre::Vector3::UNIT_Z); CSVWorld::PhysicsSystem::instance()->addObject("meshes\\" + model, - mBase->getName(), reference.mScale, position, xr*yr*zr); + mBase->getName(), mReferenceId, reference.mScale, position, xr*yr*zr); } } } diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index b7d53b9e3e..aa7409fb4e 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -190,8 +190,6 @@ void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event) { // mouse picking // FIXME: need to virtualise mouse buttons - // Issue: Say 800 pixels (a typical viewport size) representing 8000 units (in one cell) - // So best case resolution is 10 units per pixel. int viewportWidth = getCamera()->getViewport()->getActualWidth(); int viewportHeight = getCamera()->getViewport()->getActualHeight(); @@ -200,18 +198,37 @@ void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event) // Need to set each time in case there are multiple subviews CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager()); - CSVWorld::PhysicsSystem::instance()->castRay(mouseX, mouseY, NULL, NULL, getCamera()); - flagAsModified(); -#if 0 - std::cout << "geometry: " + std::to_string(width()) + ", " + std::to_string(height()) << std::endl; - std::cout << "event: " + std::to_string(event->x()) + ", " + std::to_string(event->y()) << std::endl; - std::cout << "viewport: " + std::to_string(viewportWidth) + ", " + std::to_string(viewportHeight) << std::endl; - std::cout << "mouse: " + std::to_string(mouseX) + ", " + std::to_string(mouseY) << std::endl; - std::cout << "camera: " + std::to_string(getCamera()->getPosition().x) - + ", " + std::to_string(getCamera()->getPosition().y) - + ", " + std::to_string(getCamera()->getPosition().z) - << std::endl; -#endif + std::pair result = CSVWorld::PhysicsSystem::instance()->castRay(mouseX, mouseY, NULL, NULL, getCamera()); + if(result.first) + { + flagAsModified(); + std::cout << "ReferenceId: " << result.second << std::endl; + const CSMWorld::CellRef& cellref = mDocument.getData().getReferences().getRecord (result.second).get(); + //std::cout << "CellRef mId: " << cellref.mId << std::endl; // Same as ReferenceId + std::cout << "CellRef mCell: " << cellref.mCell << std::endl; + + const CSMWorld::RefCollection& references = mDocument.getData().getReferences(); + int index = references.searchId(result.second); + if (index != -1) + { + int columnIndex = + references.findColumnIndex(CSMWorld::Columns::ColumnId_ReferenceableId); + + std::cout << "index: " + std::to_string(index) + +", column index: " + std::to_string(columnIndex) << std::endl; + } + + std::map::iterator iter (mCells.begin()); + while (iter!=mCells.end()) + { + if(iter->first.getId("dummy") == cellref.mCell) + { + std::cout << "Cell changed" << std::endl; + break; + } + ++iter; + } + } } } diff --git a/apps/opencs/view/world/physicssystem.cpp b/apps/opencs/view/world/physicssystem.cpp index 70531a5595..31413ac717 100644 --- a/apps/opencs/view/world/physicssystem.cpp +++ b/apps/opencs/view/world/physicssystem.cpp @@ -64,14 +64,15 @@ namespace CSVWorld void PhysicsSystem::addObject(const std::string &mesh, const std::string &name, + const std::string &referenceId, float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, bool placeable) { - //mHandleToMesh[name] = mesh; + mRefToSceneNode[referenceId] = name; - mEngine->createAndAdjustRigidBody(mesh, name, scale, position, rotation, + mEngine->createAndAdjustRigidBody(mesh, referenceId, scale, position, rotation, 0, // scaledBoxTranslation 0, // boxRotation true, // raycasting @@ -154,11 +155,11 @@ namespace CSVWorld mEngine->stepSimulation(0.0167); // FIXME: DebugDrawer::step() not accessible } - std::pair PhysicsSystem::castRay(float mouseX, float mouseY, + std::pair PhysicsSystem::castRay(float mouseX, float mouseY, Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera) { if(!mSceneMgr) - return std::make_pair(false, Ogre::Vector3()); // FIXME: add a warning message + return std::make_pair(false, ""); // FIXME: add a warning message // using a really small value seems to mess up with the projections float nearClipDistance = camera->getNearClipDistance(); @@ -181,18 +182,20 @@ namespace CSVWorld std::pair result = mEngine->rayTest(_from, _to, raycastingObjectOnly, ignoreHeightMap, &norm); - if ((result.first == "") || !mSceneMgr->hasSceneNode(result.first)) - return std::make_pair(false, Ogre::Vector3()); - //std::cout << "no hit" << std::endl; + std::string sceneNode; + if(result.first != "") + sceneNode = mRefToSceneNode[result.first]; + if ((result.first == "") || !mSceneMgr->hasSceneNode(sceneNode)) + return std::make_pair(false, ""); else { //TODO: Try http://www.ogre3d.org/tikiwiki/Create+outline+around+a+character - Ogre::SceneNode *scene = mSceneMgr->getSceneNode(result.first); + Ogre::SceneNode *scene = mSceneMgr->getSceneNode(sceneNode); std::map >::iterator iter = - mSelectedEntities.find(result.first); + mSelectedEntities.find(sceneNode); if(iter != mSelectedEntities.end()) // currently selected { - std::vector clonedEntities = mSelectedEntities[result.first]; + std::vector clonedEntities = mSelectedEntities[sceneNode]; while(!clonedEntities.empty()) { if(mSceneMgr->hasEntity(clonedEntities.back())) @@ -204,7 +207,7 @@ namespace CSVWorld } mSelectedEntities.erase(iter); - removeHitPoint(mSceneMgr, result.first); // FIXME: for debugging + removeHitPoint(mSceneMgr, sceneNode); // FIXME: for debugging } else { @@ -239,10 +242,10 @@ namespace CSVWorld } } - mSelectedEntities[result.first] = clonedEntities; + mSelectedEntities[sceneNode] = clonedEntities; // FIXME: show cursor position for debugging - showHitPoint(mSceneMgr, result.first, ray.getPoint(farClipDist*result.second)); + showHitPoint(mSceneMgr, sceneNode, ray.getPoint(farClipDist*result.second)); } #if 0 std::cout << "hit " << result.first @@ -254,7 +257,7 @@ namespace CSVWorld + ", " + std::to_string(ray.getPoint(farClipDist*result.second).y) + ", " + std::to_string(ray.getPoint(farClipDist*result.second).z) << std::endl; #endif - return std::make_pair(true, ray.getPoint(farClipDist*result.second)); + return std::make_pair(true, result.first); } } } diff --git a/apps/opencs/view/world/physicssystem.hpp b/apps/opencs/view/world/physicssystem.hpp index ec4ae63e19..045b7e1d57 100644 --- a/apps/opencs/view/world/physicssystem.hpp +++ b/apps/opencs/view/world/physicssystem.hpp @@ -26,7 +26,7 @@ namespace CSVWorld class PhysicsSystem { static PhysicsSystem *mPhysicsSystemInstance; - //std::map mHandleToMesh; + std::map mRefToSceneNode; OEngine::Physic::PhysicEngine* mEngine; Ogre::SceneManager *mSceneMgr; std::map > mSelectedEntities; @@ -42,20 +42,18 @@ namespace CSVWorld void addObject(const std::string &mesh, const std::string &name, + const std::string &referenceId, float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, - //Ogre::Vector3* scaledBoxTranslation = 0, - //Ogre::Quaternion* boxRotation = 0, - //bool raycasting=false, bool placeable=false); void removeObject(const std::string &name); void toggleDebugRendering(); - std::pair castRay(float mouseX, float mouseY, - Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera); + std::pair castRay(float mouseX, float mouseY, + Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera); }; }