
local demo_dir = gh_utils.get_demo_dir()
local lib_dir = gh_utils.get_lib_dir() 		
dofile(lib_dir .. "lua/gx_cam_lib_v1.lua")
dofile(lib_dir .. "lua/libfont/libfont1.lua")   
dofile(lib_dir .. "lua/imgui.lua")    
dofile(lib_dir .. "lua/gxl.lua")    






function gen_random_xyz(radius) 
    local x = gh_utils.random() * 2.0 * radius - radius
    local y = gh_utils.random() * 2.0 * radius - radius
    local z = gh_utils.random() * 2.0 * radius - radius
    return x, y, z
end    

function Random(a, b)
	if (a > b) then
		local c = b
		b = a
		a = c
	end
	local delta = b-a
	return (a + math.random()*delta)
end






winW, winH = gh_window.getsize(0)



gh_renderer.set_scissor_state(0)
    
    



camera = gx_camera.create_perspective(60, 1, 0, 0, winW, winH, 0.1, 1000)
gh_camera.set_position(camera, -80, 20, 10) 
camera_lookat_x = 0
camera_lookat_y = 0
camera_lookat_z = 0
gx_camera.init_orientation(camera, camera_lookat_x, camera_lookat_y, camera_lookat_z, 20, 180)
gx_camera.set_mode_orbit()
orbit_mode = 1
keyboard_speed = 10.0
camera_fov = 60.0
gx_camera.set_orbit_lookat(camera, camera_lookat_x, camera_lookat_y, camera_lookat_z)
gx_camera.set_keyboard_speed(keyboard_speed)





particle_prog = gh_node.getid("particle_prog")
gh_gpu_program.uniform1i(particle_prog, "tex0", 0)

color_prog = gh_node.getid("color_prog")




num_particles_render = 1
particles_index = 1
num_particles = 40000
vp = gh_vertex_pool.create(num_particles)


-- Set the initial position (and last position for computing the difference):
--
--last_position = {x=0.0, y=0.13, z=0}
--last_position = {x=-0.2, y=1.97, z=0}
--last_position = {x=2.0, y=2.02, z=2.0}
last_position = {x=2.01, y=2.03, z=2.01}



-- Init particles position and color
--
for i=0, num_particles-1 do
  local px=0
  local py=0
  local pz=0
  
  --px = Random(0, 1)
  px = 0
  py = 0
  pz = 0
  gh_vertex_pool.vertex_set_position(vp, i, px, py, pz, 1)
  gh_vertex_pool.vertex_set_color(vp, i, 1, 1, 1, alpha)
end


tex01 = gxl.load_texture_rgba_u8(demo_dir .. "assets/particle002.jpg")






grid = gh_utils.grid_create()
gh_utils.grid_set_geometry_params(grid, 100, 100, 20, 20)
gh_utils.grid_set_lines_color(grid, 0.7, 0.7, 0.7, 1.0)
gh_utils.grid_set_main_lines_color(grid, 1.0, 1.0, 0.0, 1.0)
gh_utils.grid_set_main_x_axis_color(grid, 1.0, 0.0, 0.0, 1.0)
gh_utils.grid_set_main_z_axis_color(grid, 0.0, 0.0, 1.0, 1.0)
local display_main_lines = 1
local display_lines = 1
gh_utils.grid_set_display_lines_options(grid, display_main_lines, display_lines)





gh_renderer.set_vsync(0)
gh_renderer.set_scissor_state(1)



last_time = gh_utils.get_elapsed_time()
last_particle_time = last_time
