R
Den Part hab ich schon hinbekommen
//.h
// lustig viele Variablen deklarieren
typedef float calc_type;
static const GLenum GL_TYPE = GL_FLOAT;
std::vector< calc_type > vertices;
std::vector< GLsizei > count_vec;
std::vector< GLushort > indices;
std::vector< GLushort* > indices_ptr;
std::vector< calc_type > speed;
std::vector< calc_type > accel;
unsigned short x_count;
unsigned short y_count;
double calc_time;
double delta_calc_time;
int sampling_points_count;
calc_type delta_time;
//.cpp - Initialisierung
// ein Haufen Speicher anfordern und wirr mit Pointern um die Gegend schmeißen
x_count = 101;
y_count = 101;
calc_time = 0.0;
delta_calc_time = 0.001;
delta_time = 0.5;
sampling_points_count = x_count * y_count;
// init begin
//reserve space for vertices
// 3 cords per vertex * number of vertices
vertices.reserve( 3 * sampling_points_count );
//reserve space for acceleration and speed vector
speed.assign( sampling_points_count, 0.0 );
accel.assign( sampling_points_count, 0.0 );
//init the count_vec
//we want to render y_count-1 strips each one with 2 * x_count vertices
count_vec.assign( y_count-1, 2 * x_count );
//reserve space for indices_ptr
//we want to render y_count-1 strips
indices_ptr.reserve( y_count-1 );
GLushort imax = x_count * ( y_count-1 );
//reserve space for the indices
//we need 2*(x_count+1) indices per stripe
indices.reserve( 2 * imax );
for( GLushort i = 0; i < imax; ++i )
{
indices.push_back( i );
indices.push_back( i + x_count );
if( ( i % x_count ) == 0 ) indices_ptr.push_back( &indices[i*2] );
}
for( int y = 0; y < y_count; ++y )
{
for( int x = 0; x < x_count; ++x )
{
vertices.push_back( x );
vertices.push_back( 0.0 );
vertices.push_back( -1*y );
}
}
//.cpp - Berechnungungen
// ein bisschen wirr in der Gegend rumindizieren
int y_inc = 3 * x_count,
y_max = 3 * sampling_points_count - y_inc,
x_max = 3 * ( x_count-1 ),
i_as = 0,
xAy;
for( int y = y_inc; y < y_max; y += y_inc )
{
for( int x = 4; x < x_max; x+=3 )
{
xAy = x + y;
accel[ i_as ] = vertices[ xAy + 3 ] + vertices[ xAy + y_inc ] +
vertices[ xAy - 3 ] + vertices[ xAy - y_inc ]
- 4 * vertices[ xAy ];
++i_as;
}
}
i_as = 0;
for( int y = y_inc; y < y_max; y += y_inc )
{
for( int x = 4; x < x_max; x+=3 )
{
speed[ i_as ] += delta_time * accel[ i_as ];
vertices[ x + y ] += delta_time * speed[ i_as ];
++i_as;
}
}
double freq = 10;
const double _2pi = 2.0 * M_PI;
vertices[50*3*(x_count+1)+1] = 20.0 * sin( _2pi * freq * calc_time );
calc_time += delta_calc_time;
//.cpp - Rendern
//und schließlich das ganze zeichnen
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 3, GL_TYPE, 0, &vertices[0] );
glMultiDrawElementsEXT( GL_QUAD_STRIP, &count_vec[0], GL_UNSIGNED_SHORT, (const GLvoid**)&indices_ptr[0], y_count );
glDisableClientState( GL_VERTEX_ARRAY );
Kritik/Verbesserungsvorschläge sind herzlich willkommen