walk_around.c
3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* walk_around.c - implements simple motion model
*
* The joystick is for turning left, right and moving back and forth.
* Up and down on the crosshair tilts the view up and down; left and
* right on the crosshair 'sidestep' to the left and right. The six
* 'fire buttons' accomplish the same suite of movements.
*/
#include <ultra64.h>
/*
* local includes:
*/
#include "trivial.h"
#include "walk_around.h"
/*
* The slop factor is the amount of slop we allow in the joystick
* before registering a movement.
*/
#define SLOP_FACTOR 12
/*
* Max number of major modes
*/
#define MAX_MODES 5
/*
* Globals
*/
u32 MyMode = 0;
u32 RotVal = 1;
u32 nDL = 1;
/*
* Controller globals
*/
static OSMesgQueue contMessageQ;
static OSMesg dummyMessage;
static OSContStatus statusdata[MAXCONTROLLERS];
static OSContPad controllerdata[MAXCONTROLLERS];
static int controller;
static int lastx;
static int lasty;
static int lastbutton = 0;
static int press = 0;
static int press_up = 0;
static int press_down = 0;
/*
* Print routines
*/
static void
print_initial(void) {
rmonPrintf("======= RDP Perf Counter Test ========\n\n");
rmonPrintf(" Use L key to increment mode\n");
rmonPrintf(" Use R key to decrement mode\n");
rmonPrintf(" Magenta = total clock counter\n");
rmonPrintf(" Yellow = DP input buffer busy\n");
rmonPrintf(" Blue = DP pipe busy\n");
rmonPrintf(" Red = DP TMEM load\n");
rmonPrintf(" Use A key to add display lists\n");
rmonPrintf(" Use Start key to reset display lists\n");
rmonPrintf(" Use B key to stop rotation\n");
}
/*
*
* Return the lowest number controller connected to system
*/
int
walkAroundInit(float x, float y, float z)
{
int i;
u8 pattern;
osCreateMesgQueue(&contMessageQ, &dummyMessage, 1);
osSetEventMesg(OS_EVENT_SI, &contMessageQ, (OSMesg) 0);
osContInit(&contMessageQ, &pattern, &statusdata[0]);
for (i = 0; i < MAXCONTROLLERS; i++) {
if ((pattern & (1 << i)) &&
!(statusdata[i].errno & CONT_NO_RESPONSE_ERROR)) {
osContStartReadData(&contMessageQ);
controller = i;
print_initial();
return i;
}
}
controller = -1;
return -1;
}
/*
* Update controller info
*/
static void
readControllers(void)
{
OSContPad *pad;
if (osRecvMesg(&contMessageQ, &dummyMessage, OS_MESG_NOBLOCK) == 0) {
osContGetReadData(controllerdata);
osContStartReadData(&contMessageQ);
}
pad = &controllerdata[controller];
press = lastbutton ^ pad->button;
press_up = lastbutton & press;
press_down = pad->button & press;
lastbutton = pad->button;
lastx = pad->stick_x;
lasty = pad->stick_y;
}
/*
* implement 'walk around' motion model
*
* Now map the controller to movements. The joystick is for
* turning left, right and moving back and forth. Up and down on the
* crosshair tilts the view up and down; left and right on the crosshair
* 'sidestep' to the left and right.
*
*/
void
walkAround(Dynamic *dynamicp)
{
if(controller >= 0)
readControllers();
/*
* The 'Start' button resets the user's position
*/
if (press_down & CONT_START) {
nDL = 1;
}
if (lastx > SLOP_FACTOR) {
} else if (lastx < -SLOP_FACTOR) {
}
if (lasty > SLOP_FACTOR) {
} else if (lasty < -SLOP_FACTOR) {
}
if ((press_down & CONT_UP)) {
}
if ((press_down & CONT_DOWN)) {
}
if (press_down & (CONT_LEFT)) {
}
if (press_down & (CONT_RIGHT)) {
}
if (press_down & CONT_A) {
RotVal = 0.0;
}
else if (press_up & CONT_A) {
RotVal = 1.0;
}
if (press_down & CONT_B) {
nDL++;
}
if (press_down & CONT_C) {
}
if (press_down & CONT_D) {
}
if (press_down & CONT_E) {
}
if (press_down & CONT_F) {
}
if (press_down & CONT_G) {
}
if (press_down & CONT_L) {
MyMode++;
if(MyMode > MAX_MODES)
MyMode = 0;
}
if (press_down & CONT_R) {
MyMode--;
if(MyMode < 0)
MyMode = MAX_MODES;
}
}