Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
35 chris 1
unit app_glscene_board_monkey;
2
 
3
interface
4
 
5
uses OpenGL, GLaux, glExt, sux_constant, sux_object, app_constant,
6
     resource_texture, app_particle_vertexbuffer;
7
 
8
type
9
  SAGLSBMonkey=class
10
    pos:SXVertex2D;
11
    rot:SXFloat;
12
    size:SXFloat;
13
    intensity:SXFloat;
14
    move:SXVertex2D;
15
    texture: SRTexture;
16
 
17
    procedure setTexture(const texture: SRTexture);
18
    procedure renderMonkey(const vertexbuffer: SAPVertexBuffer; const monkeyindex: SXInt);
19
    procedure onTimer;
20
 
21
    constructor Create(pos:SXVertex2D;rot,size,intensity:SXFloat);
22
    destructor Destroy; override;
23
  end;
24
 
25
implementation
26
 
27
uses sux_main, gl_main, main, Math;
28
 
29
 
30
// --- SAGLSBMonkey
31
 
32
 
33
procedure SAGLSBMonkey.setTexture(const texture: SRTexture);
34
begin
35
  self.texture := texture;
36
end;
37
 
38
 
39
procedure SAGLSBMonkey.renderMonkey(const vertexbuffer: SAPVertexBuffer; const monkeyindex: SXInt);
40
var vertexindex: SXInt;
41
    upvector: SXVertex2D;
42
    pos3D, upvectorandsize: SXVertex3D;
43
    color: SXColorRGBA;
44
    angle: SXFloat;
45
begin
46
  onTimer; // Process this monkey
47
 
48
  vertexindex := monkeyindex * 4;
49
 
50
  angle := (rot);
51
  angle := degtorad(angle);
52
  upvector := sx.convert.Vertex2DOf(sin(angle), cos(angle));
53
 
54
  pos3D := sx.convert.Vertex3DOf(pos.x, pos.y, 0);
55
  upvectorandsize := sx.convert.Vertex3DOf(upvector.x, upvector.y, size * 0.7);
56
  color := sx.convert.ColorRGBAOf(1, 1, 1, intensity * 0.7);
57
 
58
  vertexbuffer.setVertex(vertexindex, pos3D, color,
59
    sx.convert.Vertex2DOf(0, 0),
60
    sx.convert.Vertex2DOf(-1, -1), upvectorandsize);
61
 
62
  vertexbuffer.setVertex(vertexindex + 1, pos3D, color,
63
    sx.convert.Vertex2DOf(1, 0),
64
    sx.convert.Vertex2DOf( 1, -1), upvectorandsize);
65
 
66
  vertexbuffer.setVertex(vertexindex + 2, pos3D, color,
67
    sx.convert.Vertex2DOf(1, 1),
68
    sx.convert.Vertex2DOf( 1,  1), upvectorandsize);
69
 
70
  vertexbuffer.setVertex(vertexindex + 3, pos3D, color,
71
    sx.convert.Vertex2DOf(0, 1),
72
    sx.convert.Vertex2DOf(-1,  1), upvectorandsize);
73
 
74
  {// Render the monkey
75
  glPushMatrix();
76
  glTranslatef(pos.x,pos.y,0);
77
  glScalef(size*0.7,size*0.7,1);
78
  glRotatef(rot,0,0,1);
79
 
80
  glColor4f(1,1,1,intensity*0.7);
81
 
82
  glBegin(GL_QUADS);
83
    glTexCoord2f(0,1); glVertex2f(-1,-1);
84
    glTexCoord2f(1,1); glVertex2f( 1,-1);
85
    glTexCoord2f(1,0); glVertex2f( 1, 1);
86
    glTexCoord2f(0,0); glVertex2f(-1, 1);
87
  glEnd();
88
 
89
  glPopMatrix(); }
90
end;
91
 
92
 
93
procedure SAGLSBMonkey.onTimer;
94
var vector:SXVertex2D;
95
begin
96
  vector:=sx.math.setVectorLength(move,sx.timer.getTimer*4);
97
  pos:=sx.math.addVertices(pos,vector);
98
  rot:=rot+app.scene.board.settings.monkeyspeed;
99
 
100
  // Reset monkey if it is out of screen
101
  if (pos.x<-100) then pos.x:=740;
102
  if (pos.y<-100) then pos.y:=580;
103
  if (pos.x>740) then pos.x:=-100;
104
  if (pos.y>580) then pos.y:=-100;
105
end;
106
 
107
 
108
 
109
 
110
constructor SAGLSBMonkey.Create(pos:SXVertex2D;rot,size,intensity:SXFloat);
111
begin
112
  inherited Create;
113
 
114
  self.pos:=pos;
115
  self.rot:=rot;
116
  self.size:=size;
117
  self.intensity:=intensity;
118
  self.texture := nil;
119
 
120
  self.move.x:=sx.math.random.getRandomFloat(-100,100);
121
  self.move.y:=sx.math.random.getRandomFloat(-100,100);
122
end;
123
 
124
 
125
destructor SAGLSBMonkey.Destroy;
126
begin
127
  inherited;
128
end;
129
 
130
 
131
end.