Skip to content

Commit

Permalink
add an option to specify the location of the camera; fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Hlusička committed Sep 12, 2016
1 parent 77dea9b commit 50dc1ad
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
11 changes: 10 additions & 1 deletion scenes/4d_room.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"Universe4": {
"camera": {
"FreeCamera4": []
"FreeCamera4::new_with_location": [
{
"Point4": [
-10,
0,
0,
0
]
}
]
},
"entities": [
{
Expand Down
24 changes: 21 additions & 3 deletions src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,22 +1329,34 @@ impl Parser {
}
}

// TODO: Add optional parameters via `Option<$($item_type:tt)+>`
add_deserializer! {
"PitchYawCamera3", "PitchYawCamera3::new";
-> Box<Camera3<F>> {
Box::new(PitchYawCamera3::new())
}
}

// TODO: Add optional parameters via `Option<$($item_type:tt)+>`
add_deserializer! {
"PitchYawCamera3::new_with_location";
[location: Point3<F>] -> Box<Camera3<F>> {
Box::new(PitchYawCamera3::new_with_location(location))
}
}

add_deserializer! {
"FreeCamera3", "FreeCamera3::new";
-> Box<Camera3<F>> {
Box::new(FreeCamera3::new())
}
}

add_deserializer! {
"FreeCamera3::new_with_location";
[location: Point3<F>] -> Box<Camera3<F>> {
Box::new(FreeCamera3::new_with_location(location))
}
}

add_deserializer! {
"Universe4", "Universe4::new";
[camera: Box<Camera4<F>>]
Expand All @@ -1360,13 +1372,19 @@ impl Parser {
}
}

// TODO: Add optional parameters via `Option<$($item_type:tt)+>`
add_deserializer! {
"FreeCamera4", "FreeCamera4::new";
-> Box<Camera4<F>> {
Box::new(FreeCamera4::new())
}
}

add_deserializer! {
"FreeCamera4::new_with_location";
[location: Point4<F>] -> Box<Camera4<F>> {
Box::new(FreeCamera4::new_with_location(location))
}
}
}

parser
Expand Down
19 changes: 19 additions & 0 deletions src/universe/d3/entity/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ impl<F: CustomFloat> Camera3Data<F> {
}
}

pub fn new_with_location(location: Point3<F>) -> Self {
Camera3Data {
location: location,
.. Self::new()
}
}

fn get_left(&self) -> Vector3<F> {
na::cross(&self.up, &self.forward).normalize()
}
Expand All @@ -65,6 +72,12 @@ impl<F: CustomFloat> PitchYawCamera3<F> {
}
}

pub fn new_with_location(location: Point3<F>) -> Self {
PitchYawCamera3 {
data: Camera3Data::new_with_location(location)
}
}

fn update_rotation(&mut self, context: &SimulationContext) {
let delta_mouse_float: Vector2<F> =
Vector2::new(<F as NumCast>::from(context.delta_mouse.x).unwrap(),
Expand Down Expand Up @@ -266,6 +279,12 @@ impl<F: CustomFloat> FreeCamera3<F> {
}
}

pub fn new_with_location(location: Point3<F>) -> Self {
FreeCamera3 {
data: Camera3Data::new_with_location(location)
}
}

fn update_rotation(&mut self, delta_millis: F, context: &SimulationContext) {
let delta_mouse_float: Vector2<F> =
Vector2::new(<F as NumCast>::from(context.delta_mouse.x).unwrap(),
Expand Down
7 changes: 7 additions & 0 deletions src/universe/d4/entity/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ impl<F: CustomFloat> FreeCamera4<F> {
}
}

pub fn new_with_location(location: Point4<F>) -> Self {
FreeCamera4 {
location: location,
.. Self::new()
}
}

fn update_rotation(&mut self, delta_millis: F, context: &SimulationContext) {
let pressed_keys: &HashSet<VirtualKeyCode> = context.pressed_keys();
let mut angle: F = <F as Zero>::zero();
Expand Down

0 comments on commit 50dc1ad

Please sign in to comment.