Pregunta

I have a small game level laid out with a cartesian coordinate system. I have a camera class that I want to translate all of the points from cartesian space to isometric space using this matrix:

[cos(45), sin(45)]

[-sin(45), cos(45)]

On paper, multiplying any vector by the matrix successfully puts that vector into the isometric space after the first rotation.

Right now, I am only able to get the level to draw according to the cameras position using this matrix:

public Matrix GetTransformation()
    {
        _mTransform =
            Matrix.CreateTranslation(-Position.X, -Position.Y, 0);

        return _mTransform;
    }

Where I am confused is where the matrix I listed above fits into that equation.

CameraIso2D takes no parameters, but here is the Draw function

public void Draw(SpriteBatch sb)
    {
        // Start drawing from this GameLayer
        sb.Begin(
            SpriteSortMode.FrontToBack,
            BlendState.AlphaBlend,
            null,
            null,
            null,
            null,
            _transformation);

        // Draw all contained objects
        foreach (DrawableGameObject dgo in _drawableGameObjects)
            dgo.Draw(sb);

        // End drawing from this GameLayer
        sb.End();
    }

_transformation is the matrix _mTransform returned from CameraIso2D every update

¿Fue útil?

Solución

I solved this by using two matrices. The first matrix uses the regular camera transformation and is passed into spriteBatch.Begin as the transformation matrix. For the isometric transformation matrix, I used Matrix.CreateRotationZ to mimic the isometric Y axis rotation, and then I used Matrix.CreateScale to mimic the isometric rotation down from the Y axis. GameObjects need a position for cartesian coordinates, and a vector2 for their isometric coordinates. Pass the GameObject's cartesian coordinates through the isometric transformation matrix to get the isometric coordinates, and then draw to that location.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top