File include/avatar.h changed (mode: 100644) (index 3e83692..07c9d7e) |
... |
... |
class Avatar { |
68 |
68 |
double headFPS = 0.0; |
double headFPS = 0.0; |
69 |
69 |
double bodyFrame = 0.0; |
double bodyFrame = 0.0; |
70 |
70 |
double headFrame = 0.0; |
double headFrame = 0.0; |
|
71 |
|
void blendTo( const std::string &animation ); |
71 |
72 |
void simulate( const std::string &animation, double d, bool loop = true ); |
void simulate( const std::string &animation, double d, bool loop = true ); |
72 |
73 |
void draw(linalg::mat<double,4,4> modelMat, linalg::mat<double,4,4> viewMat, linalg::mat<double,4,4> projMat, GLfloat drawDist = FLT_MAX, const std::string &weap = ""); |
void draw(linalg::mat<double,4,4> modelMat, linalg::mat<double,4,4> viewMat, linalg::mat<double,4,4> projMat, GLfloat drawDist = FLT_MAX, const std::string &weap = ""); |
73 |
74 |
std::string toString(); |
std::string toString(); |
|
... |
... |
fgl::Texture *getCacheTexture( FILE *(*ModFopen)(const char*,const char*), const |
383 |
384 |
} |
} |
384 |
385 |
} |
} |
385 |
386 |
|
|
|
387 |
|
// Override current animation and blend to the first frame of new animation. |
|
388 |
|
void Avatar::blendTo( const std::string &animation ){ |
|
389 |
|
if( !smoothAnimation ) return; |
|
390 |
|
if( bodyFrame >= 0.0 ){ |
|
391 |
|
bodyAnimations["_blend"] = |
|
392 |
|
linalg::vec<int,2>(std::floor(bodyFrame), bodyAnimations[animation].x); |
|
393 |
|
bodyFrame = -1.0; |
|
394 |
|
} |
|
395 |
|
if( headFrame >= 0.0 ){ |
|
396 |
|
headAnimations["_blend"] = |
|
397 |
|
linalg::vec<int,2>(std::floor(headFrame), headAnimations[animation].x); |
|
398 |
|
headFrame = -1.0; |
|
399 |
|
} |
|
400 |
|
} |
|
401 |
|
|
386 |
402 |
void Avatar::simulate( const std::string &animation, double d, bool loop ){ |
void Avatar::simulate( const std::string &animation, double d, bool loop ){ |
387 |
|
auto bodyAnim = bodyAnimations[animation]; |
|
388 |
|
auto headAnim = headAnimations[animation]; |
|
|
403 |
|
bool blend = bodyFrame < 0.0 || headFrame < 0.0; |
|
404 |
|
if( blend ) loop = false; |
|
405 |
|
auto bodyAnim = bodyAnimations[blend ? "_blend" : animation]; |
|
406 |
|
auto headAnim = headAnimations[blend ? "_blend" : animation]; |
389 |
407 |
if( bodyFrame < bodyAnim.x || (loop && bodyFrame >= bodyAnim.y) ) |
if( bodyFrame < bodyAnim.x || (loop && bodyFrame >= bodyAnim.y) ) |
390 |
408 |
bodyFrame = bodyAnim.x; |
bodyFrame = bodyAnim.x; |
391 |
409 |
if( (double)bodyAnim.y - bodyAnim.x > 0.0 ){ |
if( (double)bodyAnim.y - bodyAnim.x > 0.0 ){ |
|
... |
... |
void Avatar::simulate( const std::string &animation, double d, bool loop ){ |
411 |
429 |
if( smoothAnimation ){ |
if( smoothAnimation ){ |
412 |
430 |
for( auto &prim : bodyPrims ){ |
for( auto &prim : bodyPrims ){ |
413 |
431 |
if( prim.meshes.size() == 0 ) continue; |
if( prim.meshes.size() == 0 ) continue; |
414 |
|
float frameA = |
|
415 |
|
std::fmod(bodyFrame - bodyAnim.x, bodyAnim.y) + bodyAnim.x; |
|
416 |
|
float frameB = |
|
417 |
|
std::fmod(frameA + 1.0 - bodyAnim.x, bodyAnim.y) + bodyAnim.x; |
|
|
432 |
|
float frameA = blend ? bodyAnim.x |
|
433 |
|
: std::fmod(bodyFrame - bodyAnim.x, bodyAnim.y) + bodyAnim.x; |
|
434 |
|
float frameB = blend ? bodyAnim.y |
|
435 |
|
: std::fmod(frameA + 1.0 - bodyAnim.x, bodyAnim.y) + bodyAnim.x; |
418 |
436 |
lerpMeshes( |
lerpMeshes( |
419 |
437 |
prim.streamingMesh, |
prim.streamingMesh, |
420 |
438 |
*prim.meshes[std::fmod((size_t)frameA, prim.meshes.size())], |
*prim.meshes[std::fmod((size_t)frameA, prim.meshes.size())], |
421 |
439 |
*prim.meshes[std::fmod((size_t)frameB, prim.meshes.size())], |
*prim.meshes[std::fmod((size_t)frameB, prim.meshes.size())], |
422 |
|
bodyFrame - std::floor(bodyFrame) |
|
|
440 |
|
bodyFrame + (blend ? 1.0 : -std::floor(bodyFrame)) |
423 |
441 |
); |
); |
424 |
442 |
} |
} |
425 |
443 |
for( auto &prim : headPrims ){ |
for( auto &prim : headPrims ){ |
426 |
444 |
if( prim.meshes.size() == 0 ) continue; |
if( prim.meshes.size() == 0 ) continue; |
427 |
|
float frameA = |
|
428 |
|
std::fmod(headFrame - headAnim.x, headAnim.y) + headAnim.x; |
|
429 |
|
float frameB = |
|
430 |
|
std::fmod(frameA + 1.0 - headAnim.x, headAnim.y) + headAnim.x; |
|
|
445 |
|
float frameA = blend ? headAnim.x |
|
446 |
|
: std::fmod(headFrame - headAnim.x, headAnim.y) + headAnim.x; |
|
447 |
|
float frameB = blend ? headAnim.y |
|
448 |
|
: std::fmod(frameA + 1.0 - headAnim.x, headAnim.y) + headAnim.x; |
431 |
449 |
lerpMeshes( |
lerpMeshes( |
432 |
450 |
prim.streamingMesh, |
prim.streamingMesh, |
433 |
451 |
*prim.meshes[std::fmod((size_t)frameA, prim.meshes.size())], |
*prim.meshes[std::fmod((size_t)frameA, prim.meshes.size())], |
434 |
452 |
*prim.meshes[std::fmod((size_t)frameB, prim.meshes.size())], |
*prim.meshes[std::fmod((size_t)frameB, prim.meshes.size())], |
435 |
|
headFrame - std::floor(headFrame) |
|
|
453 |
|
headFrame + (blend ? 1.0 : -std::floor(headFrame)) |
436 |
454 |
); |
); |
437 |
455 |
} |
} |
438 |
456 |
} |
} |