| @@ 35-131 (lines=97) @@ | ||
| 32 | * |
|
| 33 | * All entities inherently have the position component. |
|
| 34 | */ |
|
| 35 | class Position implements ComponentInterface |
|
| 36 | { |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Negative X axis extends left. |
|
| 40 | * |
|
| 41 | * Positive X Axis extends right. |
|
| 42 | * |
|
| 43 | * @var int $x |
|
| 44 | */ |
|
| 45 | protected $x; |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Negative Y axis extends up. |
|
| 49 | * Positive Y Axis extends down. |
|
| 50 | * |
|
| 51 | * @var int $y |
|
| 52 | */ |
|
| 53 | protected $y; |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Negative Z axis extends in. |
|
| 57 | * Positive Z Axis extends out. |
|
| 58 | * |
|
| 59 | * @var int $z |
|
| 60 | */ |
|
| 61 | protected $z; |
|
| 62 | ||
| 63 | /** |
|
| 64 | * Constructor |
|
| 65 | * |
|
| 66 | * @param float $x |
|
| 67 | * @param float $y |
|
| 68 | * @param float $z |
|
| 69 | */ |
|
| 70 | public function __construct(float $x = 0, float $y = 0, float $z = 0) |
|
| 71 | { |
|
| 72 | $this->update($x, $y, $z); |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * Get Component scripts |
|
| 77 | * |
|
| 78 | * {@inheritdoc} |
|
| 79 | * |
|
| 80 | * @return array |
|
| 81 | */ |
|
| 82 | public function getScripts(): array |
|
| 83 | { |
|
| 84 | return array(); |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * Does component have DOM Atributes |
|
| 89 | * |
|
| 90 | * {@inheritdoc} |
|
| 91 | * |
|
| 92 | * @return bool |
|
| 93 | */ |
|
| 94 | public function hasDOMAttributes(): bool |
|
| 95 | { |
|
| 96 | return ! empty(get_object_vars($this)); |
|
| 97 | } |
|
| 98 | ||
| 99 | /** |
|
| 100 | * Remove default DOMElement Attributes which are not required |
|
| 101 | * |
|
| 102 | * @return void |
|
| 103 | */ |
|
| 104 | public function removeDefaultDOMAttributes() |
|
| 105 | { |
|
| 106 | if ($this->x === 0 && $this->y === 0 && $this->z === 0) { |
|
| 107 | unset($this->x); |
|
| 108 | unset($this->y); |
|
| 109 | unset($this->z); |
|
| 110 | } |
|
| 111 | } |
|
| 112 | ||
| 113 | /** |
|
| 114 | * Get DOMAttr for the entity |
|
| 115 | * |
|
| 116 | * @return DOMAttr |
|
| 117 | */ |
|
| 118 | public function getDOMAttributes(): DOMAttr |
|
| 119 | { |
|
| 120 | return new \DOMAttr('position', sprintf('%s %s %s', $this->x, $this->y, $this->z)); |
|
| 121 | } |
|
| 122 | ||
| 123 | /** |
|
| 124 | * Update coordinates |
|
| 125 | * |
|
| 126 | * @param float $x |
|
| 127 | * @param float $y |
|
| 128 | * @param float $z |
|
| 129 | */ |
|
| 130 | public function update(float $x = 0, float $y = 0, float $z = 0) |
|
| 131 | { |
|
| 132 | $this->x = $x ?? 0; |
|
| 133 | $this->y = $y ?? 0; |
|
| 134 | $this->z = $z ?? 0; |
|
| @@ 36-132 (lines=97) @@ | ||
| 33 | * |
|
| 34 | * All entities inherently have the rotation component. |
|
| 35 | */ |
|
| 36 | class Rotation implements ComponentInterface |
|
| 37 | { |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Roll, rotation about the X-axis. |
|
| 41 | * |
|
| 42 | * @var int $x |
|
| 43 | */ |
|
| 44 | protected $x; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Pitch, rotation about the Y-axis. |
|
| 48 | * |
|
| 49 | * @var int $y |
|
| 50 | */ |
|
| 51 | protected $y; |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Yaw, rotation about the Z-axis. |
|
| 55 | * |
|
| 56 | * @var int $z |
|
| 57 | */ |
|
| 58 | protected $z; |
|
| 59 | ||
| 60 | /** |
|
| 61 | * Constructor |
|
| 62 | * |
|
| 63 | * @param float $x |
|
| 64 | * @param float $y |
|
| 65 | * @param float $z |
|
| 66 | */ |
|
| 67 | public function __construct(float $x = 0, float $y = 0, float $z = 0) |
|
| 68 | { |
|
| 69 | $this->update($x, $y, $z); |
|
| 70 | } |
|
| 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 rotation |
|
| 122 | * |
|
| 123 | * A-Frame uses a right-handed coordinate system. When aligning our right hand’s thumb with a positive axis, |
|
| 124 | * our hand will curl in the positive direction of rotation. |
|
| 125 | * |
|
| 126 | * @param float $x |
|
| 127 | * @param float $y |
|
| 128 | * @param float $z |
|
| 129 | */ |
|
| 130 | public function update(float $x = 0, float $y = 0, float $z = 0) |
|
| 131 | { |
|
| 132 | $this->x = $x ?? 0; |
|
| 133 | $this->y = $y ?? 0; |
|
| 134 | $this->z = $z ?? 0; |
|
| 135 | } |
|
| @@ 36-132 (lines=97) @@ | ||
| 33 | * |
|
| 34 | * All entities inherently have the rotation component. |
|
| 35 | */ |
|
| 36 | class Scale implements ComponentInterface |
|
| 37 | { |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Scaling factor in the X direction. |
|
| 41 | * |
|
| 42 | * @var int $x |
|
| 43 | */ |
|
| 44 | protected $x; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Scaling factor in the Y direction. |
|
| 48 | * |
|
| 49 | * @var int $y |
|
| 50 | */ |
|
| 51 | protected $y; |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Scaling factor in the Z direction. |
|
| 55 | * |
|
| 56 | * @var int $z |
|
| 57 | */ |
|
| 58 | protected $z; |
|
| 59 | ||
| 60 | /** |
|
| 61 | * Constructor |
|
| 62 | * |
|
| 63 | * @param float $x |
|
| 64 | * @param float $y |
|
| 65 | * @param float $z |
|
| 66 | */ |
|
| 67 | public function __construct(float $x = 0, float $y = 0, float $z = 0) |
|
| 68 | { |
|
| 69 | $this->update($x, $y, $z); |
|
| 70 | } |
|
| 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('scale', sprintf('%s %s %s', $this->x, $this->y, $this->z)); |
|
| 118 | } |
|
| 119 | ||
| 120 | /** |
|
| 121 | * Update scale |
|
| 122 | * |
|
| 123 | * If any of the scaling factors are set to 0, then A-Frame will |
|
| 124 | * assign instead an extremely small value such that things don’t break. |
|
| 125 | * |
|
| 126 | * @param float $x |
|
| 127 | * @param float $y |
|
| 128 | * @param float $z |
|
| 129 | */ |
|
| 130 | public function update(float $x = 0, float $y = 0, float $z = 00) |
|
| 131 | { |
|
| 132 | $this->x = $x ?? 0; |
|
| 133 | $this->y = $y ?? 0; |
|
| 134 | $this->z = $z ?? 0; |
|
| 135 | } |
|