Fix texture rotation issues

This commit is contained in:
Thinkofname 2016-03-30 00:36:07 +01:00
parent ec50947617
commit 4fde9161fe
1 changed files with 33 additions and 33 deletions

View File

@ -417,28 +417,28 @@ impl Factory {
let tw = texture.get_width() as i16; let tw = texture.get_width() as i16;
let th = texture.get_height() as i16; let th = texture.get_height() as i16;
if face.rotation > 0 { if face.rotation > 0 {
let x = ux1; let ox1 = ux1;
let y = uy1; let ox2 = ux2;
let w = ux2 - ux1; let oy1 = uy1;
let h = uy2 - uy1; let oy2 = uy2;
match face.rotation { match face.rotation {
270 => { 270 => {
uy2 = x + w; uy1 = tw*16 - ox2;
ux1 = tw*16 - (y + h); uy2 = tw*16 - ox1;
ux2 = tw*16 - y; ux1 = oy1;
uy1 = x; ux2 = oy2;
}, },
180 => { 180 => {
uy1 = th*16 - (y + h); uy1 = th*16 - oy2;
uy2 = th*16 - y; uy2 = th*16 - oy1;
ux1 = x + w; ux1 = tw*16 - ox2;
ux2 = x; ux2 = tw*16 - ox1;
}, },
90 => { 90 => {
uy2 = x; uy1 = ox1;
uy1 = x + w; uy2 = ox2;
ux2 = y + h; ux1 = th*16 - oy2;
ux1 = y; ux2 = th*16 - oy1;
}, },
_ => {}, _ => {},
} }
@ -543,7 +543,7 @@ impl Factory {
} }
if face.rotation > 0 { if face.rotation > 0 {
let rot_y = (face.rotation as f64 * (::std::f64::consts::PI / 180.0)) as f32; let rot_y = (-face.rotation as f64 * (::std::f64::consts::PI / 180.0)) as f32;
let c = rot_y.cos() as i16; let c = rot_y.cos() as i16;
let s = rot_y.sin() as i16; let s = rot_y.sin() as i16;
let x = v.toffsetx - 8*tw; let x = v.toffsetx - 8*tw;
@ -557,10 +557,10 @@ impl Factory {
let rot_y = (raw.y * (::std::f64::consts::PI / 180.0)) as f32; let rot_y = (raw.y * (::std::f64::consts::PI / 180.0)) as f32;
let c = rot_y.cos() as i16; let c = rot_y.cos() as i16;
let s = rot_y.sin() as i16; let s = rot_y.sin() as i16;
let x = v.toffsetx - 8*16; let x = v.toffsetx - 8*tw;
let y = v.toffsety - 8*16; let y = v.toffsety - 8*th;
v.toffsetx = 8*16 + (x*c - y*s); v.toffsetx = 8*tw + (x*c - y*s);
v.toffsety = 8*16 + (y*c + x*s); v.toffsety = 8*th + (y*c + x*s);
} }
if raw.uvlock && raw.x > 0.0 if raw.uvlock && raw.x > 0.0
@ -568,10 +568,10 @@ impl Factory {
let rot_x = (raw.x * (::std::f64::consts::PI / 180.0)) as f32; let rot_x = (raw.x * (::std::f64::consts::PI / 180.0)) as f32;
let c = rot_x.cos() as i16; let c = rot_x.cos() as i16;
let s = rot_x.sin() as i16; let s = rot_x.sin() as i16;
let x = v.toffsetx - 8*16; let x = v.toffsetx - 8*tw;
let y = v.toffsety - 8*16; let y = v.toffsety - 8*th;
v.toffsetx = 8*16 + (x*c - y*s); v.toffsetx = 8*tw + (x*c - y*s);
v.toffsety = 8*16 + (y*c + x*s); v.toffsety = 8*th + (y*c + x*s);
} }
if let Some(r) = el.rotation.as_ref() { if let Some(r) = el.rotation.as_ref() {
@ -610,17 +610,17 @@ impl Factory {
} }
const FACE_ROTATION: &'static [Direction] = &[ const FACE_ROTATION: &'static [Direction] = &[
Direction::North, Direction::North,
Direction::East, Direction::East,
Direction::South, Direction::South,
Direction::West, Direction::West,
]; ];
const FACE_ROTATION_X: &'static [Direction] = &[ const FACE_ROTATION_X: &'static [Direction] = &[
Direction::North, Direction::North,
Direction::Down, Direction::Down,
Direction::South, Direction::South,
Direction::Up, Direction::Up,
]; ];
fn rotate_direction(val: Direction, offset: i32, rots: &[Direction], invalid: &[Direction]) -> Direction { fn rotate_direction(val: Direction, offset: i32, rots: &[Direction], invalid: &[Direction]) -> Direction {