History

Added HandControl class and also Avatar Touch class

Jeffrey Ventrella committed 13 years ago

Commit ce1ceb81 parent 7a943107 files · +280 −146Browse files

Showing the changes to interface/src/HandControl.cpp (1 of 7 files). Show all

Unified · Split

interface/src/HandControl.cpp+93−0
@@ -0,0 +1,93 @@
1+//
2+// HandControl.cpp
3+// interface
4+//
5+// Created by Jeffrey Ventrella
6+// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
7+//
8+
9+#include "HandControl.h"
10+
11+// this class takes mouse movements normalized within the screen
12+// dimensions and uses those to determine avatar hand movements, as well
13+// as states for ramping up and ramping down the amplitude of such movements.
14+//
15+// This class might expand to accommodate 3D input devices
16+//
17+
18+HandControl::HandControl() {
19+
20+ _enabled = false;
21+ _width = 0;
22+ _height = 0;
23+ _startX = 0;
24+ _startY = 0;
25+ _x = 0;
26+ _y = 0;
27+ _lastX = 0;
28+ _lastY = 0;
29+ _velocityX = 0;
30+ _velocityY = 0;
31+ _rampUpRate = 0.05;
32+ _rampDownRate = 0.02;
33+ _envelope = 0.0f;
34+}
35+
36+void HandControl::setScreenDimensions( int width, int height ) {
37+ _width = width;
38+ _height = height;
39+ _startX = _width / 2;
40+ _startY = _height / 2;
41+}
42+
43+void HandControl::update( int x, int y ) {
44+ _lastX = _x;
45+ _lastY = _y;
46+ _x = x;
47+ _y = y;
48+ _velocityX = _x - _lastX;
49+ _velocityY = _y - _lastY;
50+
51+ // if the mouse is moving, ramp up the envelope to increase amplitude of hand movement...
52+ if (( _velocityX != 0 )
53+ || ( _velocityY != 0 )) {
54+ _enabled = true;
55+ if ( _envelope < 1.0 ) {
56+ _envelope += _rampUpRate;
57+ if ( _envelope >= 1.0 ) {
58+ _envelope = 1.0;
59+ }
60+ }
61+ }
62+
63+ // if not enabled ramp down the envelope to decrease amplitude of hand movement...
64+ if ( ! _enabled ) {
65+ if ( _envelope > 0.0 ) {
66+ _envelope -= _rampDownRate;
67+ if ( _envelope <= 0.0 ) {
68+ _startX = _width / 2;
69+ _startY = _height / 2;
70+ _envelope = 0.0;
71+ }
72+ }
73+ }
74+
75+ _leftRight = 0.0;
76+ _downUp = 0.0;
77+ _backFront = 0.0;
78+
79+ // if envelope is greater than zero, apply mouse movement to values to be output
80+ if ( _envelope > 0.0 ) {
81+ _leftRight += ( ( _x - _startX ) / (float)_width ) * _envelope;
82+ _downUp += ( ( _y - _startY ) / (float)_height ) * _envelope;
83+ }
84+}
85+
86+glm::vec3 HandControl::getValues() {
87+ return glm::vec3( _leftRight, _downUp, _backFront );
88+}
89+
90+void HandControl::stop() {
91+ _enabled = false;
92+}
93+