浏览代码

split up render/update

Alexander Hendrich 11 年之前
父节点
当前提交
1f7b34bd54
共有 3 个文件被更改,包括 35 次插入38 次删除
  1. 12 4
      bbiwarg/Graphics/OutputWindow.cs
  2. 22 33
      bbiwarg/InputHandler.cs
  3. 1 1
      bbiwarg/Parameters.cs

+ 12 - 4
bbiwarg/Graphics/OutputWindow.cs

@@ -58,7 +58,6 @@ namespace bbiwarg.Graphics
             if (inputProvider is VideoInputProvider)
                 Keyboard.KeyDown += HandleKeyDownVideoControls;
 
-            VSync = VSyncMode.Off;
         }
 
         protected override void OnResize(EventArgs e)
@@ -80,6 +79,17 @@ namespace bbiwarg.Graphics
             GL.LoadMatrix(ref projection);
         }
 
+        protected override void OnUpdateFrame(FrameEventArgs e)
+        {
+            base.OnUpdateFrame(e);
+
+            if (inputHandler.CurrentFrameID - inputProvider.CurrentFrameID > 20)
+                inputHandler.resetConsistentObjects();
+
+            if (inputProvider.CurrentFrameID != inputHandler.CurrentFrameID)
+                inputHandler.updateFrame();
+        }
+
         protected override void OnRenderFrame(FrameEventArgs e)
         {
             Timer.start("onRenderFrame");
@@ -89,9 +99,7 @@ namespace bbiwarg.Graphics
             Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
             GL.MatrixMode(MatrixMode.Modelview);
             GL.LoadMatrix(ref modelview);
-
-            inputHandler.updateFrame();
-
+            
             Title = Parameters.OutputTitle + " (Frame: " + inputProvider.CurrentFrameID + ")";
 
             Timer.start("buildTextures");

+ 22 - 33
bbiwarg/InputHandler.cs

@@ -21,12 +21,8 @@ namespace bbiwarg
 {
     class InputHandler
     {
-        public OutputImage[] OutputImages { get; private set; }
-
         private InputProvider inputProvider;
         private InputFrame currentInputFrame;
-        private int currentFrameID;
-        private int lastFrameID;
 
         private DepthImage depthImage;
         private EdgeImage edgeImage;
@@ -45,11 +41,13 @@ namespace bbiwarg
         private TouchEventVisualizer touchEventVisualizer;
         private TuioCommunicator tuioCommunicator;
 
+        public OutputImage[] OutputImages { get; private set; }
+        public int CurrentFrameID { get; private set; }
+
         public InputHandler(InputProvider inputProvider)
         {
             this.inputProvider = inputProvider;
-            this.currentFrameID = inputProvider.CurrentFrameID;
-            this.lastFrameID = this.currentFrameID - 1;
+            this.CurrentFrameID = inputProvider.CurrentFrameID;
 
             initializeConsistentObjects();
         }
@@ -76,7 +74,7 @@ namespace bbiwarg
             }
         }
 
-        private void resetConsistentObjects()
+        public void resetConsistentObjects()
         {
             touchTracker.reset();
             handTracker.reset();
@@ -92,33 +90,25 @@ namespace bbiwarg
         public void updateFrame()
         {
             Timer.start("updateFrame");
+            beforeUpdateFrame();
 
-            if (currentFrameID != inputProvider.CurrentFrameID)
-            {
-                beforeUpdateFrame();
+            createConfidenceImage();
+            createDepthImage();
+            createEdgeImage();
 
-                if (lastFrameID - currentFrameID > 20)
-                    resetConsistentObjects();
+            detectFingers();
+            trackFingers();
 
-                createConfidenceImage();
-                createDepthImage();
-                createEdgeImage();
+            detectHands();
+            trackHands();
 
-                detectFingers();
-                trackFingers();
+            detectPalm();
+            trackPalm();
 
-                detectHands();
-                trackHands();
-
-                detectPalm();
-                trackPalm();
-
-                detectTouchEvents();
-                trackTouchEvents();
-
-                afterUpdateFrame();
-            }
+            detectTouchEvents();
+            trackTouchEvents();
 
+            afterUpdateFrame();
             Timer.stop("updateFrame");
         }
 
@@ -128,9 +118,8 @@ namespace bbiwarg
 
             currentInputFrame = inputProvider.CurrentFrame;
 
-            lastFrameID = currentFrameID;
-            currentFrameID = currentInputFrame.FrameID;
-            Logger.CurrentFrame = currentFrameID;
+            CurrentFrameID = currentInputFrame.FrameID;
+            Logger.CurrentFrame = CurrentFrameID;
 
             if (Parameters.TuioEnabled)
                 tuioCommunicator.initFrame();
@@ -253,8 +242,8 @@ namespace bbiwarg
                 {
                     OutputImages[0].fillCircle(tf.TipPointPrediction.IntX, tf.TipPointPrediction.IntY, 3, Parameters.FingerPointsPredictionColor);
                     OutputImages[0].fillCircle(tf.HandPointPrediction.IntX, tf.HandPointPrediction.IntY, 3, Parameters.FingerPointsPredictionColor);
-                    Vector2D mid = (tf.TipPointPrediction+tf.HandPointPrediction) /2 ;
-                    OutputImages[0].drawLineSegment(new Utility.LineSegment2D(mid, mid + Parameters.FingerTrackerNumDirectionsForMeanDirection*tf.MeanDirection), Parameters.FingerMeanDirectionColor);
+                    Vector2D mid = (tf.TipPointPrediction + tf.HandPointPrediction) / 2;
+                    OutputImages[0].drawLineSegment(new Utility.LineSegment2D(mid, mid + Parameters.FingerTrackerNumDirectionsForMeanDirection * tf.MeanDirection), Parameters.FingerMeanDirectionColor);
                 }
             }
 

+ 1 - 1
bbiwarg/Parameters.cs

@@ -36,7 +36,7 @@ namespace bbiwarg
         public static readonly String OutputTitle = "BBIWARG - Output";
 
         // TUIO
-        public static bool TuioEnabled = false;
+        public static bool TuioEnabled = true;
         public static IPAddress TuioIP = new IPAddress(new byte[4] { 127, 0, 0, 1 });
         public static Int16 TuioPort = 3333;