0
|
1 createHuman = function(sgroot, w, h){
|
|
2 var walk_man = new sgroot.createSceneGraph3();
|
|
3 walk_man.xyz[0] = 100;
|
|
4 walk_man.xyz[1] = -5;
|
|
5 walk_man.xyz[2] = 100;
|
|
6 position_xyz[0] = walk_man.xyz[0];
|
|
7 position_xyz[1] = walk_man.xyz[1] - 10;
|
|
8 position_xyz[2] = walk_man.xyz[2] - 50;
|
|
9 aim_xyz[0] = position_xyz[0];
|
|
10 aim_xyz[1] = position_xyz[1];
|
|
11 aim_xyz[2] = position_xyz[2] + 1;
|
|
12 walk_man.scale = 0.01;
|
|
13 //walk_man.set_move_collision(body_move, body_collision)
|
|
14 walk_man.set_move_collision(body_move, no_collision_idle);
|
|
15
|
|
16
|
|
17 var head = new sgroot.createSceneGraph1("head");
|
|
18 head.angle[0] = 90;
|
|
19 head.angle[1] = 90;
|
|
20 head.xyz[0] = -sgroot.sg_src["head"].model_x * 100;
|
|
21 head.xyz[1] = -sgroot.sg_src["head"].model_y * 100;
|
|
22 head.xyz[2] = -sgroot.sg_src["head"].model_z * 100;
|
|
23 head.set_move_collision(head_move, no_collision_idle);
|
|
24
|
|
25
|
|
26 var body = new sgroot.createSceneGraph1("body");
|
|
27 body.xyz[0] = -sgroot.sg_src["body"].model_x * 100;
|
|
28 body.xyz[1] = -sgroot.sg_src["body"].model_y * 100;
|
|
29 body.xyz[2] = -sgroot.sg_src["body"].model_z * 100 + 200;
|
|
30 body.set_move_collision(no_move_idle, no_collision_idle);
|
|
31
|
|
32
|
|
33 var joint_rh = new sgroot.createSceneGraph1("Kata");
|
|
34 /*joint_rh.xyz[0] = -sgroot.sg_src["green"].model_x * 7
|
|
35 joint_rh.xyz[1] =- sgroot.sg_src["green"].model_y * 7
|
|
36 joint_rh.xyz[2] = -sgroot.sg_src["green"].model_z * 7
|
|
37 */
|
|
38
|
|
39 joint_rh.scale = 7;
|
|
40 joint_rh.set_move_collision(joint_rh_move, no_collision_idle);
|
|
41
|
|
42
|
|
43 var right_hand = new sgroot.createSceneGraph1("right_hand");
|
|
44 right_hand.xyz[0] = -sgroot.sg_src["right_hand"].model_x * (100/7);
|
|
45 right_hand.xyz[1] = -sgroot.sg_src["right_hand"].model_y * (100/7);
|
|
46 right_hand.xyz[2] = -sgroot.sg_src["right_hand"].model_z * (100/7) - (sgroot.sg_src["right_hand"].w / 2);
|
|
47 right_hand.scale = 1/7;
|
|
48 right_hand.set_move_collision(right_hand_move, no_collision_idle);
|
|
49
|
|
50
|
|
51 var joint_lh = new sgroot.createSceneGraph1("Kata");
|
|
52 joint_lh.scale = 7;
|
|
53 joint_lh.set_move_collision(joint_lh_move, no_collision_idle);
|
|
54
|
|
55
|
|
56 var left_hand = new sgroot.createSceneGraph1("left_hand");
|
|
57 left_hand.xyz[0] = -sgroot.sg_src["left_hand"].model_x * (100/7);
|
|
58 left_hand.xyz[1] = -sgroot.sg_src["left_hand"].model_y * (100/7);
|
|
59 left_hand.xyz[2] = -sgroot.sg_src["left_hand"].model_z * (100/7) - (sgroot.sg_src["left_hand"].w / 2);
|
|
60 left_hand.scale = 1/7;
|
|
61 left_hand.set_move_collision(left_hand_move, no_collision_idle);
|
|
62
|
|
63
|
|
64 var joint_rl = new sgroot.createSceneGraph1("Kata");
|
|
65 joint_rl.scale = 7;
|
|
66 joint_rl.set_move_collision(joint_rl_move, no_collision_idle);
|
|
67
|
|
68 var right_leg = new sgroot.createSceneGraph1("left_leg");
|
|
69 right_leg.xyz[0] = -sgroot.sg_src["left_leg"].model_x * (100/7);
|
|
70 right_leg.xyz[1] = -sgroot.sg_src["left_leg"].model_y * (100/7);
|
|
71 right_leg.xyz[2] = -sgroot.sg_src["left_leg"].model_z * (100/7) - (sgroot.sg_src["left_leg"].w / 10);
|
|
72 right_leg.scale = 1/7;
|
|
73 right_leg.set_move_collision(right_leg_move, no_collision_idle);
|
|
74
|
|
75
|
|
76 var joint_ll = new sgroot.createSceneGraph1("Kata");
|
|
77 joint_ll.scale = 7;
|
|
78 joint_ll.set_move_collision(joint_ll_move, no_collision_idle);
|
|
79
|
|
80
|
|
81 var left_leg = new sgroot.createSceneGraph1("left_leg");
|
|
82 left_leg.xyz[0] = -sgroot.sg_src["left_leg"].model_x * (100/7);
|
|
83 left_leg.xyz[1] = -sgroot.sg_src["left_leg"].model_y * (100/7);
|
|
84 left_leg.xyz[2] = -sgroot.sg_src["left_leg"].model_z * (100/7) - (sgroot.sg_src["left_leg"].w / 10);
|
|
85 left_leg.scale = 1/7;
|
|
86 left_leg.set_move_collision(left_leg_move, no_collision_idle);
|
|
87
|
|
88
|
|
89
|
|
90 walk_man.addChild(head);
|
|
91 head.addChild(body);
|
|
92
|
|
93 body.addChild(joint_rh);
|
|
94 joint_rh.addChild(right_hand);
|
|
95
|
|
96 body.addChild(joint_lh);
|
|
97 joint_lh.addChild(left_hand);
|
|
98
|
|
99 body.addChild(joint_rl);
|
|
100 joint_rl.addChild(right_leg);
|
|
101
|
|
102 body.addChild(joint_ll);
|
|
103 joint_ll.addChild(left_leg);
|
|
104
|
|
105
|
|
106
|
|
107 return walk_man;
|
|
108
|
|
109 }
|
|
110
|
|
111
|
|
112 roteta_body = function(node, sgroot, w, h){
|
|
113 node.angle[2] += 1;
|
|
114 }
|
|
115
|
|
116 head_move = function(node, sgroot, w, h){
|
|
117 var move_eye = 1.0;
|
|
118 var PI = 3.14;
|
|
119 var pad = new sgroot.getController();
|
|
120 var dx = node.parents.xyz[0] - position_xyz[0];
|
|
121 var dz = node.parents.xyz[2] - position_xyz[2];
|
|
122 var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dz,2));
|
|
123
|
|
124
|
|
125 if(pad.left_isHold()){
|
|
126 cameraAngle_xyz[0] -= move_eye;
|
|
127 theta += move_eye;
|
|
128 var radian = ((theta%360) / 360) * 2 * PI;
|
|
129 var x_rate = Math.sin(radian);
|
|
130 var z_rate = Math.cos(radian);
|
|
131 var mv_x = d * Math.cos(radian);
|
|
132 var mv_z = d * Math.sin(radian);
|
|
133
|
|
134 position_xyz[0] = node.parents.xyz[0] - mv_x;
|
|
135 position_xyz[2] = node.parents.xyz[2] - mv_z;
|
|
136 aim_xyz[0] = position_xyz[0] ;
|
|
137 aim_xyz[2] = position_xyz[2] + 1;
|
|
138 node.angle[0] -= move_eye;
|
|
139 angleRate_xyz[0] = x_rate;
|
|
140 angleRate_xyz[2] = z_rate;
|
|
141 }
|
|
142
|
|
143
|
|
144 if(pad.right_isHold()){
|
|
145 cameraAngle_xyz[0] += move_eye;
|
|
146 theta -= move_eye;
|
|
147 var radian = ((theta%360) / 360) * 2 * PI;
|
|
148 var x_rate = Math.sin(radian);
|
|
149 var z_rate = Math.cos(radian);
|
|
150 var mv_x = d * Math.cos(radian)
|
|
151 var mv_z = d * Math.sin(radian);
|
|
152
|
|
153 position_xyz[0] = node.parents.xyz[0] - mv_x;
|
|
154 position_xyz[2] = node.parents.xyz[2] - mv_z;
|
|
155 aim_xyz[0] = position_xyz[0];
|
|
156 aim_xyz[2] = position_xyz[2] + 1;
|
|
157 node.angle[0] += move_eye;
|
|
158 angleRate_xyz[0] = x_rate;
|
|
159 angleRate_xyz[2] = z_rate;
|
|
160 }
|
|
161
|
|
162
|
|
163 if(pad.up_isHold() && cameraAngle_xyz[1] > -90){
|
|
164 //node.angle[2] -= move_eye
|
|
165 cameraAngle_xyz[1] -= move_eye;
|
|
166 }
|
|
167
|
|
168 if(pad.down_isHold() && cameraAngle_xyz[1] < 90){
|
|
169 //node.angle[2] += move_eye
|
|
170 cameraAngle_xyz[1] += move_eye;
|
|
171 }
|
|
172
|
|
173 }
|
|
174
|
|
175
|
|
176
|
|
177 body_move = function(node, sgroot, w, h){
|
|
178 var move_eye = 1.0;
|
|
179 var move_walk = 1.0;
|
|
180 var PI = 3.14;
|
|
181 var pad = new sgroot.getController();
|
|
182 var dx = position_xyz[0] - aim_xyz[0];
|
|
183 var dz = position_xyz[2] - aim_xyz[2];
|
|
184 var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dz,2));
|
|
185
|
|
186 //if(node.xyz[0] >= 0 && node.xyz[2] >= 0){
|
|
187 if(pad.left_move_isHold()){
|
|
188 var radian = (((theta+90)%360) / 360) * 2 * PI;
|
|
189
|
|
190 if(!pad.zoom_in_isHold()){
|
|
191 node.xyz[0] += move_walk * Math.cos(radian);
|
|
192 node.xyz[2] += move_walk * Math.sin(radian);
|
|
193 }
|
|
194
|
|
195 aim_xyz[0] += move_walk * Math.cos(radian);
|
|
196 aim_xyz[2] += move_walk * Math.sin(radian);
|
|
197 position_xyz[0] += move_walk * Math.cos(radian);
|
|
198 position_xyz[2] += move_walk * Math.sin(radian);
|
|
199 }
|
|
200
|
|
201 if(pad.right_move_isHold()){
|
|
202 var radian = (((theta+90)%360) / 360) * 2 * PI;
|
|
203
|
|
204 if(!pad.zoom_in_isHold()){
|
|
205 node.xyz[0] -= move_walk * Math.cos(radian);
|
|
206 node.xyz[2] -= move_walk * Math.sin(radian);
|
|
207 }
|
|
208
|
|
209 aim_xyz[0] -= move_walk * Math.cos(radian);
|
|
210 aim_xyz[2] -= move_walk * Math.sin(radian);
|
|
211 position_xyz[0] -= move_walk * Math.cos(radian);
|
|
212 position_xyz[2] -= move_walk * Math.sin(radian);
|
|
213 }
|
|
214
|
|
215 if(pad.front_move_isHold()){
|
|
216 var radian = ((theta%360) / 360) * 2 * PI;
|
|
217
|
|
218 if(!pad.zoom_in_isHold()){
|
|
219 node.xyz[0] += move_walk * Math.cos(radian);
|
|
220 node.xyz[2] += move_walk * Math.sin(radian);
|
|
221 }
|
|
222
|
|
223 position_xyz[0] += move_walk * Math.cos(radian);
|
|
224 position_xyz[2] += move_walk * Math.sin(radian);
|
|
225 aim_xyz[0] += move_walk * Math.cos(radian);
|
|
226 aim_xyz[2] += move_walk * Math.sin(radian);
|
|
227
|
|
228 move_length++;
|
|
229 }
|
|
230
|
|
231 if(pad.back_move_isHold()){
|
|
232 var radian = ((theta%360) / 360) * 2 * PI;
|
|
233
|
|
234 if(!pad.zoom_in_isHold()){
|
|
235 node.xyz[0] -= move_walk * Math.cos(radian);
|
|
236 node.xyz[2] -= move_walk * Math.sin(radian);
|
|
237 }
|
|
238
|
|
239 position_xyz[0] -= move_walk * Math.cos(radian);
|
|
240 position_xyz[2] -= move_walk * Math.sin(radian);
|
|
241 aim_xyz[0] -= move_walk * Math.cos(radian);
|
|
242 aim_xyz[2] -= move_walk * Math.sin(radian);
|
|
243
|
|
244 move_length--;
|
|
245 }
|
|
246 //}
|
|
247
|
|
248 if(pad.start_isHold()){
|
|
249 var bullet_speed = 2;
|
|
250 var radian_xz = ((theta%360)/360) * 2 * PI;
|
|
251 var radian_yz = ((cameraAngle_xyz[1]%90)/90) * (PI / 2);
|
|
252 var bullet = new sgroot.createSceneGraph1("yellow");
|
|
253 bullet.xyz[0] = position_xyz[0] + Math.cos(radian_xz) * 200;
|
|
254 bullet.xyz[1] = position_xyz[1] + Math.sin(radian_yz) * 200;
|
|
255 bullet.xyz[2] = position_xyz[2] + Math.sin(radian_xz) * 200;
|
|
256 bullet.dx = Math.cos(radian_xz) * bullet_speed;
|
|
257 bullet.dy = Math.sin(radian_yz) * bullet_speed;
|
|
258 bullet.dz = Math.sin(radian_xz) * bullet_speed;
|
|
259 bullet.scale = 0.3;
|
|
260 bullet.set_move_collision(bullet_move, no_collision_idle);
|
|
261 }
|
|
262
|
|
263
|
|
264 if(pad.space_isHold()){
|
|
265 node.xyz[1] -= 0.8;
|
|
266 position_xyz[1] -= 0.8;
|
|
267 aim_xyz[1] -= 0.8;
|
|
268 }else if(pad.space_isRelease() && node.xyz[1] < -5){
|
|
269 node.xyz[1] += 0.4;
|
|
270 position_xyz[1] += 0.4;
|
|
271 aim_xyz[1] += 0.4;
|
|
272 }
|
|
273 }
|
|
274
|
|
275
|
|
276
|
|
277 body_collision = function(node, sgroot, w, h){
|
|
278 var dx = node.xyz[0] - position_xyz[0];
|
|
279 var dz = node.xyz[2] - position_xyz[2];
|
|
280 var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dz,2));
|
|
281 var PI = 3.14;
|
|
282 var radian = ((theta%360) / 360) * 2 * PI;
|
|
283 if(node.xyz[0] < 0){
|
|
284 node.xyz[0] = 0;
|
|
285 position_xyz[0] = -d * Math.cos(radian);
|
|
286 aim_xyz[0] = position_xyz[0];
|
|
287 }
|
|
288
|
|
289 if(node.xyz[0] > 350){
|
|
290 node.xyz[0] = 350;
|
|
291 position_xyz[0] = 350 + (-d * Math.cos(radian));
|
|
292 aim_xyz[0] = position_xyz[0];
|
|
293 }
|
|
294
|
|
295
|
|
296 if(node.xyz[2] < 0){
|
|
297 node.xyz[2] = 0;
|
|
298 position_xyz[2] = -d * Math.sin(radian);
|
|
299 aim_xyz[2] = position_xyz[2] + 1;
|
|
300 }
|
|
301
|
|
302 if(node.xyz[2] > 350){
|
|
303 node.xyz[2] = 350;
|
|
304 position_xyz[2] = 350 + (-d * Math.sin(radian));
|
|
305 aim_xyz[2] = position_xyz[2] + 1;
|
|
306 }
|
|
307 }
|
|
308
|
|
309
|
|
310 right_hand_move = function(node, sgroot, w, h){
|
|
311 var PI = 3.14;
|
|
312 var radian = (((move_length*5)%360) / 360) * 2 * PI;
|
|
313 var range = 90;
|
|
314 node.angle[0] = Math.sin(radian) * range;
|
|
315 }
|
|
316
|
|
317
|
|
318 left_hand_move = function(node, sgroot, w, h){
|
|
319 var PI = 3.14;
|
|
320 var radian = (((move_length*5)%360) / 360) * 2 * PI;
|
|
321 var range = 90;
|
|
322
|
|
323 node.angle[0] = Math.sin(-radian) * range;
|
|
324 }
|
|
325
|
|
326
|
|
327 right_leg_move = function(node, sgroot, w, h){
|
|
328 var PI = 3.14;
|
|
329 var radian = (((move_length*5)%360) / 360) * 2 * PI;
|
|
330 var range = 90;
|
|
331
|
|
332 node.angle[0] = Math.sin(-radian) * range;
|
|
333 }
|
|
334
|
|
335
|
|
336 left_leg_move = function(node, sgroot, w, h){
|
|
337 var PI = 3.14;
|
|
338 var radian = (((move_length*5)%360) / 360) * 2 * PI;
|
|
339 var range = 90;
|
|
340
|
|
341 node.angle[0] = Math.sin(radian) * range;
|
|
342 }
|
|
343
|
|
344
|
|
345 joint_rh_move = function(node, sgroot, w, h){
|
|
346 node.angle[1] = 45;
|
|
347 node.xyz[0] = 0;
|
|
348 node.xyz[1] = 300;
|
|
349 node.xyz[2] = 100;
|
|
350 }
|
|
351
|
|
352 joint_lh_move = function(node, sgroot, w, h){
|
|
353 node.angle[1] = -45;
|
|
354 node.xyz[0] = 0;
|
|
355 node.xyz[1] = -300;
|
|
356 node.xyz[2] = 100;
|
|
357 }
|
|
358
|
|
359
|
|
360 joint_rl_move = function(node, sgroot, w, h){
|
|
361 node.xyz[0] = 0;
|
|
362 node.xyz[1] = -60;
|
|
363 node.xyz[2] = 0;
|
|
364 }
|
|
365
|
|
366
|
|
367
|
|
368
|
|
369 joint_ll_move = function(node, sgroot, w, h){
|
|
370 node.xyz[0] = 0;
|
|
371 node.xyz[1] = 60;
|
|
372 node.xyz[2] = 0;
|
|
373 }
|
|
374
|