annotate car.c @ 22:5d41876f744a

*** empty log message ***
author gongo
date Sat, 04 Nov 2006 12:50:15 +0000
parents b1ba4dad7f6e
children 972dead2198a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
1 /*
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
2 * $Id$
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
3 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
4 #include <stdio.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
5 #include <stdlib.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
6 #include "libps2.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
7 #include "ps2util.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
8 #include "col.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
9 #include "field.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
10 #include "car.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
11 #include "mytype.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
12 #include "quotanion.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
13 #include "game.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
14
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
15 #define DEFAULT_SET (EFFECT_TEXTURE_USE | EFFECT_ALPHABLEND_UNUSE | EFFECT_SHADING_FLAT)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
16 #define BUFSIZE 256
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
17
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
18 /* $B=i4|0LCV$H=i4|J}8~(B */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
19 static FVECTOR location = {0, 0, 0, 1};
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
20 static FVECTOR direction = {0, 0, 1, 1};
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
21
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
22 extern FILE* main_fp;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
23
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
24 /* --- field.c --- */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
25 extern int field_rap_increment(int);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
26 extern void field_set_actual(FieldPtr);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
27 extern FieldPtr field_get_actual();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
28
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
29 static int *check;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
30 static int check_value;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
31
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
32 static CarPtr
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
33 car_create(int car_id, char *filename, char *texname, float speed_accel,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
34 float speed_max, float rot, float brake)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
35 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
36 CarPtr car;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
37 OBJECT *body;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
38 TEXTURE* tex;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
39 void *free_addr;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
40
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
41 body = ps2util_obj_Create_fromXML(filename);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
42 ps2util_obj_Set_effect(body, DEFAULT_SET);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
43
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
44 if (malloc_align16(&free_addr, &car, sizeof(Car)) == -1) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
45 fprintf(main_fp, "car.c: malloc_align16 error\n");
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
46 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
47 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
48 car->body = body;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
49 car->next = NULL;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
50 car->speed = 0.0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
51 car->speed_accel = speed_accel;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
52 car->speed_max = speed_max;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
53 car->brake = brake;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
54 car->rotation_angle = rot;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
55 car->y_angle = 0.0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
56 car->free_addr = free_addr;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
57
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
58 ps2_vu0_copy_vector(car->direction, direction);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
59 ps2_vu0_copy_vector(car->location, location);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
60 INIT_VECTOR(car->vertical, 0, -1, 0, 1);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
61 INIT_VECTOR(car->body->xyz, 0, 0, 0, 1);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
62 INIT_VECTOR(car->body->angle, 0, 0, 0, 1);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
63
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
64 ps2util_obj_Renew_transMatrix(car->body);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
65 ps2util_obj_Set_effect(car->body, DEFAULT_SET);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
66
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
67 if (*texname != 'n') {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
68 tex = read_png_file(texname);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
69 ps2util_tex_Set(tex);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
70 ps2util_obj_Set_texture(car->body, tex);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
71 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
72
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
73 #ifdef DEBUG
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
74 fprintf(main_fp, "malloc car addr = %x\n", (int)free_addr);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
75 #endif
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
76
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
77 return car;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
78 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
79
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
80 static CarPtr
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
81 car_new_readCSV(FILE *fp, int id)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
82 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
83 CarPtr new;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
84 int car_id;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
85 float speed_accel, speed_max, brake, rot;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
86 char buff[BUFSIZE], *bufp;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
87 char carImg[BUFSIZE], texImg[BUFSIZE];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
88 Bool flag;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
89
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
90 flag = FALSE;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
91
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
92 while ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
93 bufp++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
94
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
95 switch (buff[0]) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
96 case 'n':
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
97 if (flag == FALSE) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
98 sscanf(bufp, " %d\n", &car_id);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
99 if (id == car_id) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
100 flag = TRUE;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
101 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
102 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
103 break;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
104 case 't':
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
105 if (flag == TRUE) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
106 sscanf(bufp, " %s %s %f %f %f %f\n",
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
107 carImg, texImg, &speed_accel, &speed_max, &rot, &brake);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
108 new = car_create(id, carImg, texImg,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
109 speed_accel, speed_max, rot, brake);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
110 return new;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
111 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
112 break;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
113 default:
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
114 break;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
115 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
116 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
117
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
118 /* $B$3$3$^$GC)$jCe$$$?$iFI$_9~$_<:GT(B */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
119 fprintf(main_fp, "error - car_new_readCSV\n");
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
120 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
121 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
122
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
123 CarPtr
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
124 car_init(int id)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
125 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
126 CarPtr new;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
127 FILE *fp;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
128 char *filename = "car/car.dat";
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
129
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
130 if (!(fp = fopen(filename, "r"))) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
131 fprintf(main_fp, "error read file %s\n", filename);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
132 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
133 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
134 new = car_new_readCSV(fp, id);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
135 fclose(fp);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
136
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
137 return new;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
138 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
139
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
140 /*---------------------------
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
141 car$B$r(BY$B<4$G2sE>$5$;$k(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
142 flg: $B2sE>J}8~(B 1:$B1&(B, -1:$B:8(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
143 ---------------------------*/
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
144 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
145 car_swerve(CarPtr car, int flg)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
146 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
147 FMATRIX rot;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
148 FVECTOR v;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
149
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
150 car->y_angle += (float)flg*car->rotation_angle;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
151 car->y_angle += (car->y_angle < 0) ? 360.0 : 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
152 car->y_angle += (car->y_angle > 360.0) ? -360.0 : 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
153
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
154 ps2_vu0_unit_matrix(rot);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
155 ps2_vu0_rot_matrix_y(rot, rot, degree2radian((float)flg*car->rotation_angle));
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
156 ps2_vu0_copy_vector(v, car->direction);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
157 ps2_vu0_apply_matrix(car->direction, rot, v);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
158 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
159
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
160 /*----------------------------
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
161 car$B$r2CB.!&8:B.$9$k(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
162 (flg == 1) ? $B2CB.(B : $B8:B.(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
163 ---------------------------*/
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
164 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
165 car_accelerate(CarPtr car, int flg)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
166 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
167 car->speed += (flg == 1) ? car->speed_accel : -car->brake;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
168 car->speed = (car->speed < 0) ? 0 : car->speed;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
169 car->speed = (car->speed > car->speed_max) ? car->speed_max : car->speed;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
170 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
171
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
172
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
173 /*---------------------------------
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
174 $B?J9T8e$N(Bcar$B$KBP$7$F%3!<%9LL$NFb30H=Dj$r9T$$!"(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
175 : $B8=:_$N%3!<%9(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
176 : $B8=:_$N%3!<%9$N<!$N%3!<%9(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
177 : $B8=:_$N%3!<%9$NA0$N%3!<%9(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
178 $B$KB8:_$9$l$P(BTRUE$B$rJV$9(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
179 $B$I$N%3!<%9$K$b5o$J$$(B($BJI$K>WFM$7$?(B)$B>l9g$O(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
180 FALSE$B$rJV$9!#(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
181 ---------------------------------*/
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
182 static Bool
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
183 car_field_check(CarPtr car)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
184 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
185 FieldPtr p;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
186 FieldPtr f = field_get_actual();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
187
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
188 // $B8=:_$N%3!<%9$G>WFM!&Fb30H=Dj(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
189 p = f;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
190 if (col_detect(&p->colface, car->vertical, car->location) == TRUE) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
191 goto FIELD_CHECK_OK;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
192 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
193
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
194 // $B8=:_$N%3!<%9$N<!$KNY@\$9$k%3!<%9$G>WFM!&Fb30H=Dj(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
195 p = f->next;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
196 if (col_detect(&p->colface, car->vertical, car->location) == TRUE) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
197 if (field_rap_increment(1)) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
198 game.rap++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
199 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
200 goto FIELD_CHECK_OK;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
201 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
202
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
203 // $B8=:_$N%3!<%9$NA0$KNY@\$9$k%3!<%9$G>WFM!&Fb30H=Dj(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
204 p = f->prev;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
205 if (col_detect(&p->colface, car->vertical, car->location) == TRUE) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
206 field_rap_increment(-1);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
207 goto FIELD_CHECK_OK;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
208 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
209
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
210 // $B$I$N%3!<%9>e$K$b5o$J$$(B($BJI$K>WFM(B)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
211 return FALSE;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
212
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
213 FIELD_CHECK_OK:
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
214 field_set_actual(p);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
215 return TRUE;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
216 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
217
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
218
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
219 /*------------------------------
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
220 $BB.EY(Bspeed$B$H8~$-(Bdirection$B$+$i(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
221 $B?J9T8e$N0LCV(Blocation$B$r5a$a$k!#(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
222 $B$^$?!"?J9T8e$N>WFMH=Dj$b9T$&!#(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
223 ------------------------------*/
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
224 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
225 car_move(CarPtr car)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
226 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
227 FVECTOR mov, prev_location;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
228
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
229 ps2_vu0_scale_vector(mov, car->direction, car->speed);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
230 ps2_vu0_copy_vector(prev_location, car->location);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
231 ps2_vu0_add_vector(car->location, car->location, mov);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
232
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
233 if (car_field_check(car) == FALSE) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
234 ps2_vu0_copy_vector(car->location, prev_location);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
235 car->speed = car->speed*0.5;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
236 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
237 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
238
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
239
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
240 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
241 car_axis_rotation(CarPtr car)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
242 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
243 FMATRIX pose, yrot, yrotinv;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
244
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
245 ps2_vu0_unit_matrix(yrot);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
246 ps2_vu0_rot_matrix_y(yrot, yrot, -degree2radian(car->y_angle));
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
247 ps2_vu0_unit_matrix(yrotinv);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
248 ps2_vu0_rot_matrix_y(yrotinv, yrotinv, degree2radian(car->y_angle));
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
249
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
250 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
251 FVECTOR yd = {0, -1, 0, 1};
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
252 FVECTOR rotaxis;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
253 FVECTOR q;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
254
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
255 ps2_vu0_outer_product(rotaxis, car->vertical, yd);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
256 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
257 float scale=1/NORM(rotaxis);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
258 rotaxis[0] *= scale;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
259 rotaxis[1] *= scale;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
260 rotaxis[2] *= scale;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
261 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
262
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
263 quotanion(q, rotaxis, acos(ps2_vu0_inner_product(yd, car->vertical)/(NORM(yd)*NORM(car->vertical))));
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
264 quotanion_rotmatrix(pose, q);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
265 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
266
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
267 ps2_vu0_mul_matrix(pose, yrot, pose);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
268 ps2_vu0_mul_matrix(pose, pose, yrotinv);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
269 ps2_vu0_copy_matrix(car->body->transfer, pose);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
270 ps2_vu0_rot_matrix_y(car->body->transfer, car->body->transfer,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
271 degree2radian(car->y_angle));
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
272 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
273
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
274 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
275 car_update(CarPtr car)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
276 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
277 // $B0\F0(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
278 car_move(car);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
279
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
280 // $BK`;$$K$h$kB.EY8:>/(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
281 car->speed -= 0.005;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
282 car->speed = (car->speed < 0) ? 0 : car->speed;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
283
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
284 // $B79$-(B
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
285 car_axis_rotation(car);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
286 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
287
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
288 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
289 car_destroy(CarPtr p)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
290 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
291 TEXTURE *t;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
292
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
293 if ((t = p->body->surfaces->texture)) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
294 ps2util_tex_Exclude(t);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
295 free_texture(t);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
296 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
297 ps2util_obj_Free(p->body);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
298 free(p->free_addr);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
299
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
300 #ifdef DEBUG
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
301 fprintf(main_fp, "free car addr = %x\n", (int)p->free_addr);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
302 #endif
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
303 }