1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jul 4, 2016 - 1:31:08 AM |
5
|
|
|
* Contact [email protected] |
6
|
|
|
* @copyright 2016 Marko Kungla - https://github.com/mkungla |
7
|
|
|
* @license The MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* @category AframeVR |
10
|
|
|
* @package aframe-php |
11
|
|
|
* |
12
|
|
|
* Lang PHP (php version >= 7) |
13
|
|
|
* Encoding UTF-8 |
14
|
|
|
* File Camera.php |
15
|
|
|
* Code format PSR-2 and 12 |
16
|
|
|
* @link https://github.com/mkungla/aframe-php |
17
|
|
|
^ @issues https://github.com/mkungla/aframe-php/issues |
18
|
|
|
* ******************************************************************** |
19
|
|
|
* Contributors: |
20
|
|
|
* @author Marko Kungla <[email protected]> |
21
|
|
|
* ******************************************************************** |
22
|
|
|
* Comments: |
23
|
|
|
* @formatter:on */ |
24
|
|
|
namespace AframeVR\Extras\Primitives; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\Extras\Primitives\CameraInterface; |
27
|
|
|
use \AframeVR\Core\Entity; |
28
|
|
|
use \AframeVR\Core\Helpers\MeshAttributes; |
29
|
|
|
|
30
|
|
|
class Camera extends Entity implements CameraInterface |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Init <a-box> |
34
|
|
|
* |
35
|
|
|
* The box primitive, formerly called <a-cube>, creates shapes such as boxes, cubes, or walls. |
36
|
|
|
* It is an entity that prescribes the geometry with its geometric primitive set to box. |
37
|
|
|
* |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
6 |
|
public function init() |
43
|
|
|
{ |
44
|
6 |
|
$this->entity()->component('Camera'); |
45
|
6 |
|
$this->lookControls(true); |
46
|
6 |
|
$this->wasdControls(true); |
47
|
6 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Set defaults |
51
|
|
|
* |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
6 |
|
public function defaults() |
57
|
|
|
{ |
58
|
6 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* camera.active |
62
|
|
|
* |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
* |
65
|
|
|
* @param bool $active |
66
|
|
|
* @return CameraInterface |
67
|
|
|
*/ |
68
|
1 |
|
public function active(bool $active = false): CameraInterface |
69
|
|
|
{ |
70
|
1 |
|
$this->entity()->component('Camera')->active($active); |
71
|
1 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* camera.far |
76
|
|
|
* |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
* |
79
|
|
|
* @param int|float $far |
80
|
|
|
* @return CameraInterface |
81
|
|
|
*/ |
82
|
1 |
|
public function far(float $far = 10000): CameraInterface |
83
|
|
|
{ |
84
|
1 |
|
$this->entity()->component('Camera')->far($far); |
85
|
1 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* camera.fov |
90
|
|
|
* |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
* |
93
|
|
|
* @param int|float $fov |
94
|
|
|
* @return CameraInterface |
95
|
|
|
*/ |
96
|
1 |
|
public function fov(float $fov = 10000): CameraInterface |
97
|
|
|
{ |
98
|
1 |
|
$this->entity()->component('Camera')->fov($fov); |
99
|
1 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* look-controls.enabled |
104
|
|
|
* |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
* |
107
|
|
|
* @param bool $look_controls |
108
|
|
|
* @return CameraInterface |
109
|
|
|
*/ |
110
|
6 |
|
public function lookControls(bool $look_controls = true): CameraInterface |
111
|
|
|
{ |
112
|
6 |
|
$this->entity()->component('LookControls')->enabled($look_controls); |
113
|
6 |
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* camera.near |
118
|
|
|
* |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
* |
121
|
|
|
* @param float $near |
122
|
|
|
* @return CameraInterface |
123
|
|
|
*/ |
124
|
4 |
|
public function near(float $near = 0.5): CameraInterface |
125
|
|
|
{ |
126
|
4 |
|
$this->entity()->component('Camera')->near($near); |
127
|
4 |
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* wasd-controls.enabled |
132
|
|
|
* |
133
|
|
|
* {@inheritdoc} |
134
|
|
|
* |
135
|
|
|
* @param bool $wasd_controls |
136
|
|
|
* @return CameraInterface |
137
|
|
|
*/ |
138
|
6 |
|
public function wasdControls(bool $wasd_controls = true): CameraInterface |
139
|
|
|
{ |
140
|
6 |
|
$this->entity()->component('WASDControls')->enabled($wasd_controls); |
141
|
6 |
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* camera.zoom |
146
|
|
|
* |
147
|
|
|
* {@inheritdoc} |
148
|
|
|
* |
149
|
|
|
* @param int|float $zoom |
150
|
|
|
* @return CameraInterface |
151
|
|
|
*/ |
152
|
1 |
|
public function zoom(float $zoom = 1): CameraInterface |
153
|
|
|
{ |
154
|
1 |
|
$this->entity()->component('Camera')->zoom($zoom); |
155
|
1 |
|
return $this; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|