From 0066ef9b5491604a34a3fb69d27cbc8e61dab421 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 22 May 2012 21:40:24 -0400 Subject: [PATCH 01/11] Some cleanup --- apps/openmw/mwworld/physicssystem.cpp | 40 ++++++--------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 808c712a07..33024cfdee 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -140,8 +140,6 @@ namespace MWWorld iter!=actors.end(); ++iter) { OEngine::Physic::PhysicActor* act = mEngine->getCharacter(iter->first); - //if(iter->first == "player") - // std::cout << "This is player\n"; //dirty stuff to get the camera orientation. Must be changed! Ogre::SceneNode *sceneNode = mRender.getScene()->getSceneNode (iter->first); @@ -151,46 +149,28 @@ namespace MWWorld Ogre::Quaternion yawQuat = yawNode->getOrientation(); Ogre::Quaternion pitchQuat = pitchNode->getOrientation(); - // unused - //Ogre::Quaternion both = yawQuat * pitchQuat; + playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); - playerphysics->ps.viewangles.z = 0; + playerphysics->ps.viewangles.y = yawQuat.getYaw().valueDegrees() *-1 + 90; - if(mFreeFly) - { - Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); - - pm_ref.rightmove = -dir1.x; - pm_ref.forwardmove = dir1.z; - pm_ref.upmove = dir1.y; - - - //std::cout << "Current angle" << yawQuat.getYaw().valueDegrees() - 90<< "\n"; - //playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); - //std::cout << "Pitch: " << yawQuat.getPitch() << "Yaw:" << yawQuat.getYaw() << "Roll: " << yawQuat.getRoll() << "\n"; - dir = 0.07*(yawQuat*pitchQuat*dir1); - } - else - { Ogre::Quaternion quat = yawNode->getOrientation(); Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); - pm_ref.rightmove = -dir1.x; - pm_ref.forwardmove = dir1.z; - pm_ref.upmove = dir1.y; + pm_ref.rightmove = -iter->second.x; + pm_ref.forwardmove = -iter->second.y; + pm_ref.upmove = iter->second.z; - dir = 0.025*(quat*dir1); } - //set the walk direction - act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y)); - } + + + mEngine->stepSimulation(dt); } @@ -208,10 +188,6 @@ namespace MWWorld if(it->first == "player"){ coord = playerphysics->ps.origin; - //std::cout << "ZCoord: " << coord.z << "\n"; - //std::cout << "Coord" << coord << "\n"; - //coord = Ogre::Vector3(coord.x, coord.z, coord.y); //x, z, -y - } From fb4e7f02b9c7305d0d6140b193fd0c21b152ed8b Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 29 May 2012 22:03:00 -0400 Subject: [PATCH 02/11] code correction --- apps/openmw/mwclass/npc.cpp | 6 +++--- libs/openengine/bullet/pmove.cpp | 8 +++++--- libs/openengine/bullet/pmove.h | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index e7f6cc5270..b1d61a4ede 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -119,7 +119,7 @@ namespace MWClass void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { - + ESMS::LiveCellRef *ref = ptr.get(); @@ -128,12 +128,12 @@ namespace MWClass std::string headID = ref->base->head; std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; - + std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; - physics.insertActorPhysics(ptr, smodel); + physics.insertObjectPhysics(ptr, smodel); } diff --git a/libs/openengine/bullet/pmove.cpp b/libs/openengine/bullet/pmove.cpp index 591f1869f8..cdeb557baa 100644 --- a/libs/openengine/bullet/pmove.cpp +++ b/libs/openengine/bullet/pmove.cpp @@ -232,7 +232,7 @@ bool PM_SlideMove( bool gravity ) end = pm->ps.origin + pm->ps.velocity * time_left; // see if we can make it there - //pm->trace ( &trace, pm->ps->origin, pm->mins, pm->maxs, end, pm->ps->clientNum, pm->tracemask); + //pm->trace ( &trace, pm->ps->origin, pm->mins, pm->maxs, end, pm->ps->clientNum, pm->tracemaskg); //tracefunc(&trace, *(const D3DXVECTOR3* const)&(pm->ps.origin), *(const D3DXVECTOR3* const)&(end), *(const D3DXVECTOR3* const)&(pm->ps.velocity), 0, pml.traceObj); newtrace(&trace, pm->ps.origin, end, halfExtents, Ogre::Math::DegreesToRadians (pm->ps.viewangles.y), pm->isInterior, pm->mEngine); @@ -277,7 +277,7 @@ bool PM_SlideMove( bool gravity ) { // pm->ps->velocity += (trace.plane.normal + pm->ps->velocity) //VectorAdd( trace.plane.normal, pm->ps->velocity, pm->ps->velocity ); - pm->ps.velocity = (trace.planenormal + pm->ps.velocity); + pm->ps.velocity = trace.planenormal + pm->ps.velocity; break; } } @@ -330,7 +330,7 @@ bool PM_SlideMove( bool gravity ) if (clipVelocity.dotProduct(planes[i]) >= 0) //if ( DotProduct( clipVelocity, planes[i] ) >= 0 ) continue; - + // slide the original velocity along the crease //dProduct (planes[i], planes[j], dir); @@ -363,6 +363,7 @@ bool PM_SlideMove( bool gravity ) // see if there is a third plane the the new move enters for ( k = 0 ; k < numplanes ; k++ ) { + if ( k == i || k == j ) continue; @@ -1460,6 +1461,7 @@ static void PM_GroundTrace( void ) // slopes that are too steep will not be considered onground //if ( trace.plane.normal[2] < MIN_WALK_NORMAL ) + //std::cout << "MinWalkNormal" << trace.planenormal.z; if (trace.planenormal.z < MIN_WALK_NORMAL) { //if ( pm->debugLevel ) diff --git a/libs/openengine/bullet/pmove.h b/libs/openengine/bullet/pmove.h index e46eb9d2e7..6e67db711b 100644 --- a/libs/openengine/bullet/pmove.h +++ b/libs/openengine/bullet/pmove.h @@ -41,7 +41,7 @@ static const Ogre::Vector3 halfExtents(14.64f * 2, 14.24f * 2, 33.25f * 2); #define MAX_GENTITIES (1 << GENTITYNUM_BITS) #define ENTITYNUM_NONE (MAX_GENTITIES - 1) #define ENTITYNUM_WORLD (MAX_GENTITIES - 2) -#define MIN_WALK_NORMAL 0.7f // can't walk on very steep slopes +#define MIN_WALK_NORMAL .7f // can't walk on very steep slopes #define JUMP_VELOCITY (270) #define PS_PMOVEFRAMECOUNTBITS 6 #define MINS_Z -24 @@ -90,7 +90,7 @@ struct playerMove { struct playerStruct { - playerStruct() : gravity(800.0f), speed(480.0f), pmove_framecount(20), groundEntityNum(ENTITYNUM_NONE), commandTime(40), move_type(PM_NOCLIP), pm_time(0), snappingImplemented(true), bSnap(false), counter(-1) + playerStruct() : gravity(800.0f), speed(500.0f), pmove_framecount(20), groundEntityNum(ENTITYNUM_NONE), commandTime(40), move_type(PM_NOCLIP), pm_time(0), snappingImplemented(true), bSnap(false), counter(-1) { origin = Ogre::Vector3(733.164f,900.0f, 839.432f); velocity = Ogre::Vector3(0.0f, 0.0f, 0.0f); From d081f7ea83d55f1941f3bc953a0c44457afc5f6f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 31 May 2012 20:13:40 -0400 Subject: [PATCH 03/11] Don't run up walls --- libs/openengine/bullet/pmove.cpp | 15 ++++++++++++++- libs/openengine/bullet/pmove.h | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libs/openengine/bullet/pmove.cpp b/libs/openengine/bullet/pmove.cpp index cdeb557baa..1fc394259b 100644 --- a/libs/openengine/bullet/pmove.cpp +++ b/libs/openengine/bullet/pmove.cpp @@ -301,6 +301,12 @@ bool PM_SlideMove( bool gravity ) if ( into >= 0.1 ) continue; // move doesn't interact with the plane + std::cout << "Second plane" << planes[i] << "\n"; + if(planes[i].x >= .70) + { + pm->ps.velocity = Ogre::Vector3(0,0,0); + return true; + } // see how hard we are hitting things if ( -into > pml.impactSpeed ) pml.impactSpeed = -into; @@ -321,6 +327,13 @@ bool PM_SlideMove( bool gravity ) if (clipVelocity.dotProduct(planes[j]) >= 0.1) //if ( DotProduct( clipVelocity, planes[j] ) >= 0.1 ) continue; // move doesn't interact with the plane + + + + + //pm->ps.velocity = Ogre::Vector3(0,0,0); + //return true; + // try clipping the move to the plane PM_ClipVelocity( clipVelocity, planes[j], clipVelocity, OVERCLIP ); @@ -330,8 +343,8 @@ bool PM_SlideMove( bool gravity ) if (clipVelocity.dotProduct(planes[i]) >= 0) //if ( DotProduct( clipVelocity, planes[i] ) >= 0 ) continue; + - // slide the original velocity along the crease //dProduct (planes[i], planes[j], dir); dir = planes[i].crossProduct(planes[j]) ; diff --git a/libs/openengine/bullet/pmove.h b/libs/openengine/bullet/pmove.h index 6e67db711b..d48bd36377 100644 --- a/libs/openengine/bullet/pmove.h +++ b/libs/openengine/bullet/pmove.h @@ -90,7 +90,7 @@ struct playerMove { struct playerStruct { - playerStruct() : gravity(800.0f), speed(500.0f), pmove_framecount(20), groundEntityNum(ENTITYNUM_NONE), commandTime(40), move_type(PM_NOCLIP), pm_time(0), snappingImplemented(true), bSnap(false), counter(-1) + playerStruct() : gravity(800.0f), speed(2000.0f), pmove_framecount(20), groundEntityNum(ENTITYNUM_NONE), commandTime(40), move_type(PM_NOCLIP), pm_time(0), snappingImplemented(true), bSnap(false), counter(-1) { origin = Ogre::Vector3(733.164f,900.0f, 839.432f); velocity = Ogre::Vector3(0.0f, 0.0f, 0.0f); From 4ff36a9018834f35fa034594d76d47bfc86d2ea1 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 6 Jun 2012 16:29:44 -0400 Subject: [PATCH 04/11] Bullet loader trafos changed to match NIFLoader --- components/nifbullet/bullet_nif_loader.cpp | 97 +++++++++++++++++----- components/nifbullet/bullet_nif_loader.hpp | 8 +- 2 files changed, 82 insertions(+), 23 deletions(-) diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 30cb4562d0..153c529345 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -1,4 +1,4 @@ -/* + /* OpenMW - The completely unofficial reimplementation of Morrowind Copyright (C) 2008-2010 Nicolay Korslund Email: < korslund@gmail.com > @@ -51,19 +51,64 @@ using namespace Mangle::VFS; using namespace NifBullet; +// Helper math functions. Reinventing linear algebra for the win! + +// Computes B = AxB (matrix*matrix) +static void matrixMul(const Matrix &A, Matrix &B) +{ + for (int i=0;i<3;i++) + { + float a = B.v[0].array[i]; + float b = B.v[1].array[i]; + float c = B.v[2].array[i]; + + B.v[0].array[i] = a*A.v[0].array[0] + b*A.v[0].array[1] + c*A.v[0].array[2]; + B.v[1].array[i] = a*A.v[1].array[0] + b*A.v[1].array[1] + c*A.v[1].array[2]; + B.v[2].array[i] = a*A.v[2].array[0] + b*A.v[2].array[1] + c*A.v[2].array[2]; + } +} + +// Computes C = B + AxC*scale +static void vectorMulAdd(const Matrix &A, const Vector &B, float *C, float scale) +{ + // Keep the original values + float a = C[0]; + float b = C[1]; + float c = C[2]; + + // Perform matrix multiplication, scaling and addition + for (int i=0;i<3;i++) + C[i] = B.array[i] + (a*A.v[i].array[0] + b*A.v[i].array[1] + c*A.v[i].array[2])*scale; +} + +// Computes B = AxB (matrix*vector) +static void vectorMul(const Matrix &A, float *C) +{ + // Keep the original values + float a = C[0]; + float b = C[1]; + float c = C[2]; + + // Perform matrix multiplication, scaling and addition + for (int i=0;i<3;i++) + C[i] = a*A.v[i].array[0] + b*A.v[i].array[1] + c*A.v[i].array[2]; +} + + ManualBulletShapeLoader::~ManualBulletShapeLoader() { delete vfs; } -Ogre::Matrix3 ManualBulletShapeLoader::getMatrix(Nif::Transformation* tr) + +Ogre::Matrix3 ManualBulletShapeLoader::getMatrix(const Nif::Transformation* tr) { Ogre::Matrix3 rot(tr->rotation.v[0].array[0],tr->rotation.v[0].array[1],tr->rotation.v[0].array[2], tr->rotation.v[1].array[0],tr->rotation.v[1].array[1],tr->rotation.v[1].array[2], tr->rotation.v[2].array[0],tr->rotation.v[2].array[1],tr->rotation.v[2].array[2]); return rot; } -Ogre::Vector3 ManualBulletShapeLoader::getVector(Nif::Transformation* tr) +Ogre::Vector3 ManualBulletShapeLoader::getVector(const Nif::Transformation* tr) { Ogre::Vector3 vect3(tr->pos.array[0],tr->pos.array[1],tr->pos.array[2]); return vect3; @@ -88,6 +133,7 @@ btVector3 ManualBulletShapeLoader::getbtVector(Nif::Vector v) void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) { + std::cout << "Beginning physics\n"; cShape = static_cast(resource); resourceName = cShape->getName(); cShape->collide = false; @@ -131,12 +177,12 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) bool hasCollisionNode = hasRootCollisionNode(node); //do a first pass - handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,false); + handleNode(node,0,NULL,hasCollisionNode,false,false); //if collide = false, then it does a second pass which create a shape for raycasting. if(cShape->collide == false) { - handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,true); + handleNode(node,0,NULL,hasCollisionNode,false,true); } cShape->collide = hasCollisionNode&&cShape->collide; @@ -157,6 +203,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) currentShape = new TriangleMeshShape(mTriMesh,true); cShape->Shape = currentShape; + std::cout << "End bullet physics\n"; } bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node) @@ -186,8 +233,9 @@ bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node) } void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, - Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly) + const Nif::Transformation *trafo,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly) { + std::cout << "Handle Node\n"; // Accumulate the flags from all the child nodes. This works for all // the flags we currently use, at least. flags |= node->flags; @@ -221,19 +269,30 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, } } - //transfo of parents node + curent node - Ogre::Matrix3 finalRot; - Ogre::Vector3 finalPos; - float finalScale; + + + if (trafo) + { + std::cout << "Before trafo\n"; + // Get a non-const reference to the node's data, since we're + // overwriting it. TODO: Is this necessary? + Transformation &final = *((Transformation*)node->trafo); - Nif::Transformation &final = *((Nif::Transformation*)node->trafo); - Ogre::Vector3 nodePos = getVector(&final); - Ogre::Matrix3 nodeRot = getMatrix(&final); + // For both position and rotation we have that: + // final_vector = old_vector + old_rotation*new_vector*old_scale + vectorMulAdd(trafo->rotation, trafo->pos, final.pos.array, trafo->scale); + vectorMulAdd(trafo->rotation, trafo->velocity, final.velocity.array, trafo->scale); - finalPos = nodePos + parentPos; - finalRot = parentRot*nodeRot; - finalScale = final.scale*parentScale; + // Merge the rotations together + matrixMul(trafo->rotation, final.rotation); + // Scalar values are so nice to deal with. Why can't everything + // just be scalar? + final.scale *= trafo->scale; + std::cout << "After Trafo\n"; + } + + std::cout << "After Trafo2\n"; // For NiNodes, loop through children if (node->recType == Nif::RC_NiNode) @@ -244,14 +303,14 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, { if (list.has(i)) { - handleNode(&list[i], flags,finalRot,finalPos,finalScale,hasCollisionNode,isCollisionNode,raycastingOnly); + handleNode(&list[i], flags,node->trafo,hasCollisionNode,isCollisionNode,raycastingOnly); } } } else if (node->recType == Nif::RC_NiTriShape && (isCollisionNode || !hasCollisionNode)) { cShape->collide = true; - handleNiTriShape(dynamic_cast(node), flags,finalRot,finalPos,parentScale,raycastingOnly); + handleNiTriShape(dynamic_cast(node), flags,getMatrix(node->trafo),getVector(node->trafo),node->trafo->scale,raycastingOnly); } else if(node->recType == Nif::RC_RootCollisionNode) { @@ -260,7 +319,7 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, for (int i=0; itrafo, hasCollisionNode,true,raycastingOnly); } } } diff --git a/components/nifbullet/bullet_nif_loader.hpp b/components/nifbullet/bullet_nif_loader.hpp index ed3aceac46..488a7a42b0 100644 --- a/components/nifbullet/bullet_nif_loader.hpp +++ b/components/nifbullet/bullet_nif_loader.hpp @@ -95,9 +95,9 @@ public: void load(const std::string &name,const std::string &group); private: - Ogre::Matrix3 getMatrix(Nif::Transformation* tr); + Ogre::Matrix3 getMatrix(const Nif::Transformation* tr); - Ogre::Vector3 getVector(Nif::Transformation* tr); + Ogre::Vector3 getVector(const Nif::Transformation* tr); btQuaternion getbtQuat(Ogre::Matrix3 m); @@ -107,10 +107,10 @@ private: *Parse a node. */ void handleNode(Nif::Node *node, int flags, - Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly); + const Nif::Transformation *trafo, bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly); /** - *Helpler function + *Helper function */ bool hasRootCollisionNode(Nif::Node* node); From fb0a52809dd1da3ef953728be2200a633bb383bf Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 9 Jun 2012 15:19:15 -0400 Subject: [PATCH 05/11] Changing transformation processing --- apps/openmw/mwclass/npc.cpp | 2 +- components/nifbullet/bullet_nif_loader.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index b1d61a4ede..0a1a750f79 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -133,7 +133,7 @@ namespace MWClass std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; - physics.insertObjectPhysics(ptr, smodel); + physics.insertActorPhysics(ptr, smodel); } diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 153c529345..e87d5624e9 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -185,7 +185,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) handleNode(node,0,NULL,hasCollisionNode,false,true); } - cShape->collide = hasCollisionNode&&cShape->collide; + //cShape->collide = hasCollisionNode&&cShape->collide; struct TriangleMeshShape : public btBvhTriangleMeshShape { @@ -353,15 +353,17 @@ void ManualBulletShapeLoader::handleNiTriShape(Nif::NiTriShape *shape, int flags float* vertices = (float*)data->vertices.ptr; unsigned short* triangles = (unsigned short*)data->triangles.ptr; - + const Matrix &rot = shape->trafo->rotation; + const Vector &pos = shape->trafo->pos; + float scale = shape->trafo->scale; for(unsigned int i=0; i < data->triangles.length; i = i+3) { Ogre::Vector3 b1(vertices[triangles[i+0]*3]*parentScale,vertices[triangles[i+0]*3+1]*parentScale,vertices[triangles[i+0]*3+2]*parentScale); Ogre::Vector3 b2(vertices[triangles[i+1]*3]*parentScale,vertices[triangles[i+1]*3+1]*parentScale,vertices[triangles[i+1]*3+2]*parentScale); Ogre::Vector3 b3(vertices[triangles[i+2]*3]*parentScale,vertices[triangles[i+2]*3+1]*parentScale,vertices[triangles[i+2]*3+2]*parentScale); - b1 = parentRot * b1 + parentPos; - b2 = parentRot * b2 + parentPos; - b3 = parentRot * b3 + parentPos; + vectorMulAdd(rot, pos, b1.ptr(), scale); + vectorMulAdd(rot, pos, b2.ptr(), scale); + vectorMulAdd(rot, pos, b3.ptr(), scale); mTriMesh->addTriangle(btVector3(b1.x,b1.y,b1.z),btVector3(b2.x,b2.y,b2.z),btVector3(b3.x,b3.y,b3.z)); } } From 595b0729da99bf9a9d2d06f2a28eedbcacb9832e Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 10 Jun 2012 21:08:58 -0400 Subject: [PATCH 06/11] Few things changed --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- components/nifbullet/bullet_nif_loader.cpp | 9 +++------ libs/openengine/bullet/pmove.cpp | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 653fabd089..150cb40922 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -85,7 +85,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertActorPhysics(ptr, "meshes\\" + model); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 0a1a750f79..656e6d4447 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -133,7 +133,7 @@ namespace MWClass std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; - physics.insertActorPhysics(ptr, smodel); + //physics.insertObjectPhysics(ptr, smodel); } diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index e87d5624e9..17c5f18aca 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -133,7 +133,6 @@ btVector3 ManualBulletShapeLoader::getbtVector(Nif::Vector v) void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) { - std::cout << "Beginning physics\n"; cShape = static_cast(resource); resourceName = cShape->getName(); cShape->collide = false; @@ -203,7 +202,6 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) currentShape = new TriangleMeshShape(mTriMesh,true); cShape->Shape = currentShape; - std::cout << "End bullet physics\n"; } bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node) @@ -235,7 +233,7 @@ bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node) void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, const Nif::Transformation *trafo,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly) { - std::cout << "Handle Node\n"; + // Accumulate the flags from all the child nodes. This works for all // the flags we currently use, at least. flags |= node->flags; @@ -273,7 +271,7 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, if (trafo) { - std::cout << "Before trafo\n"; + // Get a non-const reference to the node's data, since we're // overwriting it. TODO: Is this necessary? Transformation &final = *((Transformation*)node->trafo); @@ -289,10 +287,9 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, // Scalar values are so nice to deal with. Why can't everything // just be scalar? final.scale *= trafo->scale; - std::cout << "After Trafo\n"; + } - std::cout << "After Trafo2\n"; // For NiNodes, loop through children if (node->recType == Nif::RC_NiNode) diff --git a/libs/openengine/bullet/pmove.cpp b/libs/openengine/bullet/pmove.cpp index 1fc394259b..ae160365b3 100644 --- a/libs/openengine/bullet/pmove.cpp +++ b/libs/openengine/bullet/pmove.cpp @@ -301,7 +301,7 @@ bool PM_SlideMove( bool gravity ) if ( into >= 0.1 ) continue; // move doesn't interact with the plane - std::cout << "Second plane" << planes[i] << "\n"; + if(planes[i].x >= .70) { pm->ps.velocity = Ogre::Vector3(0,0,0); From b14c132a31bc9b8f410647b502a570b92b5c6608 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 11 Jun 2012 13:25:06 -0400 Subject: [PATCH 07/11] Merging in the latest master --- apps/openmw/mwgui/settingswindow.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index ce95edbd2e..e3827c7b03 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -16,10 +16,10 @@ namespace MWGui SettingsWindow(WindowManager& parWindowManager); private: - static const float sFovMin = 30; - static const float sFovMax = 140; - static const float sViewDistMin = 2000; - static const float sViewDistMax = 5600; + static int const sFovMin = 30; + static int const sFovMax = 140; + static int const sViewDistMin = 2000; + static int const sViewDistMax = 5600; protected: MyGUI::Button* mOkButton; From 10810ee3115c2414500bb914c07f533a57dcd6fb Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 11 Jun 2012 19:55:10 -0400 Subject: [PATCH 08/11] Outputting formatted string with scale --- libs/openengine/bullet/physic.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index a94434e5b5..c33d106cd8 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -324,11 +324,18 @@ namespace Physic RigidBody* PhysicEngine::createRigidBody(std::string mesh,std::string name,float scale) { + char uniqueID[4]; + sprintf( uniqueID, "%1.2f", scale ); + std::string sid = uniqueID; + std::string outputstring = mesh + sid + ">|"; + std::cout << outputstring << "\n"; + //get the shape from the .nif mShapeLoader->load(mesh,"General"); BulletShapeManager::getSingletonPtr()->load(mesh,"General"); BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(mesh,"General"); shape->Shape->setLocalScaling(btVector3(scale,scale,scale)); + //create the motionState CMotionState* newMotionState = new CMotionState(this,name); From 5028f9926d6724f6b89aee5eb9fd330554f6d2c8 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 12 Jun 2012 18:09:58 -0400 Subject: [PATCH 09/11] Bullet scale solution --- components/nifogre/ogre_nif_loader.cpp | 2 +- libs/openengine/bullet/physic.cpp | 7 +++---- libs/openengine/bullet/pmove.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 331701c2a4..669ef584fa 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1294,7 +1294,7 @@ void NIFLoader::loadResource(Resource *resource) // Look it up resourceName = mesh->getName(); - //std::cout << resourceName << "\n"; + if (!vfs->isFile(resourceName)) { diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index c33d106cd8..0cacd67a84 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -328,12 +328,11 @@ namespace Physic sprintf( uniqueID, "%1.2f", scale ); std::string sid = uniqueID; std::string outputstring = mesh + sid + ">|"; - std::cout << outputstring << "\n"; //get the shape from the .nif - mShapeLoader->load(mesh,"General"); - BulletShapeManager::getSingletonPtr()->load(mesh,"General"); - BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(mesh,"General"); + mShapeLoader->load(outputstring,"General"); + BulletShapeManager::getSingletonPtr()->load(outputstring,"General"); + BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General"); shape->Shape->setLocalScaling(btVector3(scale,scale,scale)); diff --git a/libs/openengine/bullet/pmove.h b/libs/openengine/bullet/pmove.h index d48bd36377..f368f05f64 100644 --- a/libs/openengine/bullet/pmove.h +++ b/libs/openengine/bullet/pmove.h @@ -90,7 +90,7 @@ struct playerMove { struct playerStruct { - playerStruct() : gravity(800.0f), speed(2000.0f), pmove_framecount(20), groundEntityNum(ENTITYNUM_NONE), commandTime(40), move_type(PM_NOCLIP), pm_time(0), snappingImplemented(true), bSnap(false), counter(-1) + playerStruct() : gravity(800.0f), speed(480.0f), pmove_framecount(20), groundEntityNum(ENTITYNUM_NONE), commandTime(40), move_type(PM_NOCLIP), pm_time(0), snappingImplemented(true), bSnap(false), counter(-1) { origin = Ogre::Vector3(733.164f,900.0f, 839.432f); velocity = Ogre::Vector3(0.0f, 0.0f, 0.0f); From 897a331244443f03a21fc0ca45c6788f48cc18c5 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 13 Jun 2012 12:21:51 -0400 Subject: [PATCH 10/11] NPC activation --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 86fd1fe23d..e33fd322a7 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -84,7 +84,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); + physics.insertActorPhysics(ptr, "meshes\\" + model); } MWBase::Environment::get().getMechanicsManager()->addActor (ptr); diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index a3c20840af..8062dc35ee 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -130,7 +130,7 @@ namespace MWClass std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; - + physics.insertActorPhysics(ptr, smodel); MWBase::Environment::get().getMechanicsManager()->addActor (ptr); From c4c8288af8d51f01f22df3813a6b01b8f0e76a14 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 13 Jun 2012 19:34:13 -0400 Subject: [PATCH 11/11] Seven digit scales --- components/bsa/bsa_archive.cpp | 36 ++++++++++++++++++------------- libs/openengine/bullet/physic.cpp | 7 +++--- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index d3b75d4ae4..e9ce3f6150 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -73,14 +73,16 @@ class DirArchive: public Ogre::FileSystemArchive { { String passed = filename; - if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' + if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') + passed = filename.substr(0, filename.length() - 6); + else if(filename.at(filename.length() - 2) == '"') + passed = filename.substr(0, filename.length() - 9); + else if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' || filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':' || filename.at(filename.length() - 1) == '|') - { passed = filename.substr(0, filename.length() - 2); - } - if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') - passed = filename.substr(0, filename.length() - 6); + + copy = passed; } @@ -226,14 +228,16 @@ public: BSAFile *narc = (BSAFile*)&arc; String passed = filename; - if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' + if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') + passed = filename.substr(0, filename.length() - 6); + else if(filename.at(filename.length() - 2) == '"') + passed = filename.substr(0, filename.length() - 9); + else if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' || filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':' || filename.at(filename.length() - 1) == '|') - { passed = filename.substr(0, filename.length() - 2); - } - if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') - passed = filename.substr(0, filename.length() - 6); + + // Open the file StreamPtr strm = narc->getFile(passed.c_str()); @@ -248,14 +252,16 @@ bool exists(const String& filename) { // Check if the file exists. bool cexists(const String& filename) const { String passed = filename; - if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' + if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') + passed = filename.substr(0, filename.length() - 6); + else if(filename.at(filename.length() - 2) == '"') + passed = filename.substr(0, filename.length() - 9); + else if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' || filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':' || filename.at(filename.length() - 1) == '|') - { passed = filename.substr(0, filename.length() - 2); - } - if(filename.at(filename.length() - 2) == '>' || filename.at(filename.length() - 2) == ':') - passed = filename.substr(0, filename.length() - 6); + + return arc.exists(passed.c_str()); } diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 0cacd67a84..d075536d2b 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -324,10 +324,11 @@ namespace Physic RigidBody* PhysicEngine::createRigidBody(std::string mesh,std::string name,float scale) { - char uniqueID[4]; - sprintf( uniqueID, "%1.2f", scale ); + char uniqueID[8]; + sprintf( uniqueID, "%07.3f", scale ); std::string sid = uniqueID; - std::string outputstring = mesh + sid + ">|"; + std::string outputstring = mesh + uniqueID + "\"|"; + //std::cout << "The string" << outputstring << "\n"; //get the shape from the .nif mShapeLoader->load(outputstring,"General");