1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 21, 2016 - 12:10:50 PM |
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 Rotation.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\Components; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\ComponentInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The rotation component defines the orientation of an entity. |
30
|
|
|
* |
31
|
|
|
* It takes the roll (x), pitch (y), and yaw (z) as three space-delimited numbers indicating degrees of rotation. |
32
|
|
|
* |
33
|
|
|
* All entities inherently have the rotation component. |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
class Rotation implements ComponentInterface |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Negative X axis extends left. |
40
|
|
|
* Positive X Axis extends right. |
41
|
|
|
* |
42
|
|
|
* @var int $x |
43
|
|
|
*/ |
44
|
|
|
protected $x; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Negative Y axis extends up. |
48
|
|
|
* Positive Y Axis extends down. |
49
|
|
|
* |
50
|
|
|
* @var int $y |
51
|
|
|
*/ |
52
|
|
|
protected $y; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Negative Z axis extends in. |
56
|
|
|
* Positive Z Axis extends out. |
57
|
|
|
* |
58
|
|
|
* @var int $z |
59
|
|
|
*/ |
60
|
|
|
protected $z; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set initial coordinates |
64
|
|
|
* |
65
|
|
|
* @param string $coordinates |
|
|
|
|
66
|
|
|
*/ |
67
|
8 |
|
public function __construct($x = 0, $y = 0, $z = 0) |
68
|
|
|
{ |
69
|
8 |
|
$this->update($x, $y, $z); |
70
|
8 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get Component scripts |
74
|
|
|
* |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function getScripts(): array |
80
|
|
|
{ |
81
|
|
|
return array(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Does component have DOM Atributes |
86
|
|
|
* |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
* |
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
|
|
public function hasDOMAttributes(): bool |
92
|
|
|
{ |
93
|
|
|
return ! empty(get_object_vars($this)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Remove default DOMElement Attributes which are not required |
98
|
|
|
* |
99
|
|
|
* @return void |
100
|
|
|
*/ |
101
|
|
|
public function removeDefaultDOMAttributes() |
102
|
|
|
{ |
103
|
|
|
if ($this->x === 0 && $this->y === 0 && $this->z === 0) { |
104
|
|
|
unset($this->x); |
105
|
|
|
unset($this->y); |
106
|
|
|
unset($this->z); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get DOMAttr for the entity |
112
|
|
|
* |
113
|
|
|
* @return DOMAttr |
|
|
|
|
114
|
|
|
*/ |
115
|
|
|
public function getDOMAttributes(): \DOMAttr |
116
|
|
|
{ |
117
|
|
|
return new \DOMAttr('rotation', sprintf('%s %s %s', $this->x, $this->y, $this->z)); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Update coordinates |
122
|
|
|
* |
123
|
|
|
* @param string $coordinates |
|
|
|
|
124
|
|
|
*/ |
125
|
8 |
|
public function update($x = 0, $y = 0, $z = 0) |
126
|
|
|
{ |
127
|
8 |
|
$this->x = $x ?? 0; |
128
|
8 |
|
$this->y = $y ?? 0; |
129
|
8 |
|
$this->z = $z ?? 0; |
130
|
8 |
|
} |
131
|
|
|
} |
132
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.