![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
this code will provide the joystick code for the mouse movement for the game sniper elite.. by changing certain parameters this can be used for all th 3d computer games
main.cpp@0:bf6a4988f38f, 2013-10-28 (annotated)
- Committer:
- rockstar
- Date:
- Mon Oct 28 11:45:30 2013 +0000
- Revision:
- 0:bf6a4988f38f
mouse movement control for sniper elite
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rockstar | 0:bf6a4988f38f | 1 | // GAMING JOYSTICK for sniper elite.... |
rockstar | 0:bf6a4988f38f | 2 | //mouse part |
rockstar | 0:bf6a4988f38f | 3 | // Submitted by- |
rockstar | 0:bf6a4988f38f | 4 | // Minakshi, Vidisha, Arihant, Anshul, Manisha, Rupam, Vishal |
rockstar | 0:bf6a4988f38f | 5 | // National Institute of Technology Hamirpur, India |
rockstar | 0:bf6a4988f38f | 6 | // this code simply send some characters which are used for the movement of player in the game |
rockstar | 0:bf6a4988f38f | 7 | #include "mbed.h" |
rockstar | 0:bf6a4988f38f | 8 | #include"USBMouse.h" //USBMouse library taken to send mouse movement commands in our program |
rockstar | 0:bf6a4988f38f | 9 | USBMouse mouse1(ABS_MOUSE); // object of USBMouse library |
rockstar | 0:bf6a4988f38f | 10 | AnalogIn inputx(p15); // analog input is taken at pin p15 from the pin 'x' of accelerometer |
rockstar | 0:bf6a4988f38f | 11 | AnalogIn inputy(p17); // analog input is taken at pin p16 from the pin 'y' of accelerometer |
rockstar | 0:bf6a4988f38f | 12 | #include <math.h> |
rockstar | 0:bf6a4988f38f | 13 | int main(void) |
rockstar | 0:bf6a4988f38f | 14 | { |
rockstar | 0:bf6a4988f38f | 15 | float cal_x=0,cal_y=0; |
rockstar | 0:bf6a4988f38f | 16 | float x=0,y=0; |
rockstar | 0:bf6a4988f38f | 17 | int i=1000; |
rockstar | 0:bf6a4988f38f | 18 | while(i--) |
rockstar | 0:bf6a4988f38f | 19 | { |
rockstar | 0:bf6a4988f38f | 20 | cal_x=inputx*100; // initially at the starting of mbed, values from x pin of accelerometer is stored in variable cal_x |
rockstar | 0:bf6a4988f38f | 21 | cal_y=inputy*100; // values from y pin of accelerometer is stored in variable cal_y |
rockstar | 0:bf6a4988f38f | 22 | } |
rockstar | 0:bf6a4988f38f | 23 | // the following two lines will move the cursor to the center of the screen |
rockstar | 0:bf6a4988f38f | 24 | float x_center = (X_MAX_ABS - X_MIN_ABS)/2; |
rockstar | 0:bf6a4988f38f | 25 | float y_center = (Y_MAX_ABS - Y_MIN_ABS)/2; |
rockstar | 0:bf6a4988f38f | 26 | float x_screen = 0; |
rockstar | 0:bf6a4988f38f | 27 | float y_screen = 0; |
rockstar | 0:bf6a4988f38f | 28 | x_screen = x_center; |
rockstar | 0:bf6a4988f38f | 29 | y_screen = y_center; |
rockstar | 0:bf6a4988f38f | 30 | while (1) |
rockstar | 0:bf6a4988f38f | 31 | { |
rockstar | 0:bf6a4988f38f | 32 | x=(cal_x - inputx*100); // in program running state x is storing the difference |
rockstar | 0:bf6a4988f38f | 33 | y=(cal_y - inputy*100); |
rockstar | 0:bf6a4988f38f | 34 | if(x>=5 || x< -4) |
rockstar | 0:bf6a4988f38f | 35 | { |
rockstar | 0:bf6a4988f38f | 36 | x=abs(x)/x; |
rockstar | 0:bf6a4988f38f | 37 | x_screen -= 0.15*x;} |
rockstar | 0:bf6a4988f38f | 38 | } |
rockstar | 0:bf6a4988f38f | 39 | if(y>=5 || y< -4)// 5,-4 is choosen w.r.t tilting of accelerometer |
rockstar | 0:bf6a4988f38f | 40 | { |
rockstar | 0:bf6a4988f38f | 41 | y=abs(y)/y; |
rockstar | 0:bf6a4988f38f | 42 | y_screen -= 0.15*y;}//0.15 is choosen keeping acc. to the sensitivity of game |
rockstar | 0:bf6a4988f38f | 43 | |
rockstar | 0:bf6a4988f38f | 44 | } |
rockstar | 0:bf6a4988f38f | 45 | mouse1.move(x_screen, y_screen); // this command moves the move accordingly |
rockstar | 0:bf6a4988f38f | 46 | } |
rockstar | 0:bf6a4988f38f | 47 | } |
rockstar | 0:bf6a4988f38f | 48 | |
rockstar | 0:bf6a4988f38f | 49 |