|
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 PositionComponent.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\Position; |
|
25
|
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\Core\Components\PositionCMPTIF; |
|
27
|
|
|
use \AframeVR\Core\Helpers\ComponentAbstract; |
|
28
|
|
|
use \AframeVR\Core\Helpers\ComponentHelper; |
|
29
|
|
|
|
|
30
|
|
|
class PositionComponent extends ComponentAbstract implements PositionCMPTIF |
|
31
|
|
|
{ |
|
32
|
|
|
use ComponentHelper; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Initialize Position Component |
|
36
|
|
|
* |
|
37
|
|
|
* The position component defines where an entity is placed in the scene's world space. |
|
38
|
|
|
* It takes a coordinate value as three space-delimited numbers. |
|
39
|
|
|
* |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
* |
|
42
|
|
|
* @return bool |
|
43
|
|
|
* |
|
44
|
|
|
*/ |
|
45
|
78 |
|
public function initializeComponent(): bool |
|
46
|
|
|
{ |
|
47
|
78 |
|
$this->setDomAttribute('position'); |
|
48
|
|
|
|
|
49
|
78 |
|
return true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Return DOM attribute contents |
|
54
|
|
|
* |
|
55
|
|
|
* Position Components dom atribute contains coordinates to point in world |
|
56
|
|
|
* Ex: position="1 1 1" |
|
57
|
|
|
* |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
3 |
|
public function getDomAttributeString(): string |
|
61
|
|
|
{ |
|
62
|
3 |
|
$attrs = $this->getDOMAttributesArray(); |
|
63
|
|
|
|
|
64
|
3 |
|
return $this->createCoordinateString($attrs['x'], $attrs['y'], $attrs['z']); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get current position coordinates |
|
69
|
|
|
* |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function getPosition(): string |
|
75
|
|
|
{ |
|
76
|
1 |
|
return $this->getDomAttributeString(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Negative X axis extends left. |
|
81
|
|
|
* Positive X Axis extends right. |
|
82
|
|
|
* |
|
83
|
|
|
* @param float $x_axis |
|
84
|
|
|
* @return PositionCMPTIF |
|
85
|
|
|
*/ |
|
86
|
5 |
|
public function positionX(float $x_axis): PositionCMPTIF |
|
87
|
|
|
{ |
|
88
|
5 |
|
$this->init(); |
|
89
|
5 |
|
$this->dom_attributes['x'] = $x_axis; |
|
90
|
5 |
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Negative Y axis extends up. |
|
95
|
|
|
* Positive Y Axis extends down. |
|
96
|
|
|
* |
|
97
|
|
|
* @param float $y_axis |
|
98
|
|
|
* @return PositionCMPTIF |
|
99
|
|
|
*/ |
|
100
|
4 |
|
public function positionY(float $y_axis): PositionCMPTIF |
|
101
|
|
|
{ |
|
102
|
4 |
|
$this->init(); |
|
103
|
4 |
|
$this->dom_attributes['y'] = $y_axis; |
|
104
|
4 |
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Negative Z axis extends in. |
|
109
|
|
|
* Positive Z Axis extends out. |
|
110
|
|
|
* |
|
111
|
|
|
* @param float $z_axis |
|
112
|
|
|
* @return PositionCMPTIF |
|
113
|
|
|
*/ |
|
114
|
4 |
|
public function positionZ(float $z_axis): PositionCMPTIF |
|
115
|
|
|
{ |
|
116
|
4 |
|
$this->init(); |
|
117
|
4 |
|
$this->dom_attributes['z'] = $z_axis; |
|
118
|
4 |
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* When any position component methods are called then init others |
|
123
|
|
|
* |
|
124
|
|
|
* @return void |
|
125
|
|
|
*/ |
|
126
|
5 |
|
private function init() |
|
127
|
|
|
{ |
|
128
|
5 |
|
$this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0; |
|
129
|
5 |
|
$this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0; |
|
130
|
5 |
|
$this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0; |
|
131
|
|
|
} |
|
132
|
|
|
} |