comparison resources/render/SceneGraphRoot.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 SceneGraphRoot(w, h){
2 sg_exec_tree = null;
3
4 //controller = create_controller();
5
6 sg_draw_tree = new Array();
7 sg_available_list = null;
8
9 screen_w = w;
10 screen_h = h;
11
12 position_xyz = new Array(0, 0, 0);
13 aim_xyz = new Array(0 ,0, 1);
14 eye_xyz = new Array(0, -1, 0);
15 this.sg_src = new Array();
16 this.camera = null;
17
18 angleRate_xyz = new Array(0, 0, 0);
19 angleRate_x = new Array(1, 0, 0);
20 angleRate_y = new Array(0, 1, 0);
21 angleRate_z = new Array(0, 0, 1);
22 cameraAxis = new Array(0, 0, 0);
23
24
25 //cnt = 0;
26 }
27
28
29 SceneGraphRoot.prototype.createFromXMLfile = function(gl, sgroot, url){
30 if(gl.obj == undefined) {
31 gl.obj = new Object();
32 }
33 var xmlChara = new Object();
34 xmlChara = parsePanel(url);
35 for (var name in xmlChara){
36 gl.obj[name] = makeXmlObj(gl, xmlChara[name]);
37 gl.obj[name].texture = loadImageTexture(gl, xmlChara[name].image);
38 sgroot.sg_src[name] = gl.obj[name];
39 }
40 }
41
42 SceneGraphRoot.prototype.createFromXMLfile2 = function(gl, sgroot, url){
43 if(gl.obj == undefined) {
44 gl.obj = new Object();
45 }
46 var xmlChara = new Object();
47 xmlChara = parsePanel2(url);
48 for (var name in xmlChara){
49 gl.obj[name] = makeXmlObj(gl, xmlChara[name]);
50 gl.obj[name].texture = loadImageTexture(gl, xmlChara[name].image);
51 sgroot.sg_src[name] = gl.obj[name];
52 }
53 }
54
55 SceneGraphRoot.prototype.createSceneGraph1 = function(id){
56 if(id < 0){
57 alert("error: createSceneGraph(id): id not found");
58 return null;
59 }
60 var src = new SceneGraph(id);
61 src.id = id;
62 if(sg_exec_tree != null){
63 sg_exec_tree.addChild(src);
64 }
65 SceneGraphRoot.prototype.addNext(src);
66 return src;
67 }
68
69
70 SceneGraphRoot.prototype.createSceneGraph3 = function(){
71 var p = new SceneGraph();
72 p.sgroot = this;
73 SceneGraphRoot.prototype.addNext(p);
74 p.flag_drawable = 0;
75 return p;
76 }
77
78
79 SceneGraphRoot.prototype.addNext = function(sg){
80 sg_available_list = sg;
81 }
82
83 /* 渡された引数をもとにイメージを検索する */
84 SceneGraphRoot.prototype.getSgid = function(obj_name){
85 for(var name in sg_src){
86 if(obj_name == sg_src[name].name){
87 return sg_src[name];
88 }
89 }
90 return -1
91 }
92
93
94 SceneGraphRoot.prototype.setCamera = function(sgroot, node){
95 this.camera = node;
96 }
97
98
99
100 SceneGraphRoot.prototype.getCamera = function(ctx, node){
101 if(node.mat != null){
102 ctx.perspectiveMatrix = new J3DIMatrix4();
103 //node.mat.getAsArrayMatrix(ctx.perspectiveMatrix.$matrix);
104 }else{
105 ctx.perspectiveMatrix = new J3DIMatrix4();
106 }
107
108 ctx.perspectiveMatrix.perspective(45, width/height, 1, 10000);
109 /*
110 ctx.perspectiveMatrix.rotate(cameraAngle_xyz[0], 0,angleRate_y[1],angleRate_y[2]);
111 ctx.perspectiveMatrix.rotate(cameraAngle_xyz[1], angleRate_x[0], 0,angleRate_x[2]);
112 ctx.perspectiveMatrix.rotate(cameraAngle_xyz[2], 0, 0, 1);
113 */
114 /*
115 ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[0],0,angleRate_y[1],angleRate_y[2]);
116 ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[1],angleRate_x[0],0,angleRate_x[2]);
117 ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[2],0,0,1);
118 */
119 //ctx.perspectiveMatrix.translate(position_xyz[0],position_xyz[1],position_xyz[2]);
120 //ctx.perspectiveMatrix.rotate(cameraAngle_xyz[0],0,1,0);
121 //ctx.perspectiveMatrix.rotate(cameraAngle_xyz[1],1,0,0);
122 //ctx.perspectiveMatrix.rotate(cameraAngle_xyz[2],0,0,1);
123 ctx.perspectiveMatrix.rotate(cameraAngle_xyz[0],cameraAxis[0],cameraAxis[1],cameraAxis[2]);
124 //ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[1],1,0,0);
125 //ctx.perspectiveMatrix.quaternion(cameraAngle_xyz[2],0,0,1);
126 //ctx.perspectiveMatrix.translate(-position_xyz[0],-position_xyz[1],-position_xyz[2]);
127
128 ctx.perspectiveMatrix.lookat(position_xyz[0],position_xyz[1],position_xyz[2], aim_xyz[0], aim_xyz[1], aim_xyz[2], 0, -1, 0);
129 }
130
131
132
133
134
135
136 SceneGraphRoot.prototype.getController = function(){
137 var left_push = currentlyPressedKeys[37]; /* ← */
138 var down_push = currentlyPressedKeys[40]; /* ↓ */
139 var right_push = currentlyPressedKeys[39]; /* → */
140 var up_push = currentlyPressedKeys[38]; /* ↑ */
141 var cross_push = currentlyPressedKeys[90]; /* Z */
142 var circle_push = currentlyPressedKeys[88]; /* X */
143 var start_push = currentlyPressedKeys[13]; /* Enter */
144 var zoom_in_push = currentlyPressedKeys[75]; /* K */
145 var zoom_out_push = currentlyPressedKeys[76]; /* L */
146 var left_move = currentlyPressedKeys[65]; /* A */
147 var right_move = currentlyPressedKeys[68]; /* D */
148 var front_move = currentlyPressedKeys[87]; /* W */
149 var back_move = currentlyPressedKeys[83]; /* S */
150 var space_push = currentlyPressedKeys[32]; /* SPACE */
151
152
153 this.right_isHold = function(){
154 return right_push;
155 }
156
157 this.right_isRelease = function(){
158 return !right_push;
159 }
160
161 this.left_isHold = function(){
162 return left_push;
163 }
164
165 this.left_isRelease = function(){
166 return !left_push;
167 }
168
169 this.up_isHold = function(){
170 return up_push;
171 }
172
173 this.up_isRelease = function(){
174 return !up_push;
175 }
176
177 this.down_isHold = function(){
178 return down_push;
179 }
180
181 this.down_isRelease = function(){
182 return !down_push;
183 }
184
185 this.cross_isHold = function(){
186 return cross_push;
187 }
188
189 this.cross_isRelease = function(){
190 return !cross_push;
191 }
192
193 this.circle_isHold = function(){
194 return circle_push;
195 }
196
197 this.circle_isRelease = function(){
198 return !circle_push;
199 }
200
201 this.start_isHold = function(){
202 return start_push;
203 }
204
205 this.start_isRelease = function(){
206 return !start_push;
207 }
208
209 this.zoom_in_isHold = function(){
210 return zoom_in_push;
211 }
212
213 this.zoom_out_isHold = function(){
214 return zoom_out_push;
215 }
216
217 this.left_move_isHold = function(){
218 return left_move;
219 }
220
221 this.right_move_isHold = function(){
222 return right_move;
223 }
224
225 this.front_move_isHold = function(){
226 return front_move;
227 }
228
229 this.back_move_isHold = function(){
230 return back_move;
231 }
232
233 this.space_isHold = function(){
234 return space_push;
235 }
236
237 this.space_isRelease = function(){
238 return !space_push;
239 }
240 }
241
242
243
244 /* rootになるnodeを設定する */
245 SceneGraphRoot.prototype.setSceneData = function(sg){
246 sg.parents = null;
247 sg_exec_tree = sg;
248 }
249
250