%[v,f]=read_off('home1_shapes.off');
%[v,f]=read_off('cube.off');

obj_scale=2.5;
[v,f]=read_off('sphere_mesh_12.off');
v=v*obj_scale;
figure(1);
clf;
%subplot(1,3,1);
set(gcf,'Color',[1 1 1]);
options.line_width =2;
options.style =['-'];
options.cstyle=['r'];
plot_mesh_edges(v,f,options);
[f_n, f_flags]=calc_mesh_norm(v,f);
%plot_mesh_norms(v,f,f_n);
%The object is three walls
wall_size=40;
floor_h=-2;
ceil_h=15;
wall_pos=[-wall_size/2 -wall_size/2 floor_h];
room_h=(ceil_h-floor_h)/wall_size;
wall_v=[0 0 0  %v1
    1 0 0
    1 1 0
    0 1 0
    0 1 room_h
    0 0 room_h
    1 0 room_h];
wall_f=[1 2 3
    1 3 4
    1 4 6
    4 5 6
    1 6 7
    1 7 2];
wall_norm=[0 0 1
    0 0 1
    1 0 0
    1 0 0
    0 1 0
    0 1 0];
wall_v=wall_v*wall_size;
for i=1:size(wall_v,1),
    wall_v(i,:)=wall_v(i,:)+wall_pos;
end
figure(1);

clf;
setup_cameras;setup_projectors;

nobjects = 1;
objects=cell([nobjects 1]);

plot_mesh(v,f);
hold on;
%plot_mesh(wall_v,wall_f);
objects{1}.v=[wall_v';ones([1 size(wall_v,1)])];
objects{1}.f=wall_f';
objects{1}.norms=wall_norm';
objects{1}.bkcolor=[255 255 255];
c_obj=1;
%Here each vertex is a column
objects{c_obj}.v=[v;ones([1 size(v,2)])];
%Here we assume each triangle is a column in the face list f
objects{c_obj}.f=f;
%We assume the normal of a triangle is pointing outside
%Here each norm is a column
objects{c_obj}.norms=f_n';
objects{c_obj}.bkcolor=[0 0 255];
load floor_texture;
floor_texture=[im,im;im,im];
wall_v=wall_v';
floor_x=[wall_v(1,1) (wall_v(1,1)+wall_v(1,4))/2 wall_v(1,4)
   wall_v(1,2) (wall_v(1,2)+wall_v(1,3))/2 wall_v(1,3)];

floor_y=[wall_v(2,1) (wall_v(2,1)+wall_v(2,4))/2 wall_v(2,4)
   wall_v(2,2) (wall_v(2,2)+wall_v(2,3))/2 wall_v(2,3)];
floor_z=[wall_v(3,1) (wall_v(3,1)+wall_v(3,4))/2 wall_v(3,4)
   wall_v(3,2) (wall_v(3,2)+wall_v(3,3))/2 wall_v(3,3)];
[floor_tex, floor_map]=rgb2ind(floor_texture);
%floor_hh=warp(floor_x,floor_y,floor_z,floor_tex);
%colormap(floor_map);
