gutted and playing with pixel manipulation

This commit is contained in:
2019-06-06 22:52:56 -07:00
parent 94ce0bcd30
commit f844982553
8 changed files with 93 additions and 396 deletions

View File

@@ -5,24 +5,20 @@
extern crate quick_xml;
extern crate sfml;
extern crate cgmath;
extern crate image;
mod slider;
mod timer;
mod player;
mod input;
mod util;
mod entstate;
mod resources;
mod collision;
use crate::player::Player;
use crate::timer::Timer;
use crate::input::Input;
use crate::entstate::EntState;
use crate::resources::Resources;
use crate::collision::Collision;
use crate::slider::Slider;
extern crate nalgebra as na;
extern crate ncollide2d;
use image::{GenericImageView, GenericImage, DynamicImage, Pixel, SubImage};
use sfml::graphics::{
Color, RenderTarget, RenderWindow,
@@ -30,34 +26,48 @@ use sfml::graphics::{
use sfml::window::{ Event, Key, Style};
use sfml::system::Vector2 as sfVec2;
fn surrounding_pixels(x: u32, y: u32, img: &DynamicImage) -> Vec<image::Rgba<u8>> {
let mut pixels: Vec<image::Rgba<u8>> = Vec::new();
if img.in_bounds(x+1, y+1) {pixels.push(img.get_pixel(x+1, y+1))}
if img.in_bounds(x+1, y) {pixels.push(img.get_pixel(x+1, y))}
if img.in_bounds(x+1, y-1) {pixels.push(img.get_pixel(x+1, y-1))}
if img.in_bounds(x, y+1) {pixels.push(img.get_pixel(x, y+1))}
if img.in_bounds(x, y-1) {pixels.push(img.get_pixel(x, y-1))}
if img.in_bounds(x-1, y+1) {pixels.push(img.get_pixel(x-1, y+1))}
if img.in_bounds(x-1, y) {pixels.push(img.get_pixel(x-1, y))}
if img.in_bounds(x-1, y-1) {pixels.push(img.get_pixel(x-1, y-1))}
pixels
}
fn main() {
let mut img = image::open("test.jpg").unwrap();
let xy = img.dimensions();
// Resources
// Holds textures and their descriptions
for x in 0..xy.0 {
for y in 0..xy.1 {
let mut pixel = img.get_pixel(x, y);
// Collision
// Holds the BVT which has a reference or owns the Sprite
let v = surrounding_pixels(x, y, &img);
// EntState
// Holds the entities and the player
// let mut avg: Pixel;
//
// for p in v {
// avg += p;
// }
// Entities (Sprites) have a texture so Resources must live longer
// Collision has references to sprites so EntState must live longer
pixel.data[0] = 1;
// Resources { EntState { Collision } } }
let mut resources = Resources::new();
let mut collision = Collision::new();
let mut state = EntState::new();
// state.read_static_entities(String::from("static_entities.txt"), &resources);
//state.read_static_entities(String::from("static_entities.txt"), &resources);
//state.read_dynamic_entities(String::from("dynamic_entities.txt"));
//state.gen_bvt();
img.put_pixel(x, y, pixel);
}
}
img.save("fractal.png").unwrap();
let mut window = RenderWindow::new(
(512, 512),
@@ -66,11 +76,12 @@ fn main() {
&Default::default(),
);
let mut player = Player::new();
let mut timer = Timer::new();
let mut input = Input::new();
let mut slider = Slider::new(40.0, None);
let step_size: f32 = 0.005;
let mut elapsed_time: f32;
let mut delta_time: f32;
@@ -93,16 +104,12 @@ fn main() {
}
if input.is_held(Key::W) {
player.impulse(&sfVec2::new(0.0, -1.0));
}
if input.is_held(Key::A) {
player.impulse(&sfVec2::new(-1.0, 0.0));
}
if input.is_held(Key::S) {
player.impulse(&sfVec2::new(0.0, 1.0));
}
if input.is_held(Key::D) {
player.impulse(&sfVec2::new(1.0, 0.0));
}
elapsed_time = timer.elap_time();
@@ -117,34 +124,9 @@ fn main() {
accumulator_time -= step_size;
}
// // intersection test
// let mut interferences = Vec::new();
// {
// // Get the AABB bounding box
// let (bv, _) = player.future_bounding_aabb(delta_time);
// let mut thing = BoundingVolumeInterferencesCollector::new(&bv, &mut interferences);
// bvt.visit(&mut thing);
// }
//
// let collision_rect = player.collision(&interferences, delta_time);
player.update(delta_time);
//
// let mut collision_sprite = RectangleShape::new();
// collision_sprite.set_position((collision_rect.left, collision_rect.top));
// collision_sprite.set_size((collision_rect.width, collision_rect.height));
window.clear(&Color::BLACK);
window.draw(&player);
//window.draw(&collision_sprite);
// for ent in state.static_entities.get_mut().iter() {
// window.draw(ent);
// }
//
// for ent in state.dynamic_entities.get_mut().iter() {
// window.draw(ent);
// }
window.draw(&slider);
window.display();