All posts by kpark

Linear Interpolation (LERP)

protected override void Update(GameTime gameTime)
{
totalElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds;

// determine how far along the duration value we are (0 to 1), duration=5 sec
float fraction = totalElapsedTime / duration;

// fraction = MathHelper.Clamp(fraction, 0, 1);
while (fraction > 1) fraction -= 1;

// interpolate modelPosition between startPosition and endPosition using fraction
modelPosition = Vector3.Lerp(startPosition, endPosition, fraction);

myModel.World = Matrix.CreateTranslation(modelPosition);

/// 중간생략 …
base.Update(gameTime);
}

XNA 4.0 + Kinect SDK 1.7

Kinect for Windows SDK Quickstarts
http://channel9.msdn.com/Series/KinectSDKQuickstarts

Kinect .NET SDK를 사용하려면 다음 요구 사항을 만족해야한다.
– OS: Windows 7, 8, or Embedded Standard 7
– HW: 듀얼코어, 2.66 GHz 이상, 2GB RAM 컴퓨터,
MS DirectX 9.0c를 지원하는 그래픽카드, 키넥트 센서
– SW: MS Visual Studio 2010, MS .NET Framework 4.0, Kinect for Windows SDK

1. Set up Kinect for Windows SDK
http://www.microsoft.com/en-us/kinectforwindows/develop/developer-downloads.aspx
– “DOWNLOAD LATEST SDK” the latest Kinect for Windows SDK (March 18, 2013) 를 다운로드 받아서 설치한다.
– “DOWNLOAD TOOLKIT” 를 다운로드 받아서 설치한다.
– 키넥트 센서를 연결하면 장치로 인식되며, Device Manager (장치관리자)에서 확인한다.


사용자 삽입 이미지

2. Setting Up Your Development Environment
– Kinect for Windows SDK v.1.7 (March 18, 2013) 설치
– Visual Studio 2010 설치
– MS DirectX 9.0c SDK (June 2010) 설치
– XNA 4.0 설치

3. Setting up a new VS2010 Project
– File -> New Project -> Visual C# -> XNA Game Studio 4.0 -> Windows Game 선택하고
프로젝트를 시작
– C# 프로젝트의 Reference에 Microsoft.Kinect를 추가

사용자 삽입 이미지


4. C# 프로젝트 소스코드에 Kinect 클래스 namespace를 추가

using Microsoft.Kinect;




5. KinectColor 프로그램을 실행 (RGB camera 테스트)




6. KinectColor 프로그램을 실행 (RGB/Depth/Skeleton 테스트)




7. KinectSkeletonTracking 프로그램을 실행 (왼손&오른손 트래킹 테스트)

XNA Transformation (RHS)

Matrix A = new Matrix(1.0f, 0.0f, 0.0f, 0.0f, // row1
0.0f, 2.0f, 0.0f, 0.0f, // row2

0.0f, 0.0f, 4.0f, 0.0f, // row3
1.0f, 2.0f, 3.0f, 1.0f); // row4
System.Diagnostics.Trace.WriteLine(A);
// { {M11:1 M12:0 M13:0 M14:0}
// {M21:0 M22:2 M23:0 M24:0}
// {M31:0 M32:0 M33:4 M34:0}
//
{M41:1 M42:2 M43:3 M44:1} }


Matrix B = new Matrix(1.0f, 0.0f, 0.0f, 0.0f, // row1
0.0f, 2.0f, 0.0f, 0.0f, // row2
0.0f, 0.0f, 4.0f, 0.0f, // row3
2.0f, 2.0f, 2.0f, 1.0f); // row4
System.Diagnostics.Trace.WriteLine(B);
// { {M11:1 M12:0 M13:0 M14:0}
// {M21:0 M22:1 M23:0 M24:0}
// {M31:0 M32:0 M33:1 M34:0}
// {M41:2 M42:2 M43:2 M44:1} }


Matrix C = A * B;
System.Diagnostics.Trace.WriteLine(C);
// { {M11:1 M12:0 M13:0 M14:0}
// {M21:0 M22:2 M23:0 M24:0}
// {M31:0 M32:0 M33:4 M34:0}
// {M41:3 M42:4 M43:5 M44:1} }


Matrix D = B * A;
System.Diagnostics.Trace.WriteLine(D);
// { {M11:1 M12:0 M13:0 M14:0}
// {M21:0 M22:2 M23:0 M24:0}
// {M31:0 M32:0 M33:4 M34:0}
// {M41:3 M42:6 M43:11 M44:1} }


Matrix E = Matrix.Invert(A);
System.Diagnostics.Trace.WriteLine(E);
// { {M11:1 M12:0 M13:0 M14:0}
// {M21:0 M22:0.5 M23:0 M24:0}
// {M31:0 M32:0 M33:0.25 M34:0}
// {M41:-1 M42:-1 M43:-0.75 M44:1} }


Matrix I = E * A; // I (Identity Matrix) = A-1 * A
System.Diagnostics.Trace.WriteLine(I);
// { {M11:1 M12:0 M13:0 M14:0}
// {M21:0 M22:1 M23:0 M24:0}
// {M31:0 M32:0 M33:1 M34:0}
// {M41:0 M42:0 M43:0 M44:1} }


// p’ = p * M (XNA uses Row-Major Order)
Vector3 p = new Vector3(1.0f, 0.0f, 0.0f);
System.Diagnostics.Trace.WriteLine(p);
// {X:1 Y:0 Z:0}


Vector3 q = Vector3.Transform(p, A); // q = p * A
System.Diagnostics.Trace.WriteLine(q);
// {X:2 Y:2 Z:3}


