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 RotationComponent.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\Rotation; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\Core\Components\RotationCMPTIF; |
27
|
|
|
use \AframeVR\Core\Helpers\ComponentAbstract; |
28
|
|
|
use \AframeVR\Core\Helpers\ComponentHelper; |
29
|
|
|
|
30
|
|
|
class RotationComponent extends ComponentAbstract implements RotationCMPTIF |
31
|
|
|
{ |
32
|
|
|
use ComponentHelper; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Initialize Rotation Component |
36
|
|
|
* |
37
|
|
|
* The rotation component defines the orientation of an entity. |
38
|
|
|
* It takes the |
39
|
|
|
* roll (x), |
40
|
|
|
* pitch (y), |
41
|
|
|
* and yaw (z) |
42
|
|
|
* as three space-delimited numbers indicating degrees of rotation. |
43
|
|
|
* |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
78 |
|
public function initializeComponent(): bool |
49
|
|
|
{ |
50
|
78 |
|
$this->setDomAttribute('rotation'); |
51
|
78 |
|
return true; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get Rotation |
56
|
|
|
* |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
1 |
|
public function getRotation(): string |
62
|
|
|
{ |
63
|
1 |
|
return $this->getDomAttributeString(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Return DOM attribute contents |
68
|
|
|
* |
69
|
|
|
* Scale Components dom atribute contains roll, pitch, yaw |
70
|
|
|
* Ex: rotation="1 1 1" |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
3 |
|
public function getDomAttributeString(): string |
75
|
|
|
{ |
76
|
3 |
|
$attrs = $this->getDOMAttributesArray(); |
77
|
3 |
|
return $this->createCoordinateString($attrs['x'], $attrs['y'], $attrs['z']); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Roll, rotation about the X-axis. |
82
|
|
|
* |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
* |
85
|
|
|
* @param double $roll |
86
|
|
|
* @return RotationCMPTIF |
87
|
|
|
*/ |
88
|
5 |
|
public function roll(float $roll): RotationCMPTIF |
89
|
|
|
{ |
90
|
5 |
|
$this->init(); |
91
|
5 |
|
$this->dom_attributes['x'] = $roll; |
92
|
5 |
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Pitch, rotation about the Y-axis. |
97
|
|
|
* |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
* |
100
|
|
|
* @param double $pitch |
101
|
|
|
* @return RotationCMPTIF |
102
|
|
|
*/ |
103
|
4 |
|
public function pitch(float $pitch): RotationCMPTIF |
104
|
|
|
{ |
105
|
4 |
|
$this->init(); |
106
|
4 |
|
$this->dom_attributes['y'] = $pitch; |
107
|
4 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Yaw, rotation about the Z-axis. |
112
|
|
|
* |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
* |
115
|
|
|
* @param double $yaw |
116
|
|
|
* @return RotationCMPTIF |
117
|
|
|
*/ |
118
|
4 |
|
public function yaw(float $yaw): RotationCMPTIF |
119
|
|
|
{ |
120
|
4 |
|
$this->init(); |
121
|
4 |
|
$this->dom_attributes['z'] = $yaw; |
122
|
4 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* When any rotation component methods are called then init others |
127
|
|
|
* |
128
|
|
|
* {@inheritdoc} |
129
|
|
|
* |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
5 |
|
private function init() |
133
|
|
|
{ |
134
|
5 |
|
$this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0; |
135
|
5 |
|
$this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0; |
136
|
5 |
|
$this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0; |
137
|
|
|
} |
138
|
|
|
} |