python - How do I rotate an isometric camera around the screen center? -
i have tile-based project game, got nice pseudo-3d effect using multiple tile layers, able rotate camera (essentially, rotating sprites).
but, rotating sprites isn't equal rotating world, right?
by that, got to:
x = (x - y) * (tile_width/2); y = (x + y) * (tile_width/2);
but, see? works 45 degree rotated tiles! how can modify angle used in formulas (or maybe better, more appropriate one)?
rotating sprites part of rotating world/camera.
to rotate world/camera, each tile needs moved along arc, , rotated @ same time. need use polar coordinates. compute distance , angle center-of-rotation center of each tile. add desired angle-of-rotation polar angle each tile. compute new x
, y
values center of tile converting cartesian coordinates.
here's code might like, assuming each tile represented struct, , struct has original x
, y
coordinates of center of tile (i.e. coordinates of center of tile when world not rotated).
// compute distance center of tile center of rotation double dx = tile[t].x - centerofrotation.x; double dy = tile[t].y - centerofrotation.y; // compute new location of tile in polar coordinates relative center of rotation double r = sqrt(dx*dx + dy*dy); double angle = atan2(dy, dx) + angleofrotation; // compute display location tile x = centerofrotation.x + r * cos(angle); y = centerofrotation.y + r * sin(angle); // note tile needs rotated well, using angleofrotation // also, angles in radians
when attempting rotate graphics, helps keep things simple. use small number of tiles, make tiles different colors strong borders, , identifying mark show orientation. here's example 9 tiles in initial orientation , rotated 30 degrees counter-clockwise.
here examples of can go wrong:
1) moving tiles without rotating tiles
2) rotating tiles without moving tiles
3) rotating tiles clockwise while moving tiles counter-clockwise
bottom line: pretty mistake result in image gaps.
Comments
Post a Comment