00001
00002
00003
00004
00005
00006 namespace PendulumGame
00007 {
00008 using System;
00009 using System.Collections;
00010 using System.Collections.Generic;
00011 using System.Text;
00012
00013 using Microsoft.Xna.Framework;
00014 using Microsoft.Xna.Framework.Graphics;
00015
00016 using NewGamePhysics.Utilities;
00017 using NewGamePhysics.Mathematics;
00018 using NewGamePhysics.Physics;
00019 using NewGamePhysics.PhysicalElements;
00020
00024 public class GamePlayer
00025 {
00029 private const int ActionIntensityQueueSize = 32;
00030
00034 private int points;
00035
00039 private int selectedIndicator;
00040
00044 private DoublePendulumHinges actionMarker;
00045
00050 private double actionIntensity;
00051
00055 private ButterworthFilter filter;
00056
00060 private EdgeDetector detector;
00061
00065 private Queue<double> actionIntensityQueue;
00066
00070 public GamePlayer()
00071 {
00072 this.selectedIndicator = 0;
00073 this.points = 0;
00074 this.actionIntensityQueue =
00075 new Queue<double>(ActionIntensityQueueSize);
00076 this.filter =
00077 new ButterworthFilter(ButterworthFilterType.HighPass, 100, 20);
00078 this.detector =
00079 new EdgeDetector(EdgeDetectionType.Rising, 0.4);
00080 }
00081
00082 #region Properties
00083
00087 public int SelectedIndicator
00088 {
00089 get { return this.selectedIndicator; }
00090 set { this.selectedIndicator = value; }
00091 }
00092
00096 public int Points
00097 {
00098 get {
00099 return this.points;
00100 }
00101 set
00102 {
00103 this.points = value;
00104 }
00105 }
00106
00110 public DoublePendulumHinges ActionMarker
00111 {
00112 get {
00113 return this.actionMarker;
00114 }
00115 set {
00116 this.actionMarker = value;
00117 }
00118 }
00119
00123 public double ActionIntensity
00124 {
00125 get {
00126 return this.actionIntensity;
00127 }
00128 set {
00129 if (value < -1.0)
00130 {
00131 this.actionIntensity = -1.0;
00132 }
00133 else if (value > 1.0)
00134 {
00135 this.actionIntensity = 1.0;
00136 }
00137 else
00138 {
00139 this.actionIntensity = value;
00140 }
00141 }
00142 }
00143
00144 #endregion
00145
00149 public void TrackActionIntensity()
00150 {
00151
00152 if (this.actionIntensityQueue.Count == ActionIntensityQueueSize)
00153 {
00154 this.actionIntensityQueue.Dequeue();
00155 }
00156
00157
00158 this.actionIntensityQueue.Enqueue(this.actionIntensity);
00159 }
00160
00167 public bool ActionIntensityChanged()
00168 {
00169
00170 if (this.actionIntensityQueue.Count == ActionIntensityQueueSize)
00171 {
00172 double[] samples = this.actionIntensityQueue.ToArray();
00173
00174
00175 double[] filteredSamples = this.filter.Calculate(samples);
00176
00177
00178 double[] detectedSamples = this.detector.Calculate(samples);
00179
00180
00181 if (detectedSamples[ActionIntensityQueueSize - 1] > 0.0)
00182 {
00183 return true;
00184 }
00185 }
00186
00187 return false;
00188 }
00189 }
00190 }