Mercurial > hg > old > magoroku_racing
diff car.c @ 91:cb6c6de125dc
halfway
author | Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 May 2011 14:44:03 +0900 |
parents | 8edae89a3877 |
children | 0b65ca27f113 |
line wrap: on
line diff
--- a/car.c Thu May 19 16:41:21 2011 +0900 +++ b/car.c Thu May 26 14:44:03 2011 +0900 @@ -1,8 +1,8 @@ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> -//#include "libps2.h" -//#include "ps2util.h" +#include "libps2.h" +#include "ps2util.h" #include "field.h" #include "car.h" #include "mytype.h" @@ -14,8 +14,8 @@ #define BUFSIZE 256 /* 初期位置と初期方向 */ -//static FVECTOR location = {0, 0, 0, 1}; -//static FVECTOR direction = {0, 0, 1, 1}; +static FVECTOR location = {0, 0, 0, 1}; +static FVECTOR direction = {0, 0, 1, 1}; extern FILE* main_fp; @@ -30,18 +30,18 @@ float speed_max, float rot, float brake) { CarPtr car; - //OBJECT *body; - //TEXTURE* tex; + OBJECT *body; + TEXTURE* tex; void *free_addr; - //body = ps2util_obj_Create_fromXML(filename); - //ps2util_obj_Set_effect(body, DEFAULT_SET); + body = ps2util_obj_Create_fromXML(filename); + ps2util_obj_Set_effect(body, DEFAULT_SET); - if (true){//malloc_align16(&free_addr, &car, sizeof(Car)) == -1) { - // fprintf(main_fp, "car.c: malloc_align16 error\n"); + if (malloc_align16(&free_addr, &car, sizeof(Car)) == -1) { + fprintf(main_fp, "car.c: malloc_align16 error\n"); exit(EXIT_FAILURE); } - //car->body = body; + car->body = body; car->next = NULL; car->speed = 0.0; car->speed_accel = speed_accel; @@ -51,23 +51,23 @@ car->y_angle = 0.0; car->free_addr = free_addr; - //ps2_vu0_copy_vector(car->direction, direction); - //ps2_vu0_copy_vector(car->location, location); - //INIT_VECTOR(car->vertical, 0, -1, 0, 1); - //INIT_VECTOR(car->body->xyz, 0, 0, 0, 1); - //INIT_VECTOR(car->body->angle, 0, 0, 0, 1); + ps2_vu0_copy_vector(car->direction, direction); + ps2_vu0_copy_vector(car->location, location); + INIT_VECTOR(car->vertical, 0, -1, 0, 1); + INIT_VECTOR(car->body->xyz, 0, 0, 0, 1); + INIT_VECTOR(car->body->angle, 0, 0, 0, 1); - //ps2util_obj_Renew_transMatrix(car->body); - //ps2util_obj_Set_effect(car->body, DEFAULT_SET); + ps2util_obj_Renew_transMatrix(car->body); + ps2util_obj_Set_effect(car->body, DEFAULT_SET); if (*texname != 'n') { - //tex = read_png_file(texname); - //ps2util_tex_Set(tex); - //ps2util_obj_Set_texture(car->body, tex); + tex = read_png_file(texname); + ps2util_tex_Set(tex); + ps2util_obj_Set_texture(car->body, tex); } #ifdef DEBUG - // fprintf(main_fp, "malloc car addr = %x\n", (int)free_addr); + fprintf(main_fp, "malloc car addr = %x\n", (int)free_addr); #endif return car; @@ -140,17 +140,17 @@ void car_swerve(CarPtr car, int flg) { - //FMATRIX rot; - // FVECTOR v; + FMATRIX rot; + FVECTOR v; car->y_angle += (float)flg*car->rotation_angle; car->y_angle += (car->y_angle < 0) ? 360.0 : 0; car->y_angle += (car->y_angle > 360.0) ? -360.0 : 0; - // ps2_vu0_unit_matrix(rot); - // ps2_vu0_rot_matrix_y(rot, rot, degree2radian((float)flg*car->rotation_angle)); - // ps2_vu0_copy_vector(v, car->direction); - // ps2_vu0_apply_matrix(car->direction, rot, v); + ps2_vu0_unit_matrix(rot); + ps2_vu0_rot_matrix_y(rot, rot, degree2radian((float)flg*car->rotation_angle)); + ps2_vu0_copy_vector(v, car->direction); + ps2_vu0_apply_matrix(car->direction, rot, v); } /*---------------------------- @@ -176,20 +176,20 @@ FALSEを返す。 ---------------------------------*/ static bool -car_field_check(CarPtr car) +car_field_check(Game *game ,CarPtr car) { FieldPtr p; FieldPtr f = field_get_actual(); // 現在のコースで衝突・内外判定 p = f; - if (true){//(col_detect(&p->colface, car->vertical, car->location) == true) { + if (col_detect(&p->colface, car->vertical, car->location) == true) { goto FIELD_CHECK_OK; } // 現在のコースの次に隣接するコースで衝突・内外判定 p = f->next; - if (true){//if (col_detect(&p->colface, car->vertical, car->location) == true) { + if (col_detect(&p->colface, car->vertical, car->location) == true) { if (field_rap_increment(1)) { game->rap++; } @@ -198,7 +198,7 @@ // 現在のコースの前に隣接するコースで衝突・内外判定 p = f->prev; - if (true){//if (col_detect(&p->colface, car->vertical, car->location) == true) { + if (col_detect(&p->colface, car->vertical, car->location) == true) { field_rap_increment(-1); goto FIELD_CHECK_OK; } @@ -218,59 +218,59 @@ また、進行後の衝突判定も行う。 ------------------------------*/ static void -car_move(CarPtr car) +car_move(Game *game,CarPtr car) { - //FVECTOR mov, prev_location; + FVECTOR mov, prev_location; - // ps2_vu0_scale_vector(mov, car->direction, car->speed); - // ps2_vu0_copy_vector(prev_location, car->location); - // ps2_vu0_add_vector(car->location, car->location, mov); + ps2_vu0_scale_vector(mov, car->direction, car->speed); + ps2_vu0_copy_vector(prev_location, car->location); + ps2_vu0_add_vector(car->location, car->location, mov); - if (car_field_check(car) == false) { - // ps2_vu0_copy_vector(car->location, prev_location); + if (car_field_check(game,car) == false) { + ps2_vu0_copy_vector(car->location, prev_location); car->speed = car->speed*0.5; - } + } } static void car_axis_rotation(CarPtr car) { - // FMATRIX pose, yrot, yrotinv; + FMATRIX pose, yrot, yrotinv; - // ps2_vu0_unit_matrix(yrot); - // ps2_vu0_rot_matrix_y(yrot, yrot, -degree2radian(car->y_angle)); - // ps2_vu0_unit_matrix(yrotinv); - // ps2_vu0_rot_matrix_y(yrotinv, yrotinv, degree2radian(car->y_angle)); + ps2_vu0_unit_matrix(yrot); + ps2_vu0_rot_matrix_y(yrot, yrot, -degree2radian(car->y_angle)); + ps2_vu0_unit_matrix(yrotinv); + ps2_vu0_rot_matrix_y(yrotinv, yrotinv, degree2radian(car->y_angle)); { - // FVECTOR yd = {0, -1, 0, 1}; - // FVECTOR rotaxis; - // FVECTOR q; + FVECTOR yd = {0, -1, 0, 1}; + FVECTOR rotaxis; + FVECTOR q; - // ps2_vu0_outer_product(rotaxis, car->vertical, yd); + ps2_vu0_outer_product(rotaxis, car->vertical, yd); { - // float scale=1/NORM(rotaxis); - // rotaxis[0] *= scale; - // rotaxis[1] *= scale; - // rotaxis[2] *= scale; + float scale=1/NORM(rotaxis); + rotaxis[0] *= scale; + rotaxis[1] *= scale; + rotaxis[2] *= scale; } - // quotanion(q, rotaxis, acos(ps2_vu0_inner_product(yd, car->vertical)/(NORM(yd)*NORM(car->vertical)))); - // quotanion_rotmatrix(pose, q); + quotanion(q, rotaxis, acos(ps2_vu0_inner_product(yd, car->vertical)/(NORM(yd)*NORM(car->vertical)))); + quotanion_rotmatrix(pose, q); } - // ps2_vu0_mul_matrix(pose, yrot, pose); - // ps2_vu0_mul_matrix(pose, pose, yrotinv); - // ps2_vu0_copy_matrix(car->body->transfer, pose); - // ps2_vu0_rot_matrix_y(car->body->transfer, car->body->transfer, degree2radian(car->y_angle)); + ps2_vu0_mul_matrix(pose, yrot, pose); + ps2_vu0_mul_matrix(pose, pose, yrotinv); + ps2_vu0_copy_matrix(car->body->transfer, pose); + ps2_vu0_rot_matrix_y(car->body->transfer, car->body->transfer, degree2radian(car->y_angle)); } void -car_update(CarPtr car) +car_update(Game *game,CarPtr car) { // 移動 - car_move(car); + car_move(game,car); // 摩擦による速度減少 car->speed -= 0.005; @@ -283,16 +283,16 @@ void car_destroy(CarPtr p) { - // TEXTURE *t; + TEXTURE *t; - // if ((t = p->body->surfaces->texture)) { - // ps2util_tex_Exclude(t); - // free_texture(t); - // } - // ps2util_obj_Free(p->body); - // free(p->free_addr); + if ((t = p->body->surfaces->texture)) { + ps2util_tex_Exclude(t); + free_texture(t); + } + ps2util_obj_Free(p->body); + free(p->free_addr); #ifdef DEBUG - // fprintf(main_fp, "free car addr = %x\n", (int)p->free_addr); + fprintf(main_fp, "free car addr = %x\n", (int)p->free_addr); #endif }