clear all;
close all;
clc;

%% CREATE SYSTEM OBJECTS
colorDevice = imaq.VideoDevice('kinect',1);
depthDevice = imaq.VideoDevice('kinect',2);

%% INICIAR AS CAMARAS
colorDevice();
depthDevice();

%% Capturar um frame dos dispositivos
colorImg = colorDevice();
depthImg = depthDevice();

%% Extrair a nuvem de pontos
ptCloud = pcfromkinect(depthDevice, depthImg, colorImg);

% Iniciar o player para visualizar os dados da nuvem de pontos 3D
player = pcplayer(ptCloud.XLimits, ptCloud.YLimits,ptCloud.ZLimits, 'VerticalAxis','Y','VerticalAxisDir','Down');

xlabel(player.Axes, 'X(m)');
ylabel(player.Axes, 'Y(m)');
zlabel(player.Axes, 'Z(m)');


% Adquirir e visualizar os dados da nuvem de pontos
while isOpen(player)
    colorImg = colorDevice();
    depthImg = depthDevice();

    ptCloud = pcfromkinect(depthDevice, depthImg, colorImg);

    view(player, ptCloud);
end

release(colorDevice);
release(depthDevice);