1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 15:15:31 +00:00

Store object reference id to RigidBody instead of scene node handles.

This commit is contained in:
cc9cii 2014-10-24 21:18:29 +11:00
parent cb53e714f7
commit e5dd8d06a0
4 changed files with 53 additions and 35 deletions

View file

@ -93,7 +93,7 @@ void CSVRender::Object::update()
Ogre::Quaternion zr (Ogre::Radian (-reference.mPos.rot[2]), Ogre::Vector3::UNIT_Z); Ogre::Quaternion zr (Ogre::Radian (-reference.mPos.rot[2]), Ogre::Vector3::UNIT_Z);
CSVWorld::PhysicsSystem::instance()->addObject("meshes\\" + model, CSVWorld::PhysicsSystem::instance()->addObject("meshes\\" + model,
mBase->getName(), reference.mScale, position, xr*yr*zr); mBase->getName(), mReferenceId, reference.mScale, position, xr*yr*zr);
} }
} }
} }

View file

@ -190,8 +190,6 @@ void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
{ {
// mouse picking // mouse picking
// FIXME: need to virtualise mouse buttons // 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 viewportWidth = getCamera()->getViewport()->getActualWidth();
int viewportHeight = getCamera()->getViewport()->getActualHeight(); 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 // Need to set each time in case there are multiple subviews
CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager()); CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager());
CSVWorld::PhysicsSystem::instance()->castRay(mouseX, mouseY, NULL, NULL, getCamera()); std::pair<bool, std::string> result = CSVWorld::PhysicsSystem::instance()->castRay(mouseX, mouseY, NULL, NULL, getCamera());
flagAsModified(); if(result.first)
#if 0 {
std::cout << "geometry: " + std::to_string(width()) + ", " + std::to_string(height()) << std::endl; flagAsModified();
std::cout << "event: " + std::to_string(event->x()) + ", " + std::to_string(event->y()) << std::endl; std::cout << "ReferenceId: " << result.second << std::endl;
std::cout << "viewport: " + std::to_string(viewportWidth) + ", " + std::to_string(viewportHeight) << std::endl; const CSMWorld::CellRef& cellref = mDocument.getData().getReferences().getRecord (result.second).get();
std::cout << "mouse: " + std::to_string(mouseX) + ", " + std::to_string(mouseY) << std::endl; //std::cout << "CellRef mId: " << cellref.mId << std::endl; // Same as ReferenceId
std::cout << "camera: " + std::to_string(getCamera()->getPosition().x) std::cout << "CellRef mCell: " << cellref.mCell << std::endl;
+ ", " + std::to_string(getCamera()->getPosition().y)
+ ", " + std::to_string(getCamera()->getPosition().z) const CSMWorld::RefCollection& references = mDocument.getData().getReferences();
<< std::endl; int index = references.searchId(result.second);
#endif 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<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
while (iter!=mCells.end())
{
if(iter->first.getId("dummy") == cellref.mCell)
{
std::cout << "Cell changed" << std::endl;
break;
}
++iter;
}
}
} }
} }

View file

