bluehorizons

Ugly Quad Creation Code

Jun 30th, 2026
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 24.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #ifndef RENDER_H
  4. #define RENDER_H
  5.  
  6. #include "../raylib/raylib.h"
  7. #include "../world/world.h"
  8. #include "../types.h"
  9.  
  10. void render_chunk(struct icoord_t chunk_pos, struct chunk_t chunk);
  11.  
  12. 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);
  13.  
  14. #endif
  15.  
  16. #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
  17.  
  18. void render_chunk(struct icoord_t chunk_pos, struct chunk_t* chunk) {
  19.     if (!chunk->dirty) {
  20.         goto generated;
  21.     }
  22.     Mesh my_mesh = { 0 };
  23.     static float position_buffer[3*MAX_VERTEX_BUFFER_SIZE];
  24.     static float uv_buffer[2*MAX_VERTEX_BUFFER_SIZE];
  25.     static float normal_buffer[3*MAX_VERTEX_BUFFER_SIZE];
  26.  
  27.     my_mesh.vertices = position_buffer;
  28.     my_mesh.texcoords = uv_buffer;
  29.     my_mesh.normals = normal_buffer;
  30.     my_mesh.vertexCount = 0;
  31.     my_mesh.triangleCount = 0; // NOTE Not needed until indices
  32.    
  33.     union ccoord16_t tile_index;
  34.     for (tile_index.index = 0; tile_index.index < CHUNK_VOLUME; tile_index.index++) {
  35.         struct tile_t n, s, e, w, u, d;
  36.         struct tile_t target = chunk->tile_data[tile_index.index];
  37.        
  38.         add_tile_to_mesh(target, tile_index, n, s, e, w, u, d, &my_mesh);
  39.     }
  40.     UploadMesh(&my_mesh, false);
  41.     chunk->render = my_mesh;
  42.     chunk->dirty = false;
  43. generated:
  44.     // TODO Draw the chunk here :D
  45.     Model chunk_model = LoadModelFromMesh(chunk->render);
  46.     // Set the transformation matrix to that of the chunk coords
  47.     // Tell raylib to render it to screen (put the textures somewhere else)
  48. }
  49.  
  50. 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) {
  51.     if (mesh == NULL) {
  52.         fprintf(stderr, "ERROR: Null pointer exception in method add_tile_to_mesh\n");
  53.         return;
  54.     }
  55.  
  56.     if (tile.id == 0) { // AIR
  57.         //mesh->vertexCount += 0;
  58.         return; // Don't need to modify the mesh in any way.
  59.     }
  60.     if (tile.id == 1) { // STONE
  61.         int i = mesh->vertexCount * 3;
  62.         int j = mesh->vertexCount * 2;
  63.         int k = mesh->vertexCount * 3;
  64.         int face_count = 0;
  65.         //mesh->vertexCount += 6 * 6;
  66.  
  67.         // TODO PLEASE HELP ME AND MAKE THIS CODE LESS VERBOSE
  68.         //NORTH_FACE (POS_Z)
  69.         if (tile_registry[n.id].is_transparent) {
  70.             mesh->vertices[i++] = position.x;
  71.             mesh->vertices[i++] = position.y;
  72.             mesh->vertices[i++] = position.z + 1;
  73.             mesh->vertices[i++] = position.x + 1;
  74.             mesh->vertices[i++] = position.y;
  75.             mesh->vertices[i++] = position.z + 1;
  76.             mesh->vertices[i++] = position.x + 1;
  77.             mesh->vertices[i++] = position.y + 1;
  78.             mesh->vertices[i++] = position.z + 1;
  79.             mesh->vertices[i++] = position.x + 1;
  80.             mesh->vertices[i++] = position.y + 1;
  81.             mesh->vertices[i++] = position.z + 1;
  82.             mesh->vertices[i++] = position.x;
  83.             mesh->vertices[i++] = position.y + 1;
  84.             mesh->vertices[i++] = position.z + 1;
  85.             mesh->vertices[i++] = position.x;
  86.             mesh->vertices[i++] = position.y;
  87.             mesh->vertices[i++] = position.z + 1;
  88.             // UV
  89.             mesh->texcoords[j++] = 0;
  90.             mesh->texcoords[j++] = 0.5;
  91.             mesh->texcoords[j++] = 0.5;
  92.             mesh->texcoords[j++] = 0.5;
  93.             mesh->texcoords[j++] = 0.5;
  94.             mesh->texcoords[j++] = 1;
  95.             mesh->texcoords[j++] = 0.5;
  96.             mesh->texcoords[j++] = 1;
  97.             mesh->texcoords[j++] = 0;
  98.             mesh->texcoords[j++] = 1;
  99.             mesh->texcoords[j++] = 0;
  100.             mesh->texcoords[j++] = 0.5;
  101.             // TODO Normals :|
  102.            
  103.             face_count++;
  104.         } // AUUGH Now I got to do all the freaking stupid repeat stuff...
  105.  
  106.         //SOUTH_FACE (NEG_Z)
  107.         if (tile_registry[s.id].is_transparent) {
  108.             mesh->vertices[i++] = position.x + 1;
  109.             mesh->vertices[i++] = position.y;
  110.             mesh->vertices[i++] = position.z;
  111.             mesh->vertices[i++] = position.x;
  112.             mesh->vertices[i++] = position.y;
  113.             mesh->vertices[i++] = position.z;
  114.             mesh->vertices[i++] = position.x;
  115.             mesh->vertices[i++] = position.y + 1;
  116.             mesh->vertices[i++] = position.z;
  117.             mesh->vertices[i++] = position.x;
  118.             mesh->vertices[i++] = position.y + 1;
  119.             mesh->vertices[i++] = position.z;
  120.             mesh->vertices[i++] = position.x + 1;
  121.             mesh->vertices[i++] = position.y + 1;
  122.             mesh->vertices[i++] = position.z;
  123.             mesh->vertices[i++] = position.x + 1;
  124.             mesh->vertices[i++] = position.y;
  125.             mesh->vertices[i++] = position.z;
  126.             // UV
  127.             mesh->texcoords[j++] = 0;
  128.             mesh->texcoords[j++] = 0.5;
  129.             mesh->texcoords[j++] = 0.5;
  130.             mesh->texcoords[j++] = 0.5;
  131.             mesh->texcoords[j++] = 0.5;
  132.             mesh->texcoords[j++] = 1;
  133.             mesh->texcoords[j++] = 0.5;
  134.             mesh->texcoords[j++] = 1;
  135.             mesh->texcoords[j++] = 0;
  136.             mesh->texcoords[j++] = 1;
  137.             mesh->texcoords[j++] = 0;
  138.             mesh->texcoords[j++] = 0.5;
  139.             // TODO Normals :|
  140.            
  141.             face_count++;
  142.         }
  143.    
  144.         //EAST_FACE (NEG_X)
  145.         if (tile_registry[e.id].is_transparent) {
  146.             mesh->vertices[i++] = position.x;
  147.             mesh->vertices[i++] = position.y;
  148.             mesh->vertices[i++] = position.z;
  149.             mesh->vertices[i++] = position.x;
  150.             mesh->vertices[i++] = position.y;
  151.             mesh->vertices[i++] = position.z + 1;
  152.             mesh->vertices[i++] = position.x;
  153.             mesh->vertices[i++] = position.y + 1;
  154.             mesh->vertices[i++] = position.z + 1;
  155.             mesh->vertices[i++] = position.x;
  156.             mesh->vertices[i++] = position.y + 1;
  157.             mesh->vertices[i++] = position.z + 1;
  158.             mesh->vertices[i++] = position.x;
  159.             mesh->vertices[i++] = position.y + 1;
  160.             mesh->vertices[i++] = position.z;
  161.             mesh->vertices[i++] = position.x;
  162.             mesh->vertices[i++] = position.y;
  163.             mesh->vertices[i++] = position.z;
  164.             // UV
  165.             mesh->texcoords[j++] = 0;
  166.             mesh->texcoords[j++] = 0.5;
  167.             mesh->texcoords[j++] = 0.5;
  168.             mesh->texcoords[j++] = 0.5;
  169.             mesh->texcoords[j++] = 0.5;
  170.             mesh->texcoords[j++] = 1;
  171.             mesh->texcoords[j++] = 0.5;
  172.             mesh->texcoords[j++] = 1;
  173.             mesh->texcoords[j++] = 0;
  174.             mesh->texcoords[j++] = 1;
  175.             mesh->texcoords[j++] = 0;
  176.             mesh->texcoords[j++] = 0.5;
  177.             // TODO Normals :|
  178.            
  179.             face_count++;
  180.         }
  181.  
  182.         //WEST_FACE (POS_X)
  183.         if (tile_registry[w.id].is_transparent) {
  184.             mesh->vertices[i++] = position.x + 1;
  185.             mesh->vertices[i++] = position.y;
  186.             mesh->vertices[i++] = position.z + 1;
  187.             mesh->vertices[i++] = position.x + 1;
  188.             mesh->vertices[i++] = position.y;
  189.             mesh->vertices[i++] = position.z;
  190.             mesh->vertices[i++] = position.x + 1;
  191.             mesh->vertices[i++] = position.y + 1;
  192.             mesh->vertices[i++] = position.z;
  193.             mesh->vertices[i++] = position.x + 1;
  194.             mesh->vertices[i++] = position.y + 1;
  195.             mesh->vertices[i++] = position.z;
  196.             mesh->vertices[i++] = position.x + 1;
  197.             mesh->vertices[i++] = position.y + 1;
  198.             mesh->vertices[i++] = position.z + 1;
  199.             mesh->vertices[i++] = position.x + 1;
  200.             mesh->vertices[i++] = position.y;
  201.             mesh->vertices[i++] = position.z + 1;
  202.             // UV
  203.             mesh->texcoords[j++] = 0;
  204.             mesh->texcoords[j++] = 0.5;
  205.             mesh->texcoords[j++] = 0.5;
  206.             mesh->texcoords[j++] = 0.5;
  207.             mesh->texcoords[j++] = 0.5;
  208.             mesh->texcoords[j++] = 1;
  209.             mesh->texcoords[j++] = 0.5;
  210.             mesh->texcoords[j++] = 1;
  211.             mesh->texcoords[j++] = 0;
  212.             mesh->texcoords[j++] = 1;
  213.             mesh->texcoords[j++] = 0;
  214.             mesh->texcoords[j++] = 0.5;
  215.             // TODO Normals :|
  216.            
  217.             face_count++;
  218.         }
  219.  
  220.         //UP_FACE (POS_Y)
  221.         if (tile_registry[u.id].is_transparent) {
  222.             mesh->vertices[i++] = position.x;
  223.             mesh->vertices[i++] = position.y + 1;
  224.             mesh->vertices[i++] = position.z;
  225.             mesh->vertices[i++] = position.x;
  226.             mesh->vertices[i++] = position.y + 1;
  227.             mesh->vertices[i++] = position.z + 1;
  228.             mesh->vertices[i++] = position.x + 1;
  229.             mesh->vertices[i++] = position.y + 1;
  230.             mesh->vertices[i++] = position.z + 1;
  231.             mesh->vertices[i++] = position.x + 1;
  232.             mesh->vertices[i++] = position.y + 1;
  233.             mesh->vertices[i++] = position.z + 1;
  234.             mesh->vertices[i++] = position.x + 1;
  235.             mesh->vertices[i++] = position.y + 1;
  236.             mesh->vertices[i++] = position.z;
  237.             mesh->vertices[i++] = position.x;
  238.             mesh->vertices[i++] = position.y + 1;
  239.             mesh->vertices[i++] = position.z;
  240.             // UV
  241.             mesh->texcoords[j++] = 0;
  242.             mesh->texcoords[j++] = 0.5;
  243.             mesh->texcoords[j++] = 0.5;
  244.             mesh->texcoords[j++] = 0.5;
  245.             mesh->texcoords[j++] = 0.5;
  246.             mesh->texcoords[j++] = 1;
  247.             mesh->texcoords[j++] = 0.5;
  248.             mesh->texcoords[j++] = 1;
  249.             mesh->texcoords[j++] = 0;
  250.             mesh->texcoords[j++] = 1;
  251.             mesh->texcoords[j++] = 0;
  252.             mesh->texcoords[j++] = 0.5;
  253.             // TODO Normals :|
  254.            
  255.             face_count++;
  256.         }
  257.        
  258.         //DOWN_FACE (NEG_Y)
  259.         if (tile_registry[u.id].is_transparent) {
  260.             mesh->vertices[i++] = position.x;
  261.             mesh->vertices[i++] = position.y;
  262.             mesh->vertices[i++] = position.z + 1;
  263.             mesh->vertices[i++] = position.x;
  264.             mesh->vertices[i++] = position.y;
  265.             mesh->vertices[i++] = position.z;
  266.             mesh->vertices[i++] = position.x + 1;
  267.             mesh->vertices[i++] = position.y;
  268.             mesh->vertices[i++] = position.z;
  269.             mesh->vertices[i++] = position.x + 1;
  270.             mesh->vertices[i++] = position.y;
  271.             mesh->vertices[i++] = position.z;
  272.             mesh->vertices[i++] = position.x + 1;
  273.             mesh->vertices[i++] = position.y;
  274.             mesh->vertices[i++] = position.z + 1;
  275.             mesh->vertices[i++] = position.x;
  276.             mesh->vertices[i++] = position.y;
  277.             mesh->vertices[i++] = position.z + 1;
  278.             // UV
  279.             mesh->texcoords[j++] = 0;
  280.             mesh->texcoords[j++] = 0.5;
  281.             mesh->texcoords[j++] = 0.5;
  282.             mesh->texcoords[j++] = 0.5;
  283.             mesh->texcoords[j++] = 0.5;
  284.             mesh->texcoords[j++] = 1;
  285.             mesh->texcoords[j++] = 0.5;
  286.             mesh->texcoords[j++] = 1;
  287.             mesh->texcoords[j++] = 0;
  288.             mesh->texcoords[j++] = 1;
  289.             mesh->texcoords[j++] = 0;
  290.             mesh->texcoords[j++] = 0.5;
  291.             // TODO Normals :|
  292.            
  293.             face_count++;
  294.         }
  295.  
  296.         mesh->vertexCount += face_count * 6;
  297.     }
  298.     if (tile.id == 2) { // DIRT
  299.         int i = mesh->vertexCount * 3;
  300.         int j = mesh->vertexCount * 2;
  301.         int k = mesh->vertexCount * 3;
  302.         int face_count = 0;
  303.         //mesh->vertexCount += 6 * 6;
  304.  
  305.         //NORTH_FACE (POS_Z)
  306.         if (tile_registry[n.id].is_transparent) {
  307.             mesh->vertices[i++] = position.x;
  308.             mesh->vertices[i++] = position.y;
  309.             mesh->vertices[i++] = position.z + 1;
  310.             mesh->vertices[i++] = position.x + 1;
  311.             mesh->vertices[i++] = position.y;
  312.             mesh->vertices[i++] = position.z + 1;
  313.             mesh->vertices[i++] = position.x + 1;
  314.             mesh->vertices[i++] = position.y + 1;
  315.             mesh->vertices[i++] = position.z + 1;
  316.             mesh->vertices[i++] = position.x + 1;
  317.             mesh->vertices[i++] = position.y + 1;
  318.             mesh->vertices[i++] = position.z + 1;
  319.             mesh->vertices[i++] = position.x;
  320.             mesh->vertices[i++] = position.y + 1;
  321.             mesh->vertices[i++] = position.z + 1;
  322.             mesh->vertices[i++] = position.x;
  323.             mesh->vertices[i++] = position.y;
  324.             mesh->vertices[i++] = position.z + 1;
  325.             // UV
  326.             mesh->texcoords[j++] = 0;
  327.             mesh->texcoords[j++] = 0;
  328.             mesh->texcoords[j++] = 0.5;
  329.             mesh->texcoords[j++] = 0;
  330.             mesh->texcoords[j++] = 0.5;
  331.             mesh->texcoords[j++] = 0.5;
  332.             mesh->texcoords[j++] = 0.5;
  333.             mesh->texcoords[j++] = 0.5;
  334.             mesh->texcoords[j++] = 0;
  335.             mesh->texcoords[j++] = 0.5;
  336.             mesh->texcoords[j++] = 0;
  337.             mesh->texcoords[j++] = 0;
  338.             // TODO Normals :|
  339.            
  340.             face_count++;
  341.         } // AUUGH Now I got to do all the freaking stupid repeat stuff...
  342.  
  343.         //SOUTH_FACE (NEG_Z)
  344.         if (tile_registry[s.id].is_transparent) {
  345.             mesh->vertices[i++] = position.x + 1;
  346.             mesh->vertices[i++] = position.y;
  347.             mesh->vertices[i++] = position.z;
  348.             mesh->vertices[i++] = position.x;
  349.             mesh->vertices[i++] = position.y;
  350.             mesh->vertices[i++] = position.z;
  351.             mesh->vertices[i++] = position.x;
  352.             mesh->vertices[i++] = position.y + 1;
  353.             mesh->vertices[i++] = position.z;
  354.             mesh->vertices[i++] = position.x;
  355.             mesh->vertices[i++] = position.y + 1;
  356.             mesh->vertices[i++] = position.z;
  357.             mesh->vertices[i++] = position.x + 1;
  358.             mesh->vertices[i++] = position.y + 1;
  359.             mesh->vertices[i++] = position.z;
  360.             mesh->vertices[i++] = position.x + 1;
  361.             mesh->vertices[i++] = position.y;
  362.             mesh->vertices[i++] = position.z;
  363.             // UV
  364.             mesh->texcoords[j++] = 0;
  365.             mesh->texcoords[j++] = 0;
  366.             mesh->texcoords[j++] = 0.5;
  367.             mesh->texcoords[j++] = 0;
  368.             mesh->texcoords[j++] = 0.5;
  369.             mesh->texcoords[j++] = 0.5;
  370.             mesh->texcoords[j++] = 0.5;
  371.             mesh->texcoords[j++] = 0.5;
  372.             mesh->texcoords[j++] = 0;
  373.             mesh->texcoords[j++] = 0.5;
  374.             mesh->texcoords[j++] = 0;
  375.             mesh->texcoords[j++] = 0;
  376.             // TODO Normals :|
  377.            
  378.             face_count++;
  379.         }
  380.    
  381.         //EAST_FACE (NEG_X)
  382.         if (tile_registry[e.id].is_transparent) {
  383.             mesh->vertices[i++] = position.x;
  384.             mesh->vertices[i++] = position.y;
  385.             mesh->vertices[i++] = position.z;
  386.             mesh->vertices[i++] = position.x;
  387.             mesh->vertices[i++] = position.y;
  388.             mesh->vertices[i++] = position.z + 1;
  389.             mesh->vertices[i++] = position.x;
  390.             mesh->vertices[i++] = position.y + 1;
  391.             mesh->vertices[i++] = position.z + 1;
  392.             mesh->vertices[i++] = position.x;
  393.             mesh->vertices[i++] = position.y + 1;
  394.             mesh->vertices[i++] = position.z + 1;
  395.             mesh->vertices[i++] = position.x;
  396.             mesh->vertices[i++] = position.y + 1;
  397.             mesh->vertices[i++] = position.z;
  398.             mesh->vertices[i++] = position.x;
  399.             mesh->vertices[i++] = position.y;
  400.             mesh->vertices[i++] = position.z;
  401.             // UV
  402.             mesh->texcoords[j++] = 0;
  403.             mesh->texcoords[j++] = 0;
  404.             mesh->texcoords[j++] = 0.5;
  405.             mesh->texcoords[j++] = 0;
  406.             mesh->texcoords[j++] = 0.5;
  407.             mesh->texcoords[j++] = 0.5;
  408.             mesh->texcoords[j++] = 0.5;
  409.             mesh->texcoords[j++] = 0.5;
  410.             mesh->texcoords[j++] = 0;
  411.             mesh->texcoords[j++] = 0.5;
  412.             mesh->texcoords[j++] = 0;
  413.             mesh->texcoords[j++] = 0;
  414.             // TODO Normals :|
  415.            
  416.             face_count++;
  417.         }
  418.  
  419.         //WEST_FACE (POS_X)
  420.         if (tile_registry[w.id].is_transparent) {
  421.             mesh->vertices[i++] = position.x + 1;
  422.             mesh->vertices[i++] = position.y;
  423.             mesh->vertices[i++] = position.z + 1;
  424.             mesh->vertices[i++] = position.x + 1;
  425.             mesh->vertices[i++] = position.y;
  426.             mesh->vertices[i++] = position.z;
  427.             mesh->vertices[i++] = position.x + 1;
  428.             mesh->vertices[i++] = position.y + 1;
  429.             mesh->vertices[i++] = position.z;
  430.             mesh->vertices[i++] = position.x + 1;
  431.             mesh->vertices[i++] = position.y + 1;
  432.             mesh->vertices[i++] = position.z;
  433.             mesh->vertices[i++] = position.x + 1;
  434.             mesh->vertices[i++] = position.y + 1;
  435.             mesh->vertices[i++] = position.z + 1;
  436.             mesh->vertices[i++] = position.x + 1;
  437.             mesh->vertices[i++] = position.y;
  438.             mesh->vertices[i++] = position.z + 1;
  439.             // UV
  440.             mesh->texcoords[j++] = 0;
  441.             mesh->texcoords[j++] = 0;
  442.             mesh->texcoords[j++] = 0.5;
  443.             mesh->texcoords[j++] = 0;
  444.             mesh->texcoords[j++] = 0.5;
  445.             mesh->texcoords[j++] = 0.5;
  446.             mesh->texcoords[j++] = 0.5;
  447.             mesh->texcoords[j++] = 0.5;
  448.             mesh->texcoords[j++] = 0;
  449.             mesh->texcoords[j++] = 0.5;
  450.             mesh->texcoords[j++] = 0;
  451.             mesh->texcoords[j++] = 0;
  452.             // TODO Normals :|
  453.            
  454.             face_count++;
  455.         }
  456.  
  457.         //UP_FACE (POS_Y)
  458.         if (tile_registry[u.id].is_transparent) {
  459.             mesh->vertices[i++] = position.x;
  460.             mesh->vertices[i++] = position.y + 1;
  461.             mesh->vertices[i++] = position.z;
  462.             mesh->vertices[i++] = position.x;
  463.             mesh->vertices[i++] = position.y + 1;
  464.             mesh->vertices[i++] = position.z + 1;
  465.             mesh->vertices[i++] = position.x + 1;
  466.             mesh->vertices[i++] = position.y + 1;
  467.             mesh->vertices[i++] = position.z + 1;
  468.             mesh->vertices[i++] = position.x + 1;
  469.             mesh->vertices[i++] = position.y + 1;
  470.             mesh->vertices[i++] = position.z + 1;
  471.             mesh->vertices[i++] = position.x + 1;
  472.             mesh->vertices[i++] = position.y + 1;
  473.             mesh->vertices[i++] = position.z;
  474.             mesh->vertices[i++] = position.x;
  475.             mesh->vertices[i++] = position.y + 1;
  476.             mesh->vertices[i++] = position.z;
  477.             // UV
  478.             mesh->texcoords[j++] = 0;
  479.             mesh->texcoords[j++] = 0;
  480.             mesh->texcoords[j++] = 0.5;
  481.             mesh->texcoords[j++] = 0;
  482.             mesh->texcoords[j++] = 0.5;
  483.             mesh->texcoords[j++] = 0.5;
  484.             mesh->texcoords[j++] = 0.5;
  485.             mesh->texcoords[j++] = 0.5;
  486.             mesh->texcoords[j++] = 0;
  487.             mesh->texcoords[j++] = 0.5;
  488.             mesh->texcoords[j++] = 0;
  489.             mesh->texcoords[j++] = 0;
  490.             // TODO Normals :|
  491.            
  492.             face_count++;
  493.         }
  494.        
  495.         //DOWN_FACE (NEG_Y)
  496.         if (tile_registry[u.id].is_transparent) {
  497.             mesh->vertices[i++] = position.x;
  498.             mesh->vertices[i++] = position.y;
  499.             mesh->vertices[i++] = position.z + 1;
  500.             mesh->vertices[i++] = position.x;
  501.             mesh->vertices[i++] = position.y;
  502.             mesh->vertices[i++] = position.z;
  503.             mesh->vertices[i++] = position.x + 1;
  504.             mesh->vertices[i++] = position.y;
  505.             mesh->vertices[i++] = position.z;
  506.             mesh->vertices[i++] = position.x + 1;
  507.             mesh->vertices[i++] = position.y;
  508.             mesh->vertices[i++] = position.z;
  509.             mesh->vertices[i++] = position.x + 1;
  510.             mesh->vertices[i++] = position.y;
  511.             mesh->vertices[i++] = position.z + 1;
  512.             mesh->vertices[i++] = position.x;
  513.             mesh->vertices[i++] = position.y;
  514.             mesh->vertices[i++] = position.z + 1;
  515.             // UV
  516.             mesh->texcoords[j++] = 0;
  517.             mesh->texcoords[j++] = 0;
  518.             mesh->texcoords[j++] = 0.5;
  519.             mesh->texcoords[j++] = 0;
  520.             mesh->texcoords[j++] = 0.5;
  521.             mesh->texcoords[j++] = 0.5;
  522.             mesh->texcoords[j++] = 0.5;
  523.             mesh->texcoords[j++] = 0.5;
  524.             mesh->texcoords[j++] = 0;
  525.             mesh->texcoords[j++] = 0.5;
  526.             mesh->texcoords[j++] = 0;
  527.             mesh->texcoords[j++] = 0;
  528.             // TODO Normals :|
  529.            
  530.             face_count++;
  531.         }
  532.  
  533.         mesh->vertexCount += face_count * 6;
  534.     }
  535.     if (tile.id == 3) { // GRASS
  536.         int i = mesh->vertexCount * 3;
  537.         int j = mesh->vertexCount * 2;
  538.         int k = mesh->vertexCount * 3;
  539.         int face_count = 0;
  540.         //mesh->vertexCount += 6 * 6;
  541.  
  542.         //NORTH_FACE (POS_Z)
  543.         if (tile_registry[n.id].is_transparent) {
  544.             mesh->vertices[i++] = position.x;
  545.             mesh->vertices[i++] = position.y;
  546.             mesh->vertices[i++] = position.z + 1;
  547.             mesh->vertices[i++] = position.x + 1;
  548.             mesh->vertices[i++] = position.y;
  549.             mesh->vertices[i++] = position.z + 1;
  550.             mesh->vertices[i++] = position.x + 1;
  551.             mesh->vertices[i++] = position.y + 1;
  552.             mesh->vertices[i++] = position.z + 1;
  553.             mesh->vertices[i++] = position.x + 1;
  554.             mesh->vertices[i++] = position.y + 1;
  555.             mesh->vertices[i++] = position.z + 1;
  556.             mesh->vertices[i++] = position.x;
  557.             mesh->vertices[i++] = position.y + 1;
  558.             mesh->vertices[i++] = position.z + 1;
  559.             mesh->vertices[i++] = position.x;
  560.             mesh->vertices[i++] = position.y;
  561.             mesh->vertices[i++] = position.z + 1;
  562.             // UV
  563.             mesh->texcoords[j++] = 0.5;
  564.             mesh->texcoords[j++] = 0.5;
  565.             mesh->texcoords[j++] = 1;
  566.             mesh->texcoords[j++] = 0.5;
  567.             mesh->texcoords[j++] = 1;
  568.             mesh->texcoords[j++] = 1;
  569.             mesh->texcoords[j++] = 1;
  570.             mesh->texcoords[j++] = 1;
  571.             mesh->texcoords[j++] = 0.5;
  572.             mesh->texcoords[j++] = 1;
  573.             mesh->texcoords[j++] = 0.5;
  574.             mesh->texcoords[j++] = 0.5;
  575.             // TODO Normals :|
  576.            
  577.             face_count++;
  578.         } // AUUGH Now I got to do all the freaking stupid repeat stuff...
  579.  
  580.         //SOUTH_FACE (NEG_Z)
  581.         if (tile_registry[s.id].is_transparent) {
  582.             mesh->vertices[i++] = position.x + 1;
  583.             mesh->vertices[i++] = position.y;
  584.             mesh->vertices[i++] = position.z;
  585.             mesh->vertices[i++] = position.x;
  586.             mesh->vertices[i++] = position.y;
  587.             mesh->vertices[i++] = position.z;
  588.             mesh->vertices[i++] = position.x;
  589.             mesh->vertices[i++] = position.y + 1;
  590.             mesh->vertices[i++] = position.z;
  591.             mesh->vertices[i++] = position.x;
  592.             mesh->vertices[i++] = position.y + 1;
  593.             mesh->vertices[i++] = position.z;
  594.             mesh->vertices[i++] = position.x + 1;
  595.             mesh->vertices[i++] = position.y + 1;
  596.             mesh->vertices[i++] = position.z;
  597.             mesh->vertices[i++] = position.x + 1;
  598.             mesh->vertices[i++] = position.y;
  599.             mesh->vertices[i++] = position.z;
  600.             // UV
  601.             mesh->texcoords[j++] = 0.5;
  602.             mesh->texcoords[j++] = 0.5;
  603.             mesh->texcoords[j++] = 1;
  604.             mesh->texcoords[j++] = 0.5;
  605.             mesh->texcoords[j++] = 1;
  606.             mesh->texcoords[j++] = 1;
  607.             mesh->texcoords[j++] = 1;
  608.             mesh->texcoords[j++] = 1;
  609.             mesh->texcoords[j++] = 0.5;
  610.             mesh->texcoords[j++] = 1;
  611.             mesh->texcoords[j++] = 0.5;
  612.             mesh->texcoords[j++] = 0.5;
  613.             // TODO Normals :|
  614.            
  615.             face_count++;
  616.         }
  617.    
  618.         //EAST_FACE (NEG_X)
  619.         if (tile_registry[e.id].is_transparent) {
  620.             mesh->vertices[i++] = position.x;
  621.             mesh->vertices[i++] = position.y;
  622.             mesh->vertices[i++] = position.z;
  623.             mesh->vertices[i++] = position.x;
  624.             mesh->vertices[i++] = position.y;
  625.             mesh->vertices[i++] = position.z + 1;
  626.             mesh->vertices[i++] = position.x;
  627.             mesh->vertices[i++] = position.y + 1;
  628.             mesh->vertices[i++] = position.z + 1;
  629.             mesh->vertices[i++] = position.x;
  630.             mesh->vertices[i++] = position.y + 1;
  631.             mesh->vertices[i++] = position.z + 1;
  632.             mesh->vertices[i++] = position.x;
  633.             mesh->vertices[i++] = position.y + 1;
  634.             mesh->vertices[i++] = position.z;
  635.             mesh->vertices[i++] = position.x;
  636.             mesh->vertices[i++] = position.y;
  637.             mesh->vertices[i++] = position.z;
  638.             // UV
  639.             mesh->texcoords[j++] = 0.5;
  640.             mesh->texcoords[j++] = 0.5;
  641.             mesh->texcoords[j++] = 1;
  642.             mesh->texcoords[j++] = 0.5;
  643.             mesh->texcoords[j++] = 1;
  644.             mesh->texcoords[j++] = 1;
  645.             mesh->texcoords[j++] = 1;
  646.             mesh->texcoords[j++] = 1;
  647.             mesh->texcoords[j++] = 0.5;
  648.             mesh->texcoords[j++] = 1;
  649.             mesh->texcoords[j++] = 0.5;
  650.             mesh->texcoords[j++] = 0.5;
  651.             // TODO Normals :|
  652.            
  653.             face_count++;
  654.         }
  655.  
  656.         //WEST_FACE (POS_X)
  657.         if (tile_registry[w.id].is_transparent) {
  658.             mesh->vertices[i++] = position.x + 1;
  659.             mesh->vertices[i++] = position.y;
  660.             mesh->vertices[i++] = position.z + 1;
  661.             mesh->vertices[i++] = position.x + 1;
  662.             mesh->vertices[i++] = position.y;
  663.             mesh->vertices[i++] = position.z;
  664.             mesh->vertices[i++] = position.x + 1;
  665.             mesh->vertices[i++] = position.y + 1;
  666.             mesh->vertices[i++] = position.z;
  667.             mesh->vertices[i++] = position.x + 1;
  668.             mesh->vertices[i++] = position.y + 1;
  669.             mesh->vertices[i++] = position.z;
  670.             mesh->vertices[i++] = position.x + 1;
  671.             mesh->vertices[i++] = position.y + 1;
  672.             mesh->vertices[i++] = position.z + 1;
  673.             mesh->vertices[i++] = position.x + 1;
  674.             mesh->vertices[i++] = position.y;
  675.             mesh->vertices[i++] = position.z + 1;
  676.             // UV
  677.             mesh->texcoords[j++] = 0.5;
  678.             mesh->texcoords[j++] = 0.5;
  679.             mesh->texcoords[j++] = 1;
  680.             mesh->texcoords[j++] = 0.5;
  681.             mesh->texcoords[j++] = 1;
  682.             mesh->texcoords[j++] = 1;
  683.             mesh->texcoords[j++] = 1;
  684.             mesh->texcoords[j++] = 1;
  685.             mesh->texcoords[j++] = 0.5;
  686.             mesh->texcoords[j++] = 1;
  687.             mesh->texcoords[j++] = 0.5;
  688.             mesh->texcoords[j++] = 0.5;
  689.             // TODO Normals :|
  690.            
  691.             face_count++;
  692.         }
  693.  
  694.         //UP_FACE (POS_Y)
  695.         if (tile_registry[u.id].is_transparent) {
  696.             mesh->vertices[i++] = position.x;
  697.             mesh->vertices[i++] = position.y + 1;
  698.             mesh->vertices[i++] = position.z;
  699.             mesh->vertices[i++] = position.x;
  700.             mesh->vertices[i++] = position.y + 1;
  701.             mesh->vertices[i++] = position.z + 1;
  702.             mesh->vertices[i++] = position.x + 1;
  703.             mesh->vertices[i++] = position.y + 1;
  704.             mesh->vertices[i++] = position.z + 1;
  705.             mesh->vertices[i++] = position.x + 1;
  706.             mesh->vertices[i++] = position.y + 1;
  707.             mesh->vertices[i++] = position.z + 1;
  708.             mesh->vertices[i++] = position.x + 1;
  709.             mesh->vertices[i++] = position.y + 1;
  710.             mesh->vertices[i++] = position.z;
  711.             mesh->vertices[i++] = position.x;
  712.             mesh->vertices[i++] = position.y + 1;
  713.             mesh->vertices[i++] = position.z;
  714.             // UV
  715.             mesh->texcoords[j++] = 0.5;
  716.             mesh->texcoords[j++] = 0;
  717.             mesh->texcoords[j++] = 1;
  718.             mesh->texcoords[j++] = 0;
  719.             mesh->texcoords[j++] = 1;
  720.             mesh->texcoords[j++] = 0.5;
  721.             mesh->texcoords[j++] = 1;
  722.             mesh->texcoords[j++] = 0.5;
  723.             mesh->texcoords[j++] = 0.5;
  724.             mesh->texcoords[j++] = 0.5;
  725.             mesh->texcoords[j++] = 0.5;
  726.             mesh->texcoords[j++] = 0;
  727.             // TODO Normals :|
  728.            
  729.             face_count++;
  730.         }
  731.        
  732.         //DOWN_FACE (NEG_Y)
  733.         if (tile_registry[u.id].is_transparent) {
  734.             mesh->vertices[i++] = position.x;
  735.             mesh->vertices[i++] = position.y;
  736.             mesh->vertices[i++] = position.z + 1;
  737.             mesh->vertices[i++] = position.x;
  738.             mesh->vertices[i++] = position.y;
  739.             mesh->vertices[i++] = position.z;
  740.             mesh->vertices[i++] = position.x + 1;
  741.             mesh->vertices[i++] = position.y;
  742.             mesh->vertices[i++] = position.z;
  743.             mesh->vertices[i++] = position.x + 1;
  744.             mesh->vertices[i++] = position.y;
  745.             mesh->vertices[i++] = position.z;
  746.             mesh->vertices[i++] = position.x + 1;
  747.             mesh->vertices[i++] = position.y;
  748.             mesh->vertices[i++] = position.z + 1;
  749.             mesh->vertices[i++] = position.x;
  750.             mesh->vertices[i++] = position.y;
  751.             mesh->vertices[i++] = position.z + 1;
  752.             // UV
  753.             mesh->texcoords[j++] = 0;
  754.             mesh->texcoords[j++] = 0;
  755.             mesh->texcoords[j++] = 0.5;
  756.             mesh->texcoords[j++] = 0;
  757.             mesh->texcoords[j++] = 0.5;
  758.             mesh->texcoords[j++] = 0.5;
  759.             mesh->texcoords[j++] = 0.5;
  760.             mesh->texcoords[j++] = 0.5;
  761.             mesh->texcoords[j++] = 0;
  762.             mesh->texcoords[j++] = 0.5;
  763.             mesh->texcoords[j++] = 0;
  764.             mesh->texcoords[j++] = 0;
  765.             // TODO Normals :|
  766.            
  767.             face_count++;
  768.         }
  769.  
  770.         mesh->vertexCount += face_count * 6;
  771.     }
  772. }
  773.  
Advertisement
Add Comment
Please, Sign In to add comment