How about the collision between the trisoup and the AABB entities ? I am very interested on this approach.
The trisoup is purely for visuals, kinda like R_BeginPolygon, but with way less built-in spam, which should make it potentially much much faster. The collision in my case is handled with entities that are created on the server and the entities also tell exactly what types of blocks there are for the client so it knows how to draw the level using the trisoups.
Outstanding work, man! Could you please describe how to use FTE's trisoup drawing, because I tried but I couldn't manage how to do it
Thank you! Yeah I can go through it real quick here, Spike will hopefully clarify if I make mistakes.
1. Allocate memory for the vertex buffer (just an array of vertices), you could do this by just having a large array as a global but it slows down compilation a lot so I use memalloc and store the result in a global pointer.
You can use memalloc to allocate a vertex buffer like this:
Code: Select all
trisoup_simple_vert_s * my_vertex_data = (trisoup_simple_vert_s*)memalloc(sizeof(trisoup_simple_vert_s) * NUMBER_OF_VERTS);
2. Generate values for the vertices, the vertex is defined like this
Code: Select all
typedef struct trisoup_simple_vert_s {vec3 xyz;vec2 st;vec4 rgba;} trisoup_simple_vert_t;
The vec2, vec3 and vec4 are just float arrays of those sizes. You can setup a triangle (with default [1, 1, 1, 1] color like this:
Code: Select all
my_vertex_data[0].xyz[0] = 0
my_vertex_data[0].xyz[1] = 0;
my_vertex_data[0].xyz[2] = 0;
my_vertex_data[0].st[0] = 0;
my_vertex_data[0].st[1] = 0;
my_vertex_data[1].xyz[0] = 0
my_vertex_data[1].xyz[1] = 0;
my_vertex_data[1].xyz[2] = 100;
my_vertex_data[1].st[0] = 0;
my_vertex_data[1].st[1] = 1;
my_vertex_data[2].xyz[0] = 100
my_vertex_data[2].xyz[1] = 0;
my_vertex_data[2].xyz[2] = 0;
my_vertex_data[2].st[0] = 1;
my_vertex_data[2].st[1] = 0;
3. You also need the index array which is integers, and the size of it should be the same as the number of triangles you want to draw. The indices is the indices of the vertices in the vertex buffer to link to create triangles, so indices [0, 1, 2] will draw a triangle that connects first, second and third vertex in the buffer. In my case I just allocated and generated a list that goes from [0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ] for a nice quad pattern.
4. Draw the stuff, this is the only step you actually need to do every frame, use the builtin like this:
Code: Select all
// Definition:
// void(string texturename, int flags, struct trisoup_simple_vert_s *verts, int *indexes, int numindexes) addtrisoup_simple = #0:addtrisoup_simple;
// Usage:
addtrisoup_simple("my_shader", 0, my_vertex_data, my_indices_data, num_indices);