Mercurial > hg > Members > e085737 > sample
view map/resources/render/SceneGraphRoot.js @ 20:d322eed6e1c7
add
author | <e085737> |
---|---|
date | Thu, 13 Jan 2011 21:37:23 +0900 |
parents | |
children | 87850fc55445 |
line wrap: on
line source
function SceneGraphRoot(w, h){ sg_exec_tree = null; //controller = create_controller(); sg_draw_tree = new Array(); sg_available_list = null; screen_w = w; screen_h = h; position_xyz = new Array(0, 0, 0); aim_xyz = new Array(0 ,0, 1); eye_xyz = new Array(0, -1, 0); this.sg_src = new Array(); this.camera = null; angleRate_xyz = new Array(0, 0, 0); angleRate_x = new Array(1, 0, 0); angleRate_y = new Array(0, 1, 0); angleRate_z = new Array(0, 0, 1); cameraAxis = new Array(0, 0, 0); //cnt = 0; } SceneGraphRoot.prototype.createFromXMLfile = function(gl, sgroot, url){ if(gl.obj == undefined) gl.obj = new Object(); var xmlChara = new Object(); xmlChara = parsePanel(url); for (var name in xmlChara) { gl.obj[name] = makeXmlObj(gl, xmlChara[name]) gl.obj[name].texture = loadImageTexture(gl, xmlChara[name].image); sgroot.sg_src[name] = gl.obj[name]; } } SceneGraphRoot.prototype.createSceneGraph1 = function(id){ if(id < 0){ alert("error: createSceneGraph(id): id not found"); return null; } var src = new SceneGraph(id) src.id = id; if(sg_exec_tree != null){ sg_exec_tree.addChild(src); } SceneGraphRoot.prototype.addNext(src); return src; } SceneGraphRoot.prototype.createSceneGraph3 = function(){ var p = new SceneGraph(); p.sgroot = this; SceneGraphRoot.prototype.addNext(p); p.flag_drawable = 0; return p; } SceneGraphRoot.prototype.addNext = function(sg){ sg_available_list = sg; } /* 渡された引数をもとにイメージを検索する */ SceneGraphRoot.prototype.getSgid = function(obj_name){ for(var name in sg_src){ if(obj_name == sg_src[name].name){ return sg_src[name]; } } return -1 } SceneGraphRoot.prototype.setCamera = function(sgroot, node){ this.camera = node; } SceneGraphRoot.prototype.getCamera = function(ctx, node){ if(node.mat != null){ ctx.perspectiveMatrix = new J3DIMatrix4(); //node.mat.getAsArrayMatrix(ctx.perspectiveMatrix.$matrix); }else{ ctx.perspectiveMatrix = new J3DIMatrix4(); } ctx.perspectiveMatrix.perspective(45, width/height, 1, 10000); /* ctx.perspectiveMatrix.rotate(cameraAngle_xyz[0], 0,angleRate_y[1],angleRate_y[2]); ctx.perspectiveMatrix.rotate(cameraAngle_xyz[1], angleRate_x[0], 0,angleRate_x[2]); ctx.perspectiveMatrix.rotate(cameraAngle_xyz[2], 0, 0, 1); */ /* ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[0],0,angleRate_y[1],angleRate_y[2]); ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[1],angleRate_x[0],0,angleRate_x[2]); ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[2],0,0,1); */ //ctx.perspectiveMatrix.translate(position_xyz[0],position_xyz[1],position_xyz[2]); //ctx.perspectiveMatrix.rotate(cameraAngle_xyz[0],0,1,0); //ctx.perspectiveMatrix.rotate(cameraAngle_xyz[1],1,0,0); //ctx.perspectiveMatrix.rotate(cameraAngle_xyz[2],0,0,1); ctx.perspectiveMatrix.rotate(cameraAngle_xyz[0],cameraAxis[0],cameraAxis[1],cameraAxis[2]); //ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[1],1,0,0); //ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[2],0,0,1); //ctx.perspectiveMatrix.translate(-position_xyz[0],-position_xyz[1],-position_xyz[2]); ctx.perspectiveMatrix.lookat(position_xyz[0],position_xyz[1],position_xyz[2], aim_xyz[0], aim_xyz[1], aim_xyz[2], 0, -1, 0); } SceneGraphRoot.prototype.getController = function(){ var left_push = currentlyPressedKeys[37]; /* ← */ var down_push = currentlyPressedKeys[40]; /* ↓ */ var right_push = currentlyPressedKeys[39]; /* → */ var up_push = currentlyPressedKeys[38]; /* ↑ */ var cross_push = currentlyPressedKeys[90]; /* Z */ var circle_push = currentlyPressedKeys[88]; /* X */ var start_push = currentlyPressedKeys[13]; /* Enter */ var zoom_in_push = currentlyPressedKeys[75]; /* K */ var zoom_out_push = currentlyPressedKeys[76]; /* L */ var left_move = currentlyPressedKeys[65]; /* A */ var right_move = currentlyPressedKeys[68]; /* D */ var front_move = currentlyPressedKeys[87]; /* W */ var back_move = currentlyPressedKeys[83]; /* S */ var space_push = currentlyPressedKeys[32]; /* SPACE */ this.right_isHold = function(){ return right_push; } this.right_isRelease = function(){ return !right_push; } this.left_isHold = function(){ return left_push; } this.left_isRelease = function(){ return !left_push; } this.up_isHold = function(){ return up_push; } this.up_isRelease = function(){ return !up_push; } this.down_isHold = function(){ return down_push; } this.down_isRelease = function(){ return !down_push; } this.cross_isHold = function(){ return cross_push; } this.cross_isRelease = function(){ return !cross_push; } this.circle_isHold = function(){ return circle_push; } this.circle_isRelease = function(){ return !circle_push; } this.start_isHold = function(){ return start_push; } this.start_isRelease = function(){ return !start_push; } this.zoom_in_isHold = function(){ return zoom_in_push; } this.zoom_out_isHold = function(){ return zoom_out_push; } this.left_move_isHold = function(){ return left_move; } this.right_move_isHold = function(){ return right_move; } this.front_move_isHold = function(){ return front_move; } this.back_move_isHold = function(){ return back_move; } this.space_isHold = function(){ return space_push; } this.space_isRelease = function(){ return !space_push; } } /* rootになるnodeを設定する */ SceneGraphRoot.prototype.setSceneData = function(sg){ sg.parents = null; sg_exec_tree = sg; }