Isometric Projection

930 views Asked by At

I'm working on a Java 2.5D game, but I'm having an issue with terrain tiles displaying properly. I've followed several tutorials, surfed StackOverflow, etc, but something still seems to be missing.

Each tile stores its coordinates in top-down 2D view, so that it originally looks like this: Before Projection

When I try to project them isometrically, it looks like this (obviously incorrect): After Projection

Here is the relevant code:

    static int getIsoX(int X, int Y)
    {
        return (X-Y) - xOrientation;
    }


    static int getIsoY(int X, int Y)
    {
        return ((X+Y)/2) - yOrientation;
    }

    static void rotateBuffer()
    {
        double axis = (double) GameWorld.GRID_SIZE/2;
        AffineTransform transform = new AffineTransform();
        transform.rotate(45 * Math.PI / 180.0, axis, axis);
        op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
    }

    void draw(Graphics2D G)
    {
        int x = GameWorld.getIsoX(xCoord, yCoord);
        int y = GameWorld.getIsoY(xCoord, yCoord);
        G.drawImage(op.filter(sprite, null), x, y, null);
    }

xOrientation and yOrientation refer to the coordinates of the camera. The final isometric view should appear such that the tiles are neatly up against one another:

What am I doing wrong?

0

There are 0 answers