comparison resources/main.js @ 0:0b8d8ce99f46 default tip

commit
author Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp>
date Mon, 14 Feb 2011 17:06:56 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0b8d8ce99f46
1 function main(gl,sgroot, w, h){
2 //xmlを読む
3 sgroot.createFromXMLfile(gl, sgroot, "./xml/human.xml");
4 sgroot.createFromXMLfile(gl, sgroot, "./xml/gap_plane_test.xml");
5 sgroot.createFromXMLfile(gl, sgroot, "./xml/obj.xml");
6 sgroot.createFromXMLfile(gl, sgroot,"./xml/tukareta.xml");
7 sgroot.createFromXMLfile(gl, sgroot,"./xml/hiyoko_kari.xml");
8
9 //rootの作成
10 var root = new sgroot.createSceneGraph3();
11 root.set_move_collision(no_move_idle, no_collision_idle);
12
13 //mapの作成
14 var map = createMapFromXMLfile(gl,sgroot,"./xml/map1_forest_joincolor.xml");
15 root.addChild(map);
16
17 //オブジェクトの作成
18 var walk_man = createHuman(sgroot, w, h);
19 move_length = 0;
20
21 var combat_plane = createPlane(sgroot, w, h);
22
23 //オブジェクトをシーングラフ化
24 root.addChild(combat_plane);
25
26 //カメラとか(マダ
27 sgroot.setCamera(sgroot, root);
28 sgroot.setSceneData(root);
29
30
31 //return sgroot;
32 }
33
34 no_move_idle = function(){
35 }
36
37 no_collision_idle = function(){
38 }
39
40
41 collision_b = function(map,q0,dx,dz,r,flag){
42 var delta = new Array(dx,dz);
43 for(i=0;i < map.length/4;i=i+1){
44 var p0 = new Array(map[(i*4)+0],map[(i*4)+1]);
45 var p1 = new Array(map[(i*4)+2],map[(i*4)+3]);
46 var ap = new Array(p1[0] - p0[0],p1[1] - p0[1]);
47 var a = ap[0]*ap[0] + ap[1]*ap[1];
48 var ab = new Array(p1[0]-p0[0],p1[1]-p0[1]);
49 var ap = new Array(p0[0]-q0[0],p0[1]-q0[1]);
50 var c = ( ab[0] * ap[1] - ab[1] * ap[0] );
51 var b = (p1[0]-p0[0])*(p0[0]-q0[0]) + (p1[1]-p0[1])*(p0[1]-q0[1])
52 var t = -(b / a);
53 if(0<=t && t<=1 && c > 0){
54 tp = new Array(p0[0]+(p1[0]-p0[0])*t,p0[1]+(p1[1]-p0[1])*t);
55 d2 = (q0[0]-tp[0])*(q0[0]-tp[0]) + (q0[1]-tp[1])*(q0[1]-tp[1]);
56 //console.log(tp);
57 if(d2 - r*r < 0){
58 n = new Array(tp[0]-q0[0],tp[1]-q0[1]);
59 nlen = 1.0/Math.abs(((tp[0]-q0[0])*(tp[0]-q0[0]))+((tp[1]-q0[1])*(tp[1]-q0[1])));
60 delta[0] -= n[0]*nlen*flag;
61 delta[1] -= n[1]*nlen*flag;
62 }
63 }
64 }
65 return delta;
66 }
67
68 jump_move = function(node, sgroot, w, h){
69 var jump = -6.0;
70 var g = 0.98;
71 var t = node.time;
72 var height = jump*t + (g * t * t);
73 if(height > -5){
74 position_xyz[1] = -5;
75 aim_xyz[1] = -5;
76 node.time = 0;
77 node.set_move_collision(body_move,body_collision);
78 }else{
79 position_xyz[1] = height;
80 aim_xyz[1] = height;
81 }
82
83 node.time += 0.1;
84 }
85
86
87 earth_move = function(node, sgroot, w, h){
88 node.angle[0] += 1
89 }
90
91 test_move = function(node, sgroot, w, h){
92 //node.angle[1] += 1;
93 }
94