forked from teamnwah/openmw-tes3coop
Merge branch 'terraincollision' into physicsterrain
Conflicts: apps/openmw/mwworld/physicssystem.cpp
This commit is contained in:
commit
75dd651205
6 changed files with 117 additions and 11 deletions
|
@ -183,6 +183,19 @@ namespace MWWorld
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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::removeHeightField (int x, int y)
|
||||||
|
{
|
||||||
|
mEngine->removeHeightField(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
void PhysicsSystem::addObject (const std::string& handle, const std::string& mesh,
|
void PhysicsSystem::addObject (const std::string& handle, const std::string& mesh,
|
||||||
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
|
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,12 @@ namespace MWWorld
|
||||||
void addActor (const std::string& handle, const std::string& mesh,
|
void addActor (const std::string& handle, const std::string& mesh,
|
||||||
const Ogre::Vector3& position);
|
const Ogre::Vector3& position);
|
||||||
|
|
||||||
|
void addHeightField (float* heights,
|
||||||
|
int x, int y, float yoffset,
|
||||||
|
float triSize, float sqrtVerts);
|
||||||
|
|
||||||
|
void removeHeightField (int x, int y);
|
||||||
|
|
||||||
void removeObject (const std::string& handle);
|
void removeObject (const std::string& handle);
|
||||||
|
|
||||||
void moveObject (const std::string& handle, const Ogre::Vector3& position);
|
void moveObject (const std::string& handle, const Ogre::Vector3& position);
|
||||||
|
|
|
@ -75,11 +75,14 @@ namespace MWWorld
|
||||||
|
|
||||||
|
|
||||||
// silence annoying g++ warning
|
// silence annoying g++ warning
|
||||||
for (std::vector<Ogre::SceneNode*>::const_iterator iter (functor.mHandles.begin());
|
for (std::vector<Ogre::SceneNode*>::const_iterator iter2 (functor.mHandles.begin());
|
||||||
iter!=functor.mHandles.end(); ++iter){
|
iter2!=functor.mHandles.end(); ++iter2){
|
||||||
Ogre::SceneNode* node = *iter;
|
Ogre::SceneNode* node = *iter2;
|
||||||
mPhysics->removeObject (node->getName());
|
mPhysics->removeObject (node->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!((*iter)->cell->data.flags & ESM::Cell::Interior))
|
||||||
|
mPhysics->removeHeightField( (*iter)->cell->data.gridX, (*iter)->cell->data.gridY );
|
||||||
}
|
}
|
||||||
|
|
||||||
mRendering.removeCell(*iter);
|
mRendering.removeCell(*iter);
|
||||||
|
@ -103,14 +106,28 @@ namespace MWWorld
|
||||||
|
|
||||||
std::pair<CellStoreCollection::iterator, bool> result =
|
std::pair<CellStoreCollection::iterator, bool> result =
|
||||||
mActiveCells.insert(cell);
|
mActiveCells.insert(cell);
|
||||||
if(result.second){
|
|
||||||
insertCell(*cell, mEnvironment);
|
|
||||||
mRendering.cellAdded(cell);
|
|
||||||
mRendering.configureAmbient(*cell);
|
|
||||||
mRendering.requestMap(cell);
|
|
||||||
mRendering.configureAmbient(*cell);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(result.second)
|
||||||
|
{
|
||||||
|
insertCell(*cell, mEnvironment);
|
||||||
|
mRendering.cellAdded (cell);
|
||||||
|
|
||||||
|
float verts = ESM::Land::LAND_SIZE;
|
||||||
|
float worldsize = ESM::Land::REAL_SIZE;
|
||||||
|
|
||||||
|
if (!(cell->cell->data.flags & ESM::Cell::Interior))
|
||||||
|
{
|
||||||
|
ESM::Land* land = mWorld->getStore().lands.search(cell->cell->data.gridX,cell->cell->data.gridY);
|
||||||
|
mPhysics->addHeightField (land->landData->heights,
|
||||||
|
cell->cell->data.gridX, cell->cell->data.gridY,
|
||||||
|
0, ( worldsize/(verts-1) ), verts);
|
||||||
|
}
|
||||||
|
|
||||||
|
mRendering.configureAmbient(*cell);
|
||||||
|
mRendering.requestMap(cell);
|
||||||
|
mRendering.configureAmbient(*cell);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -776,7 +776,8 @@ namespace MWWorld
|
||||||
std::vector < std::pair < float, std::string > >::iterator it = results.begin();
|
std::vector < std::pair < float, std::string > >::iterator it = results.begin();
|
||||||
while (it != results.end())
|
while (it != results.end())
|
||||||
{
|
{
|
||||||
if ( getPtrViaHandle((*it).second) == mPlayer->getPlayer() )
|
if ( (*it).second.find("HeightField") != std::string::npos // not interested in terrain
|
||||||
|
|| getPtrViaHandle((*it).second) == mPlayer->getPlayer() ) // not interested in player (unless you want to talk to yourself)
|
||||||
{
|
{
|
||||||
it = results.erase(it);
|
it = results.erase(it);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "physic.hpp"
|
#include "physic.hpp"
|
||||||
#include <btBulletDynamicsCommon.h>
|
#include <btBulletDynamicsCommon.h>
|
||||||
#include <btBulletCollisionCommon.h>
|
#include <btBulletCollisionCommon.h>
|
||||||
|
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
|
||||||
#include <components/nifbullet/bullet_nif_loader.hpp>
|
#include <components/nifbullet/bullet_nif_loader.hpp>
|
||||||
//#include <apps\openmw\mwworld\world.hpp>
|
//#include <apps\openmw\mwworld\world.hpp>
|
||||||
#include "CMotionState.h"
|
#include "CMotionState.h"
|
||||||
|
@ -10,6 +11,8 @@
|
||||||
#include "BtOgreGP.h"
|
#include "BtOgreGP.h"
|
||||||
#include "BtOgreExtras.h"
|
#include "BtOgreExtras.h"
|
||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
#define BIT(x) (1<<(x))
|
#define BIT(x) (1<<(x))
|
||||||
|
|
||||||
namespace OEngine {
|
namespace OEngine {
|
||||||
|
@ -254,6 +257,60 @@ namespace Physic
|
||||||
delete mShapeLoader;
|
delete mShapeLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicEngine::addHeightField(float* heights,
|
||||||
|
int x, int y, float yoffset,
|
||||||
|
float triSize, float sqrtVerts)
|
||||||
|
{
|
||||||
|
const std::string name = "HeightField_"
|
||||||
|
+ boost::lexical_cast<std::string>(x) + "_"
|
||||||
|
+ boost::lexical_cast<std::string>(y);
|
||||||
|
|
||||||
|
// find the minimum and maximum heights (needed for bullet)
|
||||||
|
float minh;
|
||||||
|
float maxh;
|
||||||
|
for (int i=0; i<sqrtVerts*sqrtVerts; ++i)
|
||||||
|
{
|
||||||
|
float h = heights[i];
|
||||||
|
if (i==0)
|
||||||
|
{
|
||||||
|
minh = h;
|
||||||
|
maxh = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (h>maxh) maxh = h;
|
||||||
|
if (h<minh) minh = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
btHeightfieldTerrainShape* hfShape = new btHeightfieldTerrainShape(
|
||||||
|
sqrtVerts, sqrtVerts, heights, 1,
|
||||||
|
minh, maxh, 2,
|
||||||
|
PHY_FLOAT,true);
|
||||||
|
|
||||||
|
hfShape->setUseDiamondSubdivision(true);
|
||||||
|
|
||||||
|
btVector3 scl(triSize, triSize, 1);
|
||||||
|
hfShape->setLocalScaling(scl);
|
||||||
|
|
||||||
|
CMotionState* newMotionState = new CMotionState(this,name);
|
||||||
|
|
||||||
|
btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo(0,newMotionState,hfShape);
|
||||||
|
RigidBody* body = new RigidBody(CI,name);
|
||||||
|
body->collide = true;
|
||||||
|
body->getWorldTransform().setOrigin(btVector3( (x+0.5)*triSize*(sqrtVerts-1), (y+0.5)*triSize*(sqrtVerts-1), (maxh+minh)/2.f));
|
||||||
|
|
||||||
|
addRigidBody(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicEngine::removeHeightField(int x, int y)
|
||||||
|
{
|
||||||
|
const std::string name = "HeightField_"
|
||||||
|
+ boost::lexical_cast<std::string>(x) + "_"
|
||||||
|
+ boost::lexical_cast<std::string>(y);
|
||||||
|
|
||||||
|
removeRigidBody(name);
|
||||||
|
deleteRigidBody(name);
|
||||||
|
}
|
||||||
|
|
||||||
RigidBody* PhysicEngine::createRigidBody(std::string mesh,std::string name,float scale)
|
RigidBody* PhysicEngine::createRigidBody(std::string mesh,std::string name,float scale)
|
||||||
{
|
{
|
||||||
//get the shape from the .nif
|
//get the shape from the .nif
|
||||||
|
|
|
@ -140,6 +140,18 @@ namespace Physic
|
||||||
*/
|
*/
|
||||||
RigidBody* createRigidBody(std::string mesh,std::string name,float scale);
|
RigidBody* createRigidBody(std::string mesh,std::string name,float scale);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a HeightField to the simulation
|
||||||
|
*/
|
||||||
|
void addHeightField(float* heights,
|
||||||
|
int x, int y, float yoffset,
|
||||||
|
float triSize, float sqrtVerts);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a HeightField from the simulation
|
||||||
|
*/
|
||||||
|
void removeHeightField(int x, int y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a RigidBody to the simulation
|
* Add a RigidBody to the simulation
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue