From ca9224ed7f8813b2eb9bd4cd70e641308c2d4685 Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 21 May 2012 10:58:04 +0200 Subject: [PATCH 01/33] starting scale function --- apps/openmw/mwworld/class.cpp | 5 +++++ apps/openmw/mwworld/class.hpp | 2 ++ apps/openmw/mwworld/world.cpp | 5 +++++ apps/openmw/mwworld/world.hpp | 2 ++ 4 files changed, 14 insertions(+) diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 5fb503847..f1c50c29a 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -196,4 +196,9 @@ namespace MWWorld { return ""; } + + void adjustScale(float& x, float& y, float& z) + { + } + } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 513dc942b..0fc12bfe2 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -193,6 +193,8 @@ namespace MWWorld virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string /// (default implementation: return empty string) + + virtual void adjustScale(float& x, float& y, float& z); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index eeda92277..fbbeef154 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -611,6 +611,11 @@ namespace MWWorld mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z)); } + void World::scaleObject (Ptr ptr, float x, float y, float z) + { + MWWorld::Class::get(ptr).adjustScale(x,y,z); + } + void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const { const int cellSize = 8192; diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 49a3cf029..cb849cc1b 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -222,6 +222,8 @@ namespace MWWorld void moveObject (Ptr ptr, float x, float y, float z); + void scaleObject (Ptr ptr, float x, float y, float z); + void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const; ///< Convert cell numbers to position. From 0066ef9b5491604a34a3fb69d27cbc8e61dab421 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 22 May 2012 21:40:24 -0400 Subject: [PATCH 02/33] 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 808c712a0..33024cfde 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 51b6d5cae055a6e24fc16f706b2246950052e55b Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 25 May 2012 18:23:06 +0200 Subject: [PATCH 03/33] Scale *should* work. (no script instruction yet) --- apps/openmw/mwworld/class.cpp | 5 ++++- apps/openmw/mwworld/class.hpp | 4 +++- apps/openmw/mwworld/world.cpp | 16 ++++++++++++++-- apps/openmw/mwworld/world.hpp | 4 +++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 6a6765253..4064a451a 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -203,8 +203,11 @@ namespace MWWorld return ""; } - void adjustScale(float& x, float& y, float& z) + void Class::adjustScale(const MWWorld::Ptr& ptr,float& scale) const { } + void Class::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const + { + } } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 0ed0b0e0d..a8639daa9 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -197,7 +197,9 @@ namespace MWWorld ///< @return the enchantment ID if the object is enchanted, otherwise an empty string /// (default implementation: return empty string) - virtual void adjustScale(float& x, float& y, float& z); + virtual void adjustScale(const MWWorld::Ptr& ptr,float& scale) const; + + virtual void adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const; }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index c2926c1a3..6be4a13ba 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -611,9 +611,21 @@ namespace MWWorld mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z)); } - void World::scaleObject (Ptr ptr, float x, float y, float z) + void World::scaleObject (Ptr ptr, float scale) + { + MWWorld::Class::get(ptr).adjustScale(ptr,scale); + + ptr.getCellRef().scale = scale; + scale = scale/ptr.getRefData().getBaseNode()->getScale().x; + ptr.getRefData().getBaseNode()->setScale(scale,scale,scale); + mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale ); + /// \todo cell change for non-player ref + + //mRendering->moveObject (ptr, Ogre::Vector3 (x, y, z)); + } + + void World::rotateObject (Ptr ptr,float x,float y,float z) { - MWWorld::Class::get(ptr).adjustScale(x,y,z); } void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index cc6a665fc..e684ca39e 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -222,7 +222,9 @@ namespace MWWorld void moveObject (Ptr ptr, float x, float y, float z); - void scaleObject (Ptr ptr, float x, float y, float z); + void scaleObject (Ptr ptr, float scale); + + void rotateObject (Ptr ptr,float x,float y,float z); void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const; ///< Convert cell numbers to position. From 77084b27c07b5948717638d6a8c4f8d93bca9259 Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 28 May 2012 16:01:35 +0200 Subject: [PATCH 04/33] some work for rotation/scaling --- apps/openmw/mwscript/statsextensions.cpp | 16 ++++++++++++++++ apps/openmw/mwworld/world.cpp | 10 +++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index d23519281..6e9b1e583 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -500,6 +500,22 @@ namespace MWScript } }; + template + class OpSetScale : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + Interpreter::Type_Float scale = runtime[0].mInteger; + runtime.pop(); + + MWBase::Environment::get().getWorld()->scaleObject(ptr,scale); + } + }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 6be4a13ba..2a3332593 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -619,13 +619,17 @@ namespace MWWorld scale = scale/ptr.getRefData().getBaseNode()->getScale().x; ptr.getRefData().getBaseNode()->setScale(scale,scale,scale); mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale ); - /// \todo cell change for non-player ref - - //mRendering->moveObject (ptr, Ogre::Vector3 (x, y, z)); } void World::rotateObject (Ptr ptr,float x,float y,float z) { + MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); + + ptr.getRefData().getPosition().rot[0] = x; + ptr.getRefData().getPosition().rot[0] = y; + ptr.getRefData().getPosition().rot[0] = z; + //ptr.getRefData().getBaseNode()->rotate(ptr.getRefData().getBaseNode()->get + //mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale ); } void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const From 26d6c9453c3d1d80936189cce56a7eb38a148946 Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 29 May 2012 10:15:29 +0200 Subject: [PATCH 05/33] more work on rotation --- apps/openmw/mwworld/world.cpp | 44 ++++++++++++++++++++++++++++++++--- apps/openmw/mwworld/world.hpp | 4 +++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 2a3332593..116710a1e 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -621,17 +621,55 @@ namespace MWWorld mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale ); } - void World::rotateObject (Ptr ptr,float x,float y,float z) + void World::rotateObject (Ptr ptr,float x,float y,float z,bool WorldAxis) { MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); - ptr.getRefData().getPosition().rot[0] = x; + /*ptr.getRefData().getPosition().rot[0] = x; ptr.getRefData().getPosition().rot[0] = y; - ptr.getRefData().getPosition().rot[0] = z; + ptr.getRefData().getPosition().rot[0] = z;*/ + if(WorldAxis) + { + ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(x)); + ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(y)); + ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(z)); + } + else + { + Ogre::Matrix3 axis = ptr.getRefData().getBaseNode()->getLocalAxes(); + Ogre::Vector3 xAxis = axis.GetColumn(0); + Ogre::Vector3 yAxis = axis.GetColumn(1); + Ogre::Vector3 zAxis = axis.GetColumn(2); + ptr.getRefData().getBaseNode()->rotate(xAxis,Ogre::Degree(x)); + ptr.getRefData().getBaseNode()->rotate(yAxis,Ogre::Degree(y)); + ptr.getRefData().getBaseNode()->rotate(zAxis,Ogre::Degree(z)); + } + Ogre::Matrix3 rot; + ptr.getRefData().getBaseNode()->getOrientation().ToRotationMatrix(rot); + Ogre::Radian rx,ry,rz; + rot.ToEulerAnglesXYZ(rx,ry,rz); + + ptr.getRefData().getPosition().rot[0] = rx.valueRadians(); + ptr.getRefData().getPosition().rot[0] = ry.valueRadians(); + ptr.getRefData().getPosition().rot[0] = rz.valueRadians(); //ptr.getRefData().getBaseNode()->rotate(ptr.getRefData().getBaseNode()->get //mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale ); } + void setObjectRotation (Ptr ptr,float x,float y,float z) + { + MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); + + ptr.getRefData().getPosition().rot[0] = Ogre::Degree(x).valueRadians(); + ptr.getRefData().getPosition().rot[0] = Ogre::Degree(y).valueRadians(); + ptr.getRefData().getPosition().rot[0] = Ogre::Degree(z).valueRadians(); + + Ogre::Quaternion rotx(Ogre::Degree(x),Ogre::Vector3::UNIT_X); + Ogre::Quaternion roty(Ogre::Degree(y),Ogre::Vector3::UNIT_Y); + Ogre::Quaternion rotz(Ogre::Degree(z),Ogre::Vector3::UNIT_Z); + ptr.getRefData().getBaseNode()->setOrientation(rotx*roty*rotz); + } + void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const { const int cellSize = 8192; diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index e684ca39e..6f810e976 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -224,7 +224,9 @@ namespace MWWorld void scaleObject (Ptr ptr, float scale); - void rotateObject (Ptr ptr,float x,float y,float z); + void rotateObject (Ptr ptr,float x,float y,float z,bool WorldAxis); + + void setObjectRotation (Ptr ptr,float x,float y,float z); void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const; ///< Convert cell numbers to position. From d8051095d669c552123f4662ea501c9cd021e6bd Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 29 May 2012 10:36:12 +0200 Subject: [PATCH 06/33] rotation are updated in the physis system --- apps/openmw/mwworld/physicssystem.cpp | 13 +++++++++++-- apps/openmw/mwworld/world.cpp | 8 ++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 808c712a0..c4e34a540 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -288,17 +288,26 @@ namespace MWWorld void PhysicsSystem::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation) { - if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) + if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) { // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow // start positions others than 0, 0, 0 act->setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)); } + if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) + { + body->setWorldTransform(btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w),body->getWorldTransform().getOrigin())); + } } void PhysicsSystem::scaleObject (const std::string& handle, float scale) { - + if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) + { + // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow + // start positions others than 0, 0, 0 + //body->setWorldTransform(btTransform().se + } } bool PhysicsSystem::toggleCollisionMode() diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 116710a1e..69da98096 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -625,9 +625,6 @@ namespace MWWorld { MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); - /*ptr.getRefData().getPosition().rot[0] = x; - ptr.getRefData().getPosition().rot[0] = y; - ptr.getRefData().getPosition().rot[0] = z;*/ if(WorldAxis) { ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(x)); @@ -652,11 +649,13 @@ namespace MWWorld ptr.getRefData().getPosition().rot[0] = rx.valueRadians(); ptr.getRefData().getPosition().rot[0] = ry.valueRadians(); ptr.getRefData().getPosition().rot[0] = rz.valueRadians(); + + mPhysics->rotateObject(Class::get(ptr).getId(ptr),ptr.getRefData().getBaseNode()->getOrientation()); //ptr.getRefData().getBaseNode()->rotate(ptr.getRefData().getBaseNode()->get //mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale ); } - void setObjectRotation (Ptr ptr,float x,float y,float z) + void World::setObjectRotation (Ptr ptr,float x,float y,float z) { MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); @@ -668,6 +667,7 @@ namespace MWWorld Ogre::Quaternion roty(Ogre::Degree(y),Ogre::Vector3::UNIT_Y); Ogre::Quaternion rotz(Ogre::Degree(z),Ogre::Vector3::UNIT_Z); ptr.getRefData().getBaseNode()->setOrientation(rotx*roty*rotz); + mPhysics->rotateObject(Class::get(ptr).getId(ptr),ptr.getRefData().getBaseNode()->getOrientation()); } void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const From f83ffecae5cf5433069f355f5d41b3c87386c845 Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 29 May 2012 15:57:13 +0200 Subject: [PATCH 07/33] SetAngle and SetScale script instruction --- apps/openmw/mwscript/docs/vmformat.txt | 4 ++- apps/openmw/mwscript/statsextensions.cpp | 38 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 0920c72f8..bb8f8a214 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -146,4 +146,6 @@ op 0x200014f: ForceGreeting op 0x2000150: ForceGreeting, explicit reference op 0x2000151: ToggleFullHelp op 0x2000152: Goodbye -opcodes 0x2000153-0x3ffffff unused +op 0x2000153: SetScale +op 0x2000154: SetAngle +opcodes 0x2000155-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 6e9b1e583..c68febec3 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -516,6 +516,35 @@ namespace MWScript } }; + template + class OpSetAngle : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + Interpreter::Type_Float angle = runtime[0].mInteger; + runtime.pop(); + + if(axis == "X") + { + MWBase::Environment::get().getWorld()->setObjectRotation(ptr,angle,0,0); + } + if(axis == "Y") + { + MWBase::Environment::get().getWorld()->setObjectRotation(ptr,0,angle,0); + } + if(axis == "Z") + { + MWBase::Environment::get().getWorld()->setObjectRotation(ptr,0,0,angle); + } + } + }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; @@ -562,6 +591,9 @@ namespace MWScript const int opcodeModDisposition = 0x200014d; const int opcodeModDispositionExplicit = 0x200014e; + const int opcodeSetScale = 0x2000153; + const int opcodeSetAngle = 0x2000154; + void registerExtensions (Compiler::Extensions& extensions) { static const char *attributes[numberOfAttributes] = @@ -644,6 +676,9 @@ namespace MWScript extensions.registerInstruction("moddisposition","l",opcodeModDisposition, opcodeModDispositionExplicit); extensions.registerFunction("getpcrank",'l',"/S",opcodeGetPCRank,opcodeGetPCRankExplicit); + + extensions.registerInstruction("setscale","/l",opcodeSetScale); + extensions.registerInstruction("setangle","/Sl",opcodeSetAngle); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -715,6 +750,9 @@ namespace MWScript interpreter.installSegment5(opcodeModDispositionExplicit,new OpModDisposition); interpreter.installSegment3(opcodeGetPCRank,new OpGetPCRank); interpreter.installSegment3(opcodeGetPCRankExplicit,new OpGetPCRank); + + interpreter.installSegment5(opcodeSetScale,new OpSetScale); + interpreter.installSegment5(opcodeSetAngle,new OpSetAngle); } } } From a711a3ebe1b67886a58b004ddc13e5bbfc446fa2 Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 29 May 2012 16:45:43 +0200 Subject: [PATCH 08/33] Various fixes --- apps/openmw/mwscript/docs/vmformat.txt | 4 +++- apps/openmw/mwscript/statsextensions.cpp | 10 +++++++--- apps/openmw/mwworld/physicssystem.cpp | 4 ---- apps/openmw/mwworld/world.cpp | 1 + libs/openengine/bullet/physic.cpp | 24 ++++++++++++++++++++---- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index bb8f8a214..86cf73117 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -147,5 +147,7 @@ op 0x2000150: ForceGreeting, explicit reference op 0x2000151: ToggleFullHelp op 0x2000152: Goodbye op 0x2000153: SetScale -op 0x2000154: SetAngle +op 0x2000154: SetScale, explicit reference +op 0x2000155: SetAngle +op 0x2000156: SetAngle, explicit reference opcodes 0x2000155-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index c68febec3..83bfacf40 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -592,7 +592,9 @@ namespace MWScript const int opcodeModDispositionExplicit = 0x200014e; const int opcodeSetScale = 0x2000153; - const int opcodeSetAngle = 0x2000154; + const int opcodeSetScaleExplicit = 0x2000154; + const int opcodeSetAngle = 0x2000155; + const int opcodeSetAngleExplicit = 0x2000156; void registerExtensions (Compiler::Extensions& extensions) { @@ -677,8 +679,8 @@ namespace MWScript opcodeModDispositionExplicit); extensions.registerFunction("getpcrank",'l',"/S",opcodeGetPCRank,opcodeGetPCRankExplicit); - extensions.registerInstruction("setscale","/l",opcodeSetScale); - extensions.registerInstruction("setangle","/Sl",opcodeSetAngle); + extensions.registerInstruction("setscale","l",opcodeSetScale,opcodeSetScaleExplicit); + extensions.registerInstruction("setangle","Sl",opcodeSetAngle,opcodeSetAngleExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -752,7 +754,9 @@ namespace MWScript interpreter.installSegment3(opcodeGetPCRankExplicit,new OpGetPCRank); interpreter.installSegment5(opcodeSetScale,new OpSetScale); + interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale); interpreter.installSegment5(opcodeSetAngle,new OpSetAngle); + interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle); } } } diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index c4e34a540..8ebdf2981 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -290,8 +290,6 @@ namespace MWWorld { if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) { - // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow - // start positions others than 0, 0, 0 act->setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)); } if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) @@ -304,8 +302,6 @@ namespace MWWorld { if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) { - // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow - // start positions others than 0, 0, 0 //body->setWorldTransform(btTransform().se } } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 69da98096..db96b6a19 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -668,6 +668,7 @@ namespace MWWorld Ogre::Quaternion rotz(Ogre::Degree(z),Ogre::Vector3::UNIT_Z); ptr.getRefData().getBaseNode()->setOrientation(rotx*roty*rotz); mPhysics->rotateObject(Class::get(ptr).getId(ptr),ptr.getRefData().getBaseNode()->getOrientation()); + std::cout << Class::get(ptr).getId(ptr); } void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index d30d5e9f1..4ead88994 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -392,8 +392,16 @@ namespace Physic RigidBody* PhysicEngine::getRigidBody(std::string name) { - RigidBody* body = RigidBodyMap[name]; - return body; + RigidBodyContainer::iterator it = RigidBodyMap.find(name); + if (it != RigidBodyMap.end() ) + { + RigidBody* body = RigidBodyMap[name]; + return body; + } + else + { + return 0; + } } void PhysicEngine::stepSimulation(double deltaT) @@ -450,8 +458,16 @@ namespace Physic PhysicActor* PhysicEngine::getCharacter(std::string name) { - PhysicActor* act = PhysicActorMap[name]; - return act; + PhysicActorContainer::iterator it = PhysicActorMap.find(name); + if (it != PhysicActorMap.end() ) + { + PhysicActor* act = PhysicActorMap[name]; + return act; + } + else + { + return 0; + } } void PhysicEngine::emptyEventLists(void) From fb4e7f02b9c7305d0d6140b193fd0c21b152ed8b Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 29 May 2012 22:03:00 -0400 Subject: [PATCH 09/33] 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 e7f6cc527..b1d61a4ed 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 591f1869f..cdeb557ba 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 e46eb9d2e..6e67db711 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 10/33] 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 cdeb557ba..1fc394259 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 6e67db711..d48bd3637 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 11/33] Bullet loader trafos changed to match NIFLoader --- components/nifbullet/bullet_nif_loader.cpp | 103 ++++++++++++++++----- components/nifbullet/bullet_nif_loader.hpp | 8 +- 2 files changed, 85 insertions(+), 26 deletions(-) diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 30cb4562d..153c52934 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; - - Nif::Transformation &final = *((Nif::Transformation*)node->trafo); - Ogre::Vector3 nodePos = getVector(&final); - Ogre::Matrix3 nodeRot = getMatrix(&final); - - finalPos = nodePos + parentPos; - finalRot = parentRot*nodeRot; - finalScale = final.scale*parentScale; - + + + 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); + + // 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); + + // 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 ed3aceac4..488a7a42b 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 12/33] 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 b1d61a4ed..0a1a750f7 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 153c52934..e87d5624e 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 13/33] 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 653fabd08..150cb4092 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 0a1a750f7..656e6d444 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 e87d5624e..17c5f18ac 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 1fc394259..ae160365b 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 14/33] 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 ce95edbd2..e3827c7b0 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 15/33] 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 a94434e5b..c33d106cd 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 16/33] 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 331701c2a..669ef584f 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 c33d106cd..0cacd67a8 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 d48bd3637..f368f05f6 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 17/33] 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 86fd1fe23..e33fd322a 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 a3c20840a..8062dc35e 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 18/33] 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 d3b75d4ae..e9ce3f615 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 0cacd67a8..d075536d2 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"); From a1902b4121ba7da31ea9cbfbd7181315642178ea Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 16 Jun 2012 17:29:03 -0400 Subject: [PATCH 19/33] Tweaks for high speed --- libs/openengine/bullet/pmove.cpp | 10 ++++++++++ libs/openengine/bullet/pmove.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/openengine/bullet/pmove.cpp b/libs/openengine/bullet/pmove.cpp index ae160365b..b6876e43f 100644 --- a/libs/openengine/bullet/pmove.cpp +++ b/libs/openengine/bullet/pmove.cpp @@ -861,6 +861,8 @@ static void PM_WalkMove( playerMove* const pmove ) float accelerate; float vel; //pm->ps.gravity = 4000; + + //std::cout << "Player is walking\n"; if ( pm->ps.waterlevel > 2 && //DotProduct( pml.forward, pml.groundTrace.plane.normal ) > 0 ) pml.forward.dotProduct(pml.groundTrace.planenormal) > 0.0f) @@ -1162,6 +1164,11 @@ void PM_GroundTraceMissed() { traceResults trace; Ogre::Vector3 point; + //We should not have significant upwards velocity when in the air, unless we jumped. + //This code protects against flying into the air when moving at high speeds. + //Z velocity is set to 50, instead of 0, to help move up certain steps. + if(pm->ps.velocity.z > 50.0f) + pm->ps.velocity.z = 50.0f; //std::cout << "Ground trace missed\n"; // we just transitioned into freefall //if ( pm->debugLevel ) @@ -1587,8 +1594,11 @@ void PM_AirMove() else PM_SlideMove ( qtrue ); #endif*/ + //std::cout << "Moving in the air" << pm->ps.velocity << "\n"; /*bprintf("%i ", */PM_StepSlideMove ( true )/* )*/; + + } static void PM_NoclipMove( void ) diff --git a/libs/openengine/bullet/pmove.h b/libs/openengine/bullet/pmove.h index f368f05f6..d838f17f5 100644 --- a/libs/openengine/bullet/pmove.h +++ b/libs/openengine/bullet/pmove.h @@ -28,7 +28,7 @@ static const Ogre::Vector3 halfExtents(14.64f * 2, 14.24f * 2, 33.25f * 2); #define MAX_CLIP_PLANES 5 #define OVERCLIP 1.001f //#define STEPSIZE 18 // 18 is way too much -#define STEPSIZE (18 / 2) +#define STEPSIZE (13.5) #ifndef M_PI #define M_PI 3.14159265358979323846f #endif From ac6b455592af49c9e6603a80f8fb2991ad61a3f3 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 17 Jun 2012 12:57:59 -0400 Subject: [PATCH 20/33] StepSize moved back to 9 --- libs/openengine/bullet/pmove.cpp | 8 +++++--- libs/openengine/bullet/pmove.h | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/openengine/bullet/pmove.cpp b/libs/openengine/bullet/pmove.cpp index b6876e43f..6173acacf 100644 --- a/libs/openengine/bullet/pmove.cpp +++ b/libs/openengine/bullet/pmove.cpp @@ -530,7 +530,7 @@ int PM_StepSlideMove( bool gravity ) delta = pm->ps.origin.z - start_o.z; if ( delta > 2 ) { - pm->ps.counter = 10; + pm->ps.counter = 5; /* if (gravity) @@ -1167,8 +1167,7 @@ void PM_GroundTraceMissed() //We should not have significant upwards velocity when in the air, unless we jumped. //This code protects against flying into the air when moving at high speeds. //Z velocity is set to 50, instead of 0, to help move up certain steps. - if(pm->ps.velocity.z > 50.0f) - pm->ps.velocity.z = 50.0f; + //std::cout << "Ground trace missed\n"; // we just transitioned into freefall //if ( pm->debugLevel ) @@ -1431,10 +1430,13 @@ static void PM_GroundTrace( void ) // if the trace didn't hit anything, we are in free fall if ( trace.fraction == 1.0) { + if(pm->ps.velocity.z > 50.0f && pm->ps.bSnap) + pm->ps.velocity.z = 50.0f; if(pm->ps.snappingImplemented){ if(pm->ps.bSnap && pm->ps.counter <= 0) PM_GroundTraceMissed(); } + return; diff --git a/libs/openengine/bullet/pmove.h b/libs/openengine/bullet/pmove.h index d838f17f5..bc475a934 100644 --- a/libs/openengine/bullet/pmove.h +++ b/libs/openengine/bullet/pmove.h @@ -28,7 +28,7 @@ static const Ogre::Vector3 halfExtents(14.64f * 2, 14.24f * 2, 33.25f * 2); #define MAX_CLIP_PLANES 5 #define OVERCLIP 1.001f //#define STEPSIZE 18 // 18 is way too much -#define STEPSIZE (13.5) +#define STEPSIZE (9) #ifndef M_PI #define M_PI 3.14159265358979323846f #endif @@ -42,7 +42,7 @@ static const Ogre::Vector3 halfExtents(14.64f * 2, 14.24f * 2, 33.25f * 2); #define ENTITYNUM_NONE (MAX_GENTITIES - 1) #define ENTITYNUM_WORLD (MAX_GENTITIES - 2) #define MIN_WALK_NORMAL .7f // can't walk on very steep slopes -#define JUMP_VELOCITY (270) +#define JUMP_VELOCITY (540) #define PS_PMOVEFRAMECOUNTBITS 6 #define MINS_Z -24 #define DEFAULT_VIEWHEIGHT 26 @@ -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(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 33fe80723ccda649ed2a1391002cc32489c6d6f2 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 17 Jun 2012 20:56:10 -0400 Subject: [PATCH 21/33] btScaledBvhTriangleMeshShapes --- apps/openmw/mwworld/physicssystem.cpp | 1 + apps/openmw/mwworld/physicssystem.hpp | 1 + libs/openengine/bullet/physic.cpp | 16 ++++++++-------- libs/openengine/bullet/physic.hpp | 1 + libs/openengine/bullet/pmove.cpp | 2 +- libs/openengine/bullet/pmove.h | 4 ++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 3757609b2..46b72956d 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -237,6 +237,7 @@ namespace MWWorld void PhysicsSystem::addObject (const std::string& handle, const std::string& mesh, const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position) { + handleToMesh[handle] = mesh; OEngine::Physic::RigidBody* body = mEngine->createRigidBody(mesh,handle,scale); mEngine->addRigidBody(body); btTransform tr; diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 1a8bd87ae..b46ce117b 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -72,6 +72,7 @@ namespace MWWorld OEngine::Physic::PhysicEngine* mEngine; bool mFreeFly; playerMove* playerphysics; + std::map handleToMesh; PhysicsSystem (const PhysicsSystem&); PhysicsSystem& operator= (const PhysicsSystem&); diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index d075536d2..6c4e42697 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -324,24 +324,24 @@ namespace Physic RigidBody* PhysicEngine::createRigidBody(std::string mesh,std::string name,float scale) { - char uniqueID[8]; + /*char uniqueID[8]; sprintf( uniqueID, "%07.3f", scale ); std::string sid = uniqueID; - std::string outputstring = mesh + uniqueID + "\"|"; + std::string outputstring = mesh + uniqueID + "\"|";*/ //std::cout << "The string" << outputstring << "\n"; //get the shape from the .nif - mShapeLoader->load(outputstring,"General"); - BulletShapeManager::getSingletonPtr()->load(outputstring,"General"); - BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General"); - shape->Shape->setLocalScaling(btVector3(scale,scale,scale)); - + mShapeLoader->load(mesh,"General"); + BulletShapeManager::getSingletonPtr()->load(mesh,"General"); + BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(mesh,"General"); + //shape->Shape->setLocalScaling(); + btScaledBvhTriangleMeshShape* scaled = new btScaledBvhTriangleMeshShape(dynamic_cast (shape->Shape), btVector3(scale,scale,scale)); //create the motionState CMotionState* newMotionState = new CMotionState(this,name); //create the real body - btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo(0,newMotionState,shape->Shape); + btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo(0,newMotionState,scaled); RigidBody* body = new RigidBody(CI,name); body->collide = shape->collide; return body; diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 811572320..8a3295ec3 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -7,6 +7,7 @@ #include #include #include "BulletShapeLoader.h" +#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h" class btRigidBody; class btBroadphaseInterface; diff --git a/libs/openengine/bullet/pmove.cpp b/libs/openengine/bullet/pmove.cpp index 6173acacf..fa87e9040 100644 --- a/libs/openengine/bullet/pmove.cpp +++ b/libs/openengine/bullet/pmove.cpp @@ -1430,7 +1430,7 @@ static void PM_GroundTrace( void ) // if the trace didn't hit anything, we are in free fall if ( trace.fraction == 1.0) { - if(pm->ps.velocity.z > 50.0f && pm->ps.bSnap) + if(pm->ps.velocity.z > 50.0f && pm->ps.bSnap && pm->ps.speed > 1000.0f) pm->ps.velocity.z = 50.0f; if(pm->ps.snappingImplemented){ if(pm->ps.bSnap && pm->ps.counter <= 0) diff --git a/libs/openengine/bullet/pmove.h b/libs/openengine/bullet/pmove.h index bc475a934..592ca724d 100644 --- a/libs/openengine/bullet/pmove.h +++ b/libs/openengine/bullet/pmove.h @@ -42,7 +42,7 @@ static const Ogre::Vector3 halfExtents(14.64f * 2, 14.24f * 2, 33.25f * 2); #define ENTITYNUM_NONE (MAX_GENTITIES - 1) #define ENTITYNUM_WORLD (MAX_GENTITIES - 2) #define MIN_WALK_NORMAL .7f // can't walk on very steep slopes -#define JUMP_VELOCITY (540) +#define JUMP_VELOCITY (270) #define PS_PMOVEFRAMECOUNTBITS 6 #define MINS_Z -24 #define DEFAULT_VIEWHEIGHT 26 @@ -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 4d55ecfdbed5c09c21e7ea7bb59c675f3b007203 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 18 Jun 2012 13:03:00 -0400 Subject: [PATCH 22/33] Deleting scaled shapes; scaleObject() --- apps/openmw/mwworld/physicssystem.cpp | 10 +++++++++- libs/openengine/bullet/physic.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 46b72956d..530881ec9 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -300,7 +300,15 @@ namespace MWWorld void PhysicsSystem::scaleObject (const std::string& handle, float scale) { - + if(handleToMesh.find(handle) != handleToMesh.end()) + { + btTransform transform = mEngine->getRigidBody(handle)->getWorldTransform(); + removeObject(handle); + + Ogre::Quaternion quat = Ogre::Quaternion(transform.getRotation().getW(), transform.getRotation().getX(), transform.getRotation().getY(), transform.getRotation().getZ()); + Ogre::Vector3 vec = Ogre::Vector3(transform.getOrigin().getX(), transform.getOrigin().getY(), transform.getOrigin().getZ()); + addObject(handle, handleToMesh[handle], quat, scale, vec); + } } bool PhysicsSystem::toggleCollisionMode() diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 6c4e42697..1dc38475d 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -398,10 +398,16 @@ namespace Physic if (it != RigidBodyMap.end() ) { RigidBody* body = it->second; + btScaledBvhTriangleMeshShape* scaled = dynamic_cast (body->getCollisionShape()); + if(body != NULL) { delete body; } + if(scaled != NULL) + { + delete scaled; + } RigidBodyMap.erase(it); } } From 86d8a07fc71798927e0abfbd9f1deff1202da6e3 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 19 Jun 2012 13:28:06 -0400 Subject: [PATCH 23/33] Switching back to old scaling --- apps/openmw/mwworld/physicssystem.cpp | 5 ++++- libs/openengine/bullet/physic.cpp | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 530881ec9..94f39da7d 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -213,6 +213,8 @@ namespace MWWorld if(it->first == "player"){ coord = playerphysics->ps.origin; + //playerphysics->ps.speed = 480.0f; + //std::cout << "Position" << coord << "\n"; } @@ -300,6 +302,7 @@ namespace MWWorld void PhysicsSystem::scaleObject (const std::string& handle, float scale) { + /* if(handleToMesh.find(handle) != handleToMesh.end()) { btTransform transform = mEngine->getRigidBody(handle)->getWorldTransform(); @@ -308,7 +311,7 @@ namespace MWWorld Ogre::Quaternion quat = Ogre::Quaternion(transform.getRotation().getW(), transform.getRotation().getX(), transform.getRotation().getY(), transform.getRotation().getZ()); Ogre::Vector3 vec = Ogre::Vector3(transform.getOrigin().getX(), transform.getOrigin().getY(), transform.getOrigin().getZ()); addObject(handle, handleToMesh[handle], quat, scale, vec); - } + }*/ } bool PhysicsSystem::toggleCollisionMode() diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 1dc38475d..6a3f22565 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -324,24 +324,24 @@ namespace Physic RigidBody* PhysicEngine::createRigidBody(std::string mesh,std::string name,float scale) { - /*char uniqueID[8]; + char uniqueID[8]; sprintf( uniqueID, "%07.3f", scale ); std::string sid = uniqueID; - std::string outputstring = mesh + uniqueID + "\"|";*/ + std::string outputstring = mesh + uniqueID + "\"|"; //std::cout << "The string" << 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(); - btScaledBvhTriangleMeshShape* scaled = new btScaledBvhTriangleMeshShape(dynamic_cast (shape->Shape), btVector3(scale,scale,scale)); + mShapeLoader->load(outputstring,"General"); + BulletShapeManager::getSingletonPtr()->load(outputstring,"General"); + BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General"); + shape->Shape->setLocalScaling( btVector3(scale,scale,scale)); + //btScaledBvhTriangleMeshShape* scaled = new btScaledBvhTriangleMeshShape(dynamic_cast (shape->Shape), btVector3(scale,scale,scale)); //create the motionState CMotionState* newMotionState = new CMotionState(this,name); //create the real body - btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo(0,newMotionState,scaled); + btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo(0,newMotionState,shape->Shape); RigidBody* body = new RigidBody(CI,name); body->collide = shape->collide; return body; @@ -398,16 +398,16 @@ namespace Physic if (it != RigidBodyMap.end() ) { RigidBody* body = it->second; - btScaledBvhTriangleMeshShape* scaled = dynamic_cast (body->getCollisionShape()); + //btScaledBvhTriangleMeshShape* scaled = dynamic_cast (body->getCollisionShape()); if(body != NULL) { delete body; } - if(scaled != NULL) + /*if(scaled != NULL) { delete scaled; - } + }*/ RigidBodyMap.erase(it); } } From 5c51674070a41a261b8d6b4b9b7b944960ce3326 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 20 Jun 2012 13:14:27 -0400 Subject: [PATCH 24/33] update --- apps/openmw/mwworld/physicssystem.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 94f39da7d..530881ec9 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -213,8 +213,6 @@ namespace MWWorld if(it->first == "player"){ coord = playerphysics->ps.origin; - //playerphysics->ps.speed = 480.0f; - //std::cout << "Position" << coord << "\n"; } @@ -302,7 +300,6 @@ namespace MWWorld void PhysicsSystem::scaleObject (const std::string& handle, float scale) { - /* if(handleToMesh.find(handle) != handleToMesh.end()) { btTransform transform = mEngine->getRigidBody(handle)->getWorldTransform(); @@ -311,7 +308,7 @@ namespace MWWorld Ogre::Quaternion quat = Ogre::Quaternion(transform.getRotation().getW(), transform.getRotation().getX(), transform.getRotation().getY(), transform.getRotation().getZ()); Ogre::Vector3 vec = Ogre::Vector3(transform.getOrigin().getX(), transform.getOrigin().getY(), transform.getOrigin().getZ()); addObject(handle, handleToMesh[handle], quat, scale, vec); - }*/ + } } bool PhysicsSystem::toggleCollisionMode() From 1a5203749f6800e6674583ecdfb82f890fec80ff Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 5 Jul 2012 17:13:23 +0200 Subject: [PATCH 25/33] fix "error in framelistener" when trying to pick up lights that can't be picked up --- apps/openmw/mwgui/inventorywindow.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index dc5728283..23a96b1d3 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -310,6 +310,9 @@ namespace MWGui && (type != typeid(ESM::Potion).name())) return; + if (MWWorld::Class::get(object).getName(object) == "") // objects without name presented to user can never be picked up + return; + // sound std::string sound = MWWorld::Class::get(object).getUpSoundId(object); MWBase::Environment::get().getSoundManager()->playSound(sound, 1, 1); From 113457d9348ded20223560994bbf2ec55b152b9e Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sat, 7 Jul 2012 01:14:18 +0200 Subject: [PATCH 26/33] Fixed some windows issues and got rid of a few tiny warnings while at it. --- apps/openmw/mwdialogue/dialoguemanager.cpp | 2 +- apps/openmw/mwgui/hud.cpp | 2 +- apps/openmw/mwgui/referenceinterface.cpp | 4 ++++ apps/openmw/mwgui/referenceinterface.hpp | 1 + apps/openmw/mwgui/tooltips.cpp | 2 +- apps/openmw/mwsound/soundmanager.cpp | 2 +- apps/openmw/mwworld/cells.cpp | 2 +- apps/openmw/mwworld/player.hpp | 3 +++ apps/openmw/mwworld/worldimp.hpp | 2 +- 9 files changed, 14 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 98562c053..41ffd1e93 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -706,7 +706,7 @@ namespace MWDialogue } return false; } - catch (const Compiler::SourceException& error) + catch (const Compiler::SourceException& /* error */) { // error has already been reported via error handler } diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index d20a11009..78eefa338 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -286,7 +286,7 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) { object = MWBase::Environment::get().getWorld()->getPtrViaHandle(handle); } - catch (std::exception& e) + catch (std::exception& /* e */) { return; } diff --git a/apps/openmw/mwgui/referenceinterface.cpp b/apps/openmw/mwgui/referenceinterface.cpp index f891b3338..b1f7affb6 100644 --- a/apps/openmw/mwgui/referenceinterface.cpp +++ b/apps/openmw/mwgui/referenceinterface.cpp @@ -12,6 +12,10 @@ namespace MWGui { } + ReferenceInterface::~ReferenceInterface() + { + } + void ReferenceInterface::checkReferenceAvailable() { if (mPtr.isEmpty()) diff --git a/apps/openmw/mwgui/referenceinterface.hpp b/apps/openmw/mwgui/referenceinterface.hpp index aba9071f3..39574d0f7 100644 --- a/apps/openmw/mwgui/referenceinterface.hpp +++ b/apps/openmw/mwgui/referenceinterface.hpp @@ -13,6 +13,7 @@ namespace MWGui { public: ReferenceInterface(); + virtual ~ReferenceInterface(); void checkReferenceAvailable(); ///< closes the window, if the MW-reference has become unavailable diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 7920d88a3..679c7a59e 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -81,7 +81,7 @@ void ToolTips::onFrame(float frameDuration) { mFocusObject = MWBase::Environment::get().getWorld()->getPtrViaHandle(handle); } - catch (std::exception& e) + catch (std::exception /* & e */) { return; } diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 29563ecc1..c6332d9f3 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -90,7 +90,7 @@ namespace MWSound { if(devname.empty()) throw; - std::cout <<"Failed to open device \""<init(); Settings::Manager::setString("device", "Sound", ""); } diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index 74a91f25f..cd7ebf79a 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -91,7 +91,7 @@ MWWorld::Ptr MWWorld::Cells::getPtrAndCache (const std::string& name, Ptr::CellS MWWorld::Cells::Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader) : mStore (store), mReader (reader), - mIdCache (20, std::pair ("", 0)), /// \todo make cache size configurable + mIdCache (20, std::pair ("", (Ptr::CellStore*)0)), /// \todo make cache size configurable mIdCacheIndex (0) {} diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index b1692bd81..6f6ee93bc 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -9,6 +9,9 @@ #include "../mwmechanics/drawstate.hpp" +#undef DrawState // How did this get defined again? + // Maybe it's defined by default in every file for windows? + namespace MWBase { class World; diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index d64b3a373..62a24000e 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -188,7 +188,7 @@ namespace MWWorld virtual bool toggleSky(); ///< \return Resulting mode - virtual void changeWeather (const std::string& region, const unsigned int id); + virtual void changeWeather (const std::string& region, unsigned int id); virtual int getCurrentWeather() const; From e6716c25c382514eb06e6aeaaf4b2562e34fde7e Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Jul 2012 15:41:19 +0200 Subject: [PATCH 27/33] little correction. --- apps/openmw/mwworld/worldimp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index b623cd527..155bc8d81 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -604,7 +604,7 @@ namespace MWWorld ptr.getCellRef().scale = scale; scale = scale/ptr.getRefData().getBaseNode()->getScale().x; ptr.getRefData().getBaseNode()->setScale(scale,scale,scale); - mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale ); + mPhysics->scaleObject( ptr.getRefData().getHandle(), scale ); } void World::rotateObject (Ptr& ptr,float x,float y,float z,bool WorldAxis) @@ -636,7 +636,7 @@ namespace MWWorld ptr.getRefData().getPosition().rot[0] = ry.valueRadians(); ptr.getRefData().getPosition().rot[0] = rz.valueRadians(); - mPhysics->rotateObject(Class::get(ptr).getId(ptr),ptr.getRefData().getBaseNode()->getOrientation()); + mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode()->getOrientation()); //ptr.getRefData().getBaseNode()->rotate(ptr.getRefData().getBaseNode()->get //mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale ); } From 0a67f60a6e334a942cda7f5391b41fcf948e3d06 Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Jul 2012 18:47:59 +0200 Subject: [PATCH 28/33] Clean-up --- apps/openmw/mwbase/world.hpp | 6 +- apps/openmw/mwscript/extensions.cpp | 3 + apps/openmw/mwscript/statsextensions.cpp | 57 ------------ .../mwscript/transformationextensions.cpp | 89 +++++++++++++++++++ .../mwscript/transformationextensions.hpp | 25 ++++++ apps/openmw/mwworld/worldimp.cpp | 41 +-------- apps/openmw/mwworld/worldimp.hpp | 6 +- 7 files changed, 124 insertions(+), 103 deletions(-) create mode 100644 apps/openmw/mwscript/transformationextensions.cpp create mode 100644 apps/openmw/mwscript/transformationextensions.hpp diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 0dcf440f0..51d0a4f8e 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -178,11 +178,9 @@ namespace MWBase virtual void moveObject (const MWWorld::Ptr& ptr, float x, float y, float z) = 0; - virtual void scaleObject (MWWorld::Ptr& ptr, float scale) = 0; + virtual void scaleObject (const MWWorld::Ptr& ptr, float scale) = 0; - virtual void rotateObject (MWWorld::Ptr& ptr,float x,float y,float z,bool WorldAxis) = 0; - - virtual void setObjectRotation (MWWorld::Ptr& ptr,float x,float y,float z) = 0; + virtual void rotateObject(const MWWorld::Ptr& ptr,float x,float y,float z) = 0; virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const = 0; diff --git a/apps/openmw/mwscript/extensions.cpp b/apps/openmw/mwscript/extensions.cpp index 197494146..b7425aca0 100644 --- a/apps/openmw/mwscript/extensions.cpp +++ b/apps/openmw/mwscript/extensions.cpp @@ -15,6 +15,7 @@ #include "controlextensions.hpp" #include "dialogueextensions.hpp" #include "animationextensions.hpp" +#include "transformationextensions.hpp" namespace MWScript { @@ -31,6 +32,7 @@ namespace MWScript Control::registerExtensions (extensions); Dialogue::registerExtensions (extensions); Animation::registerExtensions (extensions); + Transformation::registerExtensions (extensions); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -47,5 +49,6 @@ namespace MWScript Control::installOpcodes (interpreter); Dialogue::installOpcodes (interpreter); Animation::installOpcodes (interpreter); + Transformation::installOpcodes (interpreter); } } diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 17cd184d7..4e41ae81d 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -505,50 +505,6 @@ namespace MWScript } }; - template - class OpSetScale : public Interpreter::Opcode0 - { - public: - - virtual void execute (Interpreter::Runtime& runtime) - { - MWWorld::Ptr ptr = R()(runtime); - - Interpreter::Type_Float scale = runtime[0].mInteger; - runtime.pop(); - - MWBase::Environment::get().getWorld()->scaleObject(ptr,scale); - } - }; - - template - class OpSetAngle : public Interpreter::Opcode0 - { - public: - - virtual void execute (Interpreter::Runtime& runtime) - { - MWWorld::Ptr ptr = R()(runtime); - - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); - runtime.pop(); - Interpreter::Type_Float angle = runtime[0].mInteger; - runtime.pop(); - - if(axis == "X") - { - MWBase::Environment::get().getWorld()->setObjectRotation(ptr,angle,0,0); - } - if(axis == "Y") - { - MWBase::Environment::get().getWorld()->setObjectRotation(ptr,0,angle,0); - } - if(axis == "Z") - { - MWBase::Environment::get().getWorld()->setObjectRotation(ptr,0,0,angle); - } - } - }; const int numberOfAttributes = 8; @@ -596,11 +552,6 @@ namespace MWScript const int opcodeModDisposition = 0x200014d; const int opcodeModDispositionExplicit = 0x200014e; - const int opcodeSetScale = 0x2000164; - const int opcodeSetScaleExplicit = 0x2000165; - const int opcodeSetAngle = 0x2000166; - const int opcodeSetAngleExplicit = 0x2000167; - void registerExtensions (Compiler::Extensions& extensions) { static const char *attributes[numberOfAttributes] = @@ -683,9 +634,6 @@ namespace MWScript extensions.registerInstruction("moddisposition","l",opcodeModDisposition, opcodeModDispositionExplicit); extensions.registerFunction("getpcrank",'l',"/S",opcodeGetPCRank,opcodeGetPCRankExplicit); - - extensions.registerInstruction("setscale","l",opcodeSetScale,opcodeSetScaleExplicit); - extensions.registerInstruction("setangle","Sl",opcodeSetAngle,opcodeSetAngleExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -757,11 +705,6 @@ namespace MWScript interpreter.installSegment5(opcodeModDispositionExplicit,new OpModDisposition); interpreter.installSegment3(opcodeGetPCRank,new OpGetPCRank); interpreter.installSegment3(opcodeGetPCRankExplicit,new OpGetPCRank); - - interpreter.installSegment5(opcodeSetScale,new OpSetScale); - interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale); - interpreter.installSegment5(opcodeSetAngle,new OpSetAngle); - interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle); } } } diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp new file mode 100644 index 000000000..14181a06e --- /dev/null +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -0,0 +1,89 @@ + +#include "statsextensions.hpp" + +#include + +#include + +#include + +#include +#include +#include + +#include "../mwbase/environment.hpp" + +#include "../mwworld/class.hpp" + +#include "interpretercontext.hpp" +#include "ref.hpp" + +namespace MWScript +{ + namespace Transformation + { + template + class OpSetScale : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + Interpreter::Type_Float scale = runtime[0].mInteger; + runtime.pop(); + + MWBase::Environment::get().getWorld()->scaleObject(ptr,scale); + } + }; + + template + class OpSetAngle : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + Interpreter::Type_Float angle = runtime[0].mInteger; + runtime.pop(); + + if(axis == "X") + { + MWBase::Environment::get().getWorld()->rotateObject(ptr,angle,0,0); + } + if(axis == "Y") + { + MWBase::Environment::get().getWorld()->rotateObject(ptr,0,angle,0); + } + if(axis == "Z") + { + MWBase::Environment::get().getWorld()->rotateObject(ptr,0,0,angle); + } + } + }; + + const int opcodeSetScale = 0x2000164; + const int opcodeSetScaleExplicit = 0x2000165; + const int opcodeSetAngle = 0x2000166; + const int opcodeSetAngleExplicit = 0x2000167; + + void registerExtensions (Compiler::Extensions& extensions) + { + extensions.registerInstruction("setscale","f",opcodeSetScale,opcodeSetScaleExplicit); + extensions.registerInstruction("setangle","Sl",opcodeSetAngle,opcodeSetAngleExplicit); + } + + void installOpcodes (Interpreter::Interpreter& interpreter) + { + interpreter.installSegment5(opcodeSetScale,new OpSetScale); + interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale); + interpreter.installSegment5(opcodeSetAngle,new OpSetAngle); + interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle); + } + } +} diff --git a/apps/openmw/mwscript/transformationextensions.hpp b/apps/openmw/mwscript/transformationextensions.hpp new file mode 100644 index 000000000..6ee1db1b8 --- /dev/null +++ b/apps/openmw/mwscript/transformationextensions.hpp @@ -0,0 +1,25 @@ +#ifndef GAME_SCRIPT_TRANSFORMATIONEXTENSIONS_H +#define GAME_SCRIPT_TRANSFORMATIONEXTENSIONS_H + +namespace Compiler +{ + class Extensions; +} + +namespace Interpreter +{ + class Interpreter; +} + +namespace MWScript +{ + /// \brief stats-related script functionality (creatures and NPCs) + namespace Transformation + { + void registerExtensions (Compiler::Extensions& extensions); + + void installOpcodes (Interpreter::Interpreter& interpreter); + } +} + +#endif \ No newline at end of file diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 155bc8d81..c6423563d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -597,7 +597,7 @@ namespace MWWorld mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z)); } - void World::scaleObject (Ptr& ptr, float scale) + void World::scaleObject (const Ptr& ptr, float scale) { MWWorld::Class::get(ptr).adjustScale(ptr,scale); @@ -607,41 +607,7 @@ namespace MWWorld mPhysics->scaleObject( ptr.getRefData().getHandle(), scale ); } - void World::rotateObject (Ptr& ptr,float x,float y,float z,bool WorldAxis) - { - MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); - - if(WorldAxis) - { - ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(x)); - ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(y)); - ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(z)); - } - else - { - Ogre::Matrix3 axis = ptr.getRefData().getBaseNode()->getLocalAxes(); - Ogre::Vector3 xAxis = axis.GetColumn(0); - Ogre::Vector3 yAxis = axis.GetColumn(1); - Ogre::Vector3 zAxis = axis.GetColumn(2); - ptr.getRefData().getBaseNode()->rotate(xAxis,Ogre::Degree(x)); - ptr.getRefData().getBaseNode()->rotate(yAxis,Ogre::Degree(y)); - ptr.getRefData().getBaseNode()->rotate(zAxis,Ogre::Degree(z)); - } - Ogre::Matrix3 rot; - ptr.getRefData().getBaseNode()->getOrientation().ToRotationMatrix(rot); - Ogre::Radian rx,ry,rz; - rot.ToEulerAnglesXYZ(rx,ry,rz); - - ptr.getRefData().getPosition().rot[0] = rx.valueRadians(); - ptr.getRefData().getPosition().rot[0] = ry.valueRadians(); - ptr.getRefData().getPosition().rot[0] = rz.valueRadians(); - - mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode()->getOrientation()); - //ptr.getRefData().getBaseNode()->rotate(ptr.getRefData().getBaseNode()->get - //mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale ); - } - - void World::setObjectRotation (Ptr& ptr,float x,float y,float z) + void World::rotateObject (const Ptr& ptr,float x,float y,float z) { MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); @@ -653,8 +619,7 @@ namespace MWWorld Ogre::Quaternion roty(Ogre::Degree(y),Ogre::Vector3::UNIT_Y); Ogre::Quaternion rotz(Ogre::Degree(z),Ogre::Vector3::UNIT_Z); ptr.getRefData().getBaseNode()->setOrientation(rotx*roty*rotz); - mPhysics->rotateObject(Class::get(ptr).getId(ptr),ptr.getRefData().getBaseNode()->getOrientation()); - std::cout << Class::get(ptr).getId(ptr); + mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode()->getOrientation()); } void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 1f3073d44..8b39a78f1 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -219,11 +219,9 @@ namespace MWWorld virtual void moveObject (const Ptr& ptr, float x, float y, float z); - virtual void scaleObject (Ptr& ptr, float scale); + virtual void scaleObject (const Ptr& ptr, float scale); - virtual void rotateObject (Ptr& ptr,float x,float y,float z,bool WorldAxis); - - virtual void setObjectRotation (Ptr& ptr,float x,float y,float z); + virtual void rotateObject (const Ptr& ptr,float x,float y,float z); virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const; From 557e114992458b1d7c2768baaf342a64dc01542e Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Jul 2012 19:28:44 +0200 Subject: [PATCH 29/33] clean-up + getScale/Angle script instructions --- .../mwscript/transformationextensions.cpp | 59 +++++++++++++++++-- apps/openmw/mwworld/worldimp.cpp | 4 +- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 14181a06e..41eba4a99 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -1,6 +1,3 @@ - -#include "statsextensions.hpp" - #include #include @@ -17,6 +14,7 @@ #include "interpretercontext.hpp" #include "ref.hpp" +#include "OgreSceneNode.h" namespace MWScript { @@ -31,13 +29,25 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - Interpreter::Type_Float scale = runtime[0].mInteger; + Interpreter::Type_Float scale = runtime[0].mFloat; runtime.pop(); MWBase::Environment::get().getWorld()->scaleObject(ptr,scale); } }; + template + class OpGetScale : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + runtime.push(ptr.getCellRef().scale); + } + }; + template class OpSetAngle : public Interpreter::Opcode0 { @@ -49,7 +59,7 @@ namespace MWScript std::string axis = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - Interpreter::Type_Float angle = runtime[0].mInteger; + Interpreter::Type_Float angle = runtime[0].mFloat; runtime.pop(); if(axis == "X") @@ -67,15 +77,48 @@ namespace MWScript } }; + template + class OpGetAngle : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + if(axis == "X") + { + runtime.push(ptr.getRefData().getPosition().rot[0]); + } + if(axis == "Y") + { + runtime.push(ptr.getRefData().getPosition().rot[1]); + } + if(axis == "Z") + { + runtime.push(ptr.getRefData().getPosition().rot[0]); + } + } + }; + const int opcodeSetScale = 0x2000164; const int opcodeSetScaleExplicit = 0x2000165; const int opcodeSetAngle = 0x2000166; const int opcodeSetAngleExplicit = 0x2000167; + const int opcodeGetScale = 0x2000168; + const int opcodeGetScaleExplicit = 0x2000169; + const int opcodeGetAngle = 0x200016a; + const int opcodeGetAngleExplicit = 0x200016b; void registerExtensions (Compiler::Extensions& extensions) { extensions.registerInstruction("setscale","f",opcodeSetScale,opcodeSetScaleExplicit); - extensions.registerInstruction("setangle","Sl",opcodeSetAngle,opcodeSetAngleExplicit); + extensions.registerFunction("getscale",'f',"",opcodeGetScale,opcodeGetScaleExplicit); + extensions.registerInstruction("setangle","Sf",opcodeSetAngle,opcodeSetAngleExplicit); + extensions.registerFunction("getangle",'f',"S",opcodeGetAngle,opcodeGetAngleExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -84,6 +127,10 @@ namespace MWScript interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale); interpreter.installSegment5(opcodeSetAngle,new OpSetAngle); interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle); + interpreter.installSegment5(opcodeGetScale,new OpGetScale); + interpreter.installSegment5(opcodeGetScaleExplicit,new OpGetScale); + interpreter.installSegment5(opcodeGetAngle,new OpGetAngle); + interpreter.installSegment5(opcodeGetAngleExplicit,new OpGetAngle); } } } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index c6423563d..5309fbe40 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -612,8 +612,8 @@ namespace MWWorld MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); ptr.getRefData().getPosition().rot[0] = Ogre::Degree(x).valueRadians(); - ptr.getRefData().getPosition().rot[0] = Ogre::Degree(y).valueRadians(); - ptr.getRefData().getPosition().rot[0] = Ogre::Degree(z).valueRadians(); + ptr.getRefData().getPosition().rot[1] = Ogre::Degree(y).valueRadians(); + ptr.getRefData().getPosition().rot[2] = Ogre::Degree(z).valueRadians(); Ogre::Quaternion rotx(Ogre::Degree(x),Ogre::Vector3::UNIT_X); Ogre::Quaternion roty(Ogre::Degree(y),Ogre::Vector3::UNIT_Y); From 410b69355539f9ad5d328e0fdd0b4b21b5962d98 Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 10 Jul 2012 11:15:46 +0200 Subject: [PATCH 30/33] setAngle improvement --- apps/openmw/mwclass/npc.cpp | 7 +++++++ apps/openmw/mwclass/npc.hpp | 2 ++ .../openmw/mwscript/transformationextensions.cpp | 16 ++++++++++------ apps/openmw/mwworld/worldimp.cpp | 4 ++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index ab4e2d5e6..0d2efcd9e 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -347,4 +347,11 @@ namespace MWClass return weight; } + + void Npc::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const + { + y = 0; + x = 0; + std::cout << "dfdfdfdfnzdofnmqsldgnmqskdhblqkdbv lqksdf"; + } } diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 4cb733977..f50ed2159 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -76,6 +76,8 @@ namespace MWClass ///< Returns total weight of objects inside this object (including modifications from magic /// effects). Throws an exception, if the object can't hold other objects. + virtual void adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const; + static void registerSelf(); }; } diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 41eba4a99..2ea80c0d8 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -62,17 +62,21 @@ namespace MWScript Interpreter::Type_Float angle = runtime[0].mFloat; runtime.pop(); + float ax = Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees(); + float ay = Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees(); + float az = Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees(); + if(axis == "X") { - MWBase::Environment::get().getWorld()->rotateObject(ptr,angle,0,0); + MWBase::Environment::get().getWorld()->rotateObject(ptr,angle,ay,az); } if(axis == "Y") { - MWBase::Environment::get().getWorld()->rotateObject(ptr,0,angle,0); + MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,angle,az); } if(axis == "Z") { - MWBase::Environment::get().getWorld()->rotateObject(ptr,0,0,angle); + MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,angle); } } }; @@ -91,15 +95,15 @@ namespace MWScript if(axis == "X") { - runtime.push(ptr.getRefData().getPosition().rot[0]); + runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees()); } if(axis == "Y") { - runtime.push(ptr.getRefData().getPosition().rot[1]); + runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees()); } if(axis == "Z") { - runtime.push(ptr.getRefData().getPosition().rot[0]); + runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees()); } } }; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5309fbe40..1e1fae154 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -602,7 +602,7 @@ namespace MWWorld MWWorld::Class::get(ptr).adjustScale(ptr,scale); ptr.getCellRef().scale = scale; - scale = scale/ptr.getRefData().getBaseNode()->getScale().x; + //scale = scale/ptr.getRefData().getBaseNode()->getScale().x; ptr.getRefData().getBaseNode()->setScale(scale,scale,scale); mPhysics->scaleObject( ptr.getRefData().getHandle(), scale ); } @@ -618,7 +618,7 @@ namespace MWWorld Ogre::Quaternion rotx(Ogre::Degree(x),Ogre::Vector3::UNIT_X); Ogre::Quaternion roty(Ogre::Degree(y),Ogre::Vector3::UNIT_Y); Ogre::Quaternion rotz(Ogre::Degree(z),Ogre::Vector3::UNIT_Z); - ptr.getRefData().getBaseNode()->setOrientation(rotx*roty*rotz); + ptr.getRefData().getBaseNode()->setOrientation(rotz*rotx*roty); mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode()->getOrientation()); } From 70c74ede055b2bbfcb727dcc9c8e92f082cd9554 Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 10 Jul 2012 11:53:12 +0200 Subject: [PATCH 31/33] changed rotation order --- apps/openmw/mwworld/worldimp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 1e1fae154..24baac144 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -618,7 +618,7 @@ namespace MWWorld Ogre::Quaternion rotx(Ogre::Degree(x),Ogre::Vector3::UNIT_X); Ogre::Quaternion roty(Ogre::Degree(y),Ogre::Vector3::UNIT_Y); Ogre::Quaternion rotz(Ogre::Degree(z),Ogre::Vector3::UNIT_Z); - ptr.getRefData().getBaseNode()->setOrientation(rotz*rotx*roty); + ptr.getRefData().getBaseNode()->setOrientation(rotz*roty*rotx); mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode()->getOrientation()); } From 164a5c8fe4d6ab0abda8116f872f90eaac6ce960 Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 10 Jul 2012 12:10:50 +0200 Subject: [PATCH 32/33] rotation now also work with the physic representation --- apps/openmw/mwworld/physicssystem.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 9848efe6e..7d7b237ae 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -291,12 +291,14 @@ namespace MWWorld void PhysicsSystem::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation) { - if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) + if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) { - // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow - // start positions others than 0, 0, 0 act->setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)); } + if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) + { + body->getWorldTransform().setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)); + } } void PhysicsSystem::scaleObject (const std::string& handle, float scale) From f11bf49a9023cff3ceebdeab6326a5379f878995 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 10 Jul 2012 13:23:41 +0200 Subject: [PATCH 33/33] cmake fix; silenced some warnings --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwworld/physicssystem.cpp | 13 ++++----- components/nifbullet/bullet_nif_loader.cpp | 34 +++++++++++----------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 9534ecc90..b12c58f0d 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -39,7 +39,7 @@ add_openmw_dir (mwscript locals scriptmanager compilercontext interpretercontext cellextensions miscextensions guiextensions soundextensions skyextensions statsextensions containerextensions aiextensions controlextensions extensions globalscripts ref dialogueextensions - animationextensions + animationextensions transformationextensions ) add_openmw_dir (mwsound diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 7d7b237ae..105995aca 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -165,7 +165,6 @@ namespace MWWorld for (std::vector >::const_iterator iter (actors.begin()); iter!=actors.end(); ++iter) { - OEngine::Physic::PhysicActor* act = mEngine->getCharacter(iter->first); //dirty stuff to get the camera orientation. Must be changed! Ogre::SceneNode *sceneNode = mRender.getScene()->getSceneNode (iter->first); @@ -175,10 +174,10 @@ namespace MWWorld Ogre::Quaternion yawQuat = yawNode->getOrientation(); Ogre::Quaternion pitchQuat = pitchNode->getOrientation(); - + playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); - + playerphysics->ps.viewangles.y = yawQuat.getYaw().valueDegrees() *-1 + 90; @@ -194,9 +193,9 @@ namespace MWWorld } - - - + + + mEngine->stepSimulation(dt); } @@ -307,7 +306,7 @@ namespace MWWorld { btTransform transform = mEngine->getRigidBody(handle)->getWorldTransform(); removeObject(handle); - + Ogre::Quaternion quat = Ogre::Quaternion(transform.getRotation().getW(), transform.getRotation().getX(), transform.getRotation().getY(), transform.getRotation().getZ()); Ogre::Vector3 vec = Ogre::Vector3(transform.getOrigin().getX(), transform.getOrigin().getY(), transform.getOrigin().getZ()); addObject(handle, handleToMesh[handle], quat, scale, vec); diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 17c5f18ac..f66239e7b 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -82,17 +82,17 @@ static void vectorMulAdd(const Matrix &A, const Vector &B, float *C, float 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]; +//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]; -} +// // 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() @@ -233,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) { - + // Accumulate the flags from all the child nodes. This works for all // the flags we currently use, at least. flags |= node->flags; @@ -267,11 +267,11 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, } } - - + + if (trafo) { - + // Get a non-const reference to the node's data, since we're // overwriting it. TODO: Is this necessary? Transformation &final = *((Transformation*)node->trafo); @@ -287,9 +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; - + } - + // For NiNodes, loop through children if (node->recType == Nif::RC_NiNode) @@ -304,7 +304,7 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, } } } - else if (node->recType == Nif::RC_NiTriShape && (isCollisionNode || !hasCollisionNode)) + else if (node->recType == Nif::RC_NiTriShape && (isCollisionNode || !hasCollisionNode)) { cShape->collide = true; handleNiTriShape(dynamic_cast(node), flags,getMatrix(node->trafo),getVector(node->trafo),node->trafo->scale,raycastingOnly);