Initial commit
This commit is contained in:
365
application/target/mesh.c
Normal file
365
application/target/mesh.c
Normal file
@@ -0,0 +1,365 @@
|
||||
/*
|
||||
* This file is automaticaly generated, Please dont edit this file!
|
||||
*/
|
||||
#include <mesh.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void mesh_createBuffers( mesh * this ) {
|
||||
|
||||
struct unsignedIntegerArray * indices = unsignedIntegerArray_newPointer();
|
||||
|
||||
struct floatArray * textureCoordinates = floatArray_newPointer();
|
||||
|
||||
struct floatArray * vertexCoordinates = floatArray_newPointer();
|
||||
|
||||
struct floatArray * normalCoordinates = floatArray_newPointer();
|
||||
|
||||
struct unsignedIntegerArray * meshIndices = unsignedIntegerArray_newPointer();
|
||||
|
||||
|
||||
int subdivisionsDepth = 1;
|
||||
|
||||
int subdivisionsWidth = 1;
|
||||
|
||||
float width = 2;
|
||||
|
||||
float depth = 2;
|
||||
|
||||
|
||||
int meshCount = 100 * 50;
|
||||
|
||||
int meshStartIndex = 0;
|
||||
|
||||
for (int meshIndex = 0; meshIndex < meshCount; ++meshIndex)
|
||||
{
|
||||
|
||||
|
||||
meshStartIndex = unsignedIntegerArray_length( meshIndices );
|
||||
|
||||
|
||||
|
||||
int numVertsAcross = subdivisionsWidth + 1;
|
||||
|
||||
for ( int z = 0; z < subdivisionsDepth; z++ ) {
|
||||
|
||||
for ( int x = 0; x < subdivisionsWidth; x++ ) {
|
||||
|
||||
|
||||
unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + meshStartIndex );
|
||||
|
||||
unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + meshStartIndex );
|
||||
|
||||
unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex );
|
||||
|
||||
|
||||
unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + meshStartIndex );
|
||||
|
||||
unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + 1 + meshStartIndex );
|
||||
|
||||
unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for ( int z = 0; z <= subdivisionsDepth; z++ ) {
|
||||
|
||||
for ( int x = 0; x <= subdivisionsWidth; x++ ) {
|
||||
|
||||
|
||||
float u = ( float ) x;
|
||||
|
||||
float v = ( float ) z;
|
||||
|
||||
|
||||
floatArray_add( textureCoordinates, u );
|
||||
|
||||
floatArray_add( textureCoordinates, ( 1 - v ) );
|
||||
|
||||
|
||||
floatArray_add( vertexCoordinates, width * u - width * 0.5 );
|
||||
|
||||
floatArray_add( vertexCoordinates, depth * v - depth * 0.5 );
|
||||
|
||||
floatArray_add( vertexCoordinates, 0 );
|
||||
|
||||
|
||||
floatArray_add( normalCoordinates, 0 );
|
||||
|
||||
floatArray_add( normalCoordinates, 0 );
|
||||
|
||||
floatArray_add( normalCoordinates, 1 );
|
||||
|
||||
|
||||
unsignedIntegerArray_add( meshIndices, meshIndex );
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int vertexBufferSize = floatArray_length( vertexCoordinates ) * sizeof( float );
|
||||
|
||||
|
||||
glGenBuffers( 1, &this->vertexbuffer );
|
||||
|
||||
glBindBuffer( GL_ARRAY_BUFFER, this->vertexbuffer );
|
||||
|
||||
glBufferData( GL_ARRAY_BUFFER, vertexBufferSize, vertexCoordinates->items, GL_STATIC_DRAW );
|
||||
|
||||
|
||||
|
||||
int meshIndexBufferSize = unsignedIntegerArray_length( meshIndices ) * sizeof( unsigned int );
|
||||
|
||||
|
||||
glGenBuffers( 1, &this->meshIndexBuffer );
|
||||
|
||||
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, this->meshIndexBuffer );
|
||||
|
||||
glBufferData( GL_ELEMENT_ARRAY_BUFFER, meshIndexBufferSize, meshIndices->items, GL_STATIC_DRAW );
|
||||
|
||||
|
||||
|
||||
int textureCoordinateSize = floatArray_length( textureCoordinates ) * sizeof( float );
|
||||
|
||||
|
||||
glGenBuffers( 1, &this->textureCoordinateBuffer );
|
||||
|
||||
glBindBuffer( GL_ARRAY_BUFFER, this->textureCoordinateBuffer );
|
||||
|
||||
glBufferData( GL_ARRAY_BUFFER, textureCoordinateSize, textureCoordinates->items, GL_STATIC_DRAW );
|
||||
|
||||
|
||||
|
||||
int indexBufferSize = unsignedIntegerArray_length( indices ) * sizeof( unsigned int );
|
||||
|
||||
|
||||
glGenBuffers( 1, &this->indexBuffer );
|
||||
|
||||
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, this->indexBuffer );
|
||||
|
||||
glBufferData( GL_ELEMENT_ARRAY_BUFFER, indexBufferSize, indices->items, GL_STATIC_DRAW );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GLint compareSize = 0;
|
||||
|
||||
glGetBufferParameteriv( GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &compareSize );
|
||||
|
||||
if( indexBufferSize != compareSize )
|
||||
{
|
||||
glDeleteBuffers(1, &this->indexBuffer);
|
||||
|
||||
|
||||
printf("ERROR: size error");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
this->indices = indices;
|
||||
|
||||
this->textureCoordinates = textureCoordinates;
|
||||
|
||||
this->vertexCoordinates = vertexCoordinates;
|
||||
|
||||
this->normalCoordinates = normalCoordinates;
|
||||
|
||||
}
|
||||
|
||||
void mesh_createOrderedTriangleStripQuad( mesh * this ) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void mesh_createBuffer( mesh * this, GLuint * buffer, int bufferSize, float * bufferData ) {
|
||||
|
||||
|
||||
glGenBuffers( 1, buffer );
|
||||
|
||||
glBindBuffer( GL_ARRAY_BUFFER, this->vertexbuffer );
|
||||
glBufferData( GL_ARRAY_BUFFER, bufferSize, bufferData, GL_STATIC_DRAW );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
mesh mesh_new() {
|
||||
|
||||
mesh instance;
|
||||
|
||||
instance.__classIndex = 18;
|
||||
|
||||
return instance;
|
||||
|
||||
}
|
||||
|
||||
mesh * mesh_newPointer() {
|
||||
|
||||
struct mesh * pointer = malloc( sizeof ( struct mesh ) );
|
||||
|
||||
pointer->__classIndex = 18;
|
||||
|
||||
return pointer;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user