@ -64,14 +64,15 @@ namespace CSVWorld
void PhysicsSystem::addObject(const std::string &mesh, void PhysicsSystem::addObject(const std::string &mesh,
const std::string &name, const std::string &name,
const std::string &referenceId,
float scale, float scale,
const Ogre::Vector3 &position, const Ogre::Vector3 &position,
const Ogre::Quaternion &rotation, const Ogre::Quaternion &rotation,
bool placeable) 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, // scaledBoxTranslation
0, // boxRotation 0, // boxRotation
true, // raycasting true, // raycasting
@ -154,11 +155,11 @@ namespace CSVWorld
mEngine->stepSimulation(0.0167); // FIXME: DebugDrawer::step() not accessible mEngine->stepSimulation(0.0167); // FIXME: DebugDrawer::step() not accessible
} }
std::pair<bool, Ogre::Vector3> PhysicsSystem::castRay(float mouseX, float mouseY, std::pair<bool, std::string> PhysicsSystem::castRay(float mouseX, float mouseY,
Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera) Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera)
{ {
if(!mSceneMgr) 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 // using a really small value seems to mess up with the projections
float nearClipDistance = camera->getNearClipDistance(); float nearClipDistance = camera->getNearClipDistance();
@ -181,18 +182,20 @@ namespace CSVWorld
std::pair<std::string, float> result = std::pair<std::string, float> result =
mEngine->rayTest(_from, _to, raycastingObjectOnly, ignoreHeightMap, &norm); mEngine->rayTest(_from, _to, raycastingObjectOnly, ignoreHeightMap, &norm);
if ((result.first == "") || !mSceneMgr->hasSceneNode(result.first)) std::string sceneNode;
return std::make_pair(false, Ogre::Vector3()); if(result.first != "")
//std::cout << "no hit" << std::endl; sceneNode = mRefToSceneNode[result.first];
if ((result.first == "") || !mSceneMgr->hasSceneNode(sceneNode))
return std::make_pair(false, "");
else else
{ {
//TODO: Try http://www.ogre3d.org/tikiwiki/Create+outline+around+a+character //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<std::string, std::vector<std::string> >::iterator iter = std::map<std::string, std::vector<std::string> >::iterator iter =
mSelectedEntities.find(result.first); mSelectedEntities.find(sceneNode);
if(iter != mSelectedEntities.end()) // currently selected if(iter != mSelectedEntities.end()) // currently selected
{ {
std::vector<std::string> clonedEntities = mSelectedEntities[result.first]; std::vector<std::string> clonedEntities = mSelectedEntities[sceneNode];
while(!clonedEntities.empty()) while(!clonedEntities.empty())
{ {
if(mSceneMgr->hasEntity(clonedEntities.back())) if(mSceneMgr->hasEntity(clonedEntities.back()))
@ -204,7 +207,7 @@ namespace CSVWorld
} }
mSelectedEntities.erase(iter); mSelectedEntities.erase(iter);
removeHitPoint(mSceneMgr, result.first); // FIXME: for debugging removeHitPoint(mSceneMgr, sceneNode); // FIXME: for debugging
} }
else else
{ {
@ -239,10 +242,10 @@ namespace CSVWorld
} }
} }
mSelectedEntities[result.first] = clonedEntities; mSelectedEntities[sceneNode] = clonedEntities;
// FIXME: show cursor position for debugging // 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 #if 0
std::cout << "hit " << result.first 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).y)
+ ", " + std::to_string(ray.getPoint(farClipDist*result.second).z) << std::endl; + ", " + std::to_string(ray.getPoint(farClipDist*result.second).z) << std::endl;
#endif #endif
return std::make_pair(true, ray.getPoint(farClipDist*result.second)); return std::make_pair(true, result.first);
} }
} }
} }

View file

@ -26,7 +26,7 @@ namespace CSVWorld
class PhysicsSystem class PhysicsSystem
{ {
static PhysicsSystem *mPhysicsSystemInstance; static PhysicsSystem *mPhysicsSystemInstance;
//std::map<std::string, std::string> mHandleToMesh; std::map<std::string, std::string> mRefToSceneNode;
OEngine::Physic::PhysicEngine* mEngine; OEngine::Physic::PhysicEngine* mEngine;
Ogre::SceneManager *mSceneMgr; Ogre::SceneManager *mSceneMgr;
std::map<std::string, std::vector<std::string> > mSelectedEntities; std::map<std::string, std::vector<std::string> > mSelectedEntities;
@ -42,20 +42,18 @@ namespace CSVWorld
void addObject(const std::string &mesh, void addObject(const std::string &mesh,
const std::string &name, const std::string &name,
const std::string &referenceId,
float scale, float scale,
const Ogre::Vector3 &position, const Ogre::Vector3 &position,
const Ogre::Quaternion &rotation, const Ogre::Quaternion &rotation,
//Ogre::Vector3* scaledBoxTranslation = 0,
//Ogre::Quaternion* boxRotation = 0,
//bool raycasting=false,
bool placeable=false); bool placeable=false);
void removeObject(const std::string &name); void removeObject(const std::string &name);
void toggleDebugRendering(); void toggleDebugRendering();
std::pair<bool, Ogre::Vector3> castRay(float mouseX, float mouseY, std::pair<bool, std::string> castRay(float mouseX, float mouseY,
Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera); Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera);
}; };
} }