You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
756 lines
19 KiB
756 lines
19 KiB
14 years ago
|
/*==LICENSE==*
|
||
|
|
||
|
CyanWorlds.com Engine - MMOG client, server and tools
|
||
|
Copyright (C) 2011 Cyan Worlds, Inc.
|
||
|
|
||
|
This program is free software: you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation, either version 3 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
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
|
||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
||
13 years ago
|
Additional permissions under GNU GPL version 3 section 7
|
||
|
|
||
|
If you modify this Program, or any covered work, by linking or
|
||
|
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
|
||
|
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
|
||
|
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
|
||
|
(or a modified version of those libraries),
|
||
|
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
|
||
|
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
|
||
|
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
|
||
|
licensors of this Program grant you additional
|
||
|
permission to convey the resulting work. Corresponding Source for a
|
||
|
non-source form of such a combination shall include the source code for
|
||
|
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
|
||
|
work.
|
||
|
|
||
14 years ago
|
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||
|
or by snail mail at:
|
||
|
Cyan Worlds, Inc.
|
||
|
14617 N Newport Hwy
|
||
|
Mead, WA 99021
|
||
|
|
||
|
*==LICENSE==*/
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// INCLUDES
|
||
|
//
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
// singular
|
||
|
#include "plAGAnim.h"
|
||
|
|
||
|
// local
|
||
|
#include "plMatrixChannel.h"
|
||
|
|
||
|
// global
|
||
|
#include "hsResMgr.h"
|
||
|
|
||
|
// other
|
||
11 years ago
|
#include "plInterp/plAnimEaseTypes.h"
|
||
14 years ago
|
#include "plMessage/plAnimCmdMsg.h"
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// STATICS
|
||
|
//
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
plAGAnim::plAnimMap plAGAnim::fAllAnims;
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// plAGAnim
|
||
|
//
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
// ctor ------------
|
||
|
// -----
|
||
|
plAGAnim::plAGAnim()
|
||
|
: plSynchedObject()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// ctor ------------------------------------------------------
|
||
|
// -----
|
||
13 years ago
|
plAGAnim::plAGAnim(const plString &name, double start, double end)
|
||
13 years ago
|
: fStart((float)start),
|
||
13 years ago
|
fEnd((float)end),
|
||
|
fName(name)
|
||
14 years ago
|
{
|
||
|
}
|
||
|
|
||
|
// dtor -------------
|
||
|
// -----
|
||
|
plAGAnim::~plAGAnim()
|
||
|
{
|
||
13 years ago
|
if (!fName.IsNull())
|
||
14 years ago
|
{
|
||
|
RemoveAnim(fName);
|
||
|
}
|
||
|
|
||
|
//int numChannels = fChannels.size();
|
||
|
int numApps = fApps.size();
|
||
|
|
||
|
for (int i = 0; i < numApps; i++)
|
||
|
{
|
||
|
plAGApplicator *app = fApps[i];
|
||
|
if (app)
|
||
|
{
|
||
|
plAGChannel *channel = app->GetChannel();
|
||
|
if(channel)
|
||
|
delete channel;
|
||
|
|
||
|
delete app;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// GetChannelCount ------------------
|
||
|
// ----------------
|
||
|
int plAGAnim::GetChannelCount() const
|
||
|
{
|
||
|
return fApps.size();
|
||
|
}
|
||
|
|
||
|
// GetChannel -------------------------------------
|
||
|
// -----------
|
||
|
plAGChannel * plAGAnim::GetChannel(int index) const
|
||
|
{
|
||
|
plAGApplicator *app = fApps[index];
|
||
|
return (app ? app->GetChannel() : nil);
|
||
|
}
|
||
|
|
||
|
// GetChannel --------------------------------------------
|
||
|
// -----------
|
||
13 years ago
|
plAGChannel * plAGAnim::GetChannel(const plString &name) const
|
||
14 years ago
|
{
|
||
|
int appCount = fApps.size();
|
||
|
|
||
|
for(int i = 0; i < appCount; i++)
|
||
|
{
|
||
|
plAGApplicator *app = fApps[i];
|
||
|
plAGChannel *channel = app->GetChannel();
|
||
13 years ago
|
plString channelName = app->GetChannelName();
|
||
14 years ago
|
|
||
13 years ago
|
if(name.Compare(channelName, plString::kCaseInsensitive) == 0)
|
||
14 years ago
|
{
|
||
|
return channel;
|
||
|
}
|
||
|
}
|
||
|
return nil;
|
||
|
}
|
||
|
|
||
|
// GetApplicatorCount ------------------
|
||
|
// -------------------
|
||
|
int plAGAnim::GetApplicatorCount() const
|
||
|
{
|
||
|
return fApps.size();
|
||
|
}
|
||
|
|
||
|
// GetApplicator -----------------------------------
|
||
|
// --------------
|
||
|
plAGApplicator *plAGAnim::GetApplicator(int i) const
|
||
|
{
|
||
|
return fApps[i];
|
||
|
}
|
||
|
|
||
|
// AddApplicator -------------------------------
|
||
|
// --------------
|
||
|
int plAGAnim::AddApplicator(plAGApplicator *app)
|
||
|
{
|
||
|
hsAssert(app->GetChannel(), "Adding an applicator with no channel");
|
||
|
fApps.push_back(app);
|
||
|
|
||
|
// return the index of the channel
|
||
|
return(fApps.size() - 1);
|
||
|
}
|
||
|
|
||
|
// RemoveApplicator ------------------------
|
||
|
// -----------------
|
||
13 years ago
|
bool plAGAnim::RemoveApplicator(int index)
|
||
14 years ago
|
{
|
||
|
hsAssert(index < fApps.size(), "Out of range index for plAGAnim::RemoveApp()");
|
||
|
|
||
|
if(index < fApps.size())
|
||
|
{
|
||
|
fApps.erase(fApps.begin() + index);
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ExtendToLength ----------------------------
|
||
|
// ---------------
|
||
13 years ago
|
void plAGAnim::ExtendToLength(float length)
|
||
14 years ago
|
{
|
||
|
if (length > GetEnd())
|
||
|
SetEnd(length);
|
||
|
}
|
||
|
|
||
|
// GetChannelName ------------------------------
|
||
|
// ---------------
|
||
13 years ago
|
plString plAGAnim::GetChannelName(int index)
|
||
14 years ago
|
{
|
||
|
hsAssert(index < fApps.size(), "Out of range index for plAGAnim::GetChannelName()");
|
||
|
|
||
|
if(index < fApps.size())
|
||
|
{
|
||
|
return fApps[index]->GetChannel()->GetName();
|
||
|
} else {
|
||
13 years ago
|
return plString::Null;
|
||
14 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// Read --------------------------------------------
|
||
|
// -----
|
||
|
void plAGAnim::Read(hsStream *stream, hsResMgr *mgr)
|
||
|
{
|
||
|
plSynchedObject::Read(stream, mgr);
|
||
|
|
||
|
// read in the name of the animation itself
|
||
11 years ago
|
fName = stream->ReadSafeString();
|
||
14 years ago
|
|
||
13 years ago
|
fStart = stream->ReadLEScalar();
|
||
|
fEnd = stream->ReadLEScalar();
|
||
14 years ago
|
|
||
13 years ago
|
int numApps = stream->ReadLE32();
|
||
14 years ago
|
|
||
|
fApps.reserve(numApps); // pre-allocate for performance
|
||
|
int i;
|
||
|
for (i = 0; i < numApps; i++)
|
||
|
{
|
||
|
plAGApplicator * app = plAGApplicator::ConvertNoRef(mgr->ReadCreatable(stream));
|
||
|
app->SetChannel(plAGChannel::ConvertNoRef(mgr->ReadCreatable(stream)));
|
||
|
fApps.push_back(app);
|
||
|
}
|
||
|
plAGAnim::AddAnim(fName, this);
|
||
|
}
|
||
|
|
||
|
// Write --------------------------------------------
|
||
|
// ------
|
||
|
void plAGAnim::Write(hsStream *stream, hsResMgr *mgr)
|
||
|
{
|
||
|
plSynchedObject::Write(stream, mgr);
|
||
|
|
||
|
stream->WriteSafeString(fName);
|
||
|
|
||
13 years ago
|
stream->WriteLEScalar(fStart);
|
||
|
stream->WriteLEScalar(fEnd);
|
||
14 years ago
|
|
||
|
int numApps = fApps.size();
|
||
|
|
||
13 years ago
|
stream->WriteLE32(numApps);
|
||
14 years ago
|
|
||
|
int i;
|
||
|
for (i = 0; i < numApps; i++)
|
||
|
{
|
||
|
plAGApplicator *app = fApps[i];
|
||
|
hsAssert(app, "Missing applicator during write.");
|
||
|
plAGChannel *channel = nil;
|
||
|
if (app)
|
||
|
channel = app->GetChannel();
|
||
|
|
||
|
hsAssert(channel, "Missing channel during write.");
|
||
|
mgr->WriteCreatable(stream, app);
|
||
|
mgr->WriteCreatable(stream, channel);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void plAGAnim::ClearAnimationRegistry()
|
||
|
{
|
||
|
fAllAnims.clear();
|
||
|
}
|
||
|
|
||
|
// AddAnim ----------------------------------------------
|
||
|
// --------
|
||
13 years ago
|
void plAGAnim::AddAnim(const plString & name, plAGAnim *anim)
|
||
14 years ago
|
{
|
||
|
// Only register the animation if it's got a "real" name. Unnamed animations
|
||
|
// all get the same standard name.
|
||
13 years ago
|
if(name.Compare(ENTIRE_ANIMATION_NAME) != 0)
|
||
14 years ago
|
{
|
||
|
hsAssert(anim, "registering nil anim");
|
||
|
fAllAnims[name] = anim;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// FindAnim -----------------------------------
|
||
|
// ---------
|
||
13 years ago
|
plAGAnim * plAGAnim::FindAnim(const plString &name)
|
||
14 years ago
|
{
|
||
|
plAnimMap::iterator i = fAllAnims.find(name);
|
||
|
|
||
|
if(i != fAllAnims.end())
|
||
|
{
|
||
|
return (*i).second;
|
||
|
} else {
|
||
|
return nil;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// RemoveAnim -------------------------------
|
||
|
// -----------
|
||
13 years ago
|
bool plAGAnim::RemoveAnim(const plString &name)
|
||
14 years ago
|
{
|
||
|
plAnimMap::iterator i = fAllAnims.find(name);
|
||
|
|
||
|
if(i != fAllAnims.end())
|
||
|
{
|
||
|
fAllAnims.erase(i);
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// DumpAnimationRegistry -------------
|
||
|
// ----------------------
|
||
|
void plAGAnim::DumpAnimationRegistry()
|
||
|
{
|
||
|
plAnimMap::iterator i = fAllAnims.begin();
|
||
|
int j = 0;
|
||
|
|
||
|
do {
|
||
|
plAGAnim *anim = (*i).second;
|
||
13 years ago
|
plString name = anim->GetName();
|
||
|
hsStatusMessageF("GLOBAL ANIMS [%d]: <%s>", j++, name.c_str());
|
||
14 years ago
|
} while(++i != fAllAnims.end());
|
||
|
}
|
||
|
|
||
|
// SharesPinsWith -----------------------------------------
|
||
|
// ---------------
|
||
13 years ago
|
bool plAGAnim::SharesPinsWith(const plAGAnim *anim) const
|
||
14 years ago
|
{
|
||
|
int i, j;
|
||
|
for (i = 0; i < fApps.size(); i++)
|
||
|
{
|
||
|
for (j = 0; j < anim->fApps.size(); j++)
|
||
|
{
|
||
13 years ago
|
if (!fApps[i]->GetChannelName().Compare(anim->fApps[j]->GetChannelName()) &&
|
||
14 years ago
|
fApps[i]->CanBlend(anim->fApps[j]))
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// plATCAnim
|
||
|
//
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
// ctor --------------
|
||
|
// -----
|
||
|
plATCAnim::plATCAnim()
|
||
|
: plAGAnim()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// ctor --------------------------------------------------------
|
||
|
// -----
|
||
13 years ago
|
plATCAnim::plATCAnim(const plString &name, double start, double end)
|
||
14 years ago
|
: plAGAnim(name, start, end),
|
||
|
fInitial(-1),
|
||
|
fAutoStart(true),
|
||
13 years ago
|
fLoopStart((float)start),
|
||
|
fLoopEnd((float)end),
|
||
14 years ago
|
fLoop(false),
|
||
|
fEaseInType(plAnimEaseTypes::kNoEase),
|
||
|
fEaseOutType(plAnimEaseTypes::kNoEase),
|
||
|
fEaseInLength(0),
|
||
|
fEaseOutLength(0),
|
||
|
fEaseInMin(0.f),
|
||
|
fEaseInMax(0.f),
|
||
|
fEaseOutMin(0.f),
|
||
|
fEaseOutMax(0.f)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// dtor ---------------
|
||
|
// -----
|
||
|
plATCAnim::~plATCAnim()
|
||
|
{
|
||
|
fMarkers.clear();
|
||
|
fLoops.clear();
|
||
|
fStopPoints.clear();
|
||
|
}
|
||
|
|
||
|
// Read ---------------------------------------------
|
||
|
// -----
|
||
|
void plATCAnim::Read(hsStream *stream, hsResMgr *mgr)
|
||
|
{
|
||
|
plAGAnim::Read(stream, mgr);
|
||
|
|
||
13 years ago
|
fInitial = stream->ReadLEScalar();
|
||
13 years ago
|
fAutoStart = stream->ReadBool();
|
||
13 years ago
|
fLoopStart = stream->ReadLEScalar();
|
||
|
fLoopEnd = stream->ReadLEScalar();
|
||
13 years ago
|
fLoop = stream->ReadBool();
|
||
14 years ago
|
|
||
|
fEaseInType = stream->ReadByte();
|
||
13 years ago
|
fEaseInMin = stream->ReadLEScalar();
|
||
|
fEaseInMax = stream->ReadLEScalar();
|
||
|
fEaseInLength = stream->ReadLEScalar();
|
||
14 years ago
|
fEaseOutType = stream->ReadByte();
|
||
13 years ago
|
fEaseOutMin = stream->ReadLEScalar();
|
||
|
fEaseOutMax = stream->ReadLEScalar();
|
||
|
fEaseOutLength = stream->ReadLEScalar();
|
||
14 years ago
|
|
||
|
int i;
|
||
13 years ago
|
int numMarkers = stream->ReadLE32();
|
||
14 years ago
|
for (i = 0; i < numMarkers; i++)
|
||
|
{
|
||
11 years ago
|
plString name = stream->ReadSafeString();
|
||
13 years ago
|
float time = stream->ReadLEFloat();
|
||
14 years ago
|
fMarkers[name] = time;
|
||
|
}
|
||
|
|
||
13 years ago
|
int numLoops = stream->ReadLE32();
|
||
14 years ago
|
for (i = 0; i < numLoops; i++)
|
||
|
{
|
||
11 years ago
|
plString name = stream->ReadSafeString();
|
||
13 years ago
|
float begin = stream->ReadLEScalar();
|
||
|
float end = stream->ReadLEScalar();
|
||
14 years ago
|
fLoops[name] = std::pair<float,float>(begin,end);
|
||
|
}
|
||
|
|
||
13 years ago
|
int numStops = stream->ReadLE32();
|
||
14 years ago
|
for (i = 0; i < numStops; i++)
|
||
13 years ago
|
fStopPoints.push_back(stream->ReadLEScalar());
|
||
14 years ago
|
}
|
||
|
|
||
|
// Write ---------------------------------------------
|
||
|
// ------
|
||
|
void plATCAnim::Write(hsStream *stream, hsResMgr *mgr)
|
||
|
{
|
||
|
plAGAnim::Write(stream, mgr);
|
||
|
|
||
13 years ago
|
stream->WriteLEScalar(fInitial);
|
||
13 years ago
|
stream->WriteBool(fAutoStart);
|
||
13 years ago
|
stream->WriteLEScalar(fLoopStart);
|
||
|
stream->WriteLEScalar(fLoopEnd);
|
||
13 years ago
|
stream->WriteBool(fLoop);
|
||
14 years ago
|
|
||
|
stream->WriteByte(fEaseInType);
|
||
13 years ago
|
stream->WriteLEScalar(fEaseInMin);
|
||
|
stream->WriteLEScalar(fEaseInMax);
|
||
|
stream->WriteLEScalar(fEaseInLength);
|
||
14 years ago
|
stream->WriteByte(fEaseOutType);
|
||
13 years ago
|
stream->WriteLEScalar(fEaseOutMin);
|
||
|
stream->WriteLEScalar(fEaseOutMax);
|
||
|
stream->WriteLEScalar(fEaseOutLength);
|
||
14 years ago
|
|
||
13 years ago
|
stream->WriteLE32(fMarkers.size());
|
||
14 years ago
|
for (MarkerMap::iterator it = fMarkers.begin(); it != fMarkers.end(); it++)
|
||
|
{
|
||
|
stream->WriteSafeString(it->first);
|
||
13 years ago
|
stream->WriteLEFloat(it->second);
|
||
14 years ago
|
}
|
||
|
|
||
13 years ago
|
stream->WriteLE32(fLoops.size());
|
||
14 years ago
|
for (LoopMap::iterator loopIt = fLoops.begin(); loopIt != fLoops.end(); loopIt++)
|
||
|
{
|
||
|
stream->WriteSafeString(loopIt->first);
|
||
|
std::pair<float,float>& loop = loopIt->second;
|
||
13 years ago
|
stream->WriteLEFloat(loop.first);
|
||
|
stream->WriteLEFloat(loop.second);
|
||
14 years ago
|
}
|
||
|
|
||
|
int i;
|
||
13 years ago
|
stream->WriteLE32(fStopPoints.size());
|
||
14 years ago
|
for (i = 0; i < fStopPoints.size(); i++)
|
||
13 years ago
|
stream->WriteLEScalar(fStopPoints[i]);
|
||
14 years ago
|
}
|
||
|
|
||
|
// CheckLoop --------------
|
||
|
// ----------
|
||
|
void plATCAnim::CheckLoop()
|
||
|
{
|
||
|
if (fLoopStart == fLoopEnd)
|
||
|
{
|
||
|
fLoopStart = fStart;
|
||
|
fLoopEnd = fEnd;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// AddLoop ------------------------------------------------------
|
||
|
// --------
|
||
13 years ago
|
void plATCAnim::AddLoop(const plString &name, float start, float end)
|
||
14 years ago
|
{
|
||
13 years ago
|
fLoops[name] = std::pair<float,float>(start, end);
|
||
14 years ago
|
}
|
||
|
|
||
|
// GetLoop --------------------------------------------------------------
|
||
|
// --------
|
||
13 years ago
|
bool plATCAnim::GetLoop(const plString &name, float &start, float &end) const
|
||
14 years ago
|
{
|
||
|
LoopMap::const_iterator it = fLoops.find(name);
|
||
|
if (it != fLoops.end())
|
||
|
{
|
||
|
const std::pair<float,float>& loop = (*it).second;
|
||
|
start = loop.first;
|
||
|
end = loop.second;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// GetLoop --------------------------------------------------------
|
||
|
// --------
|
||
13 years ago
|
bool plATCAnim::GetLoop(uint32_t num, float &start, float &end) const
|
||
14 years ago
|
{
|
||
|
if (num >= fLoops.size())
|
||
|
return false;
|
||
|
|
||
|
LoopMap::const_iterator it = fLoops.begin();
|
||
|
|
||
|
while (num > 0)
|
||
|
{
|
||
|
it++;
|
||
|
num--;
|
||
|
}
|
||
|
const std::pair<float,float>& loop = (*it).second;
|
||
|
start = loop.first;
|
||
|
end = loop.second;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// GetNumLoops ----------------------
|
||
|
// ------------
|
||
13 years ago
|
uint32_t plATCAnim::GetNumLoops() const
|
||
14 years ago
|
{
|
||
|
return fLoops.size();
|
||
|
}
|
||
|
|
||
|
// AddMarker ------------------------------------------
|
||
|
// ----------
|
||
13 years ago
|
void plATCAnim::AddMarker(const plString &name, float time)
|
||
14 years ago
|
{
|
||
13 years ago
|
fMarkers[name] = time;
|
||
14 years ago
|
}
|
||
|
|
||
|
// GetMarker -------------------------------------
|
||
|
// ----------
|
||
13 years ago
|
float plATCAnim::GetMarker(const plString &name) const
|
||
14 years ago
|
{
|
||
|
if (fMarkers.find(name) != fMarkers.end())
|
||
|
return (*fMarkers.find(name)).second;
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
// CopyMarkerNames -------------------------------------
|
||
|
// ----------------
|
||
13 years ago
|
void plATCAnim::CopyMarkerNames(std::vector<plString> &out)
|
||
14 years ago
|
{
|
||
|
MarkerMap::iterator it = fMarkers.begin();
|
||
|
|
||
13 years ago
|
out.reserve(fMarkers.size());
|
||
14 years ago
|
for (; it != fMarkers.end(); it++)
|
||
|
{
|
||
13 years ago
|
out.push_back((*it).first);
|
||
14 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// AddStopPoint ---------------------------
|
||
|
// -------------
|
||
13 years ago
|
void plATCAnim::AddStopPoint(float time)
|
||
14 years ago
|
{
|
||
|
fStopPoints.push_back(time);
|
||
|
}
|
||
|
|
||
|
// NumStopPoints ----------------
|
||
|
// --------------
|
||
13 years ago
|
uint32_t plATCAnim::NumStopPoints()
|
||
14 years ago
|
{
|
||
|
return fStopPoints.size();
|
||
|
}
|
||
|
|
||
|
// GetStopPoint --------------------------
|
||
|
// -------------
|
||
13 years ago
|
float plATCAnim::GetStopPoint(uint32_t i)
|
||
14 years ago
|
{
|
||
|
hsAssert(i < fStopPoints.size(), "Invalid index for GetStopPoint");
|
||
|
return fStopPoints[i];
|
||
|
}
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// plEmoteAnim
|
||
|
//
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
// ctor ------------------
|
||
|
// -----
|
||
|
plEmoteAnim::plEmoteAnim()
|
||
|
: fBodyUsage(kBodyFull)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// ctor ------------------------------------------------------------------------------
|
||
|
// -----
|
||
13 years ago
|
plEmoteAnim::plEmoteAnim(const plString &animName, double begin, double end, float fadeIn,
|
||
14 years ago
|
float fadeOut, BodyUsage bodyUsage)
|
||
|
: plATCAnim(animName, begin, end),
|
||
|
fFadeIn(fadeIn),
|
||
|
fFadeOut(fadeOut),
|
||
|
fBodyUsage(bodyUsage)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// Read -----------------------------------------------
|
||
|
// -----
|
||
|
void plEmoteAnim::Read(hsStream *stream, hsResMgr *mgr)
|
||
|
{
|
||
|
plATCAnim::Read(stream, mgr);
|
||
|
|
||
|
// plAGAnim::RegisterEmote(fName, this);
|
||
13 years ago
|
fFadeIn = stream->ReadLEScalar();
|
||
|
fFadeOut = stream->ReadLEScalar();
|
||
14 years ago
|
fBodyUsage = static_cast<BodyUsage>(stream->ReadByte());
|
||
|
|
||
|
}
|
||
|
|
||
|
// Write -----------------------------------------------
|
||
|
// ------
|
||
|
void plEmoteAnim::Write(hsStream *stream, hsResMgr *mgr)
|
||
|
{
|
||
|
plATCAnim::Write(stream, mgr);
|
||
13 years ago
|
stream->WriteLEScalar(fFadeIn);
|
||
|
stream->WriteLEScalar(fFadeOut);
|
||
13 years ago
|
stream->WriteByte(static_cast<uint8_t>(fBodyUsage));
|
||
14 years ago
|
}
|
||
|
|
||
|
// GetBodyUsage ----------------------------------------
|
||
|
// -------------
|
||
|
plEmoteAnim::BodyUsage plEmoteAnim::GetBodyUsage() const
|
||
|
{
|
||
|
return fBodyUsage;
|
||
|
}
|
||
|
|
||
|
// GetFadeIn -----------------------
|
||
|
// ----------
|
||
|
float plEmoteAnim::GetFadeIn() const
|
||
|
{
|
||
|
return fFadeIn;
|
||
|
}
|
||
|
|
||
|
// GetFadeOut -----------------------
|
||
|
// -----------
|
||
|
float plEmoteAnim::GetFadeOut() const
|
||
|
{
|
||
|
return fFadeOut;
|
||
|
}
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// plAgeGlobalAnim
|
||
|
//
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
// ctor --------------------------
|
||
|
// -----
|
||
|
plAgeGlobalAnim::plAgeGlobalAnim()
|
||
|
: plAGAnim()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// ctor --------------------------------------------------------------------
|
||
|
// -----
|
||
13 years ago
|
plAgeGlobalAnim::plAgeGlobalAnim(const plString &name, double start, double end)
|
||
11 years ago
|
: plAGAnim(name, start, end)
|
||
14 years ago
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
// Read ---------------------------------------------------
|
||
|
// -----
|
||
|
void plAgeGlobalAnim::Read(hsStream *stream, hsResMgr *mgr)
|
||
|
{
|
||
|
plAGAnim::Read(stream, mgr);
|
||
|
|
||
11 years ago
|
fGlobalVarName = stream->ReadSafeString();
|
||
14 years ago
|
}
|
||
|
|
||
|
// Write ---------------------------------------------------
|
||
|
// ------
|
||
|
void plAgeGlobalAnim::Write(hsStream *stream, hsResMgr *mgr)
|
||
|
{
|
||
|
plAGAnim::Write(stream, mgr);
|
||
|
|
||
|
stream->WriteSafeString(fGlobalVarName);
|
||
|
}
|
||
|
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// UTILITIES
|
||
|
//
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
// GetStartToEndTransform -----------------------------------------------
|
||
|
bool GetStartToEndTransform(const plAGAnim *anim, hsMatrix44 *startToEnd,
|
||
13 years ago
|
hsMatrix44 *endToStart, const plString &channelName)
|
||
14 years ago
|
{
|
||
|
double start = 0.0f; // assumed
|
||
|
double end = anim->GetEnd();
|
||
|
|
||
|
GetRelativeTransform(anim, start, end, startToEnd, endToStart, channelName);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// GetRelativeTransform ---------------------------------------------------
|
||
|
bool GetRelativeTransform(const plAGAnim *anim, double timeA, double timeB,
|
||
13 years ago
|
hsMatrix44 *a2b, hsMatrix44 *b2a, const plString &channelName)
|
||
14 years ago
|
{
|
||
|
bool result = false;
|
||
|
plAGChannel *maybeChannel = anim->GetChannel(channelName);
|
||
|
hsAssert(maybeChannel, "Couldn't find channel with given name.");
|
||
|
if(maybeChannel)
|
||
|
{
|
||
|
plMatrixChannel *channel = plMatrixChannel::ConvertNoRef(maybeChannel);
|
||
|
hsAssert(channel, "Found channel, but it's not a matrix channel.");
|
||
|
|
||
|
if(channel)
|
||
|
{
|
||
|
hsMatrix44 matA;
|
||
|
hsMatrix44 matB;
|
||
|
|
||
|
channel->Value(matA, timeA);
|
||
|
channel->Value(matB, timeB);
|
||
|
|
||
|
if(a2b) // requested a transform from point A to point B
|
||
|
{
|
||
|
hsMatrix44 invA;
|
||
|
matA.GetInverse(&invA);
|
||
|
*a2b = invA * matB;
|
||
|
}
|
||
|
if(b2a) // requested a transform from point B to point A
|
||
|
{
|
||
|
hsMatrix44 invB;
|
||
|
matB.GetInverse(&invB);
|
||
|
*b2a = invB * matA;
|
||
|
|
||
|
if(a2b)
|
||
|
{
|
||
|
hsMatrix44 invB2;
|
||
|
a2b->GetInverse(&invB2);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return result;
|
||
14 years ago
|
}
|