bugfixes, new scaling, double ym upd at 940
[picodrive.git] / platform / win32 / GenaDrive / LightCal.cpp
CommitLineData
cc68a136 1\r
2#include "app.h"\r
3\r
4struct Target\r
5{\r
6 int sx,sy; // Onscreen coordinates\r
7 int dx,dy; // Device values\r
8};\r
9\r
10struct Target Targ[2]=\r
11{\r
12 {0,0, 0,0},\r
13 {0,0, 0,0}\r
14};\r
15static int LightState=0;\r
16\r
17struct Calib\r
18{\r
19 float ax,bx;\r
20 float ay,by;\r
21};\r
22static struct Calib Cal={0.0f,0.0f,0.0f,0.0f};\r
23\r
24int LightCalReset()\r
25{\r
26 LightState=0;\r
27\r
28 memset(Targ,0,sizeof(Targ));\r
29 Targ[0].sx=MainWidth >>1;\r
30 Targ[0].sy=MainHeight>>1;\r
31 Targ[1].sy=Targ[0].sy-MainHeight*61/160;\r
32 Targ[1].sx=Targ[0].sx-MainWidth *61/160;\r
33 return 0;\r
34}\r
35\r
36int LightCalUpdate()\r
37{\r
38 int i=0;\r
39 struct Target *pt=NULL;\r
40\r
41 if (Inp.held[4]==1) LoopMode=3;\r
42\r
43 if (Inp.held[8]==1)\r
44 {\r
45 i=LightState&1;\r
46 pt=Targ+i;\r
47\r
48 pt->dx=Inp.axis[0];\r
49 pt->dy=Inp.axis[1];\r
50\r
51 if (i==1)\r
52 {\r
53 int num=0,den=0;\r
54\r
55 // rx= a + b*x - work out a and b:\r
56 num=Targ[0].sx-Targ[1].sx;\r
57 den=Targ[0].dx-Targ[1].dx;\r
58 if (den) Cal.bx=(float)num/(float)den;\r
59 Cal.ax=(float)Targ[0].sx-Cal.bx*(float)Targ[0].dx;\r
60\r
61 num=Targ[0].sy-Targ[1].sy;\r
62 den=Targ[0].dy-Targ[1].dy;\r
63 if (den) Cal.by=(float)num/(float)den;\r
64 Cal.ay=(float)Targ[0].sy-Cal.by*(float)Targ[0].dy;\r
65 }\r
66\r
67 LightState++;\r
68 }\r
69\r
70 return 0;\r
71}\r
72\r
73int LightCalRender()\r
74{\r
75 int i=0;\r
76 struct Target *pt=NULL;\r
77 float fx=0.0f,fy=0.0f;\r
78\r
79 DirectClear(0xffffff);\r
80\r
81 WCHAR text[80]={0};\r
82 wsprintfW(text,L"LightGun Calibration");\r
83 FontSetColour(0x0000ff);\r
84 FontText(text,240,48);\r
85\r
86 wsprintfW(text,L"Start to quit, B to call InputLightCal");\r
87 FontSetColour(0x004000);\r
88 FontText(text,64,120);\r
89\r
90 i=LightState&1;\r
91 pt=Targ+i;\r
92 FontSetColour(0);\r
93 FontText(L"X", pt->sx-8, pt->sy-12);\r
94\r
95 fx=Cal.ax+Cal.bx*(float)Inp.axis[0];\r
96 fy=Cal.ay+Cal.by*(float)Inp.axis[1];\r
97\r
98 FontSetColour(0xff0000);\r
99 FontText(L"+", (int)fx-8,(int)fy-12);\r
100\r
101 return 0;\r
102}\r