Coverage Summary for Class: Transform (com.mygdx.game.Components)

Class Class, % Method, % Line, %
Transform 100% (1/1) 55.6% (10/18) 57.6% (19/33)


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, true); 76  } 77  } 78  } 79  80  public void setScale(Vector2 pos) { 81  scale.set(pos); 82  } 83  84  public void setScale(float x, float y) { 85  scale.set(x, y); 86  } 87  88  /** 89  * @param rot in Radians 90  */ 91  public void setRotation(float rot) { 92  rotation = rot; 93  } 94  95  public Vector2 getPosition() { 96  return position; 97  } 98  99  /** 100  * returns the box2d position of the parent or the transform pos if no rigidbody found 101  * 102  * @return the center of the Entity or bottom left 103  */ 104  public Vector2 getCenter() { 105  RigidBody rb = parent.getComponent(RigidBody.class); 106  if (rb == null) { 107  return getPosition(); 108  } 109  return rb.getBody().getWorldCenter(); 110  } 111  112  // For Ai Navigation 113  114  public void getLocation() { 115  116  } 117  118  @Override 119  public float getOrientation() { 120  return 0; 121  } 122  123  @Override 124  public void setOrientation(float orientation) { 125  126  } 127  128  @Override 129  public float vectorToAngle(Vector2 vector) { 130  return Utilities.vectorToAngle(vector); 131  } 132  133  /** 134  * Return new vector combining input vector with input angle in radians. 135  * 136  * @param outVector 2D vector 137  * @param angle in radians 138  * @return the angle as a vector 139  */ 140  @Override 141  public Vector2 angleToVector(Vector2 outVector, float angle) { 142  return Utilities.angleToVector(outVector, angle); 143  } 144  145  @Override 146  public Location<Vector2> newLocation() { 147  return new Transform(); 148  } 149  150  public Vector2 getScale() { 151  return scale; 152  } 153  154  /** 155  * @return radians 156  */ 157  public float getRotation() { 158  return rotation; 159  } 160 }