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