Subversion Repositories AndroidProjects

Rev

Blame | Last modification | View Log | RSS feed

unit app_glscene_board_monkey;

interface

uses OpenGL, GLaux, glExt, sux_constant, sux_object, app_constant,
     resource_texture, app_particle_vertexbuffer;

type
  SAGLSBMonkey=class
    pos:SXVertex2D;
    rot:SXFloat;
    size:SXFloat;
    intensity:SXFloat;
    move:SXVertex2D;
    texture: SRTexture;

    procedure setTexture(const texture: SRTexture);
    procedure renderMonkey(const vertexbuffer: SAPVertexBuffer; const monkeyindex: SXInt);
    procedure onTimer;

    constructor Create(pos:SXVertex2D;rot,size,intensity:SXFloat);
    destructor Destroy; override;
  end;

implementation

uses sux_main, gl_main, main, Math;


// --- SAGLSBMonkey


procedure SAGLSBMonkey.setTexture(const texture: SRTexture);
begin
  self.texture := texture;
end;


procedure SAGLSBMonkey.renderMonkey(const vertexbuffer: SAPVertexBuffer; const monkeyindex: SXInt);
var vertexindex: SXInt;
    upvector: SXVertex2D;
    pos3D, upvectorandsize: SXVertex3D;
    color: SXColorRGBA;
    angle: SXFloat;
begin
  onTimer; // Process this monkey

  vertexindex := monkeyindex * 4;

  angle := (rot);
  angle := degtorad(angle);
  upvector := sx.convert.Vertex2DOf(sin(angle), cos(angle));

  pos3D := sx.convert.Vertex3DOf(pos.x, pos.y, 0);
  upvectorandsize := sx.convert.Vertex3DOf(upvector.x, upvector.y, size * 0.7);
  color := sx.convert.ColorRGBAOf(1, 1, 1, intensity * 0.7);

  vertexbuffer.setVertex(vertexindex, pos3D, color,
    sx.convert.Vertex2DOf(0, 0),
    sx.convert.Vertex2DOf(-1, -1), upvectorandsize);

  vertexbuffer.setVertex(vertexindex + 1, pos3D, color,
    sx.convert.Vertex2DOf(1, 0),
    sx.convert.Vertex2DOf( 1, -1), upvectorandsize);

  vertexbuffer.setVertex(vertexindex + 2, pos3D, color,
    sx.convert.Vertex2DOf(1, 1),
    sx.convert.Vertex2DOf( 1,  1), upvectorandsize);

  vertexbuffer.setVertex(vertexindex + 3, pos3D, color,
    sx.convert.Vertex2DOf(0, 1),
    sx.convert.Vertex2DOf(-1,  1), upvectorandsize);

  {// Render the monkey
  glPushMatrix();
  glTranslatef(pos.x,pos.y,0);
  glScalef(size*0.7,size*0.7,1);
  glRotatef(rot,0,0,1);

  glColor4f(1,1,1,intensity*0.7);

  glBegin(GL_QUADS);
    glTexCoord2f(0,1); glVertex2f(-1,-1);
    glTexCoord2f(1,1); glVertex2f( 1,-1);
    glTexCoord2f(1,0); glVertex2f( 1, 1);
    glTexCoord2f(0,0); glVertex2f(-1, 1);
  glEnd();

  glPopMatrix(); }

end;


procedure SAGLSBMonkey.onTimer;
var vector:SXVertex2D;
begin
  vector:=sx.math.setVectorLength(move,sx.timer.getTimer*4);
  pos:=sx.math.addVertices(pos,vector);
  rot:=rot+app.scene.board.settings.monkeyspeed;

  // Reset monkey if it is out of screen
  if (pos.x<-100) then pos.x:=740;
  if (pos.y<-100) then pos.y:=580;
  if (pos.x>740) then pos.x:=-100;
  if (pos.y>580) then pos.y:=-100;
end;




constructor SAGLSBMonkey.Create(pos:SXVertex2D;rot,size,intensity:SXFloat);
begin
  inherited Create;

  self.pos:=pos;
  self.rot:=rot;
  self.size:=size;
  self.intensity:=intensity;
  self.texture := nil;

  self.move.x:=sx.math.random.getRandomFloat(-100,100);
  self.move.y:=sx.math.random.getRandomFloat(-100,100);
end;


destructor SAGLSBMonkey.Destroy;
begin
  inherited;
end;


end.