Vector3 r = Vector3.Transform(p, B); // r = p * B
System.Diagnostics.Trace.WriteLine(r);
// {X:3 Y:2 Z:2}


Vector3 s = Vector3.Transform(p, C); // q = p * A * B (A 먼저, B 나중)
System.Diagnostics.Trace.WriteLine(s);
// {X:4 Y:4 Z:5}


Vector3 t = Vector3.Transform(p, D); // r = p * B * A (B 먼저, A 나중)
System.Diagnostics.Trace.WriteLine(t);
// {X:4 Y:6 Z:11}

Matrix Tx,Ty,Tz;
Tx = Matrix.CreateTranslation(2, 0, 0); // RHS x+ right
Ty = Matrix.CreateTranslation(0, 2, 0); // RHS y+ up
Tz = Matrix.CreateTranslation(0, 0, 2); // RHS z+ in front of screen

System.Diagnostics.Trace.WriteLine(Tx);
// { {M11:1 M12:0 M13:0 M14:0}
// {M21:0 M22:1 M23:0 M24:0}
// {M31:0 M32:0 M33:1 M34:0}
//
{M41:2 M42:0 M43:0 M44:1} }

Matrix Rx,Ry,Rz, Ra; // XNA uses RADIAN angle
Rx = Matrix.CreateRotationX(MathHelper.ToRadians(30.0)); // RHS x+ (Y->Z rotation)
Ry = Matrix.CreateRotationY(MathHelper.ToRadians(60.0)); // RHS y+ (Z->X rotation)
Rz = Matrix.CreateRotationZ(MathHelper.ToRadians(45.0)); // RHS z+ (X->Y rotation)
Ra = Matrix.CreateFromAxisAngle(new Vector3(1.0f, 1.0f, 1.0f), MathHelper.ToRadians(45.0)); // RHS (arbitrary axis)

System.Diagnostics.Trace.WriteLine(Rx);
//{ {M11:1 M12:0 M13:0 M14:0}
// {M21:0 M22:0.8660254 M23:0.5 M24:0}
// {M31:0 M32:-0.5 M33:0.8660254 M34:0}
// {M41:0 M42:0 M43:0 M44:1} }

System.Diagnostics.Trace.WriteLine(Ry);
//{ {M11:0.5 M12:0 M13:-0.8660254 M14:0}
// {M21:0 M22:1 M23:0 M24:0}
// {M31:0.8660254 M32:0 M33:0.5 M34:0}
// {M41:0 M42:0 M43:0 M44:1} }


System.Diagnostics.Trace.WriteLine(Rz);
//{ {M11:0.7071068 M12:0.7071068 M13:0 M14:0}
// {M21:-0.7071068 M22:0.7071068 M23:0 M24:0}
// {M31:0 M32:0 M33:1 M34:0}
// {M41:0 M42:0 M43:0 M44:1} }


System.Diagnostics.Trace.WriteLine(Ra);
// { {M11:1 M12:1 M13:-0.4142135 M14:0}
// {M21:-0.4142135 M22:1 M23:1 M24:0}
// {M31:1 M32:-0.4142135 M33:1 M34:0}
// {M41:0 M42:0 M43:0 M44:1} }


Matrix Sx,Sy,Sz;
Sx = Matrix.CreateScale(2, 1, 1); // RHS
Sy = Matrix.CreateScale(1, 2, 1); // RHS
Sz = Matrix.CreateScale(1, 1, 2); // RHS

System.Diagnostics.Trace.WriteLine(Sy);
// { {M11:1 M12:0 M13:0 M14:0}
// {M21:0 M22:2 M23:0 M24:0}
// {M31:0 M32:0 M33:1 M34:0}
// {M41:0 M42:0 M43:0 M44:1} }

// p’ = p * M1 * M2 * M3 (XNA uses Row-Major Order)
Matrix TR, RT, TRS, SRT
TR = Tx * Rz; // Translate X, and then Rotate Z
RT = Rz * Tx; // Rotate Z, and then Translate X
TRS = Tx * Rz * Sy; // Translate X, and then Rotate Z, and then Scale Y
SRT =
Sy * Rz * Tx; // Scale Y, and then Rotate Z, and then Translate X

System.Diagnostics.Trace.WriteLine(TR);
// { {M11:0.7071068 M12:0.7071068 M13:0 M14:0}
// {M21:-0.7071068 M22:0.7071068 M23:0 M24:0}
// {M31:0 M32:0 M33:1 M34:0}
// {M41:1.414214 M42:1.414214 M43:0 M44:1} }

System.Diagnostics.Trace.WriteLine(RT);
// { {M11:0.7071068 M12:0.7071068 M13:0 M14:0}
// {M21:-0.7071068 M22:0.7071068 M23:0 M24:0}
// {M31:0 M32:0 M33:1 M34:0}
// {M41:2 M42:0 M43:0 M44:1} }

System.Diagnostics.Trace.WriteLine(TRS);
// { {M11:0.7071068 M12:1.414214 M13:0 M14:0}
// {M21:-0.7071068 M22:1.414214 M23:0 M24:0}
// {M31:0 M32:0 M33:1 M34:0}
// {M41:1.414214 M42:2.828427 M43:0 M44:1} }

System.Diagnostics.Trace.WriteLine(SRT);
// { {M11:0.7071068 M12:0.7071068 M13:0 M14:0}
// {M21:-1.414214 M22:1.414214 M23:0 M24:0}
// {M31:0 M32:0 M33:1 M34:0}
// {M41:2 M42:0 M43:0 M44:1} }