annotate camera.cc @ 134:42337585fb7c

fix merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 22 Jul 2011 18:32:39 +0900
parents d9e3137e70a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
1 #include <stdlib.h>
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
2 #include <string.h>
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
3 #include "libps2.h"
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
4 #include "ps2util.h"
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
5 #include "car.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
6 #include "game.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
7 #include "controler.h"
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
8 #include "camera.h"
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
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
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
12
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
13 static CAMERA camera, def_camera;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
14
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
15
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
16 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
17 camera_init()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
18 {
124
e085768
parents: 99
diff changeset
19 //カメラの初期位置設定
e085768
parents: 99
diff changeset
20 def_camera.xyz[0] = 0;
e085768
parents: 99
diff changeset
21 def_camera.xyz[1] =-7;// -3;
e085768
parents: 99
diff changeset
22 def_camera.xyz[2] =-14; //0;
e085768
parents: 99
diff changeset
23 def_camera.xyz[3] = 1;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
24
124
e085768
parents: 99
diff changeset
25 def_camera.zd[0] = 0;
e085768
parents: 99
diff changeset
26 def_camera.zd[1] = 2;
e085768
parents: 99
diff changeset
27 def_camera.zd[2] = 7;
e085768
parents: 99
diff changeset
28 def_camera.zd[3] = 1;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
29
124
e085768
parents: 99
diff changeset
30 def_camera.yd[0] = 0;
e085768
parents: 99
diff changeset
31 def_camera.yd[1] = 1;
e085768
parents: 99
diff changeset
32 def_camera.yd[2] = 0;
e085768
parents: 99
diff changeset
33 def_camera.yd[3] = 1;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
34
124
e085768
parents: 99
diff changeset
35 def_camera.angle[0]=-0.2;//0; //pich
e085768
parents: 99
diff changeset
36 def_camera.angle[1]=0; //yoh
e085768
parents: 99
diff changeset
37 def_camera.angle[2]=0; //roll
e085768
parents: 99
diff changeset
38 def_camera.angle[3]=0;
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
39
124
e085768
parents: 99
diff changeset
40 //def_cameraをcameraにコピー
e085768
parents: 99
diff changeset
41 memcpy( &camera, &def_camera, sizeof(CAMERA));
e085768
parents: 99
diff changeset
42 set_camera(&def_camera);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
43 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
44
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
45 /*
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
46 ps2依存関係から拝借。
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
47 自分が消したのか、元々無いのかは覚えていないけど
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
48 呼ばれているのでとりあえず(空っぽにしておく)。
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
49 */
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
50 // set_camera must be called if camera's parameters were moved
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
51 void set_camera(CAMERA *camera)
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
52 {
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
53 //vu0_rot_camera_matrix(world_view, camera->xyz, camera->zd, camera->yd,camera->angle);
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
54 }
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
55
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
56
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
57 /**
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
58 * pose: カメラの対象物(obj)の座標行列
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
59 * カメラがobjについていくように(そのような動きに見せるため)
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
60 * カメラの位置ベクトル、視点ベクトルを更新
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
61 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
62 void
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
63 camera_update(Game *game, FMATRIX pose)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
64 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
65 FVECTOR location, eyes, vertical, angle;
128
d9e3137e70a0 xml name change
e085768
parents: 124
diff changeset
66
d9e3137e70a0 xml name change
e085768
parents: 124
diff changeset
67 //int type = game->camera_type;
0
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 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
70 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
71 ps2_vu0_apply_matrix(vertical, pose, def_camera.yd);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
72
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
73 /**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
74 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
75 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
76 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
77 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
78 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
79 }
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
80 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
81 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
82 if(game->jiki->speed !=0){
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
83 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
84 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
85 }
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 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
88 else {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
89 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
90 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
91 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
92 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
93 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
94 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
95 }
128
d9e3137e70a0 xml name change
e085768
parents: 124
diff changeset
96
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
97 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
98 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
99 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
100 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
101 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
102 set_camera(&camera);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
103 }
128
d9e3137e70a0 xml name change
e085768
parents: 124
diff changeset
104
d9e3137e70a0 xml name change
e085768
parents: 124
diff changeset
105
d9e3137e70a0 xml name change
e085768
parents: 124
diff changeset
106 CAMERA get_MagorokuCamera( void )
d9e3137e70a0 xml name change
e085768
parents: 124
diff changeset
107 {
d9e3137e70a0 xml name change
e085768
parents: 124
diff changeset
108 return camera;
d9e3137e70a0 xml name change
e085768
parents: 124
diff changeset
109 }