annotate car.cc @ 99:c534f339ee8b

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