-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic right-handed orthographic matrix function. (#33)
* Basic right-handed orthographic matrix function. A little WIP at the moment still, but it's Code That I've Used So I Know It Works(tm). Barring typos, I guess. Also checked against `glm::ortho`. I agree that we do want actual unit tests though, so that's what I'm going to attempt next. Will resolve #32. * Added unit tests for Mat4::orthographic_rh() Which actually revealed significant bugs. XD Well, that's what the test is for! * aw heck, I left in commented-out code. Removed.
- Loading branch information
1 parent
d6e6d9c
commit f4eb102
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -540,6 +540,24 @@ impl Mat4 { | |
) | ||
} | ||
|
||
/// Build right-handed orthographic projection matrix with the specified bounds and depth range. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bitshifter
Owner
|
||
pub fn orthographic_rh(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) -> Mat4 { | ||
let a = 2.0 / (right - left); | ||
let b = 2.0 / (top - bottom); | ||
let c = -2.0 / (far - near); | ||
let d1 = -(right + left) / (right - left); | ||
let d2 = -(top + bottom) / (top - bottom); | ||
let d3 = -(far + near) / (far - near); | ||
|
||
Mat4::from_cols( | ||
Vec4::new(a, 0.0, 0.0, 0.0), | ||
Vec4::new(0.0, b, 0.0, 0.0), | ||
Vec4::new(0.0, 0.0, c, 0.0), | ||
Vec4::new(d1, d2, d3, 1.0), | ||
) | ||
} | ||
|
||
|
||
#[inline] | ||
pub fn mul_vec4(&self, other: Vec4) -> Vec4 { | ||
let mut res = self.x_axis * other.dup_x(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit f4eb102
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I should have edited the commit message when I squashed it. That's what I get for merging PRs on my phone :)
It should also be mentioned in the comment that it creates a matrix for traditional OpenGL conventions with clip space Z from -1 to 1, instead of the D3D/Vulkan convention of 0 to 1.
For reference, here's a VK convention ortho matrix:
https://github.com/PacktPublishing/Vulkan-Cookbook/blob/5072918c059d3e6e18f951ecb008523c32ffb7b6/Library/Source%20Files/10%20Helper%20Recipes/05%20Preparing%20an%20orthographic%20projection%20matrix.cpp