1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 22:15:32 +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);
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
// 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<bool, std::string> 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<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,
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<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)
{
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<std::string, float> 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<std::string, std::vector<std::string> >::iterator iter =
mSelectedEntities.find(result.first);
mSelectedEntities.find(sceneNode);
if(iter != mSelectedEntities.end()) // currently selected
{
std::vector<std::string> clonedEntities = mSelectedEntities[result.first];
std::vector<std::string> 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);
}
}
}

View file

@ -26,7 +26,7 @@ namespace CSVWorld
class PhysicsSystem
{
static PhysicsSystem *mPhysicsSystemInstance;
//std::map<std::string, std::string> mHandleToMesh;
std::map<std::string, std::string> mRefToSceneNode;
OEngine::Physic::PhysicEngine* mEngine;
Ogre::SceneManager *mSceneMgr;
std::map<std::string, std::vector<std::string> > 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<bool, Ogre::Vector3> castRay(float mouseX, float mouseY,
Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera);
std::pair<bool, std::string> castRay(float mouseX, float mouseY,
Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera);
};
}