mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-01 13:06:43 +00:00
Add terrain collision. Support visibility mask for objects and terrain.
This commit is contained in:
parent
cc0acec64c
commit
9337d6533a
4 changed files with 44 additions and 15 deletions
|
@ -5,10 +5,12 @@
|
||||||
#include <OgreSceneNode.h>
|
#include <OgreSceneNode.h>
|
||||||
|
|
||||||
#include <components/misc/stringops.hpp>
|
#include <components/misc/stringops.hpp>
|
||||||
|
#include <components/esm/loadland.hpp>
|
||||||
|
|
||||||
#include "../../model/world/idtable.hpp"
|
#include "../../model/world/idtable.hpp"
|
||||||
#include "../../model/world/columns.hpp"
|
#include "../../model/world/columns.hpp"
|
||||||
#include "../../model/world/data.hpp"
|
#include "../../model/world/data.hpp"
|
||||||
|
#include "../world/physicssystem.hpp"
|
||||||
|
|
||||||
#include "elements.hpp"
|
#include "elements.hpp"
|
||||||
#include "terrainstorage.hpp"
|
#include "terrainstorage.hpp"
|
||||||
|
@ -81,6 +83,14 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
|
||||||
const ESM::Land* esmLand = land.getRecord(mId).get().mLand.get();
|
const ESM::Land* esmLand = land.getRecord(mId).get().mLand.get();
|
||||||
mTerrain->loadCell(esmLand->mX,
|
mTerrain->loadCell(esmLand->mX,
|
||||||
esmLand->mY);
|
esmLand->mY);
|
||||||
|
|
||||||
|
if(esmLand)
|
||||||
|
{
|
||||||
|
float verts = ESM::Land::LAND_SIZE;
|
||||||
|
float worldsize = ESM::Land::REAL_SIZE;
|
||||||
|
CSVWorld::PhysicsSystem::instance()->addHeightField(
|
||||||
|
esmLand->mLandData->mHeights, esmLand->mX, esmLand->mY, 0, worldsize / (verts-1), verts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,29 +187,36 @@ void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
|
||||||
bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false;
|
|
||||||
if(!debug)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// mouse picking
|
// mouse picking
|
||||||
// FIXME: need to virtualise mouse buttons
|
// FIXME: need to virtualise mouse buttons
|
||||||
|
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||||
|
bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false;
|
||||||
|
if(!debug || !getCamera()->getViewport())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!((uint32_t)getCamera()->getViewport()->getVisibilityMask() & (uint32_t)CSVRender::Element_Reference))
|
||||||
|
return;
|
||||||
|
|
||||||
int viewportWidth = getCamera()->getViewport()->getActualWidth();
|
int viewportWidth = getCamera()->getViewport()->getActualWidth();
|
||||||
int viewportHeight = getCamera()->getViewport()->getActualHeight();
|
int viewportHeight = getCamera()->getViewport()->getActualHeight();
|
||||||
|
|
||||||
float mouseX = (float) event->x()/viewportWidth;
|
float mouseX = (float) event->x()/viewportWidth;
|
||||||
float mouseY = (float) event->y()/viewportHeight;
|
float mouseY = (float) event->y()/viewportHeight;
|
||||||
|
|
||||||
|
bool ignoreHeightMap = true;
|
||||||
|
if(((uint32_t)getCamera()->getViewport()->getVisibilityMask() & (uint32_t)CSVRender::Element_Terrain))
|
||||||
|
ignoreHeightMap = false;
|
||||||
|
|
||||||
// Need to set scene manager each time in case there are multiple subviews
|
// Need to set scene manager each time in case there are multiple subviews
|
||||||
CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager());
|
CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager());
|
||||||
std::pair<bool, std::string> result =
|
std::pair<bool, std::string> result = CSVWorld::PhysicsSystem::instance()->castRay(
|
||||||
CSVWorld::PhysicsSystem::instance()->castRay(mouseX, mouseY, NULL, NULL, getCamera());
|
mouseX, mouseY, NULL, NULL, getCamera(), ignoreHeightMap);
|
||||||
if(result.first)
|
if(result.first)
|
||||||
{
|
{
|
||||||
std::cout << "ReferenceId: " << result.second << std::endl;
|
std::cout << "ReferenceId: " << result.second << std::endl;
|
||||||
const CSMWorld::CellRef& cellref = mDocument.getData().getReferences().getRecord (result.second).get();
|
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.mId: " << cellref.mId << std::endl; // Same as ReferenceId
|
||||||
std::cout << "CellRef mCell: " << cellref.mCell << std::endl;
|
std::cout << "CellRef.mCell: " << cellref.mCell << std::endl;
|
||||||
|
|
||||||
const CSMWorld::RefCollection& references = mDocument.getData().getReferences();
|
const CSMWorld::RefCollection& references = mDocument.getData().getReferences();
|
||||||
int index = references.searchId(result.second);
|
int index = references.searchId(result.second);
|
||||||
|
@ -248,8 +255,11 @@ void CSVRender::PagedWorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event
|
||||||
if(!debug)
|
if(!debug)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Need to set scene manager each time in case there are multiple subviews
|
// FIXME: OEngine::PhysicEngine creates only one child scene node for the
|
||||||
CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager());
|
// debug drawer. Hence only the first subview that creates the debug drawer
|
||||||
|
// can view the debug lines. Will need to keep a map in OEngine if multiple
|
||||||
|
// subviews are to be supported.
|
||||||
|
//CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager());
|
||||||
CSVWorld::PhysicsSystem::instance()->toggleDebugRendering();
|
CSVWorld::PhysicsSystem::instance()->toggleDebugRendering();
|
||||||
flagAsModified();
|
flagAsModified();
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,6 +146,12 @@ namespace CSVWorld
|
||||||
mEngine->deleteRigidBody(name);
|
mEngine->deleteRigidBody(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicsSystem::addHeightField(float* heights, int x, int y, float yoffset,
|
||||||
|
float triSize, float sqrtVerts)
|
||||||
|
{
|
||||||
|
mEngine->addHeightField(heights, x, y, yoffset, triSize, sqrtVerts);
|
||||||
|
}
|
||||||
|
|
||||||
void PhysicsSystem::toggleDebugRendering()
|
void PhysicsSystem::toggleDebugRendering()
|
||||||
{
|
{
|
||||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||||
|
@ -158,7 +164,7 @@ namespace CSVWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<bool, std::string> 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, bool ignoreHeightMap)
|
||||||
{
|
{
|
||||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||||
bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false;
|
bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false;
|
||||||
|
@ -179,8 +185,7 @@ namespace CSVWorld
|
||||||
_from = btVector3(from.x, from.y, from.z);
|
_from = btVector3(from.x, from.y, from.z);
|
||||||
_to = btVector3(to.x, to.y, to.z);
|
_to = btVector3(to.x, to.y, to.z);
|
||||||
|
|
||||||
bool raycastingObjectOnly = true;
|
bool raycastingObjectOnly = true; // FIXME
|
||||||
bool ignoreHeightMap = false;
|
|
||||||
Ogre::Vector3 norm;
|
Ogre::Vector3 norm;
|
||||||
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);
|
||||||
|
|
|
@ -50,10 +50,14 @@ namespace CSVWorld
|
||||||
|
|
||||||
void removeObject(const std::string &name);
|
void removeObject(const std::string &name);
|
||||||
|
|
||||||
|
void addHeightField(float* heights, int x, int y, float yoffset,
|
||||||
|
float triSize, float sqrtVerts);
|
||||||
|
|
||||||
void toggleDebugRendering();
|
void toggleDebugRendering();
|
||||||
|
|
||||||
std::pair<bool, std::string> 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, bool ignoreHeightMap);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue