store each character's center coordinates

This commit is contained in:
Josh Holtrop 2013-11-26 22:26:51 -05:00
parent 9ba5c849d6
commit 241c66e56c
2 changed files with 20 additions and 16 deletions

View File

@ -3,14 +3,16 @@
require "erb"
TEMPLATE = <<EOF
struct indices_range_t
struct char_desc_t
{
int start;
int length;
float c_x;
float c_y;
};
float[<%= vertices.size %>] vertices = [
<% vertices.each do |coord| -%>
float[<%= vertices.size * 2 %>] vertices = [
<% vertices.flatten.each do |coord| -%>
<%= coord %>,
<% end -%>
];
@ -22,10 +24,13 @@ ushort[<%= indices.size %>] indices = [
];
<% object_ranges.each_pair do |obj_name, obj_ranges| -%>
indices_range_t[] <%= obj_name %> = [
<% obj_ranges.each do |obj_range| -%>
{<%= obj_range[0] %>, <%= obj_range[1] %>},
<% end -%>
char_desc_t[] <%= obj_name %> = [
<% obj_ranges.each do |obj_range| -%>
<% obj_verts = indices[*obj_range].map {|i| vertices[i]} -%>
<% c_x = (obj_verts.map {|v| v[0]}.min + obj_verts.map {|v| v[0]}.max) / 2.0 -%>
<% c_y = (obj_verts.map {|v| v[1]}.min + obj_verts.map {|v| v[1]}.max) / 2.0 -%>
{<%= obj_range[0] %>, <%= obj_range[1] %>, <%= c_x %>, <%= c_y %>},
<% end -%>
];
<% end -%>
EOF
@ -52,7 +57,6 @@ def main(obj_fname, d_fname)
cur_obj << [$1, $2].map {|v| v.to_i - 1}
end
end
vertices.flatten!
objects.each_pair do |obj_name, obj_array|
object_ranges[obj_name] = obj_array.map do |obj_indices|
obj_indices.flatten!

View File

@ -9,30 +9,30 @@ immutable enum int WIRE = 1;
immutable enum int GENTEX = 0;
immutable enum int CORPORATION = 1;
logoobj.indices_range_t [][2][2] object_indices;
logoobj.char_desc_t [][2][2] characters;
/* Indexed by: face/wire, word, character */
VAO[][2][2] object_vaos;
void init()
{
object_indices = [[logoobj.fg, logoobj.fc],
[logoobj.lg, logoobj.lc]];
characters = [[logoobj.fg, logoobj.fc],
[logoobj.lg, logoobj.lc]];
Buffer vertices_buffer = new Buffer(logoobj.vertices);
for (int draw_type = FACE; draw_type <= WIRE; draw_type++)
{
for (int word = GENTEX; word <= CORPORATION; word++)
{
object_vaos[draw_type][word].length = object_indices[draw_type][word].length;
object_vaos[draw_type][word].length = characters[draw_type][word].length;
for (int char_index = 0;
char_index < object_indices[draw_type][word].length;
char_index < characters[draw_type][word].length;
char_index++)
{
VAO vao = new VAO();
vao.bind();
vertices_buffer.bind();
int start = object_indices[draw_type][word][char_index].start;
int length = object_indices[draw_type][word][char_index].length;
int start = characters[draw_type][word][char_index].start;
int length = characters[draw_type][word][char_index].length;
ElementBuffer ibo = new ElementBuffer(logoobj.indices[start .. (start + length)]);
ibo.bind();
@ -48,7 +48,7 @@ void draw(int draw_type, int word, int character, GLint position_idx)
glEnableVertexAttribArray(position_idx);
glVertexAttribPointer(position_idx, 2, GL_FLOAT, GL_FALSE, 0, null);
glDrawElements(draw_type == FACE ? GL_TRIANGLES : GL_LINES,
object_indices[draw_type][word][character].length,
characters[draw_type][word][character].length,
GL_UNSIGNED_SHORT,
null);
}