|
1
|
|
|
<?php |
|
2
|
|
|
/** @formatter:off |
|
3
|
|
|
* ****************************************************************** |
|
4
|
|
|
* Created by Marko Kungla on Jun 25, 2016 - 7:51:42 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 ScaleComponent.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\Scale; |
|
25
|
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\Core\Components\ScaleCMPTIF; |
|
27
|
|
|
use \AframeVR\Core\Helpers\ComponentAbstract; |
|
28
|
|
|
use \AframeVR\Core\Helpers\ComponentHelper; |
|
29
|
|
|
|
|
30
|
|
|
class ScaleComponent extends ComponentAbstract implements ScaleCMPTIF |
|
31
|
|
|
{ |
|
32
|
|
|
use ComponentHelper; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Initialize Scale Component |
|
36
|
|
|
* |
|
37
|
|
|
* The scale component defines a shrinking, stretching, or skewing transformation of an entity. |
|
38
|
|
|
* It takes three scaling factors for the X, Y, and Z axes. |
|
39
|
|
|
* |
|
40
|
|
|
* Scale compnent dom attribute is scale |
|
41
|
|
|
* |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
* |
|
44
|
|
|
* @return bool |
|
45
|
|
|
*/ |
|
46
|
82 |
|
public function initializeComponent(): bool |
|
47
|
|
|
{ |
|
48
|
82 |
|
$this->setDomAttribute('scale'); |
|
49
|
82 |
|
return true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Scaling factor in the X direction. |
|
54
|
|
|
* |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
* |
|
57
|
|
|
* @param double $scale_x |
|
58
|
|
|
* @return ScaleCMPTIF |
|
59
|
|
|
*/ |
|
60
|
9 |
|
public function scaleX(float $scale_x): ScaleCMPTIF |
|
61
|
|
|
{ |
|
62
|
9 |
|
$this->setValues(); |
|
63
|
9 |
|
$this->dom_attributes['x'] = $scale_x; |
|
64
|
9 |
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Scaling factor in the Y direction.. |
|
69
|
|
|
* |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
* |
|
72
|
|
|
* @param double $scale_y |
|
73
|
|
|
* @return ScaleCMPTIF |
|
74
|
|
|
*/ |
|
75
|
8 |
|
public function scaleY(float $scale_y): ScaleCMPTIF |
|
76
|
|
|
{ |
|
77
|
8 |
|
$this->setValues(); |
|
78
|
8 |
|
$this->dom_attributes['y'] = $scale_y; |
|
79
|
8 |
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Scaling factor in the Z direction. |
|
84
|
|
|
* |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
* |
|
87
|
|
|
* @param double $scale_z |
|
88
|
|
|
* @return ScaleCMPTIF |
|
89
|
|
|
*/ |
|
90
|
8 |
|
public function scaleZ(float $scale_z): ScaleCMPTIF |
|
91
|
|
|
{ |
|
92
|
8 |
|
$this->setValues(); |
|
93
|
8 |
|
$this->dom_attributes['z'] = $scale_z; |
|
94
|
8 |
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get scale |
|
99
|
|
|
* |
|
100
|
|
|
* {@inheritdoc} |
|
101
|
|
|
* |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
1 |
|
public function getScale(): string |
|
105
|
|
|
{ |
|
106
|
1 |
|
return $this->getDomAttributeString(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Return DOM attribute contents |
|
111
|
|
|
* |
|
112
|
|
|
* Scale Components dom atribute contains coordinates |
|
113
|
|
|
* Ex: scale="1 1 1" |
|
114
|
|
|
* |
|
115
|
|
|
* {@inheritdoc} |
|
116
|
|
|
* |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
5 |
|
public function getDomAttributeString(): string |
|
120
|
|
|
{ |
|
121
|
5 |
|
$attrs = $this->getDOMAttributesArray(); |
|
122
|
5 |
|
return $this->createCoordinateString($attrs['x'], $attrs['y'], $attrs['z']); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* When any scale component methods are called then init others |
|
127
|
|
|
* |
|
128
|
|
|
* @return void |
|
129
|
|
|
*/ |
|
130
|
9 |
|
private function setValues() |
|
131
|
|
|
{ |
|
132
|
9 |
|
$this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0; |
|
133
|
9 |
|
$this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0; |
|
134
|
9 |
|
$this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0; |
|
135
|
9 |
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|