| @@ 30-129 (lines=100) @@ | ||
| 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 | public function initializeComponent(): bool |
|
| 46 | { |
|
| 47 | $this->setDomAttribute('position'); |
|
| 48 | ||
| 49 | 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 | public function getDomAttributeString(): string |
|
| 61 | { |
|
| 62 | $attrs = $this->getDOMAttributesArray(); |
|
| 63 | ||
| 64 | 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 | public function getPosition(): string |
|
| 75 | { |
|
| 76 | 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 void |
|
| 85 | */ |
|
| 86 | public function positionX(float $x_axis) |
|
| 87 | { |
|
| 88 | $this->init(); |
|
| 89 | $this->dom_attributes['x'] = $x_axis; |
|
| 90 | } |
|
| 91 | ||
| 92 | /** |
|
| 93 | * Negative Y axis extends up. |
|
| 94 | * Positive Y Axis extends down. |
|
| 95 | * |
|
| 96 | * @param float $y_axis |
|
| 97 | * @return void |
|
| 98 | */ |
|
| 99 | public function positionY(float $y_axis) |
|
| 100 | { |
|
| 101 | $this->init(); |
|
| 102 | $this->dom_attributes['y'] = $y_axis; |
|
| 103 | } |
|
| 104 | ||
| 105 | /** |
|
| 106 | * Negative Z axis extends in. |
|
| 107 | * Positive Z Axis extends out. |
|
| 108 | * |
|
| 109 | * @param float $z_axis |
|
| 110 | * @return void |
|
| 111 | */ |
|
| 112 | public function positionZ(float $z_axis) |
|
| 113 | { |
|
| 114 | $this->init(); |
|
| 115 | $this->dom_attributes['z'] = $z_axis; |
|
| 116 | } |
|
| 117 | ||
| 118 | /** |
|
| 119 | * When any position component methods are called then init others |
|
| 120 | * |
|
| 121 | * @return void |
|
| 122 | */ |
|
| 123 | private function init() |
|
| 124 | { |
|
| 125 | $this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0; |
|
| 126 | $this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0; |
|
| 127 | $this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0; |
|
| 128 | } |
|
| 129 | } |
|
| @@ 30-136 (lines=107) @@ | ||
| 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 | public function initializeComponent(): bool |
|
| 49 | { |
|
| 50 | $this->setDomAttribute('rotation'); |
|
| 51 | return true; |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Get Rotation |
|
| 56 | * |
|
| 57 | * {@inheritdoc} |
|
| 58 | * |
|
| 59 | * @return string |
|
| 60 | */ |
|
| 61 | public function getRotation(): string |
|
| 62 | { |
|
| 63 | 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 | public function getDomAttributeString(): string |
|
| 75 | { |
|
| 76 | $attrs = $this->getDOMAttributesArray(); |
|
| 77 | 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 void |
|
| 87 | */ |
|
| 88 | public function roll(float $roll) |
|
| 89 | { |
|
| 90 | $this->init(); |
|
| 91 | $this->dom_attributes['x'] = $roll; |
|
| 92 | } |
|
| 93 | ||
| 94 | /** |
|
| 95 | * Pitch, rotation about the Y-axis. |
|
| 96 | * |
|
| 97 | * {@inheritdoc} |
|
| 98 | * |
|
| 99 | * @param double $pitch |
|
| 100 | * @return void |
|
| 101 | */ |
|
| 102 | public function pitch(float $pitch) |
|
| 103 | { |
|
| 104 | $this->init(); |
|
| 105 | $this->dom_attributes['y'] = $pitch; |
|
| 106 | } |
|
| 107 | ||
| 108 | /** |
|
| 109 | * Yaw, rotation about the Z-axis. |
|
| 110 | * |
|
| 111 | * {@inheritdoc} |
|
| 112 | * |
|
| 113 | * @param double $yaw |
|
| 114 | * @return void |
|
| 115 | */ |
|
| 116 | public function yaw(float $yaw) |
|
| 117 | { |
|
| 118 | $this->init(); |
|
| 119 | $this->dom_attributes['z'] = $yaw; |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|
| 123 | * When any rotation component methods are called then init others |
|
| 124 | * |
|
| 125 | * {@inheritdoc} |
|
| 126 | * |
|
| 127 | * @param array $dom_attributes |
|
| 128 | * @return void |
|
| 129 | */ |
|
| 130 | private function init() |
|
| 131 | { |
|
| 132 | $this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0; |
|
| 133 | $this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0; |
|
| 134 | $this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0; |
|
| 135 | } |
|
| 136 | } |
|
| @@ 30-135 (lines=106) @@ | ||
| 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 | public function initializeComponent(): bool |
|
| 47 | { |
|
| 48 | $this->setDomAttribute('scale'); |
|
| 49 | return true; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Scaling factor in the X direction. |
|
| 54 | * |
|
| 55 | * {@inheritdoc} |
|
| 56 | * |
|
| 57 | * @param double $scale_x |
|
| 58 | * @return void |
|
| 59 | */ |
|
| 60 | public function scaleX(float $scale_x) |
|
| 61 | { |
|
| 62 | $this->setValues(); |
|
| 63 | $this->dom_attributes['x'] = $scale_x; |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * Scaling factor in the Y direction.. |
|
| 68 | * |
|
| 69 | * {@inheritdoc} |
|
| 70 | * |
|
| 71 | * @param double $scale_y |
|
| 72 | * @return void |
|
| 73 | */ |
|
| 74 | public function scaleY(float $scale_y) |
|
| 75 | { |
|
| 76 | $this->setValues(); |
|
| 77 | $this->dom_attributes['y'] = $scale_y; |
|
| 78 | } |
|
| 79 | ||
| 80 | /** |
|
| 81 | * Scaling factor in the Z direction. |
|
| 82 | * |
|
| 83 | * {@inheritdoc} |
|
| 84 | * |
|
| 85 | * @param double $scale_z |
|
| 86 | * @return void |
|
| 87 | */ |
|
| 88 | public function scaleZ(float $scale_z) |
|
| 89 | { |
|
| 90 | $this->setValues(); |
|
| 91 | $this->dom_attributes['z'] = $scale_z; |
|
| 92 | } |
|
| 93 | ||
| 94 | /** |
|
| 95 | * Get scale |
|
| 96 | * |
|
| 97 | * {@inheritdoc} |
|
| 98 | * |
|
| 99 | * @return string |
|
| 100 | */ |
|
| 101 | public function getScale(): string |
|
| 102 | { |
|
| 103 | return $this->getDomAttributeString(); |
|
| 104 | } |
|
| 105 | ||
| 106 | /** |
|
| 107 | * Return DOM attribute contents |
|
| 108 | * |
|
| 109 | * Scale Components dom atribute contains coordinates |
|
| 110 | * Ex: scale="1 1 1" |
|
| 111 | * |
|
| 112 | * {@inheritdoc} |
|
| 113 | * |
|
| 114 | * @return string |
|
| 115 | */ |
|
| 116 | public function getDomAttributeString(): string |
|
| 117 | { |
|
| 118 | $attrs = $this->getDOMAttributesArray(); |
|
| 119 | return $this->createCoordinateString($attrs['x'], $attrs['y'], $attrs['z']); |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|
| 123 | * When any scale component methods are called then init others |
|
| 124 | * |
|
| 125 | * @param array $dom_attributes |
|
| 126 | * @return void |
|
| 127 | */ |
|
| 128 | private function setValues() |
|
| 129 | { |
|
| 130 | $this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0; |
|
| 131 | $this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0; |
|
| 132 | $this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0; |
|
| 133 | } |
|
| 134 | ||
| 135 | } |
|
| 136 | ||