Skip to content

Commit 0a20e9e

Browse files
committed
Add camera matrix accessors
1 parent b4ce9c8 commit 0a20e9e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

core/src/render/cam.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,18 @@ impl<T> Camera<T> {
206206
}
207207

208208
impl<T: Transform> Camera<T> {
209+
/// Returns the camera matrix.
210+
pub fn world_to_view(&self) -> Mat4<World, View> {
211+
self.transform.world_to_view()
212+
}
213+
/// Returns the inverse camera matrix.
214+
pub fn view_to_world(&self) -> Mat4<View, World> {
215+
self.world_to_view().inverse()
216+
}
217+
209218
/// Returns the composed camera and projection matrix.
210219
pub fn world_to_project(&self) -> ProjMat3<World> {
211-
self.transform.world_to_view().then(&self.project)
220+
self.world_to_view().then(&self.project)
212221
}
213222

214223
/// Renders the given geometry from the viewpoint of this camera.

demos/src/bin/sprites.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn main() {
6464
let modelview = rotate_x(theta * 0.2)
6565
.then(&rotate_z(theta * 0.14))
6666
.to()
67-
.then(&cam.transform.world_to_view());
67+
.then(&cam.world_to_view());
6868

6969
render(
7070
&tris,

0 commit comments

Comments
 (0)