1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 24, 2016 - 8:08:15 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 Scale.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
|
|
|
use \DOMAttr; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The scale component defines a shrinking, stretching, or skewing transformation of an entity. |
31
|
|
|
* |
32
|
|
|
* It takes three scaling factors for the X, Y, and Z axes. |
33
|
|
|
* Scaling factors can be negative, which results in a reflection. |
34
|
|
|
* |
35
|
|
|
* All entities inherently have the rotation component. |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
class Scale implements ComponentInterface |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Scaling factor in the X direction. |
42
|
|
|
* |
43
|
|
|
* @var integer|double $x |
44
|
|
|
*/ |
45
|
|
|
protected $x; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Scaling factor in the Y direction. |
49
|
|
|
* |
50
|
|
|
* @var integer|double $y |
51
|
|
|
*/ |
52
|
|
|
protected $y; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Scaling factor in the Z direction. |
56
|
|
|
* |
57
|
|
|
* @var integer|double $z |
58
|
|
|
*/ |
59
|
|
|
protected $z; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Constructor |
63
|
|
|
* |
64
|
|
|
* @param integer|double $x |
65
|
|
|
* @param integer|double $y |
66
|
|
|
* @param integer|double $z |
67
|
|
|
*/ |
68
|
51 |
|
public function __construct(float $x = 0, float $y = 0, float $z = 0) |
69
|
|
|
{ |
70
|
51 |
|
$this->update($x, $y, $z); |
71
|
51 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get Component scripts |
75
|
|
|
* |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
1 |
|
public function getScripts(): array |
81
|
|
|
{ |
82
|
1 |
|
return array(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Does component have DOM Atributes |
87
|
|
|
* |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
* |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
5 |
|
public function hasDOMAttributes(): bool |
93
|
|
|
{ |
94
|
5 |
|
return ! empty(get_object_vars($this)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Remove default DOMElement Attributes which are not required |
99
|
|
|
* |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
5 |
|
public function removeDefaultDOMAttributes() |
103
|
|
|
{ |
104
|
5 |
|
if (empty($this->x) && empty($this->y) && empty($this->z)) { |
105
|
4 |
|
unset($this->x); |
106
|
4 |
|
unset($this->y); |
107
|
4 |
|
unset($this->z); |
108
|
|
|
} |
109
|
5 |
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get DOMAttr for the entity |
113
|
|
|
* |
114
|
|
|
* @return DOMAttr |
115
|
|
|
*/ |
116
|
1 |
|
public function getDOMAttributes(): DOMAttr |
117
|
|
|
{ |
118
|
1 |
|
return new \DOMAttr('scale', sprintf('%s %s %s', $this->x, $this->y, $this->z)); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Update scale |
123
|
|
|
* |
124
|
|
|
* If any of the scaling factors are set to 0, then A-Frame will |
125
|
|
|
* assign instead an extremely small value such that things don’t break. |
126
|
|
|
* |
127
|
|
|
* @param integer|double $x |
128
|
|
|
* @param integer|double $y |
129
|
|
|
* @param integer|double $z |
130
|
|
|
*/ |
131
|
51 |
|
public function update(float $x = 0, float $y = 0, float $z = 00) |
132
|
|
|
{ |
133
|
51 |
|
$this->x = $x ?? 0; |
134
|
51 |
|
$this->y = $y ?? 0; |
135
|
51 |
|
$this->z = $z ?? 0; |
136
|
51 |
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
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.