void mouse_input(int button, int state, int x, int y)
{
	unsigned char pixelrgb[4];
	unsigned int distance;
	//printf("mouse button: %i state: %i position (%i,%i)\n", button, state, x, y);
	last_position.button = button;
	last_position.state = state;
	last_position.x = x;
	last_position.y = y;
	if (button == LEFT_MOUSE && state == MOUSE_DOWN)
		ray_test(glm::vec2(x,y), glm::vec2(get_screen_width(), get_screen_height()));
	else if( button == MIDDLE_MOUSE && state == MOUSE_DOWN) {
		glReadPixels(x, get_screen_height() - y - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)pixelrgb);
		glReadPixels( x, get_screen_height() - y - 1, 1, 1, GL_DEPTH_COMPONENT, GL_INT, &distance );
		printf("(%u, %u, %u, %u) Distance: %i\n", pixelrgb[0], pixelrgb[1], pixelrgb[2], pixelrgb[3], distance);
	}
}
Exemple #2
0
void PositionArrows::on_mouse_press(const vec3 & ray_pos, const vec3 & ray_dir)
{
    pan = ray_test(ray_pos, ray_dir);
    switch (pan) {
        case X_CONE:
            normal = vec3(0.0f, -ray_dir.y, -ray_dir.z);
            break;
        case Y_CONE:
            normal = vec3(-ray_dir.x, 0.0f, -ray_dir.z);
            break;
        case Z_CONE:
            normal = vec3(-ray_dir.x, -ray_dir.y, 0.0f);
            break;
    }
    if (pan != NONE_CONE) {
        update(ray_pos, ray_dir);
        return;
    }
}