Skip to content

Commit 50dc1ad

Browse files
author
Jakub Hlusička
committed
add an option to specify the location of the camera; fixes #17
1 parent 77dea9b commit 50dc1ad

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

scenes/4d_room.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
{
22
"Universe4": {
33
"camera": {
4-
"FreeCamera4": []
4+
"FreeCamera4::new_with_location": [
5+
{
6+
"Point4": [
7+
-10,
8+
0,
9+
0,
10+
0
11+
]
12+
}
13+
]
514
},
615
"entities": [
716
{

src/scene.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,22 +1329,34 @@ impl Parser {
13291329
}
13301330
}
13311331

1332-
// TODO: Add optional parameters via `Option<$($item_type:tt)+>`
13331332
add_deserializer! {
13341333
"PitchYawCamera3", "PitchYawCamera3::new";
13351334
-> Box<Camera3<F>> {
13361335
Box::new(PitchYawCamera3::new())
13371336
}
13381337
}
13391338

1340-
// TODO: Add optional parameters via `Option<$($item_type:tt)+>`
1339+
add_deserializer! {
1340+
"PitchYawCamera3::new_with_location";
1341+
[location: Point3<F>] -> Box<Camera3<F>> {
1342+
Box::new(PitchYawCamera3::new_with_location(location))
1343+
}
1344+
}
1345+
13411346
add_deserializer! {
13421347
"FreeCamera3", "FreeCamera3::new";
13431348
-> Box<Camera3<F>> {
13441349
Box::new(FreeCamera3::new())
13451350
}
13461351
}
13471352

1353+
add_deserializer! {
1354+
"FreeCamera3::new_with_location";
1355+
[location: Point3<F>] -> Box<Camera3<F>> {
1356+
Box::new(FreeCamera3::new_with_location(location))
1357+
}
1358+
}
1359+
13481360
add_deserializer! {
13491361
"Universe4", "Universe4::new";
13501362
[camera: Box<Camera4<F>>]
@@ -1360,13 +1372,19 @@ impl Parser {
13601372
}
13611373
}
13621374

1363-
// TODO: Add optional parameters via `Option<$($item_type:tt)+>`
13641375
add_deserializer! {
13651376
"FreeCamera4", "FreeCamera4::new";
13661377
-> Box<Camera4<F>> {
13671378
Box::new(FreeCamera4::new())
13681379
}
13691380
}
1381+
1382+
add_deserializer! {
1383+
"FreeCamera4::new_with_location";
1384+
[location: Point4<F>] -> Box<Camera4<F>> {
1385+
Box::new(FreeCamera4::new_with_location(location))
1386+
}
1387+
}
13701388
}
13711389

13721390
parser

src/universe/d3/entity/camera.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ impl<F: CustomFloat> Camera3Data<F> {
4242
}
4343
}
4444

45+
pub fn new_with_location(location: Point3<F>) -> Self {
46+
Camera3Data {
47+
location: location,
48+
.. Self::new()
49+
}
50+
}
51+
4552
fn get_left(&self) -> Vector3<F> {
4653
na::cross(&self.up, &self.forward).normalize()
4754
}
@@ -65,6 +72,12 @@ impl<F: CustomFloat> PitchYawCamera3<F> {
6572
}
6673
}
6774

75+
pub fn new_with_location(location: Point3<F>) -> Self {
76+
PitchYawCamera3 {
77+
data: Camera3Data::new_with_location(location)
78+
}
79+
}
80+
6881
fn update_rotation(&mut self, context: &SimulationContext) {
6982
let delta_mouse_float: Vector2<F> =
7083
Vector2::new(<F as NumCast>::from(context.delta_mouse.x).unwrap(),
@@ -266,6 +279,12 @@ impl<F: CustomFloat> FreeCamera3<F> {
266279
}
267280
}
268281

282+
pub fn new_with_location(location: Point3<F>) -> Self {
283+
FreeCamera3 {
284+
data: Camera3Data::new_with_location(location)
285+
}
286+
}
287+
269288
fn update_rotation(&mut self, delta_millis: F, context: &SimulationContext) {
270289
let delta_mouse_float: Vector2<F> =
271290
Vector2::new(<F as NumCast>::from(context.delta_mouse.x).unwrap(),

src/universe/d4/entity/camera.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ impl<F: CustomFloat> FreeCamera4<F> {
4848
}
4949
}
5050

51+
pub fn new_with_location(location: Point4<F>) -> Self {
52+
FreeCamera4 {
53+
location: location,
54+
.. Self::new()
55+
}
56+
}
57+
5158
fn update_rotation(&mut self, delta_millis: F, context: &SimulationContext) {
5259
let pressed_keys: &HashSet<VirtualKeyCode> = context.pressed_keys();
5360
let mut angle: F = <F as Zero>::zero();

0 commit comments

Comments
 (0)