载入中...
搜索中...
未找到
AnimPose.cpp
浏览该文件的文档.
21 return {a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y, a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,
61Quat worldToLocalRotation(const AnimSkeleton* skeleton, const AnimPose* pose, int bone, const Quat& world) {
69 slerpQuat(local.qx, local.qy, local.qz, local.qw, target.x, target.y, target.z, target.w, clampf(weight, 0.f, 1.f),
118 out.px = lerpf(av.px, bv.px, t); out.py = lerpf(av.py, bv.py, t); out.pz = lerpf(av.pz, bv.pz, t);
220bool AnimPose::aimBone(const AnimSkeleton* skeleton, int boneIndex, float targetX, float targetY, float targetZ,
228 if (!fromTo(mat.m[8], mat.m[9], mat.m[10], targetX - bone.px, targetY - bone.py, targetZ - bone.pz, delta)) {
237bool AnimPose::solveTwoBoneIK(const AnimSkeleton* skeleton, int rootBone, int midBone, int tipBone, float targetX,
243 return solveTwoBoneIKPoleImpl(skeleton, rootBone, midBone, tipBone, targetX, targetY, targetZ, pole.px, pole.py,
247bool AnimPose::solveTwoBoneIKPoleImpl(const AnimSkeleton* skeleton, int rootBone, int midBone, int tipBone,
254 if (skeleton->getParent(midBone) != rootBone || skeleton->getParent(tipBone) != midBone) return false;
256 if (!std::isfinite(targetX) || !std::isfinite(targetY) || !std::isfinite(targetZ) || !std::isfinite(poleX) ||
262 auto sub = [](Vector a, Vector b) -> Vector { return {a[0] - b[0], a[1] - b[1], a[2] - b[2]}; };
267 const Vector a = position(world(rootBone)), b = position(world(midBone)), c = position(world(tipBone));
283 std::sqrt(dot(sub(Vector{targetX, targetY, targetZ}, a), sub(Vector{targetX, targetY, targetZ}, a)));
284 const double reach = std::clamp(requested, std::max(std::abs(upper - lower), 1e-7), upper + lower);
314 if (!fromTo(float(ab[0]), float(ab[1]), float(ab[2]), float(knee[0] - a[0]), float(knee[1] - a[1]),
319 worldToLocalRotation(skeleton, this, rootBone, quatMul(delta, {root.qx, root.qy, root.qz, root.qw}));
323 if (fromTo(end.px - mid.px, end.py - mid.py, end.pz - mid.pz, float(tip[0] - mid.px), float(tip[1] - mid.py),
326 worldToLocalRotation(skeleton, this, midBone, quatMul(delta, {mid.qx, mid.qy, mid.qz, mid.qw}));
332 blendLocalRotation(local(rootBone), {solvedRoot.qx, solvedRoot.qy, solvedRoot.qz, solvedRoot.qw}, weight);
333 blendLocalRotation(local(midBone), {solvedMid.qx, solvedMid.qy, solvedMid.qz, solvedMid.qw}, weight);
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
float getLocalRotationX(int boneIndex) const
Returns the local rotation x.
Definition AnimPose.cpp:174
float getWorldRotationX(int boneIndex) const
Returns the world rotation x.
Definition AnimPose.cpp:350
float getWorldPositionZ(int boneIndex) const
Returns the world position z.
Definition AnimPose.cpp:346
float getLocalPositionZ(int boneIndex) const
Returns the local position z.
Definition AnimPose.cpp:170
float getWorldMatrixElement(int boneIndex, int elementIndex) const
Column-major 4x4 world matrix for boneIndex after computeWorld(). elementIndex in [0,...
Definition AnimPose.cpp:372
float getLocalPositionX(int boneIndex) const
Returns the local position x.
Definition AnimPose.cpp:162
float getLocalRotationW(int boneIndex) const
Returns the local rotation w.
Definition AnimPose.cpp:186
float getWorldPositionX(int boneIndex) const
Returns the world position x.
Definition AnimPose.cpp:338
void setLocalScale(int boneIndex, float x, float y, float z)
Sets the local scale.
Definition AnimPose.cpp:154
float getWorldPositionY(int boneIndex) const
Returns the world position y.
Definition AnimPose.cpp:342
void getWorldMatrix(int boneIndex, float *out16) const
Write 16 floats (column-major) into out16 (must not be null).
Definition AnimPose.cpp:381
void setLocalRotation(int boneIndex, float x, float y, float z, float w)
Sets the local rotation.
Definition AnimPose.cpp:144
float getWorldRotationW(int boneIndex) const
Returns the world rotation w.
Definition AnimPose.cpp:362
float getWorldRotationZ(int boneIndex) const
Returns the world rotation z.
Definition AnimPose.cpp:358
float getWorldRotationY(int boneIndex) const
Returns the world rotation y.
Definition AnimPose.cpp:354
float getLocalRotationZ(int boneIndex) const
Returns the local rotation z.
Definition AnimPose.cpp:182
void setLocalPosition(int boneIndex, float x, float y, float z)
Sets the local position.
Definition AnimPose.cpp:136
float getLocalPositionY(int boneIndex) const
Returns the local position y.
Definition AnimPose.cpp:166
float getLocalRotationY(int boneIndex) const
Returns the local rotation y.
Definition AnimPose.cpp:178
bool aimBone(const AnimSkeleton *skeleton, int boneIndex, float targetX, float targetY, float targetZ, float weight=1.f)
Rotate a bone so its local +Z axis aims at a world-space target.
Definition AnimPose.cpp:220
void computeWorld(const AnimSkeleton *skeleton)
Compute world transforms from local pose + skeleton hierarchy. World values readable via getWorld* af...
Definition AnimPose.cpp:203
bool solveTwoBoneIK(const AnimSkeleton *skeleton, int rootBone, int midBone, int tipBone, float targetX, float targetY, float targetZ, float weight=1.f)
Analytically solve a root-mid-tip chain toward a world-space target.
Definition AnimPose.cpp:237
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
Definition AnimSkeleton.h:16
TransformTRS mulTRS(const TransformTRS &parent, const TransformTRS &local)
Mul trs.
Definition AnimTransformInternal.h:8
Definition Animation.cpp:58
void slerpQuat(float ax, float ay, float az, float aw, float bx, float by, float bz, float bw, float t, float &ox, float &oy, float &oz, float &ow)
Slerp quat.
Definition AnimMath.h:43
Column-major 4x4 matrix (OpenGL / glTF / Assimp-compatible layout). Elements: m[col * 4 + row].
Definition AnimMath.h:156
Local TRS used by skeletal animation (quaternion xyzw).
Definition AnimMath.h:9