comparison fps/fps.html @ 3:aa7abf13d3f5 draft default tip

fix bug
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Wed, 16 May 2012 21:56:12 +0900
parents 47399f2f3a80
children
comparison
equal deleted inserted replaced
2:47399f2f3a80 3:aa7abf13d3f5
134 ctx.perspectiveMatrix.frustum(-0.5, 0.5, -0.5 / t, 0.5 / t, 1, 100000); 134 ctx.perspectiveMatrix.frustum(-0.5, 0.5, -0.5 / t, 0.5 / t, 1, 100000);
135 } 135 }
136 136
137 137
138 function setCamera(ctx){ 138 function setCamera(ctx){
139 ctx.viewport(0, 0, width, height); 139 ctx.viewport(0, 0, width, height);
140 140
141 var t = width/height; 141 var t = width/height;
142 142
143 ctx.perspectiveMatrix.makeIdentity(); 143 ctx.perspectiveMatrix.makeIdentity();
144 ctx.perspectiveMatrix.frustum(-0.5, 0.5, -0.5 / t, 0.5 / t, 1, 100000); 144 ctx.perspectiveMatrix.frustum(-0.5, 0.5, -0.5 / t, 0.5 / t, 1, 100000);
145 145
146 ctx.perspectiveMatrix.translate(-xPos,-yPos,-zPos); 146 var x = Math.cos((angle+90)*Math.PI/180 );
147 ctx.perspectiveMatrix.rotate(xRool,0,1,0); 147 var z = Math.sin((angle+90)*Math.PI/180 );
148 148
149 ctx.perspectiveMatrix.multiply(cameraMatrix); 149 cameraX += x * speedZ;
150 150 cameraZ += z * speedZ;
151 151
152 cameraMatrix.translate(-xPos,-yPos,-zPos); 152 ctx.perspectiveMatrix.rotate(angle,0,1,0);
153 cameraMatrix.rotate(xRool,0,1,0); 153 ctx.perspectiveMatrix.translate(cameraX,0,cameraZ);
154 154
155 if(countX < 10) 155 }
156 countX += 0.01; 156
157 } 157 angle = 0;
158 158 cameraX = 0;
159 countRool = 0; 159 cameraZ = 0;
160 countX = 0;
161 160
162 FILPCOUNT = 0; 161 FILPCOUNT = 0;
163 function loop(ctx, ortho) 162 function loop(ctx, ortho)
164 { 163 {
165 ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT); 164 ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT);
166 165
167 setCamera(ctx); 166 setCamera(ctx);
168 167
169 PutSpriteV(ctx, cube_X, cube_Y, cube_Z, 1, matrix, object); 168 PutSpriteV(ctx, cube_X, cube_Y, cube_Z, 1, matrix, object);
170 PutSpriteV(ctx, cube_X2, cube_Y2, cube_Z2, 1, matrix, object2); 169 PutSpriteV(ctx, cube_X2, cube_Y2, cube_Z2, 1, matrix, object2);
171 PutSpriteV(ctx, cube_X3, cube_Y3, cube_Z3, 1, matrix, object3); 170 PutSpriteV(ctx, cube_X3, cube_Y3, cube_Z3, 1, matrix, object3);
172 PutSpriteV(ctx, ground_X, ground_Y, ground_Z, 2, matrix2, object4); 171 PutSpriteV(ctx, ground_X, ground_Y, ground_Z, 2, matrix2, object4);
197 function start() 196 function start()
198 { 197 {
199 var ortho = {left:0, right:200, bottom:140, top:0} 198 var ortho = {left:0, right:200, bottom:140, top:0}
200 matrix = new J3DIMatrix4(); // global variable 199 matrix = new J3DIMatrix4(); // global variable
201 matrix2 = new J3DIMatrix4(); // global variable 200 matrix2 = new J3DIMatrix4(); // global variable
202 cameraMatrix = new J3DIMatrix4(); // global variable
203 cameraMatrix.makeIdentity();
204 201
205 202
206 cube_X = 0; 203 cube_X = 0;
207 cube_Y = 0; 204 cube_Y = 0;
208 cube_Z = -10; 205 cube_Z = -10;