annotate car.c @ 93:3731dd016e1b

halfway_3
author Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
date Thu, 26 May 2011 15:01:13 +0900
parents cb6c6de125dc
children 0b65ca27f113
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
1 #include <stdio.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
2 #include <stdlib.h>
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
3 #include <stdbool.h>
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
4 #include "libps2.h"
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
5 #include "ps2util.h"
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
6 #include "field.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
7 #include "car.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
8 #include "mytype.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
9 #include "quotanion.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
10 #include "game.h"
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
11 #include "stdbool.h"
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
12
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
13 #define DEFAULT_SET (EFFECT_TEXTURE_USE | EFFECT_ALPHABLEND_UNUSE | EFFECT_SHADING_FLAT)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
14 #define BUFSIZE 256
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
15
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
16 /* 初期位置と初期方向 */
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
17 static FVECTOR location = {0, 0, 0, 1};
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
18 static FVECTOR direction = {0, 0, 1, 1};
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
19
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
20 extern FILE* main_fp;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
21
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
22 /* --- field.c --- */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
23 extern int field_rap_increment(int);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
24 extern void field_set_actual(FieldPtr);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
25 extern FieldPtr field_get_actual();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
26
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
27
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
28 static CarPtr
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
29 car_create(int car_id, char *filename, char *texname, float speed_accel,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
30 float speed_max, float rot, float brake)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
31 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
32 CarPtr car;
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
33 OBJECT *body;
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
34 TEXTURE* tex;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
35 void *free_addr;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
36
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
37 body = ps2util_obj_Create_fromXML(filename);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
38 ps2util_obj_Set_effect(body, DEFAULT_SET);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
39
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
40 if (malloc_align16(&free_addr, &car, sizeof(Car)) == -1) {
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
41 fprintf(main_fp, "car.c: malloc_align16 error\n");
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
42 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
43 }
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
44 car->body = body;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
45 car->next = NULL;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
46 car->speed = 0.0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
47 car->speed_accel = speed_accel;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
48 car->speed_max = speed_max;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
49 car->brake = brake;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
50 car->rotation_angle = rot;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
51 car->y_angle = 0.0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
52 car->free_addr = free_addr;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
53
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
54 ps2_vu0_copy_vector(car->direction, direction);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
55 ps2_vu0_copy_vector(car->location, location);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
56 INIT_VECTOR(car->vertical, 0, -1, 0, 1);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
57 INIT_VECTOR(car->body->xyz, 0, 0, 0, 1);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
58 INIT_VECTOR(car->body->angle, 0, 0, 0, 1);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
59
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
60 ps2util_obj_Renew_transMatrix(car->body);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
61 ps2util_obj_Set_effect(car->body, DEFAULT_SET);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
62
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
63 if (*texname != 'n') {
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
64 tex = read_png_file(texname);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
65 ps2util_tex_Set(tex);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
66 ps2util_obj_Set_texture(car->body, tex);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
67 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
68
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
69 #ifdef DEBUG
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
70 fprintf(main_fp, "malloc car addr = %x\n", (int)free_addr);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
71 #endif
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
72
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
73 return car;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
74 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
75
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
76 static CarPtr
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
77 car_new_readCSV(FILE *fp, int id)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
78 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
79 CarPtr new;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
80 int car_id;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
81 float speed_accel, speed_max, brake, rot;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
82 char buff[BUFSIZE], *bufp;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
83 char carImg[BUFSIZE], texImg[BUFSIZE];
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
84 bool flag;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
85
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
86 flag = false;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
87
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
88 while ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
89 bufp++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
90
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
91 switch (buff[0]) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
92 case 'n':
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
93 if (flag == false) {
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
94 sscanf(bufp, " %d\n", &car_id);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
95 if (id == car_id) {
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
96 flag = true;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
97 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
98 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
99 break;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
100 case 't':
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
101 if (flag == true) {
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
102 sscanf(bufp, " %s %s %f %f %f %f\n",
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
103 carImg, texImg, &speed_accel, &speed_max, &rot, &brake);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
104 new = car_create(id, carImg, texImg,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
105 speed_accel, speed_max, rot, brake);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
106 return new;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
107 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
108 break;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
109 default:
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
110 break;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
111 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
112 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
113
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
114 /* ここまで辿り着いたら読み込み失敗 */
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
115 fprintf(main_fp, "error - car_new_readCSV\n");
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
116 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
117 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
118
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
119 CarPtr
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
120 car_init(int id)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
121 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
122 CarPtr new;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
123 FILE *fp;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
124 char *filename = "car/car.dat";
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
125
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
126 if (!(fp = fopen(filename, "r"))) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
127 fprintf(main_fp, "error read file %s\n", filename);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
128 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
129 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
130 new = car_new_readCSV(fp, id);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
131 fclose(fp);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
132
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
133 return new;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
134 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
135
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
136 /*---------------------------
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
137 carをY軸で回転させる
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
138 flg: 回転方向 1:右, -1:左
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
139 ---------------------------*/
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
140 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
141 car_swerve(CarPtr car, int flg)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
142 {
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
143 FMATRIX rot;
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
144 FVECTOR v;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
145
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
146 car->y_angle += (float)flg*car->rotation_angle;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
147 car->y_angle += (car->y_angle < 0) ? 360.0 : 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
148 car->y_angle += (car->y_angle > 360.0) ? -360.0 : 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
149
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
150 ps2_vu0_unit_matrix(rot);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
151 ps2_vu0_rot_matrix_y(rot, rot, degree2radian((float)flg*car->rotation_angle));
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
152 ps2_vu0_copy_vector(v, car->direction);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
153 ps2_vu0_apply_matrix(car->direction, rot, v);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
154 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
155
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
156 /*----------------------------
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
157 carを加速・減速する
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
158 (flg == 1) ? 加速 : 減速
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
159 ---------------------------*/
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
160 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
161 car_accelerate(CarPtr car, int flg)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
162 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
163 car->speed += (flg == 1) ? car->speed_accel : -car->brake;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
164 car->speed = (car->speed < 0) ? 0 : car->speed;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
165 car->speed = (car->speed > car->speed_max) ? car->speed_max : car->speed;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
166 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
167
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
168
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
169 /*---------------------------------
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
170 進行後のcarに対してコース面の内外判定を行い、
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
171 : 現在のコース
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
172 : 現在のコースの次のコース
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
173 : 現在のコースの前のコース
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
174 に存在すればTRUEを返す
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
175 どのコースにも居ない(壁に衝突した)場合は
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
176 FALSEを返す。
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
177 ---------------------------------*/
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
178 static bool
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
179 car_field_check(Game *game ,CarPtr car)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
180 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
181 FieldPtr p;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
182 FieldPtr f = field_get_actual();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
183
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
184 // 現在のコースで衝突・内外判定
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
185 p = f;
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
186 if (col_detect(&p->colface, car->vertical, car->location) == true) {
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
187 goto FIELD_CHECK_OK;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
188 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
189
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
190 // 現在のコースの次に隣接するコースで衝突・内外判定
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
191 p = f->next;
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
192 if (col_detect(&p->colface, car->vertical, car->location) == true) {
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
193 if (field_rap_increment(1)) {
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
194 game->rap++;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
195 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
196 goto FIELD_CHECK_OK;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
197 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
198
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
199 // 現在のコースの前に隣接するコースで衝突・内外判定
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
200 p = f->prev;
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
201 if (col_detect(&p->colface, car->vertical, car->location) == true) {
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
202 field_rap_increment(-1);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
203 goto FIELD_CHECK_OK;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
204 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
205
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
206 // どのコース上にも居ない(壁に衝突)
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
207 return false;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
208
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
209 FIELD_CHECK_OK:
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
210 field_set_actual(p);
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
211 return true;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
212 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
213
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
214
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
215 /*------------------------------
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
216 速度speedと向きdirectionから
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
217 進行後の位置locationを求める。
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
218 また、進行後の衝突判定も行う。
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
219 ------------------------------*/
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
220 static void
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
221 car_move(Game *game,CarPtr car)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
222 {
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
223 FVECTOR mov, prev_location;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
224
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
225 ps2_vu0_scale_vector(mov, car->direction, car->speed);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
226 ps2_vu0_copy_vector(prev_location, car->location);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
227 ps2_vu0_add_vector(car->location, car->location, mov);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
228
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
229 if (car_field_check(game,car) == false) {
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
230 ps2_vu0_copy_vector(car->location, prev_location);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
231 car->speed = car->speed*0.5;
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
232 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
233 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
234
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
235
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
236 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
237 car_axis_rotation(CarPtr car)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
238 {
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
239 FMATRIX pose, yrot, yrotinv;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
240
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
241 ps2_vu0_unit_matrix(yrot);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
242 ps2_vu0_rot_matrix_y(yrot, yrot, -degree2radian(car->y_angle));
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
243 ps2_vu0_unit_matrix(yrotinv);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
244 ps2_vu0_rot_matrix_y(yrotinv, yrotinv, degree2radian(car->y_angle));
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
245
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
246 {
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
247 FVECTOR yd = {0, -1, 0, 1};
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
248 FVECTOR rotaxis;
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
249 FVECTOR q;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
250
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
251 ps2_vu0_outer_product(rotaxis, car->vertical, yd);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
252 {
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
253 float scale=1/NORM(rotaxis);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
254 rotaxis[0] *= scale;
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
255 rotaxis[1] *= scale;
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
256 rotaxis[2] *= scale;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
257 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
258
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
259 quotanion(q, rotaxis, acos(ps2_vu0_inner_product(yd, car->vertical)/(NORM(yd)*NORM(car->vertical))));
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
260 quotanion_rotmatrix(pose, q);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
261 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
262
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
263 ps2_vu0_mul_matrix(pose, yrot, pose);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
264 ps2_vu0_mul_matrix(pose, pose, yrotinv);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
265 ps2_vu0_copy_matrix(car->body->transfer, pose);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
266 ps2_vu0_rot_matrix_y(car->body->transfer, car->body->transfer, degree2radian(car->y_angle));
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
267 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
268
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
269 void
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
270 car_update(Game *game,CarPtr car)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
271 {
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
272 // 移動
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
273 car_move(game,car);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
274
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
275 // 摩擦による速度減少
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
276 car->speed -= 0.005;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
277 car->speed = (car->speed < 0) ? 0 : car->speed;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
278
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
279 // 傾き
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
280 car_axis_rotation(car);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
281 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
282
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
283 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
284 car_destroy(CarPtr p)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
285 {
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
286 TEXTURE *t;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
287
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
288 if ((t = p->body->surfaces->texture)) {
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
289 ps2util_tex_Exclude(t);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
290 free_texture(t);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
291 }
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
292 ps2util_obj_Free(p->body);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
293 free(p->free_addr);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
294
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
295 #ifdef DEBUG
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
296 fprintf(main_fp, "free car addr = %x\n", (int)p->free_addr);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
297 #endif
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
298 }