OSDN Git Service

[fixed] rotation issue. fucking mathutils.
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Tue, 8 Feb 2011 19:35:42 +0000 (19:35 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Tue, 8 Feb 2011 19:35:42 +0000 (19:35 +0000)
gdx/src/com/badlogic/gdx/utils/MathUtils.java
tests/gdx-tests-jogl/src/com/badlogic/gdx/tests/jogl/JoglDebugStarter.java
tests/gdx-tests/src/com/badlogic/gdx/tests/RotationTest.java

index 2f672b5..25d85aa 100644 (file)
@@ -37,6 +37,7 @@ public class MathUtils {
 \r
        static public final float[] sin = new float[SIN_COUNT];\r
        static public final float[] cos = new float[SIN_COUNT];\r
+       \r
        static {\r
                for (int i = 0; i < SIN_COUNT; i++) {\r
                        float a = (i + 0.5f) / SIN_COUNT * radFull;\r
@@ -46,19 +47,23 @@ public class MathUtils {
        }\r
 \r
        static public final float sin (float rad) {\r
-               return sin[(int)(rad * radToIndex) & SIN_MASK];\r
+               return (float)Math.sin(rad);\r
+//             return sin[(int)(rad * radToIndex) & SIN_MASK];\r
        }\r
 \r
        static public final float cos (float rad) {\r
-               return cos[(int)(rad * radToIndex) & SIN_MASK];\r
+               return (float)Math.cos(rad);\r
+//             return cos[(int)(rad * radToIndex) & SIN_MASK];\r
        }\r
 \r
        static public final float sinDeg (float deg) {\r
-               return sin[(int)(deg * degToIndex) & SIN_MASK];\r
+               return (float)Math.sin(degreesToRadians * deg);\r
+//             return sin[(int)(deg * degToIndex) & SIN_MASK];\r
        }\r
 \r
        static public final float cosDeg (float deg) {\r
-               return cos[(int)(deg * degToIndex) & SIN_MASK];\r
+               return (float)Math.cos(degreesToRadians * deg);\r
+//             return cos[(int)(deg * degToIndex) & SIN_MASK];\r
        }\r
 \r
        // ---\r
index 7b3feef..d84eb52 100644 (file)
@@ -18,6 +18,6 @@ import com.badlogic.gdx.backends.jogl.JoglApplication;
 public class JoglDebugStarter {\r
 \r
        public static void main (String[] argv) {\r
-               new JoglApplication(new com.badlogic.gdx.tests.Gdx2DTest(), "Debug Test", 480, 320, false);\r
+               new JoglApplication(new com.badlogic.gdx.tests.RotationTest(), "Debug Test", 480, 320, false);\r
        }\r
 }\r
index e08234e..e3f9636 100644 (file)
@@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.GL10;\r
 import com.badlogic.gdx.graphics.Texture;\r
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
+import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
 import com.badlogic.gdx.tests.utils.GdxTest;\r
 \r
 public class RotationTest extends GdxTest {\r
@@ -13,18 +14,25 @@ public class RotationTest extends GdxTest {
        }\r
        \r
        Texture texture;\r
+       TextureRegion region;\r
        SpriteBatch batch;\r
        \r
        \r
+       \r
        @Override public void create() {\r
                texture = new Texture(Gdx.files.internal("data/black_marked_0.png"));\r
+               region = new TextureRegion(texture);\r
                batch = new SpriteBatch();\r
+               batch.getTransformMatrix().setToTranslation(30.5f, 30.5f, 0);\r
        }\r
        \r
        @Override public void render() {\r
                Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
                batch.begin();\r
-               batch.draw(texture, 100.5f, 100.5f);\r
+               batch.draw(texture, 0, 0);\r
+               batch.draw(region, 128, 0, 64, 64, 128, 128, 1, 1, 90);\r
+               batch.draw(region, 128, 128, 64, 64, 128, 128, 1, 1, 180);\r
+               batch.draw(region, 0, 128, 64, 64, 128, 128, 1, 1, 270);\r
                batch.end();\r
        }\r
 }\r