Mercurial > hg > old > magoroku_racing
view test_vector.cc @ 122:5219bf3d5e71
title_draw
author | e085768 |
---|---|
date | Mon, 27 Jun 2011 19:44:46 +0900 |
parents | c534f339ee8b |
children | 4f50f5a3b363 |
line wrap: on
line source
#include <stdio.h> #include "ps2util.h" #include "libps2.h" void init_FVECTOR(FVECTOR v, float num); void init_FMATRIX(FMATRIX m, float num); void output_FVECTOR(FVECTOR v); void output_FMATRIX(FMATRIX m); void all_init(FVECTOR v0, FVECTOR v1, FMATRIX m0, FMATRIX m1, float num); /* ps2util.c にある、vector 計算のテスト用処理です。 */ int main(){ FVECTOR resultV; FMATRIX resultM; float resultf; FVECTOR v0,v1; FMATRIX m0,m1; float f0 = 0.5; float num = 0.1; int i,j; int lim1 = 4; //v0,v1,m0,m1 を初期化 all_init(v0, v1, m0, m1, num); printf("v0\n"); output_FVECTOR(v0); printf("v1\n"); output_FVECTOR(v1); printf("m0\n"); output_FMATRIX(m0); printf("m1\n"); output_FMATRIX(m1); printf("\n"); printf("\n"); /*-----------ps2util.c test----------*/ ps2_vu0_copy_vector(v0, v1); printf("ps2_vu0_copy_vector(v0, v1)\n"); output_FVECTOR(v0); output_FVECTOR(v1); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_unit_matrix(m0); printf("ps2_vu0_unit_matrix(m0)\n"); output_FMATRIX(m0); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_rot_matrix_y(resultM, m0, f0); printf("ps2_vu0_rot_matrix_y(resultM, m0, f0)\n"); output_FMATRIX(resultM); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_apply_matrix(resultV, m0, v0); printf("ps2_vu0_apply_matrix(resultV, m0, v0)\n"); output_FVECTOR(resultV); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_scale_vector(resultV, v0, f0); printf("ps2_vu0_sacle_vector(resultV, v0, f0)\n"); output_FVECTOR(resultV); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_add_vector(resultV, v0, v1); printf("ps2_vu0_add_vector(resultV, v0, v1)\n"); output_FVECTOR(resultV); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_outer_product(resultV, v0, v1); printf("ps2_vu0_outer_product(resultV, v0, v1)\n"); output_FVECTOR(resultV); printf("\n"); all_init(v0, v1, m0, m1, num); resultf = ps2_vu0_inner_product(v0, v1); printf("ps2_vu0_inner_product(v0, v1)\n"); printf("resultf = %10f\n",resultf); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_mul_matrix(resultM, m0, m1); printf("ps2_vu0_mul_matrix(resultM, m0, m1)\n"); output_FMATRIX(resultM); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_copy_matrix(m0, m1); printf("ps2_vu0_copy_matrix(m0, m1)\n"); output_FMATRIX(m0); output_FMATRIX(m0); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_sub_vector(resultV, v0, v1); printf("ps2_vu0_sub_vector(resultV, v0, v1)\n"); output_FVECTOR(resultV); printf("\n"); all_init(v0, v1, m0, m1, num); ps2_vu0_normalize(resultV, v0); printf("ps2_vu0_normalize(result, v0)\n"); output_FVECTOR(resultV); printf("\n"); all_init(v0, v1, m0, m1, num); } //使用する値の初期化 FVECTOR void init_FVECTOR(FVECTOR v, float num){ int i; int lim1=4; for ( i=0; i<lim1; i++ ) { v[i] = num + ( (float)i * num * 0.3 ) ; } v[3] = 1; } //使用する値の初期化 FMATRIX void init_FMATRIX(FMATRIX m, float num){ int i,j; int lim1=4; for ( i=0; i<lim1; i++ ) { for ( j=0; j<lim1; j++ ) { m[i][j] = ( num * (float)j ) + ( (float)i * num*4.0 ) ; } } m[0][3] = m[1][3] = m[2][3] = 0; m[3][0] = m[3][1] = m[3][2] = 0; m[3][3] = 1; } //--------出力--------- void output_FVECTOR(FVECTOR v){ int i; int lim1 = 4; for ( i=0; i<lim1; i++ ) { printf("%10f ",v[i]); } printf("\n\n"); } //--------出力--------- void output_FMATRIX(FMATRIX m){ int i,j; int lim1 = 4; for ( i=0; i<lim1; i++ ) { for ( j=0; j<lim1; j++ ) { printf("%10f",m[i][j]); } printf("\n"); } printf("\n"); } //全部を初期値に戻す。 void all_init(FVECTOR v0, FVECTOR v1, FMATRIX m0, FMATRIX m1, float num){ init_FVECTOR(v0, num); init_FVECTOR(v1, num*2); init_FMATRIX(m0, num); init_FMATRIX(m1, num*2); }