internal void AddInfo(Microsoft.Research.Kinect.Nui.Vector vector) { prevInfo = (list[0] != null) ? this.list[(currentIndex + capacity - 1) % capacity] : null; refInfo = (list[5] != null) ? this.list[(currentIndex + capacity - 5) % capacity] : null; currentInfo = new AccelInfo(vector, refInfo); this.list[currentIndex] = currentInfo; currentIndex = (currentIndex+1) % capacity; }
public AccelInfo(Vector vector, AccelInfo prevInfo) { i++; timestamp = System.DateTime.Now; this.vector = new Vector3D(vector.X, vector.Y, vector.Z); if (prevInfo != null) { TimeSpan span = timestamp - prevInfo.timestamp; spanSec = (float)span.TotalMilliseconds / 1000f; if (spanSec < 20f /1000f) { spanSec = 20f/1000f; } //速度を計算 velocity = new Vector3D(); velocity.X = (vector.X - prevInfo.vector.X)/spanSec; velocity.Y = (vector.Y - prevInfo.vector.Y) / spanSec; velocity.Z = (vector.Z - prevInfo.vector.Z) / spanSec; //加速度を計算 acceleration = new Vector3D(); acceleration.X = (velocity.X - prevInfo.velocity.X) / spanSec; acceleration.Y = (velocity.Y - prevInfo.velocity.Y) / spanSec; acceleration.Z = (velocity.Z - prevInfo.velocity.Z) / spanSec; } else { velocity = new Vector3D(); velocity.X = 0; velocity.Y = 0; velocity.Z = 0; acceleration = new Vector3D(); acceleration.X = 0; acceleration.Y = 0; acceleration.Z = 0; } }