Mercurial > hg > Members > e085737 > sample
view Pants_FPS/resources/SceneGraph.js @ 17:bf87fe5a9797
ver3
author | <e085737> |
---|---|
date | Fri, 10 Dec 2010 20:19:03 +0900 |
parents | 9367d87879ee |
children | 931ad40d56f5 |
line wrap: on
line source
// ループさせる処理を入れる function MainLoop(ctx,sgroot,w,h){ collision_object(sg_exec_tree,sgroot,w,h) move_object(sg_exec_tree,sgroot,w,h) draw_object(ctx,sg_exec_tree,sgroot) camera_object(ctx, sgroot, sgroot.camera) } /* 再帰的に呼び出して全てのnodeのcollisionを実行する */ function collision_object(node,sgroot,w,h){ if(node.collision != null){ node.collision(node,sgroot,w,h) node.frame++ } for(num in node.child){ collision_object(node.child[num],sgroot,w,h) } } /* 再帰的に呼び出して全てのnodeのmoveを実行する */ function move_object(node,sgroot,w,h){ if(node.move != null){ node.move(node,sgroot,w,h) } for(num in node.child){ move_object(node.child[num],sgroot,w,h) } } /* 再帰的に呼び出して全てのnodeをdrawする */ function draw_object(ctx,node,sgroot){ if(node.id != null){ drawObject_link(ctx, node, node.angle, node.xyz, node.scale, sgroot.sg_src[node.id]) }else if(node.id != null && node.link == true){ drawObject_link(ctx, node, node.angle, node.xyz, node.scale, sgroot.sg_src[node.id]) }else{ create_matrix(node, node.angle, node.xyz, node.scale) } for(num in node.child){ draw_object(ctx,node.child[num],sgroot) } } function camera_object(ctx, sgroot, node){ sgroot.getCamera(ctx, node) } hand_mat = function(node){ for(var num in node.child){ node.child[num].parents_mat = new J3DIMatrix4() //node.child[num].parents_mat = node.mat node.mat.getAsArrayMatrix(node.child[num].parents_mat.$matrix) } } SceneGraph = function(){ this.next = null this.prev = null this.last = null this.parents = null this.children = null this.lastChild = null this.xyz = new Array(0,0,0) this.angle = new Array(0,0,0) this.stack_xyz = new Array(0,0,0) this.stack_angle = new Array(0,0,0) this.w = 0 this.h = 0 this.scale = 1.0 this.dx = 1.0 this.dy = 1.0 this.dz = 1.0 this.id = null this.num = 0 this.parents_mat = null this.mat = null this.link = false this.move = null this.collision = null this.child = new Array() this.flag_remove = 0 this.flag_drawable = 1 this.frame = 0 } // SceneGraphを削除する SceneGraph.prototype.remove = function(node){ if(node.parents != null){ var length = node.parents.child.length if(length != 0){ // 親の書き換え for(num in node.child){ node.child[num].parents = node.parents } // 要素を取り除く node.parents.child.splice(node.num, 1) // 取り除いたnodeのchildをnodeのparentsに追加 for(num in node.child){ if(node.child[num].id != "LOCK"){ node.parents.child.push(node.child[num]) } } // idの振りなおし for(num in node.parents.child){ node.parents.child[num].num = num } }else{ node.parents.child.length = 0 } } } /* moveとcollisionをsetする */ SceneGraph.prototype.set_move_collision = function(new_move, new_collision){ this.move = new_move this.collision = new_collision } SceneGraph.prototype.addBrother = function(bro){ if(this.parents != null){ parents.addChild(bro) }else{ alert("error : doesn't have parent") } return bro } /* 子どもの追加 */ SceneGraph.prototype.addChild = function(node){ var num = this.child.length this.child.push(node) node.parents = this node.num = num }