10 static const int subd = 50;
11 static const int vsz = subd + 2;
12 static int vcount, icount;
14 DistFx::DistFx() : Part("distort") {
18 create_plane(&mesh, Vector3(0, 0, -1), Vector2(1.0, 1.0), subd);
20 vcount = mesh.get_vertex_array()->get_count();
21 icount = mesh.get_index_array()->get_count();
23 varray = new Vertex[vcount];
24 Vertex *vptr = varray;
25 for(int i=0; i<vcount; i++) {
26 *vptr = mesh.get_vertex_array()->get_data()[i];
27 vptr->pos += Vector3(0.5, 0.5);
31 iarray = new Index[icount];
33 for(int i=0; i<icount; i++) {
34 *iptr++ = mesh.get_index_array()->get_data()[i];
37 tc = new TexCoord[vcount];
39 for(int y=0; y<vsz; y++) {
40 for(int x=0; x<vsz; x++) {
41 *tptr++ = TexCoord((float)x / (float)(vsz - 1), 1.0 - (float)y / (float)(vsz - 1));
52 #define MIN(a, b) ((a) < (b) ? (a) : (b))
53 #define MAX(a, b) ((a) > (b) ? (a) : (b))
54 #define CLAMP(x, a, b) MIN(MAX(x, a), b)
56 void DistFx::draw_part() {
58 float t = (float)time / 1000.0;
59 float cost = cos(t * 2.0);
60 float sint = sin(t * 2.0);
62 Vertex *vptr = varray;
63 for(int y=0; y<vsz; y++) {
64 for(int x=0; x<vsz; x++) {
65 float u = (float)x / (float)(vsz - 1);
66 float v = (1.0 - (float)y / (float)(vsz - 1));
71 float du = sin(pu + cost) * 10.0 +
72 cos((pu + sint) * 2.0) * 5.0 +
73 sin((pu + cost) * 3.0) * 3.33 +
74 cos((pv + sint) * 2.0) * 5.0 +
75 sin(pv + cost) * 10.0;
77 float dv = cos(pv + sint) * 10.0 +
78 sin((pv + cost) * 2.0) * 5.0 +
79 cos((pu + sint) * 3.0) * 3.33 +
80 sin((pv + cost) * 2.0) * 6.0;
82 du *= sin(t / 2.0) * 0.003 + 0.003;
83 dv *= sin(t / 2.0) * 0.003 + 0.003;
85 vptr->tex[0].u = CLAMP(u + du, 0.0, 1.0);
86 vptr->tex[0].v = CLAMP(v + dv, 0.0, 1.0);
92 set_matrix(XFORM_TEXTURE, Matrix4x4::identity_matrix);
93 load_xform_matrices();
95 glMatrixMode(GL_MODELVIEW);
97 glMatrixMode(GL_PROJECTION);
99 glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
102 set_zbuffering(false);
103 set_backface_culling(false);
105 set_texture(0, dsys::tex[0]);
106 enable_texture_unit(0);
108 glBegin(GL_TRIANGLES);
109 glColor4f(1.0, 1.0, 1.0, 0.5);
110 for(int i=0; i<icount; i++) {
111 Vertex *vptr = &varray[iarray[i]];
112 glTexCoord2f(tc[iarray[i]].u, tc[iarray[i]].v);
113 glVertex3f(vptr->pos.x, vptr->pos.y, vptr->pos.z);
117 set_alpha_blending(true);
118 set_blend_func(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
120 glBegin(GL_TRIANGLES);
121 glColor4f(1.0, 1.0, 1.0, 0.7);
122 for(int i=0; i<icount; i++) {
123 Vertex *vptr = &varray[iarray[i]];
124 glTexCoord2f(vptr->tex[0].u, vptr->tex[0].v);
125 glVertex3f(vptr->pos.x, vptr->pos.y, vptr->pos.z);
129 set_alpha_blending(false);
131 disable_texture_unit(0);
134 set_zbuffering(true);
135 set_backface_culling(true);