Mercurial > hg > Members > e085722 > map
view 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 |
line wrap: on
line source
function main(gl,sgroot, w, h){ //xmlを読む sgroot.createFromXMLfile(gl, sgroot, "./xml/human.xml"); sgroot.createFromXMLfile(gl, sgroot, "./xml/gap_plane_test.xml"); sgroot.createFromXMLfile(gl, sgroot, "./xml/obj.xml"); sgroot.createFromXMLfile(gl, sgroot,"./xml/tukareta.xml"); sgroot.createFromXMLfile(gl, sgroot,"./xml/hiyoko_kari.xml"); //rootの作成 var root = new sgroot.createSceneGraph3(); root.set_move_collision(no_move_idle, no_collision_idle); //mapの作成 var map = createMapFromXMLfile(gl,sgroot,"./xml/map1_forest_joincolor.xml"); root.addChild(map); //オブジェクトの作成 var walk_man = createHuman(sgroot, w, h); move_length = 0; var combat_plane = createPlane(sgroot, w, h); //オブジェクトをシーングラフ化 root.addChild(combat_plane); //カメラとか(マダ sgroot.setCamera(sgroot, root); sgroot.setSceneData(root); //return sgroot; } no_move_idle = function(){ } no_collision_idle = function(){ } collision_b = function(map,q0,dx,dz,r,flag){ var delta = new Array(dx,dz); for(i=0;i < map.length/4;i=i+1){ var p0 = new Array(map[(i*4)+0],map[(i*4)+1]); var p1 = new Array(map[(i*4)+2],map[(i*4)+3]); var ap = new Array(p1[0] - p0[0],p1[1] - p0[1]); var a = ap[0]*ap[0] + ap[1]*ap[1]; var ab = new Array(p1[0]-p0[0],p1[1]-p0[1]); var ap = new Array(p0[0]-q0[0],p0[1]-q0[1]); var c = ( ab[0] * ap[1] - ab[1] * ap[0] ); var b = (p1[0]-p0[0])*(p0[0]-q0[0]) + (p1[1]-p0[1])*(p0[1]-q0[1]) var t = -(b / a); if(0<=t && t<=1 && c > 0){ tp = new Array(p0[0]+(p1[0]-p0[0])*t,p0[1]+(p1[1]-p0[1])*t); d2 = (q0[0]-tp[0])*(q0[0]-tp[0]) + (q0[1]-tp[1])*(q0[1]-tp[1]); //console.log(tp); if(d2 - r*r < 0){ n = new Array(tp[0]-q0[0],tp[1]-q0[1]); nlen = 1.0/Math.abs(((tp[0]-q0[0])*(tp[0]-q0[0]))+((tp[1]-q0[1])*(tp[1]-q0[1]))); delta[0] -= n[0]*nlen*flag; delta[1] -= n[1]*nlen*flag; } } } return delta; } jump_move = function(node, sgroot, w, h){ var jump = -6.0; var g = 0.98; var t = node.time; var height = jump*t + (g * t * t); if(height > -5){ position_xyz[1] = -5; aim_xyz[1] = -5; node.time = 0; node.set_move_collision(body_move,body_collision); }else{ position_xyz[1] = height; aim_xyz[1] = height; } node.time += 0.1; } earth_move = function(node, sgroot, w, h){ node.angle[0] += 1 } test_move = function(node, sgroot, w, h){ //node.angle[1] += 1; }