Skip to content

Commit

Permalink
Tilted Iso Alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Mar 20, 2024
1 parent bd5bdde commit 9721261
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
17 changes: 15 additions & 2 deletions shared/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ impl Camera {
Ray::new(out_origin, normalize(-w))
}

pub fn create_tilted_isometric_ray(&self, uv: Vec2f, screen: Vec2f, offset: Vec2f) -> Ray {
pub fn create_tilted_isometric_ray(
&self,
uv: Vec2f,
screen: Vec2f,
offset: Vec2f,
alignment: i32,
) -> Ray {
let ratio = screen.x / screen.y;
let pixel_size = Vec2f::new(1.0 / screen.x, 1.0 / screen.y);

Expand All @@ -194,7 +200,14 @@ impl Camera {
out_origin += vertical * (pixel_size.y * offset.y + uv.y - 0.5);
out_origin.y = cam_origin.y;

Ray::new(out_origin, normalize(vec3f(-0.35, -1.0, -0.35)))
Ray::new(
out_origin,
normalize(vec3f(
if alignment == 0 { -0.35 } else { 0.35 },
-1.0,
-0.35,
)),
)
}

/// Computes the orbi camera vectors. Based on https://www.shadertoy.com/view/ttfyzN
Expand Down
5 changes: 4 additions & 1 deletion shared/src/regionfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ impl RegionFX {

coll.set("", TheValue::Empty);

//coll.set("Tilted Iso Height", TheValue::FloatRange(3.0, 0.0..=20.0));
coll.set(
"Tilted Iso Alignment",
TheValue::TextList(0, vec![str!("Right"), str!("Left")]),
);
coll.set("Tilted Iso FoV", TheValue::FloatRange(70.0, 0.0..=80.0));
}
let mut meta = RegionFXMetaData::new();
Expand Down
33 changes: 22 additions & 11 deletions shared/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ impl Renderer {
}
}

let mut tilted_iso_alignment = 0;
if let Some(TheValue::TextList(value, _)) = region.regionfx.get(
str!("Camera"),
str!("Tilted Iso Alignment"),
&settings.time,
TheInterpolation::Switch,
) {
tilted_iso_alignment = value;
}

// Fill the code level with the blocking info and collect lights
let mut level = Level::new(region.width, region.height, settings.time);
region.fill_code_level(&mut level, &self.textures, update);
Expand All @@ -107,6 +117,7 @@ impl Renderer {
vec2f(xx / width_f, yy / height_f),
vec2f(width_f, height_f),
vec2f(1.0, 1.0),
tilted_iso_alignment,
)
} else if camera_mode == CameraMode::Pinhole {
camera.create_ray(
Expand Down Expand Up @@ -783,17 +794,6 @@ impl Renderer {
}
}

// if let Some(v) = region.regionfx.get(
// str!("Camera"),
// str!("Tilted Iso Height"),
// &settings.time,
// TheInterpolation::Linear,
// ) {
// if let Some(value) = v.to_f32() {
// tilted_iso_height = value;
// }
// }

if let Some(v) = region.regionfx.get(
str!("Camera"),
str!("Tilted Iso FoV"),
Expand Down Expand Up @@ -868,6 +868,16 @@ impl Renderer {
let width_f = width as f32;
let height_f = height as f32;

let mut tilted_iso_alignment = 0;
if let Some(TheValue::TextList(value, _)) = region.regionfx.get(
str!("Camera"),
str!("Tilted Iso Alignment"),
&settings.time,
TheInterpolation::Switch,
) {
tilted_iso_alignment = value;
}

let camera = Camera::new(ro, rd, fov);
let ray = if camera_type == CameraType::TiltedIso {
camera.create_tilted_isometric_ray(
Expand All @@ -877,6 +887,7 @@ impl Renderer {
),
vec2f(width_f, height_f),
vec2f(1.0, 1.0),
tilted_iso_alignment,
)
} else if camera_mode == CameraMode::Pinhole {
camera.create_ray(
Expand Down

0 comments on commit 9721261

Please sign in to comment.