0

I am using DirectXTK for C++, and am making heavy use of the sprite batch function.

I am trying to develop an isometric rendering engine. I've already gotten the isometric rendering to work properly. Along with offsetting. However I run into one major problem.

I can't for the life of me figure out how to center the camera's center to the world's (0,0) or any other coord.

And after injecting this transformation matrix generated directly from the camera into SpriteBatch.Begin()

Matrix Camera::getTransformMatrix() {

    Matrix Transform = Transform.CreateTranslation(Vector3(World_Pos.x, World_Pos.y, 0));
    Matrix Rotation = Rotation.CreateRotationZ(0);
    Matrix Scale = Scale.CreateScale(ZoomFactor, ZoomFactor, 1);
    return  Transform * Rotation * Scale;
}

Nothing seems to happen. This is with the Camera's world position set to (0,0) and the sprite's world position set to (0,0).

This is the resulting image.

https://i.stack.imgur.com/STyqO.png

I turned off alpha blending, and sprite offsets for debugging reasons.

Can anyone help me please? Also, if anyone can tell me how to flip the y that would be great as well.

2 Answers2

1

Remember that the default transformation for the screen viewport is still applied if you provide a custom transformation to SpriteBatch. The default transformation makes SpriteBatch work with pixel coordinates starting at the upper-left corner of the screen.

If you want the custom transformation to be used "as is" without concatenating with the final viewport transformation, you can use this special case for the orientation handling:

spriteBatch->SetRotation(DXGI_MODE_ROTATION_UNSPECIFIED);

Be sure to read the wiki.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • If you set the rotation mode to this, you don't need to do any translation because it puts the coordinates back into the standard normalized space of -1 to 1 with 0,0 in the center and skips the default scale & offset that put it into the 0,0,width,height with the center in the upper-left. – Chuck Walbourn Nov 02 '16 at 04:40
1

I found my answer. To those who run into this problem as well. you'll need to compensate for the fact that the view port needs to be translated to center (0,0) to the center of the screen.

That is to say that the matrix you need is...

View * Translation(width * .05, height * .05)

Where View is the inverse matrix of the product of your world scale, world rotation, and world transformation.

Such that the product of the final world transformation matrix F, and view matrix V satisfies...

I=F*V

I is the identity matrix.