From 241c66e56cb832109ae00c5b7c70dc171273041d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 26 Nov 2013 22:26:51 -0500 Subject: [PATCH] store each character's center coordinates --- obj2d.rb | 20 ++++++++++++-------- src/logo.d | 16 ++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/obj2d.rb b/obj2d.rb index 6908c01..fcb70b4 100644 --- a/obj2d.rb +++ b/obj2d.rb @@ -3,14 +3,16 @@ require "erb" TEMPLATE = <] 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! diff --git a/src/logo.d b/src/logo.d index 9b0a185..c20772e 100644 --- a/src/logo.d +++ b/src/logo.d @@ -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); }