1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jul 4, 2016 - 3:21:00 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 WASDControlsComponent.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\Core\Components\WASDControls; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\Core\Components\WASDControlsCMPTIF; |
27
|
|
|
use \AframeVR\Core\Helpers\ComponentAbstract; |
28
|
|
|
|
29
|
|
|
class WASDControlsComponent extends ComponentAbstract implements WASDControlsCMPTIF |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Initialize Component |
34
|
|
|
* |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
* |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
9 |
|
public function initializeComponent(): bool |
40
|
|
|
{ |
41
|
9 |
|
$this->setDomAttribute('wasd-controls'); |
42
|
9 |
|
return true; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Entity acceleration |
47
|
|
|
* |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
* |
50
|
|
|
* @param int $acceleration |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
2 |
|
public function acceleration(int $acceleration = 65) |
54
|
|
|
{ |
55
|
2 |
|
$this->dom_attributes['acceleration'] = $acceleration; |
56
|
2 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* AD Axis |
60
|
|
|
* |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
* |
63
|
|
|
* @param string $axis |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
1 |
|
public function adAxis(string $axis = 'x') |
67
|
|
|
{ |
68
|
1 |
|
$this->dom_attributes['adAxis'] = $axis; |
69
|
1 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* AD Inverted |
73
|
|
|
* |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
* |
76
|
|
|
* @param bool $inverted |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
1 |
|
public function adInverted(bool $inverted = false) |
80
|
|
|
{ |
81
|
1 |
|
$this->dom_attributes['adInverted'] = $inverted; |
82
|
1 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Easing |
86
|
|
|
* |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
* |
89
|
|
|
* @param int $easing |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
1 |
|
public function easing(int $easing = 20) |
93
|
|
|
{ |
94
|
1 |
|
$this->dom_attributes['easing'] = $easing; |
95
|
1 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Enaled |
99
|
|
|
* |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
* |
102
|
|
|
* @param bool $enabled |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
6 |
|
public function enabled(bool $enabled = true) |
106
|
|
|
{ |
107
|
6 |
|
$this->dom_attributes['enabled'] = $enabled ? 'true' : 'false'; |
108
|
6 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Fly |
112
|
|
|
* |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
* |
115
|
|
|
* @param bool $fly |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
1 |
|
public function fly(bool $fly = false) |
119
|
|
|
{ |
120
|
1 |
|
$this->dom_attributes['fly'] = $fly ? 'true' : 'false'; |
121
|
1 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* WS Axis |
125
|
|
|
* |
126
|
|
|
* {@inheritdoc} |
127
|
|
|
* |
128
|
|
|
* @param string $axis |
129
|
|
|
* @return void |
130
|
|
|
*/ |
131
|
1 |
|
public function wsAxis(string $axis = 'z') |
132
|
|
|
{ |
133
|
1 |
|
$this->dom_attributes['wsAxis'] = $axis; |
134
|
1 |
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* WS Inverted |
138
|
|
|
* |
139
|
|
|
* {@inheritdoc} |
140
|
|
|
* |
141
|
|
|
* @param bool $inverted |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
1 |
|
public function wsInverted(bool $inverted = false) |
145
|
|
|
{ |
146
|
1 |
|
$this->dom_attributes['wsInverted'] = $inverted ? 'true' : 'false';; |
|
|
|
|
147
|
1 |
|
} |
148
|
|
|
} |
149
|
|
|
|
Let’s take a look at an example: