Skip to content

Commit

Permalink
Merge pull request #6 from bwasty/pbr_refactor
Browse files Browse the repository at this point in the history
Finish basic PBR integration
  • Loading branch information
bwasty authored Sep 22, 2017
2 parents 2d72d85 + 689ed63 commit 5188436
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 138 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ matrix:
- env: TARGET=x86_64-unknown-linux-gnu
#- env: TARGET=x86_64-unknown-linux-musl

# # OSX
# - env: TARGET=x86_64-apple-darwin
# os: osx
# OSX
- env: TARGET=x86_64-apple-darwin
os: osx

# Testing other channels
- env: TARGET=x86_64-unknown-linux-gnu
rust: nightly
# - env: TARGET=x86_64-apple-darwin
# os: osx
# rust: nightly
- env: TARGET=x86_64-apple-darwin
os: osx
rust: nightly

before_install: set -e

Expand Down
51 changes: 32 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "Unlicense"
name = "gltf-viewer"
readme = "README.md"
repository = "https://github.com/bwasty/gltf-viewer"
version = "0.0.4-pre"
version = "0.1.0-pre"

[badges]

Expand All @@ -36,18 +36,18 @@ simplelog = "0.4.2"
itertools = "0.6.1"

[dependencies.gltf]
version = "0.9.0"
version = "0.9.2"
# git = "https://github.com/alteous/gltf"
# branch = "simplify"
features = ["names"]

[dependencies.gltf-importer]
version = "0.9.0"
version = "0.9.2"
# git = "https://github.com/alteous/gltf"
# branch = "simplify"

[dependencies.gltf-utils]
version = "0.1.0"
version = "0.9.2"
# git = "https://github.com/alteous/gltf"
# branch = "simplify"

Expand Down
19 changes: 15 additions & 4 deletions src/camera.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cgmath;
use cgmath::vec3;
use cgmath::{vec3, Deg, perspective};
use cgmath::prelude::*;

type Point3 = cgmath::Point3<f32>;
Expand Down Expand Up @@ -31,7 +31,6 @@ pub struct Camera {
pub position: Point3,

/// mutually exlusive: if center is set, it is used
// TODO!!!: consider this (center) for navigation
pub front: Vector3,
pub center: Option<Point3>,

Expand All @@ -45,6 +44,7 @@ pub struct Camera {
pub movement_speed: f32,
pub mouse_sensitivity: f32,
pub zoom: f32,
pub aspect_ratio: f32,

// pub moving_up: bool,
pub moving_left: bool,
Expand All @@ -68,6 +68,7 @@ impl Default for Camera {
movement_speed: SPEED,
mouse_sensitivity: SENSITIVTY,
zoom: ZOOM,
aspect_ratio: 1.0,

// moving_up: false,
moving_left: false,
Expand All @@ -76,15 +77,16 @@ impl Default for Camera {
moving_forward: false,
moving_backward: false,
};
// TODO!!: overriding default order...? -> NO!
camera.update_camera_vectors();
camera
}
}

impl Camera {
// TODO!: cache matrices? doesn't change every frame...
/// Returns the view matrix calculated using Eular Angles and the LookAt Matrix
pub fn get_view_matrix(&self) -> Matrix4 {
// TODO!: cache? doesn't change every frame...
pub fn view_matrix(&self) -> Matrix4 {
if let Some(center) = self.center {
Matrix4::look_at(self.position, center, self.up)
}
Expand All @@ -93,6 +95,11 @@ impl Camera {
}
}

// TODO!!: cache + avoid repeatedly setting same uniform
pub fn projection_matrix(&self) -> Matrix4 {
perspective(Deg(self.zoom), self.aspect_ratio, 0.01, 1000.0)
}

pub fn update(&mut self, delta_time: f64) {
let velocity = self.movement_speed * delta_time as f32;
if self.moving_forward {
Expand Down Expand Up @@ -156,6 +163,10 @@ impl Camera {

/// Calculates the front vector from the Camera's (updated) Eular Angles
fn update_camera_vectors(&mut self) {
if let Some(center) = self.center {
self.front = center - self.position; // TODO!!!: overwritten again immediately...
self.center = None;
}
// Calculate the new front vector
let front = Vector3 {
x: self.yaw.to_radians().cos() * self.pitch.to_radians().cos(),
Expand Down
Loading

0 comments on commit 5188436

Please sign in to comment.