Add rotation to structures rendering
This commit is contained in:
+12
-3
@@ -4,6 +4,7 @@ extern crate glium;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate load_file;
|
extern crate load_file;
|
||||||
|
|
||||||
|
use std::f32::consts::PI;
|
||||||
use glium::texture::SrgbTexture2d;
|
use glium::texture::SrgbTexture2d;
|
||||||
use phf::phf_map;
|
use phf::phf_map;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@@ -463,9 +464,17 @@ fn main() {
|
|||||||
out vec2 v_texture_coordinates;
|
out vec2 v_texture_coordinates;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
float cos_rotation = cos(w_rotation);
|
||||||
|
float sin_rotation = sin(w_rotation);
|
||||||
|
|
||||||
|
vec3 rotated_position = position;
|
||||||
|
|
||||||
|
rotated_position.x = cos_rotation * position.x + sin_rotation * position.z;
|
||||||
|
rotated_position.z = -sin_rotation * position.x + cos_rotation * position.z;
|
||||||
|
|
||||||
v_texture_index = texture_index;
|
v_texture_index = texture_index;
|
||||||
v_texture_coordinates = texture_coordinates;
|
v_texture_coordinates = texture_coordinates;
|
||||||
gl_Position = persp_matrix * view_matrix * vec4(position + w_position, 1.0);
|
gl_Position = persp_matrix * view_matrix * vec4(rotated_position + w_position, 1.0);
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
|
|
||||||
@@ -507,11 +516,11 @@ fn main() {
|
|||||||
let x: f32 = object_line_parts[1].parse().unwrap();
|
let x: f32 = object_line_parts[1].parse().unwrap();
|
||||||
let y: f32 = object_line_parts[2].parse().unwrap();
|
let y: f32 = object_line_parts[2].parse().unwrap();
|
||||||
let z = object_line_parts[3].parse().unwrap();
|
let z = object_line_parts[3].parse().unwrap();
|
||||||
let rotation = object_line_parts[4].parse().unwrap();
|
let rotation: f32 = object_line_parts[4].parse().unwrap();
|
||||||
let structure_per_instance: &mut Vec<PerInstance> = structures_per_instance.get_mut(structure_id).unwrap();
|
let structure_per_instance: &mut Vec<PerInstance> = structures_per_instance.get_mut(structure_id).unwrap();
|
||||||
structure_per_instance.push(PerInstance {
|
structure_per_instance.push(PerInstance {
|
||||||
w_position: (offset_x + x, z, offset_y + y),
|
w_position: (offset_x + x, z, offset_y + y),
|
||||||
w_rotation: rotation,
|
w_rotation: 2.0 * PI * rotation / 360.0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ pub struct CameraState {
|
|||||||
rotate_right: bool,
|
rotate_right: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const SPEED: f32 = 1.0; //1.0;
|
const SPEED: f32 = 10.0; //1.0;
|
||||||
|
|
||||||
impl CameraState {
|
impl CameraState {
|
||||||
pub fn new() -> CameraState {
|
pub fn new() -> CameraState {
|
||||||
CameraState {
|
CameraState {
|
||||||
aspect_ratio: 1_024.0 / 768.0,
|
aspect_ratio: 1_920.0 / 1_080.0,
|
||||||
// The second coordinate is for the altitude.
|
// The second coordinate is for the altitude.
|
||||||
position: (3_646.41, 12.3622, 13_113.7),
|
position: (3_646.41, 12.3622, 13_113.7),
|
||||||
direction: (0.0, 0.0, -1.0),
|
direction: (0.0, 0.0, -1.0),
|
||||||
|
|||||||
Reference in New Issue
Block a user