| @@ 30-132 (lines=103) @@ | ||
| 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 PositionCMPTIF |
|
| 85 | */ |
|
| 86 | public function positionX(float $x_axis): PositionCMPTIF |
|
| 87 | { |
|
| 88 | $this->init(); |
|
| 89 | $this->dom_attributes['x'] = $x_axis; |
|
| 90 | 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 | public function positionY(float $y_axis): PositionCMPTIF |
|
| 101 | { |
|
| 102 | $this->init(); |
|
| 103 | $this->dom_attributes['y'] = $y_axis; |
|
| 104 | 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 | public function positionZ(float $z_axis): PositionCMPTIF |
|
| 115 | { |
|
| 116 | $this->init(); |
|
| 117 | $this->dom_attributes['z'] = $z_axis; |
|
| 118 | return $this; |
|
| 119 | } |
|
| 120 | ||
| 121 | /** |
|
| 122 | * When any position component methods are called then init others |
|
| 123 | * |
|
| 124 | * @return void |
|
| 125 | */ |
|
| 126 | private function init() |
|
| 127 | { |
|
| 128 | $this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0; |
|
| 129 | $this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0; |
|
| 130 | $this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0; |
|
| 131 | } |
|
| 132 | } |
|
| @@ 30-138 (lines=109) @@ | ||
| 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 RotationCMPTIF |
|
| 87 | */ |
|
| 88 | public function roll(float $roll): RotationCMPTIF |
|
| 89 | { |
|
| 90 | $this->init(); |
|
| 91 | $this->dom_attributes['x'] = $roll; |
|
| 92 | 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 | public function pitch(float $pitch): RotationCMPTIF |
|
| 104 | { |
|
| 105 | $this->init(); |
|
| 106 | $this->dom_attributes['y'] = $pitch; |
|
| 107 | 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 | public function yaw(float $yaw): RotationCMPTIF |
|
| 119 | { |
|
| 120 | $this->init(); |
|
| 121 | $this->dom_attributes['z'] = $yaw; |
|
| 122 | 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 | private function init() |
|
| 133 | { |
|
| 134 | $this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0; |
|
| 135 | $this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0; |
|
| 136 | $this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0; |
|
| 137 | } |
|
| 138 | } |
|
| @@ 30-136 (lines=107) @@ | ||
| 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 ScaleCMPTIF |
|
| 59 | */ |
|
| 60 | public function scaleX(float $scale_x): ScaleCMPTIF |
|
| 61 | { |
|
| 62 | $this->setValues(); |
|
| 63 | $this->dom_attributes['x'] = $scale_x; |
|
| 64 | 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 | public function scaleY(float $scale_y): ScaleCMPTIF |
|
| 76 | { |
|
| 77 | $this->setValues(); |
|
| 78 | $this->dom_attributes['y'] = $scale_y; |
|
| 79 | 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 | public function scaleZ(float $scale_z): ScaleCMPTIF |
|
| 91 | { |
|
| 92 | $this->setValues(); |
|
| 93 | $this->dom_attributes['z'] = $scale_z; |
|
| 94 | return $this; |
|
| 95 | } |
|
| 96 | ||
| 97 | /** |
|
| 98 | * Get scale |
|
| 99 | * |
|
| 100 | * {@inheritdoc} |
|
| 101 | * |
|
| 102 | * @return string |
|
| 103 | */ |
|
| 104 | public function getScale(): string |
|
| 105 | { |
|
| 106 | 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 | public function getDomAttributeString(): string |
|
| 120 | { |
|
| 121 | $attrs = $this->getDOMAttributesArray(); |
|
| 122 | 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 | private function setValues() |
|
| 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 | } |
|
| 137 | ||