view webGL/dandy/resources/Character.js @ 6:881478004f18

update Bullet.js
author NOBUYASU Oshiro
date Mon, 21 Jun 2010 17:37:26 +0900
parents 7f615f5f5220
children 4343c1feedb5
line wrap: on
line source

active_chara_list = new Object();
active_chara_list.enemy = [];


function Character()
{
    this.x=0;
    this.y=0;
    this.dx=0;
    this.dy=0;
    this.vit=0;
    this.score=0;
    this.dt1=0;
    this.dt2=0;
    this.charano=0;
    this.tama=0;
    this.f=false;
    this.s=0;

    this.state=0;
    this.collision=0;

    this.next=0;
    this.prev=0;

    this.image=new Object();
    this.texture=new Object();

    return this;
}

function PutSprite( ctx, glObj)
{

    // setup VBOs
    ctx.enableVertexAttribArray(0);
    ctx.enableVertexAttribArray(1);
    ctx.enableVertexAttribArray(2);
				
    ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.image.vertexObject);
    ctx.vertexAttribPointer(2, 3, ctx.FLOAT, false, 0, 0);
    ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.image.normalObject);
    ctx.vertexAttribPointer(0, 3, ctx.FLOAT, false, 0, 0);
    
    ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.image.texCoordObject);
    ctx.vertexAttribPointer(1, 2, ctx.FLOAT, false, 0, 0);
				
    ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, glObj.image.indexObject);

    // generate the model-view matrix
    var mvMatrix = new CanvasMatrix4();
    mvMatrix.scale(1, 1, 1);
    mvMatrix.translate(0,0,0);
    mvMatrix.rotate(180, 0,0,1);
    mvMatrix.translate(glObj.x,glObj.y,10);
    
    // construct the normal matrix from the model-view matrix
    var normalMatrix = new CanvasMatrix4(mvMatrix);
    normalMatrix.invert();
    normalMatrix.transpose();
    ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_normalMatrix"), false, normalMatrix.getAsWebGLFloatArray());
    
    // construct the model-view * projection matrix
    var mvpMatrix = new CanvasMatrix4(mvMatrix);
    mvpMatrix.multRight(ctx.perspectiveMatrix);
    ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_modelViewProjMatrix"), false, mvpMatrix.getAsWebGLFloatArray());
    
    ctx.bindTexture(ctx.TEXTURE_2D, glObj.texture);
    ctx.drawElements(ctx.TRIANGLES, glObj.image.numIndices, ctx.UNSIGNED_SHORT, 0);
}

function obj_draw( ctx )
{
    for(var i = 0; Boolean(active_chara_list.enemy[i]) ; i++)
	{
	    if(active_chara_list.enemy[i].f == true)
		{
		    PutSprite(ctx,active_chara_list.enemy[i]);
		}
	}
}