RavEngine
Loading...
Searching...
No Matches
ik_aim_job.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_ANIMATION_RUNTIME_IK_AIM_JOB_H_
29#define OZZ_OZZ_ANIMATION_RUNTIME_IK_AIM_JOB_H_
30
31#include "ozz/animation/runtime/export.h"
32#include "ozz/base/platform.h"
33
34#include "ozz/base/maths/simd_math.h"
35
36namespace ozz {
37// Forward declaration of math structures.
38namespace math {
39struct SimdQuaternion;
40}
41
42namespace animation {
43
44// ozz::animation::IKAimJob rotates a joint so it aims at a target. Joint aim
45// direction and up vectors can be different from joint axis. The job computes
46// the transformation (rotation) that needs to be applied to the joints such
47// that a provided forward vector (in joint local-space) aims at the target
48// position (in skeleton model-space). Up vector (in joint local-space) is also
49// used to keep the joint oriented in the same direction as the pole vector.
50// The job also exposes an offset (in joint local-space) from where the forward
51// vector should aim the target.
52// Result is unstable if joint-to-target direction is parallel to pole vector,
53// or if target is too close to joint position.
54struct OZZ_ANIMATION_DLL IKAimJob {
55 // Default constructor, initializes default values.
56 IKAimJob();
57
58 // Validates job parameters. Returns true for a valid job, or false otherwise:
59 // -if output quaternion pointer is nullptr
60 bool Validate() const;
61
62 // Runs job's execution task.
63 // The job is validated before any operation is performed, see Validate() for
64 // more details.
65 // Returns false if *this job is not valid.
66 bool Run() const;
67
68 // Job input.
69
70 // Target position to aim at, in model-space
71 math::SimdFloat4 target;
72
73 // Joint forward axis, in joint local-space, to be aimed at target position.
74 // This vector shall be normalized, otherwise validation will fail.
75 // Default is x axis.
76 math::SimdFloat4 forward;
77
78 // Offset position from the joint in local-space, that will aim at target.
79 math::SimdFloat4 offset;
80
81 // Joint up axis, in joint local-space, used to keep the joint oriented in the
82 // same direction as the pole vector. Default is y axis.
84
85 // Pole vector, in model-space. The pole vector defines the direction
86 // the up should point to. Note that IK chain orientation will flip when
87 // target vector and the pole vector are aligned/crossing each other. It's
88 // caller responsibility to ensure that this doesn't happen.
89 math::SimdFloat4 pole_vector;
90
91 // Twist_angle rotates joint around the target vector.
92 // Default is 0.
93 float twist_angle;
94
95 // Weight given to the IK correction clamped in range [0,1]. This allows to
96 // blend / interpolate from no IK applied (0 weight) to full IK (1).
97 float weight;
98
99 // Joint model-space matrix.
100 const math::Float4x4* joint;
101
102 // Job output.
103
104 // Output local-space joint correction quaternion. It needs to be multiplied
105 // with joint local-space quaternion.
106 math::SimdQuaternion* joint_correction;
107
108 // Optional boolean output value, set to true if target can be reached with IK
109 // computations. Target is considered not reachable when target is between
110 // joint and offset position.
111 bool* reached;
112};
113} // namespace animation
114} // namespace ozz
115#endif // OZZ_OZZ_ANIMATION_RUNTIME_IK_AIM_JOB_H_
Definition simd_math_config.h:121
Definition ik_aim_job.h:54
Definition simd_math.h:1066
Definition simd_quaternion.h:39