Compute angles for raycaster
This commit is contained in:
parent
3106b01f3f
commit
343ccdd12a
24
src/main.rs
24
src/main.rs
|
@ -14,7 +14,7 @@ struct Position {
|
|||
|
||||
struct Player {
|
||||
pos: Position,
|
||||
angle: f64,
|
||||
angle: f64, // radian or degree
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,10 +33,10 @@ fn main() {
|
|||
Tile::Wall, Tile::Wall, Tile::Wall, Tile::Wall, Tile::Wall,
|
||||
];
|
||||
|
||||
let mut player: Player;
|
||||
player.pos.x = 2.0;
|
||||
player.pos.y = 2.0;
|
||||
player.angle = 0.0;
|
||||
let mut player = Player { pos: Position { x: 2.0, y: 2.0}, angle: 0.0};
|
||||
|
||||
let horiz_fov = 90 as f64;
|
||||
//let height_unit = 64;
|
||||
|
||||
while let Some(event) = window.next() {
|
||||
let window_size = window.size();
|
||||
|
@ -64,6 +64,20 @@ fn main() {
|
|||
[0.0, h / 2.0, w, h / 2.0],
|
||||
context.transform,
|
||||
graphics);
|
||||
|
||||
// Walls
|
||||
let left = player.angle + (horiz_fov / 2.0);
|
||||
let right = player.angle - (horiz_fov / 2.0);
|
||||
// for every angle (range / w)
|
||||
let step = (left - right) / w;
|
||||
let mut ray_angle = left;
|
||||
for n in 0..(window_size.width - 1) {
|
||||
// cast a ray
|
||||
// see what wall it hits
|
||||
// compute wall height
|
||||
// draw wall portion
|
||||
ray_angle += step;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue