
separate (adagate.drawroom)

procedure drawBarrels is
begin

	--draw barrels
	glUseProgram(pidzpm21);

	for i in 1..nbarrels loop

		bmvp := mvp;

		if rolling(i) then
			barreltime := float(sdl_getticks)/1000.0;
			tt := float( barreltime - timeofroll ) / secperroll;
			barangle := onepi*tt*rad2deg;

			if( tt<1.0 ) then
				posbar(i)(1):=olbarrl(1)+tt*(nubarrl(1)-olbarrl(1));
				posbar(i)(2):=olbarrl(2)+tt*(nubarrl(2)-olbarrl(2));
				posbar(i)(3):=olbarrl(3)+tt*(nubarrl(3)-olbarrl(3));

				if    (rolldir=-1) then axis:=xaxis; barangle:=-barangle;
				elsif (rolldir=+1) then axis:=xaxis;
				elsif (rolldir=+3) then axis:=zaxis; barangle:=-barangle;
				elsif (rolldir=-3) then axis:=zaxis;
				end if;

				cyl2obj.updcyl2(barrel(i), 
					posbar(i)(1),posbar(i)(2),posbar(i)(3));

				bmm:=identity;
				translate(bmm, -posbar(i)(1), -posbar(i)(2), -posbar(i)(3) );
				degRotate(bmm, barangle, axis(1), axis(2), axis(3) );
				translate(bmm, posbar(i)(1), posbar(i)(2), posbar(i)(3) );

				bmvp := bmm;
				matXmat( bmvp, viewMatrix );
				matXmat( bmvp, projMatrix );

			else
				rolling(i):=false;
				posbar(i):=nubarrl;

				cyl2obj.updcyl2(barrel(i), 
					posbar(i)(1),posbar(i)(2),posbar(i)(3));

			end if; -- tt

		end if; -- rolling

		-- we have to register bmvp for each i AFTER it is redefined:
		gluniformmatrix4fv( imvp21, 1, gl_false, bmvp(1,1)'address );
		cyl2obj.draw(barrel(i),vertbuff,rgbbuff,elembuff, seated(i));

	end loop;

end drawBarrels;


