Mercurial > hg > old > magoroku_racing
annotate camera.cc @ 124:6ef3b0efdeaf
test
author | e085768 |
---|---|
date | Thu, 30 Jun 2011 12:43:18 +0900 |
parents | c534f339ee8b |
children | d9e3137e70a0 |
rev | line source |
---|---|
0 | 1 #include <stdlib.h> |
91 | 2 #include <string.h> |
3 #include "libps2.h" | |
4 #include "ps2util.h" | |
0 | 5 #include "car.h" |
6 #include "game.h" | |
7 #include "controler.h" | |
91 | 8 #include "camera.h" |
0 | 9 |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
10 //大域変数、各部で共有 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
11 extern SGO_PAD pad; |
0 | 12 |
91 | 13 static CAMERA camera, def_camera; |
0 | 14 |
15 | |
16 void | |
17 camera_init() | |
18 { | |
91 | 19 |
124 | 20 //カメラの初期位置設定 |
21 def_camera.xyz[0] = 0; | |
22 def_camera.xyz[1] =-7;// -3; | |
23 def_camera.xyz[2] =-14; //0; | |
24 def_camera.xyz[3] = 1; | |
0 | 25 |
124 | 26 def_camera.zd[0] = 0; |
27 def_camera.zd[1] = 2; | |
28 def_camera.zd[2] = 7; | |
29 def_camera.zd[3] = 1; | |
0 | 30 |
124 | 31 def_camera.yd[0] = 0; |
32 def_camera.yd[1] = 1; | |
33 def_camera.yd[2] = 0; | |
34 def_camera.yd[3] = 1; | |
0 | 35 |
124 | 36 def_camera.angle[0]=-0.2;//0; //pich |
37 def_camera.angle[1]=0; //yoh | |
38 def_camera.angle[2]=0; //roll | |
39 def_camera.angle[3]=0; | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
40 |
124 | 41 //def_cameraをcameraにコピー |
42 memcpy( &camera, &def_camera, sizeof(CAMERA)); | |
43 set_camera(&def_camera); | |
91 | 44 |
0 | 45 } |
46 | |
91 | 47 /* |
48 ps2依存関係から拝借。 | |
49 自分が消したのか、元々無いのかは覚えていないけど | |
50 呼ばれているのでとりあえず(空っぽにしておく)。 | |
51 */ | |
52 // set_camera must be called if camera's parameters were moved | |
53 void set_camera(CAMERA *camera) | |
54 { | |
55 //vu0_rot_camera_matrix(world_view, camera->xyz, camera->zd, camera->yd,camera->angle); | |
56 } | |
57 | |
58 | |
0 | 59 /** |
88 | 60 * pose: カメラの対象物(obj)の座標行列 |
61 * カメラがobjについていくように(そのような動きに見せるため) | |
62 * カメラの位置ベクトル、視点ベクトルを更新 | |
0 | 63 */ |
64 void | |
91 | 65 camera_update(Game *game, FMATRIX pose) |
0 | 66 { |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
67 FVECTOR location, eyes, vertical, angle; |
91 | 68 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
69 //int type = game->camera_type; |
0 | 70 |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
71 ps2_vu0_apply_matrix(location, pose, def_camera.xyz); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
72 ps2_vu0_apply_matrix(eyes, pose, def_camera.zd); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
73 ps2_vu0_apply_matrix(vertical, pose, def_camera.yd); |
0 | 74 |
75 /**When the car bends, the angle of the camera is changed**/ | |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
76 if(pad.left>0 && game->jiki->speed !=0){ |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
77 if(game->jiki->speed !=0){ |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
78 if(def_camera.angle[1]<=0.2){ |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
79 def_camera.angle[1]+=0.02; |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
80 } |
0 | 81 } |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
82 } |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
83 else if(pad.right>0 && game->jiki->speed !=0){ |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
84 if(game->jiki->speed !=0){ |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
85 if(def_camera.angle[1]>=-0.2){ |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
86 def_camera.angle[1]-=0.02; |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
87 } |
0 | 88 } |
96
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
89 } |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
90 else { |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
91 if(def_camera.angle[1]<-0.01){ |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
92 def_camera.angle[1]+=0.02; |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
93 } |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
94 else if(def_camera.angle[1]>0.01){ |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
95 def_camera.angle[1]-=0.02; |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
96 } |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
97 } |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
98 ps2_vu0_apply_matrix(angle, pose, def_camera.angle); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
99 ps2_vu0_copy_vector(camera.xyz, location); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
100 ps2_vu0_copy_vector(camera.zd, eyes); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
101 ps2_vu0_copy_vector(camera.yd, vertical); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
102 ps2_vu0_copy_vector(camera.angle, angle); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
103 set_camera(&camera); |
0b65ca27f113
compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
91
diff
changeset
|
104 |
0 | 105 } |