1#include "Game/Camera/CameraAnim.hpp"
2#include "Game/Camera/CamTranslatorAnim.hpp"
4KeyCamAnmDataAccessor::~KeyCamAnmDataAccessor() {
8void KeyCamAnmDataAccessor::set(
void *pInfo,
void *pValues) {
10 mValues =
reinterpret_cast<f32 *
>(pValues);
13void KeyCamAnmDataAccessor::getPos(TVec3f *pPos,
float key)
const {
22 z = get(key, infoZ.mOffset, infoZ.mCount, infoZ.mType);
23 y = get(key, infoY.mOffset, infoY.mCount, infoY.mType);
24 x = get(key, infoX.mOffset, infoX.mCount, infoX.mType);
29void KeyCamAnmDataAccessor::getWatchPos(TVec3f *pWatchPos,
float key)
const {
38 z = get(key, infoZ.mOffset, infoZ.mCount, infoZ.mType);
39 y = get(key, infoY.mOffset, infoY.mCount, infoY.mType);
40 x = get(key, infoX.mOffset, infoX.mCount, infoX.mType);
42 pWatchPos->set(x, y, z);
45float KeyCamAnmDataAccessor::getTwist(
float key)
const {
48 return get(key, info.mOffset, info.mCount, info.mType);
51float KeyCamAnmDataAccessor::getFovy(
float key)
const {
54 return get(key, info.mOffset, info.mCount, info.mType);
57float KeyCamAnmDataAccessor::get(
float key,
unsigned long offset,
unsigned long count,
unsigned long type)
const {
59 return mValues[offset];
63 return get3f(key, offset, count);
66 return get4f(key, offset, count);
70u32 KeyCamAnmDataAccessor::searchKeyFrameIndex(
float key,
unsigned long offset,
unsigned long count,
unsigned long stride)
const {
75 u32 middle = (low + high) / 2;
77 if (mValues[offset + middle * stride] <= key) {
88float KeyCamAnmDataAccessor::get3f(
float key,
unsigned long offset,
unsigned long count)
const {
89 u32 index = searchKeyFrameIndex(key, offset, count, 3);
90 f32 *values = mValues + offset + index * 3;
92 return calcHermite(key, values[0], values[1], values[2], values[3], values[4], values[5]);
95float KeyCamAnmDataAccessor::get4f(
float key,
unsigned long offset,
unsigned long count)
const {
96 u32 index = searchKeyFrameIndex(key, offset, count, 4);
97 f32 *values = mValues + offset + index * 4;
99 return calcHermite(key, values[0], values[1], values[2], values[3], values[4], values[5]);
104float KeyCamAnmDataAccessor::calcHermite(
float key,
float a2,
float a3,
float a4,
float a5,
float a6,
float a7)
const {
105 float fVar1 = a4 / 30.0f;
106 float fVar2 = (key - a2) / (a5 - a2);
107 float fVar3 = fVar2 * fVar2 - fVar2;
109 return -(key - a2) * (fVar2 * fVar1 - a7 / 30.0f * fVar3 + fVar1 * fVar3 + fVar1) - (((fVar2 + fVar2) * fVar3 - fVar2 * fVar2) * (a3 - a6) + a3);
113CamAnmDataAccessor::~CamAnmDataAccessor() {
117void CamAnmDataAccessor::set(
void *pInfo,
void *pValues) {
119 mValues =
reinterpret_cast<f32 *
>(pValues);
122void CamAnmDataAccessor::getPos(TVec3f *pPos,
float key)
const {
131 z = get(key, infoZ.mOffset, infoZ.mCount);
132 y = get(key, infoY.mOffset, infoY.mCount);
133 x = get(key, infoX.mOffset, infoX.mCount);
138void CamAnmDataAccessor::getWatchPos(TVec3f *pWatchPos,
float key)
const {
147 z = get(key, infoZ.mOffset, infoZ.mCount);
148 y = get(key, infoY.mOffset, infoY.mCount);
149 x = get(key, infoX.mOffset, infoX.mCount);
151 pWatchPos->set(x, y, z);
154float CamAnmDataAccessor::getTwist(
float key)
const {
157 return get(key, info.mOffset, info.mCount);
160float CamAnmDataAccessor::getFovy(
float key)
const {
163 return get(key, info.mOffset, info.mCount);
177CameraAnim::CameraAnim(
const char *pName) :
Camera(pName) {
183 mFileDataAccessor =
nullptr;
192CameraAnim::~CameraAnim() {
196bool CameraAnim::isZeroFrameMoveOff()
const {
200bool CameraAnim::isCollisionOff()
const {
204bool CameraAnim::isInterpolationOff()
const {
212void CameraAnim::setParam(
unsigned char *pFile,
float speed) {
218bool CameraAnim::isAnimEnd()
const {
219 bool hasEnded =
true;
220 u32 nrFrames = mNrFrames;
223 if (!(mCurrentFrame >= nrFrames)) {
231u32 CameraAnim::getAnimFrame(
unsigned char *pFile) {
232 if (pFile ==
nullptr) {
238 if (pHeader->mMagic[0] !=
'A' || pHeader->mMagic[1] !=
'N' || pHeader->mMagic[2] !=
'D' || pHeader->mMagic[3] !=
'O') {
242 if ((pHeader->mType[0] !=
'C' || pHeader->mType[1] !=
'A' || pHeader->mType[2] !=
'N' || pHeader->mType[3] !=
'M') &&
243 (pHeader->mType[0] !=
'C' || pHeader->mType[1] !=
'K' || pHeader->mType[2] !=
'A' || pHeader->mType[3] !=
'N')) {
247 if (pHeader->_8 == 0) {
251 return pHeader->mNrFrames;
254bool CameraAnim::loadBin(
unsigned char *pFile) {
257 if (pHeader->mMagic[0] !=
'A' || pHeader->mMagic[1] !=
'N' || pHeader->mMagic[2] !=
'D' || pHeader->mMagic[3] !=
'O') {
261 if (pHeader->mType[0] ==
'C' && pHeader->mType[1] ==
'A' && pHeader->mType[2] ==
'N' && pHeader->mType[3] ==
'M') {
263 mFileDataAccessor = mDataAccessor;
265 else if (pHeader->mType[0] ==
'C' && pHeader->mType[1] ==
'K' && pHeader->mType[2] ==
'A' && pHeader->mType[3] ==
'N') {
267 mFileDataAccessor = mKeyDataAccessor;
273 if (pHeader->_8 == 0) {
277 u8 *pEntry =
reinterpret_cast<u8 *
>(pFile +
sizeof(
CanmFileHeader));
280 mNrFrames = pHeader->mNrFrames;
282 u32 valueOffset = pHeader->mValueOffset;
284 mNrValues = *(
reinterpret_cast<u32 *
>(&pEntry[valueOffset])) /
sizeof(f32);
286 mFileDataAccessor->set(pEntry, pEntry + valueOffset + 4);