forked from teamnwah/openmw-tes3coop
Merge remote-tracking branch 'chris/animation2'
commit
cd40d167ce
@ -0,0 +1,74 @@
|
|||||||
|
#include "activators.hpp"
|
||||||
|
|
||||||
|
#include <OgreVector3.h>
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
|
namespace MWMechanics
|
||||||
|
{
|
||||||
|
|
||||||
|
Activators::Activators()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Activators::addActivator(const MWWorld::Ptr& ptr)
|
||||||
|
{
|
||||||
|
MWRender::Animation *anim = MWBase::Environment::get().getWorld()->getAnimation(ptr);
|
||||||
|
if(anim != NULL)
|
||||||
|
mActivators.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Idle, true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Activators::removeActivator (const MWWorld::Ptr& ptr)
|
||||||
|
{
|
||||||
|
PtrControllerMap::iterator iter = mActivators.find(ptr);
|
||||||
|
if(iter != mActivators.end())
|
||||||
|
mActivators.erase(iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Activators::updateActivatorCell(const MWWorld::Ptr &ptr)
|
||||||
|
{
|
||||||
|
PtrControllerMap::iterator iter = mActivators.find(ptr);
|
||||||
|
if(iter != mActivators.end())
|
||||||
|
{
|
||||||
|
CharacterController ctrl = iter->second;
|
||||||
|
mActivators.erase(iter);
|
||||||
|
mActivators.insert(std::make_pair(ptr, ctrl));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Activators::dropActivators (const MWWorld::Ptr::CellStore *cellStore)
|
||||||
|
{
|
||||||
|
PtrControllerMap::iterator iter = mActivators.begin();
|
||||||
|
while(iter != mActivators.end())
|
||||||
|
{
|
||||||
|
if(iter->first.getCell()==cellStore)
|
||||||
|
mActivators.erase(iter++);
|
||||||
|
else
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Activators::update(float duration, bool paused)
|
||||||
|
{
|
||||||
|
if(!paused)
|
||||||
|
{
|
||||||
|
for(PtrControllerMap::iterator iter(mActivators.begin());iter != mActivators.end();++iter)
|
||||||
|
iter->second.update(duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Activators::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number)
|
||||||
|
{
|
||||||
|
PtrControllerMap::iterator iter = mActivators.find(ptr);
|
||||||
|
if(iter != mActivators.end())
|
||||||
|
iter->second.playGroup(groupName, mode, number);
|
||||||
|
}
|
||||||
|
void Activators::skipAnimation(const MWWorld::Ptr& ptr)
|
||||||
|
{
|
||||||
|
PtrControllerMap::iterator iter = mActivators.find(ptr);
|
||||||
|
if(iter != mActivators.end())
|
||||||
|
iter->second.skipAnim();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
#ifndef GAME_MWMECHANICS_ACTIVATORS_H
|
||||||
|
#define GAME_MWMECHANICS_ACTOVATRS_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include "character.hpp"
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
class Ptr;
|
||||||
|
class CellStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWMechanics
|
||||||
|
{
|
||||||
|
class Activators
|
||||||
|
{
|
||||||
|
typedef std::map<MWWorld::Ptr,CharacterController> PtrControllerMap;
|
||||||
|
PtrControllerMap mActivators;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Activators();
|
||||||
|
|
||||||
|
void addActivator (const MWWorld::Ptr& ptr);
|
||||||
|
///< Register an animated activator
|
||||||
|
|
||||||
|
void removeActivator (const MWWorld::Ptr& ptr);
|
||||||
|
///< Deregister an activator
|
||||||
|
|
||||||
|
void updateActivatorCell(const MWWorld::Ptr& ptr);
|
||||||
|
///< Updates an activator with a new cell store
|
||||||
|
|
||||||
|
void dropActivators (const MWWorld::CellStore *cellStore);
|
||||||
|
///< Deregister all activators in the given cell.
|
||||||
|
|
||||||
|
void update (float duration, bool paused);
|
||||||
|
///< Update activator animations
|
||||||
|
|
||||||
|
void playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number);
|
||||||
|
void skipAnimation(const MWWorld::Ptr& ptr);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,290 @@
|
|||||||
|
/*
|
||||||
|
* OpenMW - The completely unofficial reimplementation of Morrowind
|
||||||
|
*
|
||||||
|
* This file (character.cpp) is part of the OpenMW package.
|
||||||
|
*
|
||||||
|
* OpenMW is distributed as free software: you can redistribute it
|
||||||
|
* and/or modify it under the terms of the GNU General Public License
|
||||||
|
* version 3, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* version 3 along with this program. If not, see
|
||||||
|
* http://www.gnu.org/licenses/ .
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "character.hpp"
|
||||||
|
|
||||||
|
#include <OgreStringConverter.h>
|
||||||
|
|
||||||
|
#include "../mwrender/animation.hpp"
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace MWMechanics
|
||||||
|
{
|
||||||
|
|
||||||
|
static const struct {
|
||||||
|
CharacterState state;
|
||||||
|
const char groupname[32];
|
||||||
|
} sStateList[] = {
|
||||||
|
{ CharState_Idle, "idle" },
|
||||||
|
{ CharState_Idle2, "idle2" },
|
||||||
|
{ CharState_Idle3, "idle3" },
|
||||||
|
{ CharState_Idle4, "idle4" },
|
||||||
|
{ CharState_Idle5, "idle5" },
|
||||||
|
{ CharState_Idle6, "idle6" },
|
||||||
|
{ CharState_Idle7, "idle7" },
|
||||||
|
{ CharState_Idle8, "idle8" },
|
||||||
|
{ CharState_Idle9, "idle9" },
|
||||||
|
{ CharState_IdleSwim, "idleswim" },
|
||||||
|
|
||||||
|
{ CharState_WalkForward, "walkforward" },
|
||||||
|
{ CharState_WalkBack, "walkback" },
|
||||||
|
{ CharState_WalkLeft, "walkleft" },
|
||||||
|
{ CharState_WalkRight, "walkright" },
|
||||||
|
|
||||||
|
{ CharState_SwimWalkForward, "swimwalkforward" },
|
||||||
|
{ CharState_SwimWalkBack, "swimwalkback" },
|
||||||
|
{ CharState_SwimWalkLeft, "swimwalkleft" },
|
||||||
|
{ CharState_SwimWalkRight, "swimwalkright" },
|
||||||
|
|
||||||
|
{ CharState_RunForward, "runforward" },
|
||||||
|
{ CharState_RunBack, "runback" },
|
||||||
|
{ CharState_RunLeft, "runleft" },
|
||||||
|
{ CharState_RunRight, "runright" },
|
||||||
|
|
||||||
|
{ CharState_SwimRunForward, "swimrunforward" },
|
||||||
|
{ CharState_SwimRunBack, "swimrunback" },
|
||||||
|
{ CharState_SwimRunLeft, "swimrunleft" },
|
||||||
|
{ CharState_SwimRunRight, "swimrunright" },
|
||||||
|
|
||||||
|
{ CharState_Jump, "jump" },
|
||||||
|
|
||||||
|
{ CharState_Death1, "death1" },
|
||||||
|
{ CharState_Death2, "death2" },
|
||||||
|
{ CharState_Death3, "death3" },
|
||||||
|
{ CharState_Death4, "death4" },
|
||||||
|
{ CharState_Death5, "death5" },
|
||||||
|
};
|
||||||
|
static const size_t sStateListSize = sizeof(sStateList)/sizeof(sStateList[0]);
|
||||||
|
|
||||||
|
static void getStateInfo(CharacterState state, std::string *group)
|
||||||
|
{
|
||||||
|
for(size_t i = 0;i < sStateListSize;i++)
|
||||||
|
{
|
||||||
|
if(sStateList[i].state == state)
|
||||||
|
{
|
||||||
|
*group = sStateList[i].groupname;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop)
|
||||||
|
: mPtr(ptr), mAnimation(anim), mState(state), mSkipAnim(false)
|
||||||
|
{
|
||||||
|
if(!mAnimation)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mAnimation->setController(this);
|
||||||
|
|
||||||
|
getStateInfo(mState, &mCurrentGroup);
|
||||||
|
if(ptr.getTypeName() == typeid(ESM::Activator).name())
|
||||||
|
{
|
||||||
|
/* Don't accumulate with activators (they don't get moved). */
|
||||||
|
mAnimation->setAccumulation(Ogre::Vector3::ZERO);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Accumulate along X/Y only for now, until we can figure out how we should
|
||||||
|
* handle knockout and death which moves the character down. */
|
||||||
|
mAnimation->setAccumulation(Ogre::Vector3(1.0f, 1.0f, 0.0f));
|
||||||
|
}
|
||||||
|
if(mAnimation->hasAnimation(mCurrentGroup))
|
||||||
|
mAnimation->play(mCurrentGroup, "stop", "stop", loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
CharacterController::CharacterController(const CharacterController &rhs)
|
||||||
|
: mPtr(rhs.mPtr), mAnimation(rhs.mAnimation), mAnimQueue(rhs.mAnimQueue)
|
||||||
|
, mCurrentGroup(rhs.mCurrentGroup), mState(rhs.mState)
|
||||||
|
, mSkipAnim(rhs.mSkipAnim)
|
||||||
|
{
|
||||||
|
if(!mAnimation)
|
||||||
|
return;
|
||||||
|
/* We've been copied. Update the animation with the new controller. */
|
||||||
|
mAnimation->setController(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
CharacterController::~CharacterController()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CharacterController::markerEvent(float time, const std::string &evt)
|
||||||
|
{
|
||||||
|
if(evt == "stop")
|
||||||
|
{
|
||||||
|
if(mAnimQueue.size() >= 2 && mAnimQueue[0] == mAnimQueue[1])
|
||||||
|
{
|
||||||
|
mAnimQueue.pop_front();
|
||||||
|
mAnimation->play(mCurrentGroup, "loop start", "stop", false);
|
||||||
|
}
|
||||||
|
else if(mAnimQueue.size() > 0)
|
||||||
|
{
|
||||||
|
mAnimQueue.pop_front();
|
||||||
|
if(mAnimQueue.size() > 0)
|
||||||
|
{
|
||||||
|
mCurrentGroup = mAnimQueue.front();
|
||||||
|
mAnimation->play(mCurrentGroup, "start", "stop", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr<< "Unhandled animation event: "<<evt <<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Ogre::Vector3 CharacterController::update(float duration)
|
||||||
|
{
|
||||||
|
Ogre::Vector3 movement(0.0f);
|
||||||
|
|
||||||
|
float speed = 0.0f;
|
||||||
|
if(!(getState() >= CharState_Death1))
|
||||||
|
{
|
||||||
|
const MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
|
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
|
||||||
|
const Ogre::Vector3 &vec = cls.getMovementVector(mPtr);
|
||||||
|
|
||||||
|
bool onground = world->isOnGround(mPtr);
|
||||||
|
bool inwater = world->isSwimming(mPtr);
|
||||||
|
bool isrunning = cls.getStance(mPtr, MWWorld::Class::Run);
|
||||||
|
speed = cls.getSpeed(mPtr);
|
||||||
|
|
||||||
|
/* FIXME: The state should be set to Jump, and X/Y movement should be disallowed except
|
||||||
|
* for the initial thrust (which would be carried by "physics" until landing). */
|
||||||
|
if(onground && vec.z > 0.0f)
|
||||||
|
{
|
||||||
|
float x = cls.getJump(mPtr);
|
||||||
|
|
||||||
|
if(vec.x == 0 && vec.y == 0)
|
||||||
|
movement.z += x*duration;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* FIXME: this would be more correct if we were going into a jumping state,
|
||||||
|
* rather than normal walking/idle states. */
|
||||||
|
//Ogre::Vector3 lat = Ogre::Vector3(vec.x, vec.y, 0.0f).normalisedCopy();
|
||||||
|
//movement += Ogre::Vector3(lat.x, lat.y, 1.0f) * x * 0.707f * duration;
|
||||||
|
movement.z += x * 0.707f * duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
//decrease fatigue by fFatigueJumpBase + (1 - normalizedEncumbrance) * fFatigueJumpMult;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(std::abs(vec.x/2.0f) > std::abs(vec.y) && speed > 0.0f)
|
||||||
|
{
|
||||||
|
if(vec.x > 0.0f)
|
||||||
|
setState(isrunning ?
|
||||||
|
(inwater ? CharState_SwimRunRight : CharState_RunRight) :
|
||||||
|
(inwater ? CharState_SwimWalkRight : CharState_WalkRight), true);
|
||||||
|
else if(vec.x < 0.0f)
|
||||||
|
setState(isrunning ?
|
||||||
|
(inwater ? CharState_SwimRunLeft: CharState_RunLeft) :
|
||||||
|
(inwater ? CharState_SwimWalkLeft : CharState_WalkLeft), true);
|
||||||
|
// Apply any forward/backward movement manually
|
||||||
|
movement.y += vec.y * (speed*duration);
|
||||||
|
}
|
||||||
|
else if(vec.y != 0.0f && speed > 0.0f)
|
||||||
|
{
|
||||||
|
if(vec.y > 0.0f)
|
||||||
|
setState(isrunning ?
|
||||||
|
(inwater ? CharState_SwimRunForward : CharState_RunForward) :
|
||||||
|
(inwater ? CharState_SwimWalkForward : CharState_WalkForward), true);
|
||||||
|
else if(vec.y < 0.0f)
|
||||||
|
setState(isrunning ?
|
||||||
|
(inwater ? CharState_SwimRunBack : CharState_RunBack) :
|
||||||
|
(inwater ? CharState_SwimWalkBack : CharState_WalkBack), true);
|
||||||
|
// Apply any sideways movement manually
|
||||||
|
movement.x += vec.x * (speed*duration);
|
||||||
|
}
|
||||||
|
else if(mAnimQueue.size() == 0)
|
||||||
|
setState((inwater ? CharState_IdleSwim : CharState_Idle), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mAnimation && !mSkipAnim)
|
||||||
|
{
|
||||||
|
mAnimation->setSpeed(speed);
|
||||||
|
movement += mAnimation->runAnimation(duration);
|
||||||
|
}
|
||||||
|
mSkipAnim = false;
|
||||||
|
|
||||||
|
return movement;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CharacterController::playGroup(const std::string &groupname, int mode, int count)
|
||||||
|
{
|
||||||
|
if(!mAnimation || !mAnimation->hasAnimation(groupname))
|
||||||
|
std::cerr<< "Animation "<<groupname<<" not found" <<std::endl;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count = std::max(count, 1);
|
||||||
|
if(mode != 0 || mAnimQueue.size() == 0)
|
||||||
|
{
|
||||||
|
mAnimQueue.clear();
|
||||||
|
while(count-- > 0)
|
||||||
|
mAnimQueue.push_back(groupname);
|
||||||
|
mCurrentGroup = groupname;
|
||||||
|
mState = CharState_SpecialIdle;
|
||||||
|
mAnimation->play(mCurrentGroup, ((mode==2) ? "loop start" : "start"), "stop", false);
|
||||||
|
}
|
||||||
|
else if(mode == 0)
|
||||||
|
{
|
||||||
|
mAnimQueue.resize(1);
|
||||||
|
while(count-- > 0)
|
||||||
|
mAnimQueue.push_back(groupname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterController::skipAnim()
|
||||||
|
{
|
||||||
|
mSkipAnim = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CharacterController::setState(CharacterState state, bool loop)
|
||||||
|
{
|
||||||
|
if(mState == state)
|
||||||
|
{
|
||||||
|
if(mAnimation)
|
||||||
|
mAnimation->setLooping(loop);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mState = state;
|
||||||
|
|
||||||
|
if(!mAnimation)
|
||||||
|
return;
|
||||||
|
mAnimQueue.clear();
|
||||||
|
|
||||||
|
std::string anim;
|
||||||
|
getStateInfo(mState, &anim);
|
||||||
|
if(mAnimation->hasAnimation(anim))
|
||||||
|
{
|
||||||
|
mCurrentGroup = anim;
|
||||||
|
mAnimation->play(mCurrentGroup, "start", "stop", loop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
#ifndef GAME_MWMECHANICS_CHARACTER_HPP
|
||||||
|
#define GAME_MWMECHANICS_CHARACTER_HPP
|
||||||
|
|
||||||
|
#include <OgreVector3.h>
|
||||||
|
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
|
namespace MWRender
|
||||||
|
{
|
||||||
|
class Animation;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWMechanics
|
||||||
|
{
|
||||||
|
|
||||||
|
enum CharacterState {
|
||||||
|
CharState_SpecialIdle,
|
||||||
|
CharState_Idle,
|
||||||
|
CharState_Idle2,
|
||||||
|
CharState_Idle3,
|
||||||
|
CharState_Idle4,
|
||||||
|
CharState_Idle5,
|
||||||
|
CharState_Idle6,
|
||||||
|
CharState_Idle7,
|
||||||
|
CharState_Idle8,
|
||||||
|
CharState_Idle9,
|
||||||
|
CharState_IdleSwim,
|
||||||
|
|
||||||
|
CharState_WalkForward,
|
||||||
|
CharState_WalkBack,
|
||||||
|
CharState_WalkLeft,
|
||||||
|
CharState_WalkRight,
|
||||||
|
|
||||||
|
CharState_SwimWalkForward,
|
||||||
|
CharState_SwimWalkBack,
|
||||||
|
CharState_SwimWalkLeft,
|
||||||
|
CharState_SwimWalkRight,
|
||||||
|
|
||||||
|
CharState_RunForward,
|
||||||
|
CharState_RunBack,
|
||||||
|
CharState_RunLeft,
|
||||||
|
CharState_RunRight,
|
||||||
|
|
||||||
|
CharState_SwimRunForward,
|
||||||
|
CharState_SwimRunBack,
|
||||||
|
CharState_SwimRunLeft,
|
||||||
|
CharState_SwimRunRight,
|
||||||
|
|
||||||
|
CharState_Jump,
|
||||||
|
|
||||||
|
/* Death states must be last! */
|
||||||
|
CharState_Death1,
|
||||||
|
CharState_Death2,
|
||||||
|
CharState_Death3,
|
||||||
|
CharState_Death4,
|
||||||
|
CharState_Death5
|
||||||
|
};
|
||||||
|
|
||||||
|
class CharacterController
|
||||||
|
{
|
||||||
|
MWWorld::Ptr mPtr;
|
||||||
|
MWRender::Animation *mAnimation;
|
||||||
|
|
||||||
|
typedef std::deque<std::string> AnimationQueue;
|
||||||
|
AnimationQueue mAnimQueue;
|
||||||
|
|
||||||
|
std::string mCurrentGroup;
|
||||||
|
CharacterState mState;
|
||||||
|
bool mSkipAnim;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* Called by the animation whenever a new text key is reached. */
|
||||||
|
void markerEvent(float time, const std::string &evt);
|
||||||
|
|
||||||
|
friend class MWRender::Animation;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop);
|
||||||
|
CharacterController(const CharacterController &rhs);
|
||||||
|
virtual ~CharacterController();
|
||||||
|
|
||||||
|
Ogre::Vector3 update(float duration);
|
||||||
|
|
||||||
|
void playGroup(const std::string &groupname, int mode, int count);
|
||||||
|
void skipAnim();
|
||||||
|
|
||||||
|
void setState(CharacterState state, bool loop);
|
||||||
|
CharacterState getState() const
|
||||||
|
{ return mState; }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* GAME_MWMECHANICS_CHARACTER_HPP */
|
@ -0,0 +1,58 @@
|
|||||||
|
#include "activatoranimation.hpp"
|
||||||
|
|
||||||
|
#include <OgreEntity.h>
|
||||||
|
#include <OgreSceneManager.h>
|
||||||
|
#include <OgreSubEntity.h>
|
||||||
|
|
||||||
|
#include "renderconst.hpp"
|
||||||
|
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
|
namespace MWRender
|
||||||
|
{
|
||||||
|
|
||||||
|
ActivatorAnimation::~ActivatorAnimation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ActivatorAnimation::ActivatorAnimation(const MWWorld::Ptr &ptr)
|
||||||
|
: Animation(ptr)
|
||||||
|
{
|
||||||
|
MWWorld::LiveCellRef<ESM::Activator> *ref = mPtr.get<ESM::Activator>();
|
||||||
|
|
||||||
|
assert (ref->mBase != NULL);
|
||||||
|
if(!ref->mBase->mModel.empty())
|
||||||
|
{
|
||||||
|
std::string mesh = "meshes\\" + ref->mBase->mModel;
|
||||||
|
|
||||||
|
createEntityList(mPtr.getRefData().getBaseNode(), mesh);
|
||||||
|
for(size_t i = 0;i < mEntityList.mEntities.size();i++)
|
||||||
|
{
|
||||||
|
Ogre::Entity *ent = mEntityList.mEntities[i];
|
||||||
|
|
||||||
|
bool transparent = false;
|
||||||
|
for (unsigned int j=0;j < ent->getNumSubEntities() && !transparent; ++j)
|
||||||
|
{
|
||||||
|
Ogre::MaterialPtr mat = ent->getSubEntity(j)->getMaterial();
|
||||||
|
Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
|
||||||
|
while (techIt.hasMoreElements() && !transparent)
|
||||||
|
{
|
||||||
|
Ogre::Technique* tech = techIt.getNext();
|
||||||
|
Ogre::Technique::PassIterator passIt = tech->getPassIterator();
|
||||||
|
while (passIt.hasMoreElements() && !transparent)
|
||||||
|
{
|
||||||
|
Ogre::Pass* pass = passIt.getNext();
|
||||||
|
|
||||||
|
if (pass->getDepthWriteEnabled() == false)
|
||||||
|
transparent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ent->setVisibilityFlags(RV_Misc);
|
||||||
|
ent->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
|
||||||
|
}
|
||||||
|
setAnimationSource(mesh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef _GAME_RENDER_ACTIVATORANIMATION_H
|
||||||
|
#define _GAME_RENDER_ACTIVATORANIMATION_H
|
||||||
|
|
||||||
|
#include "animation.hpp"
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
class Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWRender
|
||||||
|
{
|
||||||
|
class ActivatorAnimation : public Animation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ActivatorAnimation(const MWWorld::Ptr& ptr);
|
||||||
|
virtual ~ActivatorAnimation();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,148 +1,460 @@
|
|||||||
#include "animation.hpp"
|
#include "animation.hpp"
|
||||||
|
|
||||||
#include <OgreHardwarePixelBuffer.h>
|
#include <OgreSkeletonManager.h>
|
||||||
#include <OgreSkeletonInstance.h>
|
#include <OgreSkeletonInstance.h>
|
||||||
#include <OgreEntity.h>
|
#include <OgreEntity.h>
|
||||||
#include <OgreBone.h>
|
#include <OgreBone.h>
|
||||||
#include <OgreSubMesh.h>
|
#include <OgreSubMesh.h>
|
||||||
#include <OgreSceneManager.h>
|
#include <OgreSceneManager.h>
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/soundmanager.hpp"
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
|
#include "../mwmechanics/character.hpp"
|
||||||
|
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
Animation::Animation()
|
Animation::Animation(const MWWorld::Ptr &ptr)
|
||||||
: mInsert(NULL)
|
: mPtr(ptr)
|
||||||
, mTime(0.0f)
|
, mController(NULL)
|
||||||
, mSkipFrame(false)
|
, mInsert(NULL)
|
||||||
|
, mAccumRoot(NULL)
|
||||||
|
, mNonAccumRoot(NULL)
|
||||||
|
, mAccumulate(Ogre::Vector3::ZERO)
|
||||||
|
, mLastPosition(0.0f)
|
||||||
|
, mCurrentKeys(NULL)
|
||||||
|
, mCurrentAnim(NULL)
|
||||||
|
, mCurrentTime(0.0f)
|
||||||
|
, mStopTime(0.0f)
|
||||||
|
, mPlaying(false)
|
||||||
|
, mLooping(false)
|
||||||
|
, mAnimVelocity(0.0f)
|
||||||
|
, mAnimSpeedMult(1.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation::~Animation()
|
Animation::~Animation()
|
||||||
{
|
{
|
||||||
Ogre::SceneManager *sceneMgr = mInsert->getCreator();
|
if(mInsert)
|
||||||
for(size_t i = 0;i < mEntityList.mEntities.size();i++)
|
{
|
||||||
sceneMgr->destroyEntity(mEntityList.mEntities[i]);
|
Ogre::SceneManager *sceneMgr = mInsert->getCreator();
|
||||||
|
for(size_t i = 0;i < mEntityList.mEntities.size();i++)
|
||||||
|
sceneMgr->destroyEntity(mEntityList.mEntities[i]);
|
||||||
|
}
|
||||||
mEntityList.mEntities.clear();
|
mEntityList.mEntities.clear();
|
||||||
|
mEntityList.mSkelBase = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct checklow {
|
void Animation::setAnimationSources(const std::vector<std::string> &names)
|
||||||
bool operator()(const char &a, const char &b) const
|
{
|
||||||
|
if(!mEntityList.mSkelBase)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Ogre::SkeletonManager &skelMgr = Ogre::SkeletonManager::getSingleton();
|
||||||
|
|
||||||
|
mCurrentAnim = NULL;
|
||||||
|
mCurrentKeys = NULL;
|
||||||
|
mAnimVelocity = 0.0f;
|
||||||
|
mAccumRoot = NULL;
|
||||||
|
mNonAccumRoot = NULL;
|
||||||
|
mSkeletonSources.clear();
|
||||||
|
|
||||||
|
std::vector<std::string>::const_iterator nameiter = names.begin();
|
||||||
|
for(nameiter = names.begin();nameiter != names.end();nameiter++)
|
||||||
{
|
{
|
||||||
return ::tolower(a) == ::tolower(b);
|
Ogre::SkeletonPtr skel = skelMgr.getByName(*nameiter);
|
||||||
|
if(skel.isNull())
|
||||||
|
{
|
||||||
|
NifOgre::Loader::createSkeleton(*nameiter);
|
||||||
|
skel = skelMgr.getByName(*nameiter);
|
||||||
|
if(skel.isNull())
|
||||||
|
{
|
||||||
|
std::cerr<< "Failed to get skeleton source "<<*nameiter <<std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
skel->touch();
|
||||||
|
|
||||||
|
Ogre::Skeleton::BoneIterator boneiter = skel->getBoneIterator();
|
||||||
|
while(boneiter.hasMoreElements())
|
||||||
|
{
|
||||||
|
Ogre::Bone *bone = boneiter.getNext();
|
||||||
|
Ogre::UserObjectBindings &bindings = bone->getUserObjectBindings();
|
||||||
|
const Ogre::Any &data = bindings.getUserAny(NifOgre::sTextKeyExtraDataID);
|
||||||
|
if(data.isEmpty() || !Ogre::any_cast<bool>(data))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!mNonAccumRoot)
|
||||||
|
{
|
||||||
|
mAccumRoot = mInsert;
|
||||||
|
mNonAccumRoot = mEntityList.mSkelBase->getSkeleton()->getBone(bone->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
mSkeletonSources.push_back(skel);
|
||||||
|
for(int i = 0;i < skel->getNumAnimations();i++)
|
||||||
|
{
|
||||||
|
Ogre::Animation *anim = skel->getAnimation(i);
|
||||||
|
const Ogre::Any &groupdata = bindings.getUserAny(std::string(NifOgre::sTextKeyExtraDataID)+
|
||||||
|
"@"+anim->getName());
|
||||||
|
if(!groupdata.isEmpty())
|
||||||
|
mTextKeys[anim->getName()] = Ogre::any_cast<NifOgre::TextKeyMap>(groupdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
bool Animation::findGroupTimes(const std::string &groupname, Animation::GroupTimes *times)
|
void Animation::createEntityList(Ogre::SceneNode *node, const std::string &model)
|
||||||
{
|
{
|
||||||
const std::string &start = groupname+": start";
|
mInsert = node->createChildSceneNode();
|
||||||
const std::string &startloop = groupname+": loop start";
|
assert(mInsert);
|
||||||
const std::string &stop = groupname+": stop";
|
|
||||||
const std::string &stoploop = groupname+": loop stop";
|
|
||||||
|
|
||||||
NifOgre::TextKeyMap::const_iterator iter;
|
mEntityList = NifOgre::Loader::createEntities(mInsert, model);
|
||||||
for(iter = mTextKeys.begin();iter != mTextKeys.end();iter++)
|
if(mEntityList.mSkelBase)
|
||||||
{
|
{
|
||||||
if(times->mStart >= 0.0f && times->mLoopStart >= 0.0f && times->mLoopStop >= 0.0f && times->mStop >= 0.0f)
|
Ogre::AnimationStateSet *aset = mEntityList.mSkelBase->getAllAnimationStates();
|
||||||
|
Ogre::AnimationStateIterator asiter = aset->getAnimationStateIterator();
|
||||||
|
while(asiter.hasMoreElements())
|
||||||
|
{
|
||||||
|
Ogre::AnimationState *state = asiter.getNext();
|
||||||
|
state->setEnabled(false);
|
||||||
|
state->setLoop(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the bones as manually controlled since we're applying the
|
||||||
|
// transformations manually (needed if we want to apply an animation
|
||||||
|
// from one skeleton onto another).
|
||||||
|
Ogre::SkeletonInstance *skelinst = mEntityList.mSkelBase->getSkeleton();
|
||||||
|
Ogre::Skeleton::BoneIterator boneiter = skelinst->getBoneIterator();
|
||||||
|
while(boneiter.hasMoreElements())
|
||||||
|
boneiter.getNext()->setManuallyControlled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Animation::hasAnimation(const std::string &anim)
|
||||||
|
{
|
||||||
|
for(std::vector<Ogre::SkeletonPtr>::const_iterator iter(mSkeletonSources.begin());iter != mSkeletonSources.end();iter++)
|
||||||
|
{
|
||||||
|
if((*iter)->hasAnimation(anim))
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Animation::setController(MWMechanics::CharacterController *controller)
|
||||||
|
{
|
||||||
|
mController = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Animation::setAccumulation(const Ogre::Vector3 &accum)
|
||||||
|
{
|
||||||
|
mAccumulate = accum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Animation::setSpeed(float speed)
|
||||||
|
{
|
||||||
|
mAnimSpeedMult = 1.0f;
|
||||||
|
if(mAnimVelocity > 1.0f && speed > 0.0f)
|
||||||
|
mAnimSpeedMult = speed / mAnimVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Animation::setLooping(bool loop)
|
||||||
|
{
|
||||||
|
mLooping = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Animation::updatePtr(const MWWorld::Ptr &ptr)
|
||||||
|
{
|
||||||
|
mPtr = ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string::const_iterator strpos = iter->second.begin();
|
void Animation::calcAnimVelocity()
|
||||||
std::string::const_iterator strend = iter->second.end();
|
{
|
||||||
size_t strlen = strend-strpos;
|
const Ogre::NodeAnimationTrack *track = 0;
|
||||||
|
|
||||||
if(start.size() <= strlen && std::mismatch(strpos, strend, start.begin(), checklow()).first == strend)
|
Ogre::Animation::NodeTrackIterator trackiter = mCurrentAnim->getNodeTrackIterator();
|
||||||
|
while(!track && trackiter.hasMoreElements())
|
||||||
|
{
|
||||||
|
const Ogre::NodeAnimationTrack *cur = trackiter.getNext();
|
||||||
|
if(cur->getAssociatedNode()->getName() == mNonAccumRoot->getName())
|
||||||
|
track = cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(track && track->getNumKeyFrames() > 1)
|
||||||
|
{
|
||||||
|
float loopstarttime = 0.0f;
|
||||||
|
float loopstoptime = mCurrentAnim->getLength();
|
||||||
|
NifOgre::TextKeyMap::const_iterator keyiter = mCurrentKeys->begin();
|
||||||
|
while(keyiter != mCurrentKeys->end())
|
||||||
{
|
{
|
||||||
times->mStart = iter->first;
|
if(keyiter->second == "loop start")
|
||||||
times->mLoopStart = iter->first;
|
loopstarttime = keyiter->first;
|
||||||
|
else if(keyiter->second == "loop stop")
|
||||||
|
{
|
||||||
|
loopstoptime = keyiter->first;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
keyiter++;
|
||||||
}
|
}
|
||||||
else if(startloop.size() <= strlen && std::mismatch(strpos, strend, startloop.begin(), checklow()).first == strend)
|
|
||||||
|
if(loopstoptime > loopstarttime)
|
||||||
{
|
{
|
||||||
times->mLoopStart = iter->first;
|
Ogre::TransformKeyFrame startkf(0, loopstarttime);
|
||||||
|
Ogre::TransformKeyFrame endkf(0, loopstoptime);
|
||||||
|
|
||||||
|
track->getInterpolatedKeyFrame(mCurrentAnim->_getTimeIndex(loopstarttime), &startkf);
|
||||||
|
track->getInterpolatedKeyFrame(mCurrentAnim->_getTimeIndex(loopstoptime), &endkf);
|
||||||
|
|
||||||
|
mAnimVelocity = startkf.getTranslate().distance(endkf.getTranslate()) /
|
||||||
|
(loopstoptime-loopstarttime);
|
||||||
}
|
}
|
||||||
else if(stoploop.size() <= strlen && std::mismatch(strpos, strend, stoploop.begin(), checklow()).first == strend)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Animation::applyAnimation(const Ogre::Animation *anim, float time, Ogre::SkeletonInstance *skel)
|
||||||
|
{
|
||||||
|
Ogre::TimeIndex timeindex = anim->_getTimeIndex(time);
|
||||||
|
Ogre::Animation::NodeTrackIterator tracks = anim->getNodeTrackIterator();
|
||||||
|
while(tracks.hasMoreElements())
|
||||||
|
{
|
||||||
|
Ogre::NodeAnimationTrack *track = tracks.getNext();
|
||||||
|
const Ogre::String &targetname = track->getAssociatedNode()->getName();
|
||||||
|
if(!skel->hasBone(targetname))
|
||||||
|
continue;
|
||||||
|
Ogre::Bone *bone = skel->getBone(targetname);
|
||||||
|
bone->setOrientation(Ogre::Quaternion::IDENTITY);
|
||||||
|
bone->setPosition(Ogre::Vector3::ZERO);
|
||||||
|
bone->setScale(Ogre::Vector3::UNIT_SCALE);
|
||||||
|
track->applyToNode(bone, timeindex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// HACK: Dirty the animation state set so that Ogre will apply the
|
||||||
|
// transformations to entities this skeleton instance is shared with.
|
||||||
|
mEntityList.mSkelBase->getAllAnimationStates()->_notifyDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void updateBoneTree(const Ogre::SkeletonInstance *skelsrc, Ogre::Bone *bone)
|
||||||
|
{
|
||||||
|
if(skelsrc->hasBone(bone->getName()))
|
||||||
|
{
|
||||||
|
Ogre::Bone *srcbone = skelsrc->getBone(bone->getName());
|
||||||
|
if(!srcbone->getParent() || !bone->getParent())
|
||||||
{
|
{
|
||||||
times->mLoopStop = iter->first;
|
bone->setOrientation(srcbone->getOrientation());
|
||||||
|
bone->setPosition(srcbone->getPosition());
|
||||||
|
bone->setScale(srcbone->getScale());
|
||||||
}
|
}
|
||||||
else if(stop.size() <= strlen && std::mismatch(strpos, strend, stop.begin(), checklow()).first == strend)
|
else
|
||||||
{
|
{
|
||||||
times->mStop = iter->first;
|
bone->_setDerivedOrientation(srcbone->_getDerivedOrientation());
|
||||||
if(times->mLoopStop < 0.0f)
|
bone->_setDerivedPosition(srcbone->_getDerivedPosition());
|
||||||
times->mLoopStop = iter->first;
|
bone->setScale(Ogre::Vector3::UNIT_SCALE);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No matching bone in the source. Make sure it stays properly offset
|
||||||
|
// from its parent.
|
||||||
|
bone->resetToInitialState();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ogre::Node::ChildNodeIterator boneiter = bone->getChildIterator();
|
||||||
|
while(boneiter.hasMoreElements())
|
||||||
|
updateBoneTree(skelsrc, static_cast<Ogre::Bone*>(boneiter.getNext()));
|
||||||
|
}
|
||||||
|
|
||||||
return (times->mStart >= 0.0f && times->mLoopStart >= 0.0f && times->mLoopStop >= 0.0f && times->mStop >= 0.0f);
|
void Animation::updateSkeletonInstance(const Ogre::SkeletonInstance *skelsrc, Ogre::SkeletonInstance *skel)
|
||||||
|
{
|
||||||
|
Ogre::Skeleton::BoneIterator boneiter = skel->getRootBoneIterator();
|
||||||
|
while(boneiter.hasMoreElements())
|
||||||
|
updateBoneTree(skelsrc, boneiter.getNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Animation::playGroup(std::string groupname, int mode, int loops)
|
Ogre::Vector3 Animation::updatePosition(float time)
|
||||||
{
|
{
|
||||||
GroupTimes times;
|
if(mLooping)
|
||||||
times.mLoops = loops;
|
mCurrentTime = std::fmod(std::max(time, 0.0f), mCurrentAnim->getLength());
|
||||||
|
else
|
||||||
|
mCurrentTime = std::min(mCurrentAnim->getLength(), std::max(time, 0.0f));
|
||||||
|
applyAnimation(mCurrentAnim, mCurrentTime, mEntityList.mSkelBase->getSkeleton());
|
||||||
|
|
||||||
if(groupname == "all")
|
Ogre::Vector3 posdiff = Ogre::Vector3::ZERO;
|
||||||
|
if(mNonAccumRoot)
|
||||||
{
|
{
|
||||||
times.mStart = times.mLoopStart = 0.0f;
|
/* Get the non-accumulation root's difference from the last update. */
|
||||||
times.mLoopStop = times.mStop = 0.0f;
|
posdiff = (mNonAccumRoot->getPosition() - mLastPosition) * mAccumulate;
|
||||||
|
|
||||||
NifOgre::TextKeyMap::const_reverse_iterator iter = mTextKeys.rbegin();
|
/* Translate the accumulation root back to compensate for the move. */
|
||||||
if(iter != mTextKeys.rend())
|
mLastPosition += posdiff;
|
||||||
times.mLoopStop = times.mStop = iter->first;
|
mAccumRoot->setPosition(-mLastPosition);
|
||||||
}
|
}
|
||||||
else if(!findGroupTimes(groupname, ×))
|
return posdiff;
|
||||||
throw std::runtime_error("Failed to find animation group "+groupname);
|
}
|
||||||
|
|
||||||
|
void Animation::reset(const std::string &start, const std::string &stop)
|
||||||
|
{
|
||||||
|
mNextKey = mCurrentKeys->begin();
|
||||||
|
|
||||||
if(mode == 0 && mCurGroup.mLoops > 0)
|
while(mNextKey != mCurrentKeys->end() && mNextKey->second != start)
|
||||||
mNextGroup = times;
|
mNextKey++;
|
||||||
|
if(mNextKey != mCurrentKeys->end())
|
||||||
|
mCurrentTime = mNextKey->first;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mCurGroup = times;
|
mNextKey = mCurrentKeys->begin();
|
||||||
mNextGroup = GroupTimes();
|
mCurrentTime = 0.0f;
|
||||||
mTime = ((mode==2) ? mCurGroup.mLoopStart : mCurGroup.mStart);
|
}
|
||||||
|
|
||||||
|
if(stop.length() > 0)
|
||||||
|
{
|
||||||
|
NifOgre::TextKeyMap::const_iterator stopKey = mNextKey;
|
||||||
|
while(stopKey != mCurrentKeys->end() && stopKey->second != stop)
|
||||||
|
stopKey++;
|
||||||
|
if(stopKey != mCurrentKeys->end())
|
||||||
|
mStopTime = stopKey->first;
|
||||||
|
else
|
||||||
|
mStopTime = mCurrentAnim->getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mNonAccumRoot)
|
||||||
|
{
|
||||||
|
const Ogre::NodeAnimationTrack *track = 0;
|
||||||
|
Ogre::Animation::NodeTrackIterator trackiter = mCurrentAnim->getNodeTrackIterator();
|
||||||
|
while(!track && trackiter.hasMoreElements())
|
||||||
|
{
|
||||||
|
const Ogre::NodeAnimationTrack *cur = trackiter.getNext();
|
||||||
|
if(cur->getAssociatedNode()->getName() == mNonAccumRoot->getName())
|
||||||
|
track = cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(track)
|
||||||
|
{
|
||||||
|
Ogre::TransformKeyFrame kf(0, mCurrentTime);
|
||||||
|
track->getInterpolatedKeyFrame(mCurrentAnim->_getTimeIndex(mCurrentTime), &kf);
|
||||||
|
mLastPosition = kf.getTranslate() * mAccumulate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::skipAnim()
|
|
||||||
|
bool Animation::handleEvent(float time, const std::string &evt)
|
||||||
{
|
{
|
||||||
mSkipFrame = true;
|
if(evt == "start" || evt == "loop start")
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(evt.compare(0, 7, "sound: ") == 0)
|
||||||
|
{
|
||||||
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||||
|
sndMgr->playSound3D(mPtr, evt.substr(7), 1.0f, 1.0f);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(evt.compare(0, 10, "soundgen: ") == 0)
|
||||||
|
{
|
||||||
|
// FIXME: Lookup the SoundGen (SNDG) for the specified sound that corresponds
|
||||||
|
// to this actor type
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(evt == "loop stop")
|
||||||
|
{
|
||||||
|
if(mLooping)
|
||||||
|
{
|
||||||
|
reset("loop start", "");
|
||||||
|
if(mCurrentTime >= time)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(evt == "stop")
|
||||||
|
{
|
||||||
|
if(mLooping)
|
||||||
|
{
|
||||||
|
reset("loop start", "");
|
||||||
|
if(mCurrentTime >= time)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// fall-through
|
||||||
|
}
|
||||||
|
if(mController)
|
||||||
|
mController->markerEvent(time, evt);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::runAnimation(float timepassed)
|
|
||||||
|
void Animation::play(const std::string &groupname, const std::string &start, const std::string &stop, bool loop)
|
||||||
{
|
{
|
||||||
if(mCurGroup.mLoops > 0 && !mSkipFrame)
|
try {
|
||||||
{
|
bool found = false;
|
||||||
mTime += timepassed;
|
/* Look in reverse; last-inserted source has priority. */
|
||||||
if(mTime >= mCurGroup.mLoopStop)
|
for(std::vector<Ogre::SkeletonPtr>::const_reverse_iterator iter(mSkeletonSources.rbegin());iter != mSkeletonSources.rend();iter++)
|
||||||
{
|
{
|
||||||
if(mCurGroup.mLoops > 1)
|
if((*iter)->hasAnimation(groupname))
|
||||||
{
|
|
||||||
mCurGroup.mLoops--;
|
|
||||||
mTime = mTime - mCurGroup.mLoopStop + mCurGroup.mLoopStart;
|
|
||||||
}
|
|
||||||
else if(mTime >= mCurGroup.mStop)
|
|
||||||
{
|
{
|
||||||
if(mNextGroup.mLoops > 0)
|
mCurrentAnim = (*iter)->getAnimation(groupname);
|
||||||
mTime = mTime - mCurGroup.mStop + mNextGroup.mStart;
|
mCurrentKeys = &mTextKeys[groupname];
|
||||||
else
|
mAnimVelocity = 0.0f;
|
||||||
mTime = mCurGroup.mStop;
|
|
||||||
mCurGroup = mNextGroup;
|
if(mNonAccumRoot)
|
||||||
mNextGroup = GroupTimes();
|
calcAnimVelocity();
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!found)
|
||||||
|
throw std::runtime_error("Failed to find animation "+groupname);
|
||||||
|
|
||||||
|
reset(start, stop);
|
||||||
|
setLooping(loop);
|
||||||
|
mPlaying = true;
|
||||||
|
}
|
||||||
|
catch(std::exception &e) {
|
||||||
|
std::cerr<< e.what() <<std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(mEntityList.mSkelBase)
|
Ogre::Vector3 Animation::runAnimation(float timepassed)
|
||||||
|
{
|
||||||
|
Ogre::Vector3 movement = Ogre::Vector3::ZERO;
|
||||||
|
|
||||||
|
timepassed *= mAnimSpeedMult;
|
||||||
|
while(mCurrentAnim && mPlaying)
|
||||||
|
{
|
||||||
|
float targetTime = std::min(mStopTime, mCurrentTime+timepassed);
|
||||||
|
if(mNextKey == mCurrentKeys->end() || mNextKey->first > targetTime)
|
||||||
{
|
{
|
||||||
Ogre::AnimationStateSet *aset = mEntityList.mSkelBase->getAllAnimationStates();
|
movement += updatePosition(targetTime);
|
||||||
Ogre::AnimationStateIterator as = aset->getAnimationStateIterator();
|
mPlaying = (mLooping || mStopTime > targetTime);
|
||||||
while(as.hasMoreElements())
|
break;
|
||||||
{
|
|
||||||
Ogre::AnimationState *state = as.getNext();
|
|
||||||
state->setTimePosition(mTime);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float time = mNextKey->first;
|
||||||
|
const std::string &evt = mNextKey->second;
|
||||||
|
mNextKey++;
|
||||||
|
|
||||||
|
movement += updatePosition(time);
|
||||||
|
mPlaying = (mLooping || mStopTime > time);
|
||||||
|
|
||||||
|
timepassed = targetTime - time;
|
||||||
|
|
||||||
|
if(!handleEvent(time, evt))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
mSkipFrame = false;
|
|
||||||
|
return movement;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,200 +0,0 @@
|
|||||||
#ifndef OENGINE_BULLET_PMOVE_H
|
|
||||||
#define OENGINE_BULLET_PMOVE_H
|
|
||||||
/*
|
|
||||||
This source file is a *modified* version of various header files from the Quake 3 Arena source code,
|
|
||||||
which was released under the GNU GPL (v2) in 2005.
|
|
||||||
Quake 3 Arena is copyright (C) 1999-2005 Id Software, Inc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <OgreMath.h>
|
|
||||||
#include <float.h>
|
|
||||||
#include "trace.h"
|
|
||||||
#include "physic.hpp"
|
|
||||||
|
|
||||||
#include <OgreVector3.h>
|
|
||||||
|
|
||||||
//#include "GameMath.h"
|
|
||||||
//#include "GameTime.h"
|
|
||||||
|
|
||||||
// Forwards-declare it!
|
|
||||||
|
|
||||||
/*#ifndef COMPILING_PMOVE
|
|
||||||
#include "Scene.h"
|
|
||||||
extern SceneInstance* global_lastscene;
|
|
||||||
#endif*/
|
|
||||||
|
|
||||||
static const Ogre::Vector3 halfExtentsDefault(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 (9)
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.14159265358979323846f
|
|
||||||
#endif
|
|
||||||
#define YAW 0
|
|
||||||
#define PITCH /*1*/2
|
|
||||||
#define ROLL /*2*/1
|
|
||||||
#define SHORT2ANGLE(x) ( (x) * (360.0f / 65536.0f) )
|
|
||||||
#define ANGLE2SHORT(x) ( (const short)( (x) / (360.0f / 65536.0f) ) )
|
|
||||||
#define GENTITYNUM_BITS 10 // don't need to send any more
|
|
||||||
#define MAX_GENTITIES (1 << GENTITYNUM_BITS)
|
|
||||||
#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 PS_PMOVEFRAMECOUNTBITS 6
|
|
||||||
#define MINS_Z -24
|
|
||||||
#define DEFAULT_VIEWHEIGHT 26
|
|
||||||
#define CROUCH_VIEWHEIGHT 12
|
|
||||||
#define DEAD_VIEWHEIGHT (-16)
|
|
||||||
#define CONTENTS_SOLID 1 // an eye is never valid in a solid
|
|
||||||
#define CONTENTS_LAVA 8
|
|
||||||
#define CONTENTS_SLIME 16
|
|
||||||
#define CONTENTS_WATER 32
|
|
||||||
#define CONTENTS_FOG 64
|
|
||||||
static const float pm_accelerate = 10.0f;
|
|
||||||
static const float pm_stopspeed = 100.0f;
|
|
||||||
static const float pm_friction = 12.0f;
|
|
||||||
static const float pm_flightfriction = 3.0f;
|
|
||||||
static const float pm_waterfriction = 1.0f;
|
|
||||||
static const float pm_airaccelerate = 1.0f;
|
|
||||||
static const float pm_swimScale = 0.50f;
|
|
||||||
static const float pm_duckScale = 0.25f;
|
|
||||||
static const float pm_flyaccelerate = 8.0f;
|
|
||||||
static const float pm_wateraccelerate = 4.0f;
|
|
||||||
|
|
||||||
enum pmtype_t
|
|
||||||
{
|
|
||||||
PM_NORMAL, // can accelerate and turn
|
|
||||||
PM_NOCLIP, // noclip movement
|
|
||||||
PM_SPECTATOR, // still run into walls
|
|
||||||
PM_DEAD, // no acceleration or turning, but free falling
|
|
||||||
PM_FREEZE, // stuck in place with no control
|
|
||||||
PM_INTERMISSION, // no movement or status bar
|
|
||||||
PM_SPINTERMISSION // no movement or status bar
|
|
||||||
};
|
|
||||||
|
|
||||||
enum waterlevel_t
|
|
||||||
{
|
|
||||||
WL_DRYLAND = 0,
|
|
||||||
WL_ANKLE,
|
|
||||||
WL_WAIST,
|
|
||||||
WL_UNDERWATER
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//#include "bprintf.h"
|
|
||||||
|
|
||||||
struct playerMove
|
|
||||||
{
|
|
||||||
struct playerStruct
|
|
||||||
{
|
|
||||||
playerStruct() : gravity(800.0f), speed(480.0f), jump_velocity(270), pmove_framecount(20), groundEntityNum(ENTITYNUM_NONE), commandTime(40), move_type(PM_NOCLIP), pm_time(0), snappingImplemented(true), bSnap(false), counter(-1), halfExtents(halfExtentsDefault)
|
|
||||||
{
|
|
||||||
origin = Ogre::Vector3(0.0f, 0.0f, 0.0f);
|
|
||||||
velocity = Ogre::Vector3(0.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
viewangles = Ogre::Vector3(0.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
delta_angles[0] = delta_angles[1] = delta_angles[2] = 0;
|
|
||||||
|
|
||||||
lastframe_origin.x = lastframe_origin.y = lastframe_origin.z = 0;
|
|
||||||
lerp_multiplier.x = lerp_multiplier.y = lerp_multiplier.z = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void SpeedUp(void)
|
|
||||||
{
|
|
||||||
//printf("speed up to: %f\n", speed);
|
|
||||||
speed *= 1.25f;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void SpeedDown(void)
|
|
||||||
{
|
|
||||||
//printf("speed down to %f\n", speed);
|
|
||||||
speed /= 1.25f;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ogre::Vector3 velocity;
|
|
||||||
Ogre::Vector3 origin;
|
|
||||||
Ogre::Vector3 halfExtents;
|
|
||||||
bool bSnap;
|
|
||||||
bool snappingImplemented;
|
|
||||||
int counter;
|
|
||||||
float gravity; // default = 800
|
|
||||||
float speed; // default = 320
|
|
||||||
float jump_velocity; //default = 270
|
|
||||||
|
|
||||||
int commandTime; // the time at which this command was issued (in milliseconds)
|
|
||||||
|
|
||||||
int pm_time;
|
|
||||||
|
|
||||||
Ogre::Vector3 viewangles;
|
|
||||||
|
|
||||||
int groundEntityNum;
|
|
||||||
|
|
||||||
int pmove_framecount;
|
|
||||||
|
|
||||||
int watertype;
|
|
||||||
waterlevel_t waterlevel;
|
|
||||||
|
|
||||||
signed short delta_angles[3];
|
|
||||||
|
|
||||||
pmtype_t move_type;
|
|
||||||
|
|
||||||
float last_compute_time;
|
|
||||||
Ogre::Vector3 lastframe_origin;
|
|
||||||
Ogre::Vector3 lerp_multiplier;
|
|
||||||
} ps;
|
|
||||||
|
|
||||||
struct playercmd
|
|
||||||
{
|
|
||||||
enum CMDstateChange
|
|
||||||
{
|
|
||||||
NO_CHANGE,
|
|
||||||
KEYDOWN,
|
|
||||||
KEYUP
|
|
||||||
};
|
|
||||||
|
|
||||||
playercmd() : forwardmove(0), rightmove(0), upmove(0), serverTime(50), ducking(false),
|
|
||||||
activating(false), lastActivatingState(false), procActivating(NO_CHANGE),
|
|
||||||
dropping(false), lastDroppingState(false), procDropping(NO_CHANGE)
|
|
||||||
{
|
|
||||||
angles[0] = angles[1] = angles[2] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int serverTime;
|
|
||||||
|
|
||||||
short angles[3];
|
|
||||||
|
|
||||||
signed char forwardmove;
|
|
||||||
signed char rightmove;
|
|
||||||
signed char upmove;
|
|
||||||
|
|
||||||
bool ducking;
|
|
||||||
bool activating; // if the user is holding down the activate button
|
|
||||||
bool dropping; // if the user is dropping an item
|
|
||||||
|
|
||||||
bool lastActivatingState;
|
|
||||||
bool lastDroppingState;
|
|
||||||
|
|
||||||
CMDstateChange procActivating;
|
|
||||||
CMDstateChange procDropping;
|
|
||||||
} cmd;
|
|
||||||
|
|
||||||
playerMove() : msec(50), pmove_fixed(false), pmove_msec(50), waterHeight(0), isInterior(true), hasWater(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int msec;
|
|
||||||
int pmove_msec;
|
|
||||||
bool pmove_fixed;
|
|
||||||
int waterHeight;
|
|
||||||
bool hasWater;
|
|
||||||
bool isInterior;
|
|
||||||
OEngine::Physic::PhysicEngine* mEngine;
|
|
||||||
};
|
|
||||||
|
|
||||||
void Pmove (playerMove* const pmove);
|
|
||||||
void Ext_UpdateViewAngles(playerMove* const pm);
|
|
||||||
void AngleVectors( const Ogre::Vector3& angles, Ogre::Vector3* const forward, Ogre::Vector3* const right, Ogre::Vector3* const up) ;
|
|
||||||
#endif
|
|
@ -1,196 +1,57 @@
|
|||||||
|
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include <btBulletDynamicsCommon.h>
|
||||||
|
#include <btBulletCollisionCommon.h>
|
||||||
|
|
||||||
|
#include "physic.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
enum traceWorldType
|
||||||
|
|
||||||
|
|
||||||
void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBHalfExtents, const float rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass) //Traceobj was a Aedra Object
|
|
||||||
{
|
{
|
||||||
//static float lastyaw = 0.0f;
|
collisionWorldTrace = 1,
|
||||||
//static float lastpitch = 0.0f;
|
pickWorldTrace = 2,
|
||||||
//if (!traceobj)
|
bothWorldTrace = collisionWorldTrace | pickWorldTrace
|
||||||
// return;
|
};
|
||||||
|
|
||||||
//if (!traceobj->incellptr)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
|
|
||||||
const Ogre::Vector3 rayDir = end - start;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NewPhysTraceResults out;
|
|
||||||
//std::cout << "Starting trace\n";
|
|
||||||
//Ogre::Vector3 startReplace = Ogre::Vector3(650,950, 45);
|
|
||||||
//Ogre::Vector3 endReplace = startReplace;
|
|
||||||
//endReplace.z -= .25;
|
|
||||||
|
|
||||||
const bool hasHit = NewPhysicsTrace<collisionWorldTrace>(&out, start, end, BBHalfExtents, Ogre::Vector3(0.0f, 0.0f, 0.0f), isInterior, enginePass);
|
|
||||||
|
|
||||||
if (out.fraction < 0.001f)
|
|
||||||
results->startsolid = true;
|
|
||||||
else
|
|
||||||
results->startsolid = false;
|
|
||||||
|
|
||||||
|
|
||||||
//results->allsolid = out.startSolid;
|
enum collaborativePhysicsType
|
||||||
|
|
||||||
// If outside and underground, we're solid
|
|
||||||
/*if (isInterior)
|
|
||||||
{
|
|
||||||
const Ogre::Vector3 height = GetGroundPosition(start, CellCoords(traceCell->data->gridX, traceCell->data->gridY) );
|
|
||||||
if (start.yPos - height.yPos < (-2.0f * BBHalfExtents.yPos) )
|
|
||||||
{
|
|
||||||
results->allsolid = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
results->allsolid = false;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// If inside and out of the tree, we're solid
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
results->allsolid = out.startSolid;
|
|
||||||
//std::cout << "allsolid" << results->allsolid << "\n";
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (!hasHit)
|
|
||||||
{
|
|
||||||
results->endpos = end;
|
|
||||||
results->planenormal = Ogre::Vector3(0.0f, 0.0f, 1.0f);
|
|
||||||
results->entityNum = ENTITYNUM_NONE;
|
|
||||||
results->fraction = 1.0f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
results->fraction = out.fraction;
|
|
||||||
results->planenormal = out.hitNormal;
|
|
||||||
results->endpos = rayDir * results->fraction + start;
|
|
||||||
results->entityNum = ENTITYNUM_WORLD;
|
|
||||||
/*bprintf("Start: (%f, %f, %f) End: (%f, %f, %f) TraceDir: (%f, %f, %f) HitNormal: (%f, %f, %f) Fraction: %f Hitpos: (%f, %f, %f) CompensatedHitpos: (%f, %f, %f)\n",
|
|
||||||
start.xPos, start.yPos, start.zPos,
|
|
||||||
end.xPos, end.yPos, end.zPos,
|
|
||||||
rayDir.xPos, rayDir.yPos, rayDir.zPos,
|
|
||||||
results->planenormal.xPos, results->planenormal.yPos, results->planenormal.zPos, results->fraction,
|
|
||||||
out.endPos.xPos, out.endPos.yPos, out.endPos.zPos,
|
|
||||||
results->endpos.xPos, results->endpos.yPos, results->endpos.zPos);*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <const traceWorldType traceType>
|
|
||||||
const bool NewPhysicsTrace(NewPhysTraceResults* const out, const Ogre::Vector3& start, const Ogre::Vector3& end,
|
|
||||||
const Ogre::Vector3& BBHalfExtents, const Ogre::Vector3& rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass)
|
|
||||||
{
|
{
|
||||||
//if (!traceobj->incellptr)
|
No_Physics = 0, // Both are empty (example: statics you can walk through, like tall grass)
|
||||||
// return false;
|
Only_Collision = 1, // This object only has collision physics but no pickup physics (example: statics)
|
||||||
//if(enginePass->dynamicsWorld->getCollisionObjectArray().at(60)->getCollisionShape()->isConvex())
|
Only_Pickup = 2, // This object only has pickup physics but no collision physics (example: items dropped on the ground)
|
||||||
// std::cout << "It's convex\n";
|
Both_Physics = 3 // This object has both kinds of physics (example: activators)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const btVector3 btstart(start.x, start.y, start.z + BBHalfExtents.z);
|
void newtrace(traceResults *results, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBHalfExtents, bool isInterior, OEngine::Physic::PhysicEngine *enginePass) //Traceobj was a Aedra Object
|
||||||
const btVector3 btend(end.x, end.y, end.z + BBHalfExtents.z);
|
{
|
||||||
const btQuaternion btrot(rotation.y, rotation.x, rotation.z); //y, x, z
|
const btVector3 btstart(start.x, start.y, start.z + BBHalfExtents.z);
|
||||||
|
const btVector3 btend(end.x, end.y, end.z + BBHalfExtents.z);
|
||||||
|
const btQuaternion btrot(0.0f, 0.0f, 0.0f); //y, x, z
|
||||||
|
|
||||||
const btBoxShape newshape(btVector3(BBHalfExtents.x, BBHalfExtents.y, BBHalfExtents.z));
|
const btBoxShape newshape(btVector3(BBHalfExtents.x, BBHalfExtents.y, BBHalfExtents.z));
|
||||||
//const btCapsuleShapeZ newshape(BBHalfExtents.x, BBHalfExtents.z * 2 - BBHalfExtents.x * 2);
|
//const btCapsuleShapeZ newshape(BBHalfExtents.x, BBHalfExtents.z * 2 - BBHalfExtents.x * 2);
|
||||||
const btTransform from(btrot, btstart);
|
const btTransform from(btrot, btstart);
|
||||||
const btTransform to(btrot, btend);
|
const btTransform to(btrot, btend);
|
||||||
|
|
||||||
// warning: unused variable ...
|
btCollisionWorld::ClosestConvexResultCallback newTraceCallback(btstart, btend);
|
||||||
/*
|
newTraceCallback.m_collisionFilterMask = Only_Collision;
|
||||||
float x = from.getOrigin().getX();
|
|
||||||
float y = from.getOrigin().getY();
|
enginePass->dynamicsWorld->convexSweepTest(&newshape, from, to, newTraceCallback);
|
||||||
float z = from.getOrigin().getZ();
|
|
||||||
float x2 = to.getOrigin().getX();
|
// Copy the hit data over to our trace results struct:
|
||||||
float y2 = to.getOrigin().getY();
|
if(newTraceCallback.hasHit())
|
||||||
float z2 = to.getOrigin().getZ();
|
{
|
||||||
*/
|
const btVector3& tracehitnormal = newTraceCallback.m_hitNormalWorld;
|
||||||
|
results->fraction = newTraceCallback.m_closestHitFraction;
|
||||||
//std::cout << "BtFrom: " << x << "," << y << "," << z << "\n";
|
results->planenormal = Ogre::Vector3(tracehitnormal.x(), tracehitnormal.y(), tracehitnormal.z());
|
||||||
//std::cout << "BtTo: " << x2 << "," << y2 << "," << z2 << "\n";
|
results->endpos = (end-start)*results->fraction + start;
|
||||||
//std::cout << "BtTo: " << to.getOrigin().getX() << "," << to.getOrigin().getY() << "," << to.getOrigin().getZ() << "\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
btCollisionWorld::ClosestConvexResultCallback
|
results->endpos = end;
|
||||||
newTraceCallback(btstart, btend);
|
results->planenormal = Ogre::Vector3(0.0f, 0.0f, 1.0f);
|
||||||
|
results->fraction = 1.0f;
|
||||||
newTraceCallback.m_collisionFilterMask = (traceType == collisionWorldTrace) ? Only_Collision : Only_Pickup;
|
}
|
||||||
|
|
||||||
|
|
||||||
enginePass->dynamicsWorld->convexSweepTest(&newshape, from, to, newTraceCallback);
|
|
||||||
//newTraceCallback.
|
|
||||||
|
|
||||||
|
|
||||||
//std::cout << "NUM: " << enginePass->dynamicsWorld->getNumCollisionObjects() << "\n";
|
|
||||||
|
|
||||||
// Copy the hit data over to our trace results struct:
|
|
||||||
out->fraction = newTraceCallback.m_closestHitFraction;
|
|
||||||
|
|
||||||
Ogre::Vector3& outhitnormal = out->hitNormal;
|
|
||||||
const btVector3& tracehitnormal = newTraceCallback.m_hitNormalWorld;
|
|
||||||
|
|
||||||
outhitnormal.x = tracehitnormal.x();
|
|
||||||
outhitnormal.y = tracehitnormal.y();
|
|
||||||
outhitnormal.z = tracehitnormal.z();
|
|
||||||
|
|
||||||
Ogre::Vector3& outhitpos = out->endPos;
|
|
||||||
const btVector3& tracehitpos = newTraceCallback.m_hitPointWorld;
|
|
||||||
|
|
||||||
outhitpos.x = tracehitpos.x();
|
|
||||||
outhitpos.y = tracehitpos.y();
|
|
||||||
outhitpos.z= tracehitpos.z();
|
|
||||||
|
|
||||||
// StartSolid test:
|
|
||||||
{
|
|
||||||
out->startSolid = false;
|
|
||||||
//btCollisionObject collision;
|
|
||||||
//collision.setCollisionShape(const_cast<btBoxShape* const>(&newshape) );
|
|
||||||
|
|
||||||
//CustomContactCallback crb;
|
|
||||||
|
|
||||||
//world.world->contactTest(&collision, crb);
|
|
||||||
//out->startSolid = crb.hit;
|
|
||||||
|
|
||||||
// If outside and underground, we're solid
|
|
||||||
if (!isInterior) //Check if we are interior
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// If inside and out of the tree, we're solid
|
|
||||||
else
|
|
||||||
{
|
|
||||||
btVector3 aabbMin, aabbMax;
|
|
||||||
enginePass->broadphase->getBroadphaseAabb(aabbMin, aabbMax);
|
|
||||||
//std::cout << "AABBMIN" << aabbMin.getX() <<"," <<aabbMin.getY() << "," << aabbMin.getZ() << "\n";
|
|
||||||
//std::cout << "AABBMAX" << aabbMax.getX() <<"," <<aabbMax.getY() << "," << aabbMax.getZ() << "\n";
|
|
||||||
//std::cout << "AABBMAX" << aabbMax << "\n";
|
|
||||||
if (!TestPointAgainstAabb2(aabbMin, aabbMax, *(const btVector3* const)&(start) ) )
|
|
||||||
{
|
|
||||||
//We're solid
|
|
||||||
//THIS NEEDS TO BE TURNED OFF IF WE WANT FALLING IN EXTERIORS TO WORK CORRECTLY!!!!!!!
|
|
||||||
//out->startSolid = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool hasHit = newTraceCallback.hasHit();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return hasHit;
|
|
||||||
}
|
}
|
||||||
|
@ -1,60 +1,26 @@
|
|||||||
#ifndef OENGINE_BULLET_TRACE_H
|
#ifndef OENGINE_BULLET_TRACE_H
|
||||||
#define OENGINE_BULLET_TRACE_H
|
#define OENGINE_BULLET_TRACE_H
|
||||||
|
|
||||||
|
#include <OgreVector3.h>
|
||||||
|
|
||||||
#include <btBulletDynamicsCommon.h>
|
|
||||||
#include <btBulletCollisionCommon.h>
|
|
||||||
#include <components/nifbullet/bullet_nif_loader.hpp>
|
|
||||||
#include <openengine/bullet/physic.hpp>
|
|
||||||
#include "pmove.h"
|
|
||||||
|
|
||||||
|
namespace OEngine
|
||||||
enum traceWorldType
|
|
||||||
{
|
{
|
||||||
collisionWorldTrace = 1,
|
namespace Physic
|
||||||
pickWorldTrace = 2,
|
{
|
||||||
bothWorldTrace = collisionWorldTrace | pickWorldTrace
|
class PhysicEngine;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum collaborativePhysicsType
|
|
||||||
{
|
|
||||||
No_Physics = 0, // Both are empty (example: statics you can walk through, like tall grass)
|
|
||||||
Only_Collision = 1, // This object only has collision physics but no pickup physics (example: statics)
|
|
||||||
Only_Pickup = 2, // This object only has pickup physics but no collision physics (example: items dropped on the ground)
|
|
||||||
Both_Physics = 3 // This object has both kinds of physics (example: activators)
|
|
||||||
};
|
|
||||||
|
|
||||||
struct NewPhysTraceResults
|
|
||||||
{
|
|
||||||
Ogre::Vector3 endPos;
|
|
||||||
Ogre::Vector3 hitNormal;
|
|
||||||
float fraction;
|
|
||||||
bool startSolid;
|
|
||||||
//const Object* hitObj;
|
|
||||||
};
|
|
||||||
struct traceResults
|
struct traceResults
|
||||||
{
|
{
|
||||||
Ogre::Vector3 endpos;
|
Ogre::Vector3 endpos;
|
||||||
Ogre::Vector3 planenormal;
|
Ogre::Vector3 planenormal;
|
||||||
|
|
||||||
float fraction;
|
float fraction;
|
||||||
|
|
||||||
int surfaceFlags;
|
|
||||||
int contents;
|
|
||||||
int entityNum;
|
|
||||||
|
|
||||||
bool allsolid;
|
|
||||||
bool startsolid;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void newtrace(traceResults *results, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBHalfExtents, bool isInterior, OEngine::Physic::PhysicEngine* enginePass);
|
||||||
|
|
||||||
template <const traceWorldType traceType>
|
|
||||||
const bool NewPhysicsTrace(NewPhysTraceResults* const out, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBExtents, const Ogre::Vector3& rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass);
|
|
||||||
//template const bool NewPhysicsTrace<collisionWorldTrace>(NewPhysTraceResults* const out, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBExtents, const Ogre::Vector3& rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass);
|
|
||||||
//template const bool NewPhysicsTrace<pickWorldTrace>(NewPhysTraceResults* const out, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBExtents, const Ogre::Vector3& rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass);
|
|
||||||
|
|
||||||
void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBExtents, const float rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue