porky11 / planet-fight

simple_working_version

By fabio.u.krapohl@fau.de on October 7, 2017
This patch is not signed.
88tiMivXZkiQGg1njL2vw6WCzdudpCeCGfNSSeB6oraDnwLZXdCWoz3n3WaxcDHiCHq5bwjuF3QGCQfmGeVviyD2
This patch is in the following branches:
master





















































































impl_vertex!(iBall, pos, vel, rad);
    let data = (0 .. 16).map(|p| Ball::<i32>{pos: Vector3::new(p, -2*p, 3*p).into(), vel: Vector3::new(-3*p, 2*p, -p).into(), rad: 16});
    {
        let shader = pos_vel::Shader::load(device.clone())
            .expect("Loading shader failed");
        
        use vulkano::pipeline::ComputePipeline;
        let compute_pipeline = Arc::new(ComputePipeline::new(device.clone(), &shader.main_entry_point(), &())
            .expect("failed to create compute pipeline"));
        
        

        let command_buffer = AutoCommandBufferBuilder::new(device.clone(), queue.family()).unwrap()
            .dispatch([16,1,1], compute_pipeline.clone(), set.clone(), ()).unwrap()
            .build().unwrap();
        let finished = command_buffer.execute(queue.clone()).unwrap();
        
        use vulkano::sync::GpuFuture;

        finished.then_signal_fence_and_flush().unwrap().wait(None).unwrap();
    }


        let shader = collide::Shader::load(device.clone())
            .expect("Loading shader failed");
        let compute_pipeline = Arc::new(ComputePipeline::new(device.clone(), &shader.main_entry_point(), &())
            .expect("failed to create compute pipeline"));
        let set = Arc::new(PersistentDescriptorSet::start(compute_pipeline.clone(), 0)
            .add_buffer(buffer.clone()).unwrap()
            .build().unwrap());
        let command_buffer = AutoCommandBufferBuilder::new(device.clone(), queue.family()).unwrap()
            .dispatch([16,16,1], compute_pipeline.clone(), set.clone(), ()).unwrap()
            .build().unwrap();
        use vulkano::sync::GpuFuture;

        let finished = command_buffer.execute(queue.clone()).unwrap();
        finished.then_signal_fence_and_flush().unwrap().wait(None).unwrap();

        
    
    /*
    use vulkano::image::{
        StorageImage,
        Dimensions
    };
    use vulkano::format::Format;
    let image = StorageImage::new(device.clone(), Dimensions::Dim2d {width: 1024, height: 1024},
                                Format::R8G8B8A8Unorm, Some(queue.family())).unwrap();
    let framebuffer = Arc::new(Framebuffer::start(render_pass.clone())
        .add(image.clone()).unwrap()
        .build().unwrap());
    



    */

    use vulkano::pipeline::GraphicsPipeline;
    use vulkano::framebuffer::Subpass;
    use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;

    let set = Arc::new(PersistentDescriptorSet::start(pipeline.clone(), 0)
        
        
        
                dimensions: [dimensions[0] as f32, dimensions[1] as f32],
        println!("got here");


                .expect("failed 1")
                .expect("failed 2")
                .draw(pipeline.clone(), dynamic_state, buffer.clone(), set.clone(), ())
                .expect("failed 3")
                .expect("failed 4")
                .expect("failed 5");
        println!("got there");
    
        let future = previous_frame_end.join(acquire_future)
            .then_execute(queue.clone(), command_buffer).unwrap()
            .then_swapchain_present(queue.clone(), swapchain.clone(), image_num)
            use winit::Event::*;
                WindowEvent {event: Closed, ..} => done = false,
        return;}
            let wait = time::Duration::from_millis(250);
            //thread::sleep(wait-now.elapsed());






























        layout(location = 0) out vec3 center;
        layout(location = 1) out vec3 pos;
        layout(location = 2) flat out int gs_rad;
            vec3 c = p.xyz/p.w;
            int rad = vs_rad[0];
            pos = c + rad*vec3(1, 1, 0);
            gl_Position = vec4(pos, 1);
            pos = c + rad*vec3(1, -1, 0);
            gl_Position = vec4(pos, 1);
            pos = c + rad*vec3(-1, 1, 0);
            gl_Position = vec4(pos, 1);
            pos = c + rad*vec3(-1, -1, 0);
            gl_Position = vec4(pos, 1);
        layout(location = 0) in vec3 center;
        layout(location = 1) in vec3 pos;
        layout(location = 2) flat in int gs_rad;
            color = vec4(1, 0, 0, 1);
    Ball b0 = buf.balls[idx];
    Ball b1 = buf.balls[idy];
    ivec3 disvec = b0.pos - b1.pos;
    float dis = length(disvec);
    ivec3 dir = disvec/int(dis);
    int rad = b0.rad + b1.rad;
    
    int acc = int(rad-dis);
    
    ivec3 accvec = acc*dir;
    
    buf.balls[idx].vel += accvec;
    buf.balls[idy].vel -= accvec;