Successfully reported this slideshow.
(
l i g
• l k dsl
• !" = $%, $', $(, $) , !* = $%, $', $( ⇒ !" = !*, $)
•
• !" = !*, $) = ,$% + .$' + /$( + $) = !* + $)
• !* = ,$...
l l l
i
j
k
ij
l
•
ˆqˆr = iqx + jqy + kqz + qw( ) irx + jry + krz +rw( )
= i qyrz − qzry +rwqx + qwrx( )
+ j qzrx − qxrz +rwqy + qwry( )
...
l l
/*
** p <- q * r
*/
void qmul(float *p, const float *q, const float *r)
{
p[0] = q[1]*r[2] - q[2]*r[1] + r[3]*q[0] + q...
l
•
• !" + 56 = !*, $) + 5*, 7) = !* + 5*, $) + 7)
•
• !"∗ = !*, $)
∗ = −!*, $)
•
• 9 !" = !"!"∗ = !"∗!" = $%
0
+ $'
0
+ $...
•
• 9 !" = !"!"∗ ⇔
!"!"∗
? !"
= 1
• t m
• !"@A =
!"∗
? !" B
l i
• l
• !"∗ ∗ = !"
• !" + 56 ∗ = !"∗ + 56∗
• !"56 ∗ = 56∗!"∗
• l
• 9 !"∗ = 9 !"
• 9 !"56 = 9 !" 9 56
•
• C" D!" + E56 = ...
• !" = !*, $) Rl li
• 9 !" = 1 ⟹ !" = sin J KL, cos J = sin J KL + cos J
• KL m KL = 1 l
• h
• 9 !" = 9 sin J KL, cos J = ...
l i
•
• log !" = log PRKS = JKL
•
• !"V = sin J KL, cos J
V
= PRVKS = sin JE KL, cos JE
l
lp m
dsl
k dsl
ktw
• dm C
• C = W%, W', W(, W)
• i g
• C" = C*, W)
• C* = W%, W', W(
•
• !" = sin J KL, cos J
• l
• C"X = !"C"!"@A
• hm !...
l
X Z
Y
ˆqx(✓) =
✓
sin
✓
2
, 0, 0, cos
✓
2
◆
= i sin
✓
2
+ cos
✓
2
ˆqy(✓) =
✓
0, sin
✓
2
, 0, cos
✓
2
◆
= j sin
✓
2
+ cos
...
i u rw
/*
** q <- (x, y, z) (a)
*/
void qmake(float *q, float x, float y, float z, float a)
{
float l = x * x + y * y + z ...
• Z%, Z', Z( = 0, 1, 0 k  2⁄ bw
b !" rj Kcos
^
_
= sin
^
_
=
A
0
ibwK
• C" = 1, 0, 0, 0 !" ktfg d r56 =
!"C"!"∗ rj K
ˆq = ...
ktw l
• !" g u k 56 bw
• 56 !"C"!"∗ 56∗ = 56!" C" !"∗56∗ = 56!" C" 56!" ∗
• d fg l 56!" s b
kt gs b n hTw im d w
bwkm h w ...
u
jlh hm lt k h wh
Mq
=
0
B
B
@
1 s(q2
y + q2
z) s(qxqy qwqz) s(qzqx + qwqy) 0
s(qxqy + qwqz) 1 s(q2
z + q2
x) s(qyqz qwqx...
u w
/*
** m <- q
*/
void qrot(float *m, const float *q)
{
float xx = q[0] * q[0] * 2.0f;
float yy = q[1] * q[1] * 2.0f;
fl...
u ol
( ) ( ) ( )
( ) ( ) ( )
( ) ( ) ( )
÷
÷
÷
÷
÷
ø
ö
ç
ç
ç
ç
ç
è
æ
+-+-
-+-+
+-+-
=
÷
÷
÷
÷
÷
ø
ö
ç
ç
ç
ç
ç
è
æ
=
1000
0...
u ol
qw =
1
2
tr Mq
( )
4qx
2
= +m00
q
− m11
q
− m22
q
+ m33
q
4qy
2
= −m00
q
+ m11
q
− m22
q
+ m33
q
4qz
2
= −m00
q
− m11...
d l
t
s
u
p
s×t = sin2φ = 2sinφ cosφ2f
( )ff cos,sinˆ uq =
ˆq =
sinφ
sin2φ
s×t,cosφ
"
#
$
%
&
' =
1
2cosφ
s×t,cosφ
"
#
$
%...
l l
R s,t( )=
e+ hux
2
huxuy −uz huzux +uy 0
huxuy +uz e+ huy
2
huyuz −ux 0
huzux −uy huyuz +ux e+ huz
2
0
0 0 0 1
"
#
$
$...
• ktw
• l yj
•
t t( )= P t( ) E h, p,r( )= Ry h( )Rx p( )Rz r( )
⇓
R t( )= Ry h t( )( )Rx p t( )( )Rz r t( )( )
M = R t
0T...
l
• l u w
• hm : H2 @ : H. @ bw
const double cycle(5.0);
…
// l
glfwSetTime(0.0);
…
// g w bw
while (window.shouldClose() ...
P0
P1
P(t)
t
P t( )= P0 1−t( )+ P1t
l rw
/*
** rw
*/
void translate(float *m, float x, float y, float z)
{
m[ 3] = x; m[ 7] = y; m[11] = z;
m[ 0] = m[ 5] = m[...
bw w
/*
** l rw
*/
void linearMotion(
float *m, const float *p0, const float *p1, float t)
{
float x = (p1[0] - p0[0]) * t...
-G / @ 2C
P0
P1P(t)
t
m0
m1
P t( )= P0 2t3
−3t2
+1( )+ m0 t3
− 2t2
+t( )
+P1 −2t3
+3t2
( )+ m1 t3
−t2
( )
-4 @G 1B@ 2C
P0
P1
P(t)
t m0 m1
P-1
P2
• -G / @ 2C k
g
• `a =
A
0
bA − b@A
• `A =
A
0
b0 − ba
• -4 4 2C
• `a =
A@c
0
bA − ...
-4 @G 1B@ 2C l
/*
** Catmull-Rom Spline
*/
static float catmull_rom(
float x0, float x1, float x2, float x3, float t)
{
fl...
-4 @G 1B@ 2C ktw
/*
** Catmull-Rom Spline
*/
void interpolate(
float *p,
const float *p0, const float *p1,
const float *p2...
0B 4 ,4 2C
• -G / @ 2C k g
si =
1−t( ) 1+ b( ) 1−c( )
2
Pi − Pi−1( )+
1−t( ) 1− b( ) 1+c( )
2
Pi+1 − Pi( )
di =
1−t( ) 1+ ...
l
ˆqt = 1−t( ) ˆq0 +tˆqn, t ∈ 0,1[ ]
ˆqt=0 = ˆq0
ˆqt+Δt = 1− t + Δt( )( ) ˆq0 + t + Δt( ) ˆqn
= 1−t( ) ˆq0 +tˆqn + Δt ˆqn ...
2 C
( ) ( ) [ ]1,0,ˆˆˆ,ˆ,ˆˆ 1
Î= -
tt
t
qqrrqs
( )
( ) rrqs
qrqs
ˆ,ˆ,ˆˆ1
ˆ,ˆ,ˆˆ0
®Þ®
®Þ®
tt
tt
( ) ( ) ( )( ) ( )rqrqrqs ˆ...
l
#include <cmath>
/*
** p ← q i r t h
*/
void slerp(float *p,
const float *q,
const float *r,
const float t)
{
float qr =...
l l
( )itii -= + ,ˆ,ˆˆ 1qqq Slerp[ ]1
ˆ,ˆ +ii qq
l
( ) ( )
( )
( ) ( ) ( )( )tttt
t
iiii
iiii
iiii
ii
-
=
þ
ý
ü
î
í
ì +
-=
++
++
+
-
-
-
12,,ˆ,ˆ,,ˆ,ˆ
,ˆ,ˆ,ˆ,ˆ
4
ˆˆlogˆˆlog...
• fg k l
g e
• l m l bw
b
• C : G B@ B B :: 4@C (
• l h k c u
k g k d k w l
g e
• i u rw g e
• bw g e
• u rw g e
• @4 CC k...
lt j
n hbK
ゲームグラフィックス特論 第4回
Upcoming SlideShare
Loading in …5
×

ゲームグラフィックス特論 第4回

1,559 views

Published on

四元数,線形補間,曲線補間

Published in: Education
  • Be the first to comment

ゲームグラフィックス特論 第4回

  1. 1. (
  2. 2. l i g
  3. 3. • l k dsl • !" = $%, $', $(, $) , !* = $%, $', $( ⇒ !" = !*, $) • • !" = !*, $) = ,$% + .$' + /$( + $) = !* + $) • !* = ,$% + .$' + /$( = $%, $', $( • ,0 = .0 = /0 = ,./ = −1 • ./ = −/. = ,, /, = −,/ = ., ,. = −., = / $3: !4: ,, ., /:
  4. 4. l l l i j k ij
  5. 5. l • ˆqˆr = iqx + jqy + kqz + qw( ) irx + jry + krz +rw( ) = i qyrz − qzry +rwqx + qwrx( ) + j qzrx − qxrz +rwqy + qwry( ) +k qxry − qyrx +rwqz + qwrz( ) +qwrw − qxrx − qyry − qzrz = qv ×rv +rwqv + qwrv,qwrw − qv ⋅rv( )
  6. 6. l l /* ** p <- q * r */ void qmul(float *p, const float *q, const float *r) { p[0] = q[1]*r[2] - q[2]*r[1] + r[3]*q[0] + q[3]*r[0]; p[1] = q[2]*r[0] - q[0]*r[2] + r[3]*q[1] + q[3]*r[1]; p[2] = q[0]*r[1] - q[1]*r[0] + r[3]*q[2] + q[3]*r[2]; p[3] = q[3]*r[3] - q[0]*r[0] - r[1]*q[1] - q[2]*r[2]; }
  7. 7. l • • !" + 56 = !*, $) + 5*, 7) = !* + 5*, $) + 7) • • !"∗ = !*, $) ∗ = −!*, $) • • 9 !" = !"!"∗ = !"∗!" = $% 0 + $' 0 + $( 0 + $) 0 • • ;̂ = =, 1
  8. 8. • • 9 !" = !"!"∗ ⇔ !"!"∗ ? !" = 1 • t m • !"@A = !"∗ ? !" B
  9. 9. l i • l • !"∗ ∗ = !" • !" + 56 ∗ = !"∗ + 56∗ • !"56 ∗ = 56∗!"∗ • l • 9 !"∗ = 9 !" • 9 !"56 = 9 !" 9 56 • • C" D!" + E56 = DC"!" + EC"56 • DC" + E!" 56 = DC"56 + E!"56 • l • C" !"56 = C"!" 56
  10. 10. • !" = !*, $) Rl li • 9 !" = 1 ⟹ !" = sin J KL, cos J = sin J KL + cos J • KL m KL = 1 l • h • 9 !" = 9 sin J KL, cos J = sin0 J KL ⋅ KL + cos0 J = 1 • cos J + , sin J = PQR hTw i u • !" = sin J KL + cos J = PRKS
  11. 11. l i • • log !" = log PRKS = JKL • • !"V = sin J KL, cos J V = PRVKS = sin JE KL, cos JE l lp m dsl k dsl
  12. 12. ktw • dm C • C = W%, W', W(, W) • i g • C" = C*, W) • C* = W%, W', W( • • !" = sin J KL, cos J • l • C"X = !"C"!"@A • hm !@A = !∗ jlh • C"X = !"C"!"∗ !" i −!" m a b KL J J C" C"X KL k C 2J
  13. 13. l X Z Y ˆqx(✓) = ✓ sin ✓ 2 , 0, 0, cos ✓ 2 ◆ = i sin ✓ 2 + cos ✓ 2 ˆqy(✓) = ✓ 0, sin ✓ 2 , 0, cos ✓ 2 ◆ = j sin ✓ 2 + cos ✓ 2 ˆqz(✓) = ✓ 0, 0, sin ✓ 2 , cos ✓ 2 ◆ = k sin ✓ 2 + cos ✓ 2
  14. 14. i u rw /* ** q <- (x, y, z) (a) */ void qmake(float *q, float x, float y, float z, float a) { float l = x * x + y * y + z * z; if (l != 0.0f) { float s = sin(a *= 0.5f) / sqrt(l); q[0] = x * s; q[1] = y * s; q[2] = z * s; q[3] = cos(a); } }
  15. 15. • Z%, Z', Z( = 0, 1, 0 k 2⁄ bw b !" rj Kcos ^ _ = sin ^ _ = A 0 ibwK • C" = 1, 0, 0, 0 !" ktfg d r56 = !"C"!"∗ rj K ˆq = iqx + jqy + kqz + qw = sin ✓ (iux + iuy + iuz) + cos ✓
  16. 16. ktw l • !" g u k 56 bw • 56 !"C"!"∗ 56∗ = 56!" C" !"∗56∗ = 56!" C" 56!" ∗ • d fg l 56!" s b kt gs b n hTw im d w bwkm h w l i ajlh l m l kjw
  17. 17. u jlh hm lt k h wh Mq = 0 B B @ 1 s(q2 y + q2 z) s(qxqy qwqz) s(qzqx + qwqy) 0 s(qxqy + qwqz) 1 s(q2 z + q2 x) s(qyqz qwqx) 0 s(qzqx qwqy) s(qyqz + qwqx) 1 s(q2 x + q2 y) 0 0 0 0 1 1 C C A Mq = 0 B B @ 1 2(q2 y + q2 z) 2(qxqy qwqz) 2(qzqx + qwqy) 0 2(qxqy + qwqz) 1 2(q2 z + q2 x) 2(qyqz qwqx) 0 2(qzqx qwqy) 2(qyqz + qwqx) 1 2(q2 x + q2 y) 0 0 0 0 1 1 C C A ˆq = (qx, qy, qz, qw) s = 2/n(ˆq) k g n k m
  18. 18. u w /* ** m <- q */ void qrot(float *m, const float *q) { float xx = q[0] * q[0] * 2.0f; float yy = q[1] * q[1] * 2.0f; float zz = q[2] * q[2] * 2.0f; float xy = q[0] * q[1] * 2.0f; float yz = q[1] * q[2] * 2.0f; float zx = q[2] * q[0] * 2.0f; float xw = q[0] * q[3] * 2.0f; float yw = q[1] * q[3] * 2.0f; float zw = q[2] * q[3] * 2.0f; m[ 0] = 1.0f - yy - zz; m[ 1] = xy + zw; m[ 2] = zx - yw; m[ 4] = xy - zw; m[ 5] = 1.0f - zz - xx; m[ 6] = yz + xw; m[ 8] = zx + yw; m[ 9] = yz - xw; m[10] = 1.0f - xx - yy; m[ 3] = m[ 7] = m[11] = m[12] = m[13] = m[14] = 0.0f; m[15] = 1.0f; }
  19. 19. u ol ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ÷ ÷ ÷ ÷ ÷ ø ö ç ç ç ç ç è æ +-+- -+-+ +-+- = ÷ ÷ ÷ ÷ ÷ ø ö ç ç ç ç ç è æ = 1000 02122 02212 02221 22 22 22 33323130 23222120 13121110 03020100 yxxwzyywxz xwzyxzzwyx ywxzzwyxzy qqqq qqqq qqqq qqqq q qqqqqqqqqq qqqqqqqqqq qqqqqqqqqq mmmm mmmm mmmm mmmm M tr Mq ( )= mii q i=0 3 ∑ = m00 q + m11 q + m22 q + m33 q = 4− 4 qx 2 + qy 2 + qz 2 ( )= 4qw 2
  20. 20. u ol qw = 1 2 tr Mq ( ) 4qx 2 = +m00 q − m11 q − m22 q + m33 q 4qy 2 = −m00 q + m11 q − m22 q + m33 q 4qz 2 = −m00 q − m11 q + m22 q + m33 q Tw m qx = m21 q − m12 q 4qw qy = m02 q − m20 q 4qw qz = m10 q − m01 q 4qw
  21. 21. d l t s u p s×t = sin2φ = 2sinφ cosφ2f ( )ff cos,sinˆ uq = ˆq = sinφ sin2φ s×t,cosφ " # $ % & ' = 1 2cosφ s×t,cosφ " # $ % & ' = 1 2 1+e( ) s×t, 2 1+e( ) 2 " # $ $ % & ' ' u = s×t s×t s⋅t = cos2φ = e cosφ = 1+e 2
  22. 22. l l R s,t( )= e+ hux 2 huxuy −uz huzux +uy 0 huxuy +uz e+ huy 2 huyuz −ux 0 huzux −uy huyuz +ux e+ huz 2 0 0 0 0 1 " # $ $ $ $ $$ % & ' ' ' ' '' u = ux uy uz( )= s×t s×t e = cos2φ = s⋅t h = 1−cos2φ sin2 2φ = 1−e u⋅u ˆq = qv,qw( )= 1 2 1+e( ) s×t, 2 1+e( ) 2 " # $ $ % & ' '
  23. 23. • ktw • l yj • t t( )= P t( ) E h, p,r( )= Ry h( )Rx p( )Rz r( ) ⇓ R t( )= Ry h t( )( )Rx p t( )( )Rz r t( )( ) M = R t 0T 1 ! " # $ % & = I t 0T 1 ! " # $ % & R 0 0T 1 ! " # $ % & t: R: I
  24. 24. l • l u w • hm : H2 @ : H. @ bw const double cycle(5.0); … // l glfwSetTime(0.0); … // g w bw while (window.shouldClose() == GL_FALSE) { … // l S float t((float)(fmod(glfwGetTime(), cycle) / cycle)); …
  25. 25. P0 P1 P(t) t P t( )= P0 1−t( )+ P1t
  26. 26. l rw /* ** rw */ void translate(float *m, float x, float y, float z) { m[ 3] = x; m[ 7] = y; m[11] = z; m[ 0] = m[ 5] = m[10] = m[15] = 1.0f; m[ 1] = m[ 2] = m[ 4] = m[ 6] = m[ 8] = m[ 9] = m[12] = m[13] = m[14] = 0.0f; }
  27. 27. bw w /* ** l rw */ void linearMotion( float *m, const float *p0, const float *p1, float t) { float x = (p1[0] - p0[0]) * t + p0[0]; float y = (p1[1] - p0[1]) * t + p0[1]; float z = (p1[2] - p0[2]) * t + p0[2]; translate(m, x, y, z); }
  28. 28. -G / @ 2C P0 P1P(t) t m0 m1 P t( )= P0 2t3 −3t2 +1( )+ m0 t3 − 2t2 +t( ) +P1 −2t3 +3t2 ( )+ m1 t3 −t2 ( )
  29. 29. -4 @G 1B@ 2C P0 P1 P(t) t m0 m1 P-1 P2 • -G / @ 2C k g • `a = A 0 bA − b@A • `A = A 0 b0 − ba • -4 4 2C • `a = A@c 0 bA − b@A • `A = A@c 0 b0 − ba • d m • d = 1 • d = 0 -4 @G 1B@ 2C
  30. 30. -4 @G 1B@ 2C l /* ** Catmull-Rom Spline */ static float catmull_rom( float x0, float x1, float x2, float x3, float t) { float m0 = (x2 - x0) * 0.5f, m1 = (x3 - x1) * 0.5f; return (((2.0f * x1 - 2.0f * x2 + m0 + m1) * t - 3.0f * x1 + 3.0f * x2 - 2.0f * m0 - m1) * t + m0) * t + x1; }
  31. 31. -4 @G 1B@ 2C ktw /* ** Catmull-Rom Spline */ void interpolate( float *p, const float *p0, const float *p1, const float *p2, const float *p3, float t) { p[0] = catmull_rom(p0[0], p1[0], p2[0], p3[0], t); p[1] = catmull_rom(p0[1], p1[1], p2[1], p3[1], t); p[2] = catmull_rom(p0[2], p1[2], p2[2], p3[2], t); }
  32. 32. 0B 4 ,4 2C • -G / @ 2C k g si = 1−t( ) 1+ b( ) 1−c( ) 2 Pi − Pi−1( )+ 1−t( ) 1− b( ) 1+c( ) 2 Pi+1 − Pi( ) di = 1−t( ) 1+ b( ) 1+c( ) 2 Pi − Pi−1( )+ 1−t( ) 1− b( ) 1−c( ) 2 Pi+1 − Pi( ) Pi si di+1Pi+1 Pi-1 m0 m1 si+1di Pi+2 B , 4 -B G ,- 2C
  33. 33. l ˆqt = 1−t( ) ˆq0 +tˆqn, t ∈ 0,1[ ] ˆqt=0 = ˆq0 ˆqt+Δt = 1− t + Δt( )( ) ˆq0 + t + Δt( ) ˆqn = 1−t( ) ˆq0 +tˆqn + Δt ˆqn − ˆq0( ) = ˆqt + Δˆq qn q0qtqt+ t Δˆq = Δt ˆqn − ˆq0( )h yw
  34. 34. 2 C ( ) ( ) [ ]1,0,ˆˆˆ,ˆ,ˆˆ 1 Î= - tt t qqrrqs ( ) ( ) rrqs qrqs ˆ,ˆ,ˆˆ1 ˆ,ˆ,ˆˆ0 ®Þ® ®Þ® tt tt ( ) ( ) ( )( ) ( )rqrqrqs ˆ sin sin ˆ sin 1sin ,ˆ,ˆ,ˆ,ˆˆ f f f f tt tt + - ==slerp ( ) ( )2 1 ˆˆ1sin ˆˆcos ˆˆcos rq rq rq ×-= ×= +++=×= - f f f wwzzyyxx rqrqrqrq qˆ rˆ ( )t,ˆ,ˆˆ rqs
  35. 35. l #include <cmath> /* ** p ← q i r t h */ void slerp(float *p, const float *q, const float *r, const float t) { float qr = q[0] * r[0] + q[1] * r[1] + q[2] * r[2] + q[3] * r[3]; float ss = 1.0f - qr * qr; if (ss == 0.0) { p[0] = q[0]; p[1] = q[1]; p[2] = q[2]; p[3] = q[3]; } else { float sp = sqrt(ss); float ph = acos(qr); float pt = ph * t; float t1 = sin(pt) / sp; float t0 = sin(ph - pt) / sp; p[0] = q[0] * t0 + r[0] * t1; p[1] = q[1] * t0 + r[1] * t1; p[2] = q[2] * t0 + r[2] * t1; p[3] = q[3] * t0 + r[3] * t1; } }
  36. 36. l l ( )itii -= + ,ˆ,ˆˆ 1qqq Slerp[ ]1 ˆ,ˆ +ii qq
  37. 37. l ( ) ( ) ( ) ( ) ( ) ( )( )tttt t iiii iiii iiii ii - = þ ý ü î í ì + -= ++ ++ + - - - 12,,ˆ,ˆ,,ˆ,ˆ ,ˆ,ˆ,ˆ,ˆ 4 ˆˆlogˆˆlog expˆˆ 11 11 1 1 1 1 aaqq aaqq qqqq qa slerpslerpslerp squad iqˆ 1 ˆ -iq 1 ˆ +iq
  38. 38. • fg k l g e • l m l bw b • C : G B@ B B :: 4@C ( • l h k c u k g k d k w l g e • i u rw g e • bw g e • u rw g e • @4 CC k g e • B B H4 4 4@4 G 4 C
  39. 39. lt j n hbK

×