Coverage Summary for Class: Transform (com.mygdx.game.Components)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| Transform | 100% (1/1) | 60% (9/15) | 66.7% (18/27) |
1 package com.mygdx.game.Components; 2 3 import com.badlogic.gdx.ai.utils.Location; 4 import com.badlogic.gdx.math.Vector2; 5 import com.mygdx.utils.Utilities; 6 7 /** 8 * Position, Scale, Rotation (in radians clockwise) 9 */ 10 public class Transform extends Component implements Location<Vector2> { 11 private final Vector2 position; 12 private final Vector2 scale; 13 private float rotation; 14 15 /** 16 * position = (0, 0) 17 * scale = (0, 0) 18 * rotation = 0 19 * rot not used but easy to add functionality for 20 */ 21 public Transform() { 22 position = new Vector2(); 23 scale = new Vector2(1, 1); 24 rotation = 0; 25 type = ComponentType.Transform; 26 } 27 28 /** 29 * Set position associated with the Transform component. 30 * 31 * @param pos 2D vector specifying the position 32 * @param rb true to pass on the position to the parent's RigidBody 33 */ 34 public void setPosition(Vector2 pos, boolean rb) { 35 setPosition(pos.x, pos.y, rb); 36 } 37 38 /** 39 * Set position associated with the Transform component. 40 * 41 * @param x coordinate 42 * @param y coordinate 43 * @param rb_ true to pass on the position to the parent's RigidBody 44 */ 45 public void setPosition(float x, float y, boolean rb_) { 46 position.set(x, y); 47 if (parent != null && rb_) { 48 RigidBody rb = parent.getComponent(RigidBody.class); 49 if (rb != null) { 50 rb.setPosition(position); 51 } 52 } 53 } 54 55 /** 56 * Set position associated with the Transform component. 57 * 58 * @param pos 2D vector specifying the position 59 */ 60 public void setPosition(Vector2 pos) { 61 setPosition(pos.x, pos.y); 62 } 63 64 /** 65 * Set position associated with the Transform component. 66 * 67 * @param x coordinate 68 * @param y coordinate 69 */ 70 public void setPosition(float x, float y) { 71 position.set(x, y); 72 if (parent != null) { 73 RigidBody rb = parent.getComponent(RigidBody.class); 74 if (rb != null) { 75 rb.setPosition(position); 76 } 77 } 78 } 79 80 /** 81 * Sets the scale of the component 82 * @param x the x dimension 83 * @param y the y dimension 84 */ 85 public void setScale(float x, float y) { 86 scale.set(x, y); 87 } 88 89 /** 90 * @param rot in Radians 91 */ 92 public void setRotation(float rot) { 93 rotation = rot; 94 } 95 96 /** 97 * @return the position of the component on the grid 98 */ 99 public Vector2 getPosition() { 100 return position; 101 } 102 103 /** 104 * @return the orientation of the component `unused` 105 */ 106 @Override 107 public float getOrientation() { 108 return 0; 109 } 110 111 /** 112 * @param orientation the float value to set the orientation of the component to `unused` 113 */ 114 @Override 115 public void setOrientation(float orientation) {} 116 117 /** 118 * Return new angle in radians from input vector. 119 * @param vector 2D vector 120 * @return the vector as an angle 121 */ 122 @Override 123 public float vectorToAngle(Vector2 vector) { 124 return Utilities.vectorToAngle(vector); 125 } 126 127 /** 128 * Return new vector combining input vector with input angle in radians. 129 * @param outVector 2D vector 130 * @param angle in radians 131 * @return the angle as a vector 132 */ 133 @Override 134 public Vector2 angleToVector(Vector2 outVector, float angle) { 135 return Utilities.angleToVector(outVector, angle); 136 } 137 138 /** 139 * @return a Transform object at a new location 140 */ 141 @Override 142 public Location<Vector2> newLocation() { 143 return new Transform(); 144 } 145 146 /** 147 * @return the scale of this object 148 */ 149 public Vector2 getScale() { 150 return scale; 151 } 152 153 /** 154 * @return the angle of this object in radians 155 */ 156 public float getRotation() { 157 return rotation; 158 } 159 160 //public void setScale(Vector2 pos) { 161 // scale.set(pos); 162 // } 163 164 // public Vector2 getCenter() { 165 // RigidBody rb = parent.getComponent(RigidBody.class); 166 // if (rb == null) { 167 // return getPosition(); 168 // } 169 // return rb.getBody().getWorldCenter(); 170 // } 171 }