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