Пример #1
0
    void Projection::render_crosshairs (const Point<>& focus) const
    {
      if (!crosshairs_VB || !crosshairs_VAO) {
        crosshairs_VB.gen();
        crosshairs_VAO.gen();

        crosshairs_VB.bind (gl::ARRAY_BUFFER);
        crosshairs_VAO.bind();

        gl::EnableVertexAttribArray (0);
        gl::VertexAttribPointer (0, 2, gl::FLOAT, gl::FALSE_, 0, (void*)0);
      }
      else {
        crosshairs_VB.bind (gl::ARRAY_BUFFER);
        crosshairs_VAO.bind();
      }

      if (!crosshairs_program) {
        GL::Shader::Vertex vertex_shader (
            "layout(location=0) in vec2 pos;\n"
            "void main () {\n"
            "  gl_Position = vec4 (pos, 0.0, 1.0);\n"
            "}\n");
        GL::Shader::Fragment fragment_shader (
            "out vec4 color;\n"
            "void main () {\n"
            "  color = vec4 (0.5, 0.5, 0.0, 1.0);\n"
            "}\n");
        crosshairs_program.attach (vertex_shader);
        crosshairs_program.attach (fragment_shader);
        crosshairs_program.link();
      }

      Point<> F = model_to_screen (focus);
      F[0] = std::round (F[0] - x_position()) - 0.5f;
      F[1] = std::round (F[1] - y_position()) + 0.5f;

      F[0] = 2.0f * F[0] / width() - 1.0f;
      F[1] = 2.0f * F[1] / height() - 1.0f;

      GLfloat data [] = {
        F[0], -1.0f,
        F[0], 1.0f,
        -1.0f, F[1],
        1.0f, F[1]
      };
      gl::BufferData (gl::ARRAY_BUFFER, sizeof(data), data, gl::STATIC_DRAW);

      gl::DepthMask (gl::TRUE_);
      gl::Disable (gl::BLEND);
      gl::LineWidth (1.0);

      crosshairs_program.start();
      gl::DrawArrays (gl::LINES, 0, 4);
      crosshairs_program.stop();
    }
Пример #2
0
        void EdgeDetector:: non_maxima_suppress(xpatch &xp,  lockable &access) throw()
        {
            assert(Gmax>0);
            pixmap<float> &G   = *this;
            for(unit_t y=xp.upper.y;y>=xp.lower.y;--y)
            {
                const bitmap::position_type ypos = y_position(y);
                unit_t                      yu   = y+1;
                unit_t                      yl   = y-1;
                switch(ypos)
                {
                    case bitmap::at_lower: yl = y; break;
                    case bitmap::at_upper: yu = y; break;
                    default:
                        break;
                }

                for(unit_t x=xp.upper.x;x>=xp.lower.x;--x)
                {
                    const bitmap::position_type xpos = x_position(x);
                    const float                 G0   = G[y][x];
                    bool                        keep = false;
                    unit_t                      xu   = x+1;
                    unit_t                      xl   = x-1;

                    switch(xpos)
                    {
                        case bitmap::at_lower: xl=x; break;
                        case bitmap::at_upper: xu=x; break;
                        default:
                            break;
                    }

                    switch(A[y][x])
                    {
                        case DIR_VERT:       keep = ( G[yu][x] <=G0 && G[yl][x] <=G0); break;
                        case DIR_HORZ:       keep = ( G[y][xu] <=G0 && G[y][xl] <=G0); break;
                        case DIR_DIAG_RIGHT: keep = ( G[yu][xu]<=G0 && G[yl][xl]<=G0); break;
                        case DIR_DIAG_LEFT:  keep = ( G[yl][xu]<=G0 && G[yu][xl]<=G0); break;
                        default:
                            break;
                    }

                    if(keep)
                    {
                        const uint8_t px = gist::float2byte(G0);
                        E[y][x] = px;
                    }
                    else
                    {
                        E[y][x] = 0;
                    }
                }
            }
        }
Пример #3
0
/* removes a wall from wallIndexes and removes it
** from the board. Note, they will be removed in the
** order they were added
*/
void remove_wall(){
	int8_t i, j, start, stop;
	start = x_position(wallIndexes[0]);
	stop = y_position(wallIndexes[0]);
	//shift wallPositions to create more space at the end
	//remove from board as we go along
	for(i = start; i < stop; i++) {
		remove_food_item_from_board(wallPositions[start]);
		
		//empty_display();
		for(j = start; j < MAX_WALL_SIZE; j++){
			wallPositions[j] = wallPositions[j + 1];
		}
	}
	wallInsertionIndex -= stop - start;

	//shift wallIndexes
	for(i = 0; i < MAX_NUM_WALLS; i++){
		wallIndexes[i] = wallIndexes[i + 1];
	}
	newWallIndex--;
}