void Transform::setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight) { assert(blendWeight >= 0.0f && blendWeight <= 1.0f); if (blendWeight == 0.0f) return; switch (propertyId) { case ANIMATE_SCALE_UNIT: { float scale = value->getFloat(0); if (blendWeight != 1.0f) scale *= blendWeight; applyAnimationValueScaleX(scale); applyAnimationValueScaleY(scale); applyAnimationValueScaleZ(scale); break; } case ANIMATE_SCALE: { float sx = value->getFloat(0); float sy = value->getFloat(1); float sz = value->getFloat(2); if (blendWeight != 1.0f) { sx *= blendWeight; sy *= blendWeight; sz *= blendWeight; } applyAnimationValueScaleX(sx); applyAnimationValueScaleY(sy); applyAnimationValueScaleZ(sz); break; } case ANIMATE_SCALE_X: { float sx = value->getFloat(0); if (blendWeight != 1.0f) sx *= blendWeight; applyAnimationValueScaleX(sx); break; } case ANIMATE_SCALE_Y: { float sy = value->getFloat(0); if (blendWeight != 1.0f) sy *= blendWeight; applyAnimationValueScaleY(sy); break; } case ANIMATE_SCALE_Z: { float sz = value->getFloat(0); if (blendWeight != 1.0f) sz *= blendWeight; applyAnimationValueScaleZ(sz); break; } case ANIMATE_ROTATE: { Quaternion q(value->getFloat(0), value->getFloat(1), value->getFloat(2), value->getFloat(3)); if (blendWeight != 1.0f) Quaternion::slerp(Quaternion::identity(), q, blendWeight, &q); applyAnimationValueRotation(&q); break; } case ANIMATE_TRANSLATE: { float tx = value->getFloat(0); float ty = value->getFloat(1); float tz = value->getFloat(2); if (blendWeight != 1.0f) { tx *= blendWeight; ty *= blendWeight; tz *= blendWeight; } applyAnimationValueTranslationX(tx); applyAnimationValueTranslationY(ty); applyAnimationValueTranslationZ(tz); break; } case ANIMATE_TRANSLATE_X: { float tx = value->getFloat(0); if (blendWeight != 1.0f) tx *= blendWeight; applyAnimationValueTranslationX(tx); break; } case ANIMATE_TRANSLATE_Y: { float ty = value->getFloat(0); if (blendWeight != 1.0f) ty *= blendWeight; applyAnimationValueTranslationY(ty); break; } case ANIMATE_TRANSLATE_Z: { float tz = value->getFloat(0); if (blendWeight != 1.0f) tz *= blendWeight; applyAnimationValueTranslationZ(tz); break; } case ANIMATE_ROTATE_TRANSLATE: { Quaternion q(value->getFloat(0), value->getFloat(1), value->getFloat(2), value->getFloat(3)); float tx = value->getFloat(4); float ty = value->getFloat(5); float tz = value->getFloat(6); if (blendWeight != 1.0f) { Quaternion::slerp(Quaternion::identity(), q, blendWeight, &q); tx *= blendWeight; ty *= blendWeight; tz *= blendWeight; } applyAnimationValueRotation(&q); applyAnimationValueTranslationX(tx); applyAnimationValueTranslationY(ty); applyAnimationValueTranslationZ(tz); break; } case ANIMATE_SCALE_ROTATE_TRANSLATE: { float sx = value->getFloat(0); float sy = value->getFloat(1); float sz = value->getFloat(2); Quaternion q(value->getFloat(3), value->getFloat(4), value->getFloat(5), value->getFloat(6)); float tx = value->getFloat(7); float ty = value->getFloat(8); float tz = value->getFloat(9); if (blendWeight != 1.0f) { sx *= blendWeight; sy *= blendWeight; sz *= blendWeight; Quaternion::slerp(Quaternion::identity(), q, blendWeight, &q); tx *= blendWeight; ty *= blendWeight; tz *= blendWeight; } applyAnimationValueScaleX(sx); applyAnimationValueScaleY(sy); applyAnimationValueScaleZ(sz); applyAnimationValueRotation(&q); applyAnimationValueTranslationX(tx); applyAnimationValueTranslationY(ty); applyAnimationValueTranslationZ(tz); break; } default: break; } }
void Transform::setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight) { GP_ASSERT(value); GP_ASSERT(blendWeight >= 0.0f && blendWeight <= 1.0f); switch (propertyId) { case ANIMATE_SCALE_UNIT: { float scale = Curve::lerp(blendWeight, _scale.x, value->getFloat(0)); setScale(scale); break; } case ANIMATE_SCALE: { setScale(Curve::lerp(blendWeight, _scale.x, value->getFloat(0)), Curve::lerp(blendWeight, _scale.y, value->getFloat(1)), Curve::lerp(blendWeight, _scale.z, value->getFloat(2))); break; } case ANIMATE_SCALE_X: { setScaleX(Curve::lerp(blendWeight, _scale.x, value->getFloat(0))); break; } case ANIMATE_SCALE_Y: { setScaleY(Curve::lerp(blendWeight, _scale.y, value->getFloat(0))); break; } case ANIMATE_SCALE_Z: { setScaleZ(Curve::lerp(blendWeight, _scale.z, value->getFloat(0))); break; } case ANIMATE_ROTATE: { applyAnimationValueRotation(value, 0, blendWeight); break; } case ANIMATE_TRANSLATE: { setTranslation(Curve::lerp(blendWeight, _translation.x, value->getFloat(0)), Curve::lerp(blendWeight, _translation.y, value->getFloat(1)), Curve::lerp(blendWeight, _translation.z, value->getFloat(2))); break; } case ANIMATE_TRANSLATE_X: { setTranslationX(Curve::lerp(blendWeight, _translation.x, value->getFloat(0))); break; } case ANIMATE_TRANSLATE_Y: { setTranslationY(Curve::lerp(blendWeight, _translation.y, value->getFloat(0))); break; } case ANIMATE_TRANSLATE_Z: { setTranslationZ(Curve::lerp(blendWeight, _translation.z, value->getFloat(0))); break; } case ANIMATE_ROTATE_TRANSLATE: { applyAnimationValueRotation(value, 0, blendWeight); setTranslation(Curve::lerp(blendWeight, _translation.x, value->getFloat(4)), Curve::lerp(blendWeight, _translation.y, value->getFloat(5)), Curve::lerp(blendWeight, _translation.z, value->getFloat(6))); break; } case ANIMATE_SCALE_ROTATE: { setScale(Curve::lerp(blendWeight, _scale.x, value->getFloat(0)), Curve::lerp(blendWeight, _scale.y, value->getFloat(1)), Curve::lerp(blendWeight, _scale.z, value->getFloat(2))); applyAnimationValueRotation(value, 3, blendWeight); break; } case ANIMATE_SCALE_TRANSLATE: { setScale(Curve::lerp(blendWeight, _scale.x, value->getFloat(0)), Curve::lerp(blendWeight, _scale.y, value->getFloat(1)), Curve::lerp(blendWeight, _scale.z, value->getFloat(2))); setTranslation(Curve::lerp(blendWeight, _translation.x, value->getFloat(3)), Curve::lerp(blendWeight, _translation.y, value->getFloat(4)), Curve::lerp(blendWeight, _translation.z, value->getFloat(5))); break; } case ANIMATE_SCALE_ROTATE_TRANSLATE: { setScale(Curve::lerp(blendWeight, _scale.x, value->getFloat(0)), Curve::lerp(blendWeight, _scale.y, value->getFloat(1)), Curve::lerp(blendWeight, _scale.z, value->getFloat(2))); applyAnimationValueRotation(value, 3, blendWeight); setTranslation(Curve::lerp(blendWeight, _translation.x, value->getFloat(7)), Curve::lerp(blendWeight, _translation.y, value->getFloat(8)), Curve::lerp(blendWeight, _translation.z, value->getFloat(9))); break; } default: break; } }