use triangle fan for top and bottom of pudding model
This commit is contained in:
parent
eb391b911a
commit
9271ba9226
|
@ -46,7 +46,7 @@
|
|||
"enabled": true,
|
||||
"json-save": true,
|
||||
"json-save-directory": "local/scans",
|
||||
"barcode": "",
|
||||
"barcode": "1703543090000",
|
||||
"capture-device": "/dev/video0"
|
||||
},
|
||||
"api":
|
||||
|
|
2
lib/sb
2
lib/sb
|
@ -1 +1 @@
|
|||
Subproject commit 87b1fa735c5d663052995177c6d2f639eeac713b
|
||||
Subproject commit 1f8de2f5f1b6a83a6c235d65030a709441f3cd37
|
|
@ -113,33 +113,39 @@ void Pudding::set_pudding_model(
|
|||
ring_start_vertex_u += u_step;
|
||||
}
|
||||
}
|
||||
pudding_triangle_vertex_count = pudding_vertices.size();
|
||||
/* process the top and bottom of pudding, filling each face with a triangle fan */
|
||||
layer_top_ring.clear();
|
||||
float y = max_y;
|
||||
const glm::vec3* face_color = &PUDDING_BROWN;
|
||||
Box texture_box = Box({0, 0}, {1, 1});
|
||||
for (float radius : {top_radius, base_radius})
|
||||
{
|
||||
/* first point in a GL_TRIANGLE_FAN is the center */
|
||||
pudding_vertices.push_back({0, y, 0});
|
||||
pudding_uv.push_back({0, 0});
|
||||
layer_top_ring.clear();
|
||||
sb::points_on_circle(layer_top_ring, ring_vertex_count, radius);
|
||||
/* loop through points on the face */
|
||||
for (ii = 0; ii < layer_top_ring.size(); ii++)
|
||||
{
|
||||
start_vertex = &layer_top_ring[ii];
|
||||
end_vertex = &layer_top_ring[(ii + 1) % layer_top_ring.size()];
|
||||
/* triangle from the center of the layer_top_ring to the edge */
|
||||
/* for GL_TRIANGLE_FAN we just need to add an outer vertex */
|
||||
pudding_vertices.push_back({start_vertex->x, y, start_vertex->y});
|
||||
pudding_vertices.push_back({end_vertex->x, y, end_vertex->y});
|
||||
pudding_vertices.push_back({0, y, 0});
|
||||
/* map circle points to UV points of the texture */
|
||||
pudding_uv.push_back(*start_vertex);
|
||||
/* connect the ring on the last vertex */
|
||||
if (ii == layer_top_ring.size() - 1)
|
||||
{
|
||||
end_vertex = &layer_top_ring[(ii + 1) % layer_top_ring.size()];
|
||||
pudding_vertices.push_back({end_vertex->x, y, end_vertex->y});
|
||||
pudding_uv.push_back(*end_vertex);
|
||||
pudding_uv.push_back({0, 0});
|
||||
}
|
||||
}
|
||||
/* single color for the entire layer_top_ring */
|
||||
pudding_colors.insert(pudding_colors.end(), 3 * layer_top_ring.size(), *face_color);
|
||||
pudding_colors.insert(pudding_colors.end(), layer_top_ring.size() + 2, *face_color);
|
||||
y = min_y;
|
||||
face_color = &PUDDING_YELLOW;
|
||||
}
|
||||
pudding_fan_vertex_count = (pudding_vertices.size() - pudding_triangle_vertex_count) / 2;
|
||||
}
|
||||
|
||||
/* Create GL context via super class and load vertices, UV data, and shaders */
|
||||
|
@ -756,7 +762,7 @@ void Pudding::update()
|
|||
/* set blend to modify white part of background, color passed is in HSV format */
|
||||
GLint blend_min_hsv_location = glGetUniformLocation(flat_program, "blend_min_hsv");
|
||||
float hue = std::abs(std::abs(model[0][0]) - 0.5) * 2;
|
||||
glUniform3f(blend_min_hsv_location, hue, 0.9, 1);
|
||||
glUniform3f(blend_min_hsv_location, 0, 0, 0);
|
||||
/* draws rectangle vertices and rectangle texture using UV coords */
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
/* draw pudding model using MVP shader */
|
||||
|
@ -781,6 +787,7 @@ void Pudding::update()
|
|||
else
|
||||
{
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
GLuint pudding_texture_location = glGetUniformLocation(mvp_program, "pudding_texture");
|
||||
glUniform1i(pudding_texture_location, 0);
|
||||
|
@ -789,7 +796,9 @@ void Pudding::update()
|
|||
}
|
||||
/* draw pudding model */
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDrawArrays(GL_TRIANGLES, 0, pudding_vertices.size());
|
||||
glDrawArrays(GL_TRIANGLES, 0, pudding_triangle_vertex_count);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, pudding_triangle_vertex_count, pudding_fan_vertex_count);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, pudding_triangle_vertex_count + pudding_fan_vertex_count, pudding_fan_vertex_count);
|
||||
/* regular fill mode enabled for all other drawing */
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
/* only do more drawing if items are downloaded or camera is enabled */
|
||||
|
|
|
@ -54,7 +54,7 @@ private:
|
|||
const glm::vec3 PUDDING_YELLOW = glm::vec3(0.878f, 0.859f, 0.122f);
|
||||
std::string current_barcode, previous_barcode, current_config_barcode, current_camera_barcode;
|
||||
std::vector<Item> items;
|
||||
int current_item_index = 0;
|
||||
int current_item_index = 0, effect_id = Effect::NONE, pudding_triangle_vertex_count = 0, pudding_fan_vertex_count = 0;
|
||||
cv::VideoCapture capture;
|
||||
zbar::ImageScanner image_scanner;
|
||||
GLuint flat_program, mvp_program, capture_texture_front_buffer_id, capture_texture_back_buffer_id, capture_texture_id,
|
||||
|
@ -63,7 +63,6 @@ private:
|
|||
std::vector<glm::vec3> pudding_vertices, pudding_colors;
|
||||
std::vector<glm::vec2> pudding_uv;
|
||||
bool show_item = false, reading_capture_frame = false;
|
||||
int effect_id = Effect::NONE;
|
||||
SDL_GLContext capture_frame_thread_context = nullptr;
|
||||
|
||||
void set_pudding_model(float, float, int, int = 1, float = -1, float = 1, float = 0.3f);
|
||||
|
|
34
src/mvp.frag
34
src/mvp.frag
|
@ -5,21 +5,25 @@ in float x;
|
|||
in vec2 uv;
|
||||
uniform sampler2D pudding_texture;
|
||||
|
||||
void main(void)
|
||||
void color()
|
||||
{
|
||||
vec3 shadowed = min(ex_color, 1.0);
|
||||
float dx = abs(floor(gl_FragCoord[0]) - 480) / 480.0;
|
||||
if (int(floor(gl_FragCoord[0] / 2) + floor(gl_FragCoord[1]) / 2) % 2 == 0)
|
||||
{
|
||||
gl_FragColor = vec4(shadowed * 1.2, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_FragColor = vec4(shadowed * 0.7, 1);
|
||||
}
|
||||
gl_FragColor[0] = int(gl_FragColor[0] * 4) / 4.0;
|
||||
gl_FragColor[1] = int(gl_FragColor[1] * 4) / 4.0;
|
||||
gl_FragColor[2] = int(gl_FragColor[2] * 4) / 4.0;
|
||||
gl_FragColor *= x;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// vec3 shadowed = min(ex_color, 1.0);
|
||||
// float dx = abs(floor(gl_FragCoord[0]) - 480) / 480.0;
|
||||
// if (int(floor(gl_FragCoord[0] / 3) + floor(gl_FragCoord[1]) / 3) % 2 == 0)
|
||||
// {
|
||||
// gl_FragColor = vec4(shadowed * 1.3, 1);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// gl_FragColor = vec4(shadowed * 0.6, 1);
|
||||
// }
|
||||
// gl_FragColor[0] = int(gl_FragColor[0] * 4) / 4.0;
|
||||
// gl_FragColor[1] = int(gl_FragColor[1] * 4) / 4.0;
|
||||
// gl_FragColor[2] = int(gl_FragColor[2] * 4) / 4.0;
|
||||
// gl_FragColor *= x;
|
||||
gl_FragColor = texture(pudding_texture, uv);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue