-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdiary
182 lines (148 loc) · 5.1 KB
/
diary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# llafuente developer diary, important notes, links, notes...
# maybe don't worth reading ^.^
Physics
* http://www.metanetsoftware.com/technique/tutorialB.html
* http://www.metanetsoftware.com/technique/tutorialA.html
* http://buildnewgames.com/gamephysics/
* Algorithm
* Backtracking
* A*
* IK
* FABRIK
vec2 distances (minkowski distance, euclidean, Manhattan)
https://github.com/abeja-inc/vector-algebra/blob/master/lib/vectorAlgebra.js
http://www.ryanjuckett.com/programming/constraint-relaxation-ik-in-2d/
http://www.dhteumeuleu.com/dhtml/robot-arm-ik.html
http://www.gvh.co.za/basic-inverse-kinematics/
http://arifudin.com/view.php?id=andreasaristidou.com/publications/FABRIK.pdf&k=gmod%20rating
https://github.com/RGBboy/fabrik-2d
Input: The joint positions pi for i = 1,...,n, the target position t and the distances between each joint
di = jpi+1 А
pij for i = 1,...,n А 1.
Output: The new joint positions pi for i = 1,...,n.
% The distance between root and target
dist = jp1 А tj
% Check whether the target is within reach
if dist > d1 + d2 +...+ dnА1 then
% The target is unreachable
for i = 1,...,n А 1 do
% Find the distance ri between the target t and the joint position pi
ri = jt А pij
ki = di/ri
% Find the new joint positions pi.
pi+1 = (1 А ki) pi + kit
end
else
% The target is reachable; thus, set as b the initial position of the joint p1
b = p1
% Check whether the distance between the end effector pn and the target t is greater than a tolerance.
difA = jpn А tj
while difA > tol do
% STAGE 1: FORWARD REACHING
% Set the end effector pn as target t
pn = t
for i = n А 1,...,1 do
% Find the distance ri between the new joint position pi+1 and the joint pi
ri = jpi+1 А pij
ki = di/ri
% Find the new joint positions pi.
pi = (1 А ki) pi+1 + kipi
end
% STAGE 2: BACKWARD REACHING
% Set the root p1 its initial position.
p1 = b
for i = 1,...,n А 1 do
% Find the distance ri between the new joint position pi and the joint pi+1
ri = jpi+1 А pij
ki = di/ri
% Find the new joint positions pi.
pi+1 = (1 А ki)pi + kipi+1
end
difA = jpn А tj
end
end
/**
* closestPointToBezier Find the closest point on a quadratic or cubic Bezier curve to an arbitrary point
*
* @param _curve:Geometry reference that must be a quadratic or cubic Bezier3
* @param _p:Point reference to <code>Point</code> to which the closest point on the Bezier curve is desired
*
* @return Number t-parameter of the closest point on the parametric curve. Returns 0 if inputs are <code>null</code> or not a valid reference to a Bezier curve.
*
* This code is derived from the Graphic Gem, "Solving the Nearest-Point-On-Curve Problem", by P.J. Schneider, published in 'Graphic Gems',
* A.S. Glassner, ed., Academic Press, Boston, 1990, pp. 607-611.
*
* @since 1.0
*
*/
function closestPoint (out_vec2, curve, vec2) {
// record distances from point to endpoints
var p:Point = _curve.pointAt(0);
var deltaX:Number = p.x-_p.x;
var deltaY:Number = p.y-_p.y;
var d0:Number = Math.sqrt(deltaX*deltaX + deltaY*deltaY);
p = _curve.pointAt(1);
deltaX = p.x-_p.x;
deltaY = p.y-_p.y;
var d1:Number = Math.sqrt(deltaX*deltaX + deltaY*deltaY);
var n:uint = (_curve is QuadraticBezier) ? 2 : 3; // degree of input Bezier curve
// array of control points
var v:Array = new Array();
if( n == 2 )
{
var quad:QuadraticBezier = _curve as QuadraticBezier;
v[0] = new Point(quad.x0, quad.y0);
v[1] = new Point(quad.cx, quad.cy);
v[2] = new Point(quad.x1, quad.y1);
}
else
{
var cubic:CubicBezier = _curve as CubicBezier;
v[0] = new Point(cubic.x0 , cubic.y0 );
v[1] = new Point(cubic.cx , cubic.cy );
v[2] = new Point(cubic.cx1, cubic.cy1);
v[3] = new Point(cubic.x1 , cubic.y1 );
}
// instaead of power form, convert the function whose zeros are required to Bezier form
var w:Array = toBezierForm(_p, v);
// Find roots of the Bezier curve with control points stored in 'w' (algorithm is recursive, this is root depth of 0)
var roots:Array = findRoots(w, 2*n-1, 0);
// compare the candidate distances to the endpoints and declare a winner :)
if( d0 < d1 )
{
var tMinimum:Number = 0;
__dMinimum = d0;
}
else
{
tMinimum = 1;
__dMinimum = d1;
}
// tbd - compare 2-norm squared
for( var i:uint=0; i<roots.length; ++i )
{
var t:Number = roots[i];
if( t >= 0 && t <= 1 )
{
p = _curve.pointAt(t);
deltaX = p.x - _p.x;
deltaY = p.y - _p.y;
var d:Number = Math.sqrt(deltaX*deltaX + deltaY*deltaY);
if( d < __dMinimum )
{
tMinimum = t;
__dMinimum = d;
}
}
}
// tbd - alternate optima.
return tMinimum;
}
* Posts and links you should have read
http://realtimecollisiondetection.net/blog/?p=80
* How Valve Connects Art Direction to Gameplay
http://www.microsoft.com/en-us/download/details.aspx?id=18638
* Bringing Characters to Life: Using Physics to Enhance Animation
http://www.microsoft.com/en-us/download/details.aspx?id=3507
* Bit Twiddling Hacks
http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2