Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #ifndef RENDER_H
- #define RENDER_H
- #include "../raylib/raylib.h"
- #include "../world/world.h"
- #include "../types.h"
- void render_chunk(struct icoord_t chunk_pos, struct chunk_t chunk);
- void add_tile_to_mesh(struct tile_t tile, union ccoord16_t position, struct tile_t n, struct tile_t s, struct tile_t e, struct tile_t w, struct tile_t u, struct tile_t d, Mesh* mesh);
- #endif
- #define MAX_VERTEX_BUFFER_SIZE (32*32*32 * 6 * 6) // Tiles * sides * vertices per side and TODO Add indices once you care to figure out how
- void render_chunk(struct icoord_t chunk_pos, struct chunk_t* chunk) {
- if (!chunk->dirty) {
- goto generated;
- }
- Mesh my_mesh = { 0 };
- static float position_buffer[3*MAX_VERTEX_BUFFER_SIZE];
- static float uv_buffer[2*MAX_VERTEX_BUFFER_SIZE];
- static float normal_buffer[3*MAX_VERTEX_BUFFER_SIZE];
- my_mesh.vertices = position_buffer;
- my_mesh.texcoords = uv_buffer;
- my_mesh.normals = normal_buffer;
- my_mesh.vertexCount = 0;
- my_mesh.triangleCount = 0; // NOTE Not needed until indices
- union ccoord16_t tile_index;
- for (tile_index.index = 0; tile_index.index < CHUNK_VOLUME; tile_index.index++) {
- struct tile_t n, s, e, w, u, d;
- struct tile_t target = chunk->tile_data[tile_index.index];
- add_tile_to_mesh(target, tile_index, n, s, e, w, u, d, &my_mesh);
- }
- UploadMesh(&my_mesh, false);
- chunk->render = my_mesh;
- chunk->dirty = false;
- generated:
- // TODO Draw the chunk here :D
- Model chunk_model = LoadModelFromMesh(chunk->render);
- // Set the transformation matrix to that of the chunk coords
- // Tell raylib to render it to screen (put the textures somewhere else)
- }
- void add_tile_to_mesh(struct tile_t tile, union ccoord16_t position, struct tile_t n, struct tile_t s, struct tile_t e, struct tile_t w, struct tile_t u, struct tile_t d, Mesh* mesh) {
- if (mesh == NULL) {
- fprintf(stderr, "ERROR: Null pointer exception in method add_tile_to_mesh\n");
- return;
- }
- if (tile.id == 0) { // AIR
- //mesh->vertexCount += 0;
- return; // Don't need to modify the mesh in any way.
- }
- if (tile.id == 1) { // STONE
- int i = mesh->vertexCount * 3;
- int j = mesh->vertexCount * 2;
- int k = mesh->vertexCount * 3;
- int face_count = 0;
- //mesh->vertexCount += 6 * 6;
- // TODO PLEASE HELP ME AND MAKE THIS CODE LESS VERBOSE
- //NORTH_FACE (POS_Z)
- if (tile_registry[n.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- } // AUUGH Now I got to do all the freaking stupid repeat stuff...
- //SOUTH_FACE (NEG_Z)
- if (tile_registry[s.id].is_transparent) {
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- }
- //EAST_FACE (NEG_X)
- if (tile_registry[e.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- }
- //WEST_FACE (POS_X)
- if (tile_registry[w.id].is_transparent) {
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- }
- //UP_FACE (POS_Y)
- if (tile_registry[u.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- }
- //DOWN_FACE (NEG_Y)
- if (tile_registry[u.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- }
- mesh->vertexCount += face_count * 6;
- }
- if (tile.id == 2) { // DIRT
- int i = mesh->vertexCount * 3;
- int j = mesh->vertexCount * 2;
- int k = mesh->vertexCount * 3;
- int face_count = 0;
- //mesh->vertexCount += 6 * 6;
- //NORTH_FACE (POS_Z)
- if (tile_registry[n.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- // TODO Normals :|
- face_count++;
- } // AUUGH Now I got to do all the freaking stupid repeat stuff...
- //SOUTH_FACE (NEG_Z)
- if (tile_registry[s.id].is_transparent) {
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- // TODO Normals :|
- face_count++;
- }
- //EAST_FACE (NEG_X)
- if (tile_registry[e.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- // TODO Normals :|
- face_count++;
- }
- //WEST_FACE (POS_X)
- if (tile_registry[w.id].is_transparent) {
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- // TODO Normals :|
- face_count++;
- }
- //UP_FACE (POS_Y)
- if (tile_registry[u.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- // TODO Normals :|
- face_count++;
- }
- //DOWN_FACE (NEG_Y)
- if (tile_registry[u.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- // TODO Normals :|
- face_count++;
- }
- mesh->vertexCount += face_count * 6;
- }
- if (tile.id == 3) { // GRASS
- int i = mesh->vertexCount * 3;
- int j = mesh->vertexCount * 2;
- int k = mesh->vertexCount * 3;
- int face_count = 0;
- //mesh->vertexCount += 6 * 6;
- //NORTH_FACE (POS_Z)
- if (tile_registry[n.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- // UV
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- } // AUUGH Now I got to do all the freaking stupid repeat stuff...
- //SOUTH_FACE (NEG_Z)
- if (tile_registry[s.id].is_transparent) {
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- // UV
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- }
- //EAST_FACE (NEG_X)
- if (tile_registry[e.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- // UV
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- }
- //WEST_FACE (POS_X)
- if (tile_registry[w.id].is_transparent) {
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- // UV
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- // TODO Normals :|
- face_count++;
- }
- //UP_FACE (POS_Y)
- if (tile_registry[u.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y + 1;
- mesh->vertices[i++] = position.z;
- // UV
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 1;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- // TODO Normals :|
- face_count++;
- }
- //DOWN_FACE (NEG_Y)
- if (tile_registry[u.id].is_transparent) {
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z;
- mesh->vertices[i++] = position.x + 1;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- mesh->vertices[i++] = position.x;
- mesh->vertices[i++] = position.y;
- mesh->vertices[i++] = position.z + 1;
- // UV
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0.5;
- mesh->texcoords[j++] = 0;
- mesh->texcoords[j++] = 0;
- // TODO Normals :|
- face_count++;
- }
- mesh->vertexCount += face_count * 6;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment