Mercurial > hg > Game > WebGL
comparison dandy/resources/bom.js @ 1:54589bb5e57d
add dandy
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 23 Feb 2012 14:51:33 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:718974a1a32b | 1:54589bb5e57d |
---|---|
1 bomend = 0; | |
2 bchar = []; | |
3 function bcharClass() | |
4 { | |
5 this.x = 0; | |
6 this.y = 0; | |
7 this.no = 0; | |
8 this.scale = 1.0; | |
9 this.flag = 0; | |
10 this.image = new Object(); | |
11 this.texture = new Object(); | |
12 return this; | |
13 } | |
14 | |
15 function Bom(x, y) | |
16 { | |
17 var i; | |
18 if ( bomend > 49) { | |
19 bomend = 49; | |
20 return ; | |
21 } | |
22 i = bomend; | |
23 bchar[i] = new bcharClass(); | |
24 bchar[i].x = x; | |
25 bchar[i].y = y; | |
26 bchar[i].scale = 1.0; | |
27 bchar[i].no = 0; | |
28 bchar[i].flag = 0; | |
29 bomend++; | |
30 return ; | |
31 } | |
32 | |
33 function loadBomImage(charano, p) | |
34 { | |
35 p.image = bomImage[charano]; | |
36 p.texture = bomImage[charano].texture; | |
37 p.w = bomImage[charano].w; | |
38 p.h = bomImage[charano].h; | |
39 } | |
40 | |
41 | |
42 function PutBom(gl) | |
43 { | |
44 for(var i=0; i < bomend ; i++) | |
45 { | |
46 if(bchar[i].no != 8) { | |
47 count++; | |
48 // DefSpriteEx(30 + bchar[i].no, 8, 8); | |
49 // PutSpriteEx(30 + bchar[i].no, bchar[i].x+96, bchar[i].y+96, 2, 2, 1); | |
50 PutSpriteEx(gl, bchar[i], bomImage[bchar[i].no]); | |
51 bchar[i].no++; | |
52 } | |
53 /* bchar[] の中身は Character.js の celete_obj() で消す | |
54 if(bchar[i].no == 8){ | |
55 if(bomend == i-1 ){ | |
56 bomend--; | |
57 break; | |
58 } | |
59 if(bomend > i) { | |
60 bchar[i] = bchar[bomend]; | |
61 bomend--; | |
62 i--; | |
63 } | |
64 } | |
65 */ | |
66 } | |
67 } | |
68 | |
69 //function PutSpriteEx(number, x, y, scalex, scaley, angle) | |
70 function PutSpriteEx( ctx, glObj, image) | |
71 { | |
72 | |
73 // setup VBOs | |
74 ctx.enableVertexAttribArray(0); | |
75 ctx.enableVertexAttribArray(1); | |
76 ctx.enableVertexAttribArray(2); | |
77 | |
78 ctx.bindBuffer(ctx.ARRAY_BUFFER, image.vertexObject); | |
79 ctx.vertexAttribPointer(2, 3, ctx.FLOAT, false, 0, 0); | |
80 ctx.bindBuffer(ctx.ARRAY_BUFFER, image.normalObject); | |
81 ctx.vertexAttribPointer(0, 3, ctx.FLOAT, false, 0, 0); | |
82 | |
83 ctx.bindBuffer(ctx.ARRAY_BUFFER, image.texCoordObject); | |
84 ctx.vertexAttribPointer(1, 2, ctx.FLOAT, false, 0, 0); | |
85 | |
86 ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, image.indexObject); | |
87 | |
88 // generate the model-view matrix | |
89 var mvMatrix = new J3DIMatrix4(); | |
90 mvMatrix.scale(glObj.scale, glObj.scale, glObj.scale); | |
91 mvMatrix.translate(glObj.x,glObj.y,10); | |
92 | |
93 // construct the normal matrix from the model-view matrix | |
94 var normalMatrix = new J3DIMatrix4(mvMatrix); | |
95 normalMatrix.invert(); | |
96 normalMatrix.transpose(); | |
97 normalMatrix.setUniform(ctx, ctx.getUniformLocation(ctx.program, "u_normalMatrix"), false); | |
98 | |
99 // construct the model-view * projection matrix | |
100 var mvpMatrix = new J3DIMatrix4(ctx.perspectiveMatrix); | |
101 mvpMatrix.multiply(mvMatrix); | |
102 mvpMatrix.setUniform(ctx, ctx.getUniformLocation(ctx.program, "u_modelViewProjMatrix"), false); | |
103 | |
104 | |
105 ctx.bindTexture(ctx.TEXTURE_2D, image.texture); | |
106 ctx.drawElements(ctx.TRIANGLES, image.numIndices, ctx.UNSIGNED_SHORT, 0); | |
107 } |