--- /dev/null
+package com.badlogic.gdx.tests;\r
+\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.graphics.Color;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.OrthographicCamera;\r
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;\r
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;\r
+import com.badlogic.gdx.math.MathUtils;\r
+import com.badlogic.gdx.math.Vector2;\r
+import com.badlogic.gdx.scenes.scene2d.Stage;\r
+import com.badlogic.gdx.scenes.scene2d.ui.Table;\r
+import com.badlogic.gdx.tests.utils.GdxTest;\r
+\r
+public class Vector2dTest extends GdxTest {\r
+ private ShapeRenderer renderer;\r
+ private OrthographicCamera camera;\r
+\r
+ private Vector2 rotating = new Vector2(Vector2.X);\r
+ private Vector2 scalingX = new Vector2(Vector2.Y);\r
+ private Vector2 scalingY = new Vector2(Vector2.X);\r
+ private Vector2 lerping1 = new Vector2(Vector2.X);\r
+ private Vector2 lerpTarget = new Vector2(Vector2.Y);\r
+ private Vector2 sum = new Vector2().add(Vector2.X).add(Vector2.Y).nor();\r
+ private Vector2 mash = new Vector2(Vector2.Y);\r
+\r
+ \r
+ private final long start = System.currentTimeMillis();\r
+ \r
+ @Override\r
+ public void create () {\r
+ renderer = new ShapeRenderer();\r
+ }\r
+ \r
+ private void renderVectorAt(float x, float y, Vector2 v) {\r
+ renderer.line(x, y, x + v.x, y + v.y);\r
+ }\r
+\r
+ @Override\r
+ public void render () {\r
+ Gdx.gl.glClearColor(0, 0, 0, 0);\r
+ Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
+ \r
+ renderer.setProjectionMatrix(camera.combined);\r
+ \r
+ // Render the 'lerp' vector target as a circle\r
+ renderer.begin(ShapeType.FilledCircle);\r
+ renderer.setColor(1.0f, 0, 0, 0.3f);\r
+ renderer.filledCircle(-2 + lerpTarget.x, 2 + lerpTarget.y , 0.08f, 16);\r
+ renderer.end();\r
+\r
+ renderer.begin(ShapeType.Line);\r
+ \r
+ // Render the three fixed X, Y and sum vectors:\r
+ renderer.setColor(Color.RED);\r
+ renderVectorAt(0, 0, Vector2.X);\r
+ renderer.setColor(Color.GREEN);\r
+ renderVectorAt(0, 0, Vector2.Y);\r
+ renderer.setColor(Color.YELLOW);\r
+ renderVectorAt(0, 0, sum);\r
+ \r
+ final float changeRate = Gdx.graphics.getDeltaTime();\r
+ renderer.setColor(Color.WHITE);\r
+ \r
+ renderVectorAt(2, 2, rotating);\r
+ rotating.rotate(93 * changeRate);\r
+ \r
+ renderVectorAt(2, -2, scalingX);\r
+ scalingX.set(0, MathUtils.sin((System.currentTimeMillis() - start)/520.0f));\r
+ renderVectorAt(2, -2, scalingY);\r
+ scalingY.set(MathUtils.cos((System.currentTimeMillis() - start)/260.0f), 0);\r
+ \r
+ renderVectorAt(-2, 2, lerping1);\r
+ lerping1.lerp(lerpTarget, 0.025f);\r
+ if (lerping1.epsilonEquals(lerpTarget, 0.05f)) {\r
+ lerpTarget.set(-1.0f + MathUtils.random(2.0f), -1.0f + MathUtils.random(2.0f)).nor();\r
+ }\r
+\r
+ renderVectorAt(-2, -2, mash);\r
+ mash.set(0, 0).add(rotating).add(scalingX).add(scalingY).add(lerping1);\r
+ \r
+ renderer.end();\r
+ }\r
+\r
+ @Override\r
+ public void resize (int width, int height) {\r
+ float ratio = ((float)Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight());\r
+ int h = 10;\r
+ int w = (int)(h * ratio);\r
+ camera = new OrthographicCamera(w, h);\r
+ }\r
+ \r
+ @Override\r
+ public boolean needsGL20 () {\r
+ return false;\r
+ }\r
+}\r