diff --git a/src/Sky.hx b/src/Sky.hx index 3434a145..567d5c9d 100644 --- a/src/Sky.hx +++ b/src/Sky.hx @@ -35,6 +35,8 @@ class Sky extends Object { var lines = dmlFile.split('\n').map(x -> x.toLowerCase()); var skyboxImages = []; + // 5: bottom, to be rotated/flipped + // 0: front var skyboxIndices = [3, 1, 2, 0, 4, 5]; for (i in 0...6) { @@ -56,7 +58,16 @@ class Sky extends Object { maxwidth = texture.width; } - Util.rotateImage(skyboxImages[0], Math.PI / 2); + Util.flipImage(skyboxImages[0], true, false); + Util.flipImage(skyboxImages[4], true, false); + Util.rotateImage(skyboxImages[5], Math.PI); + Util.flipImage(skyboxImages[5], true, false); + Util.rotateImage(skyboxImages[1], -Math.PI / 2); + Util.flipImage(skyboxImages[1], true, false); + Util.rotateImage(skyboxImages[2], Math.PI); + Util.flipImage(skyboxImages[2], true, false); + Util.rotateImage(skyboxImages[3], Math.PI / 2); + Util.flipImage(skyboxImages[3], true, false); var cubemaptexture = new Texture(maxheight, maxwidth, [Cube]); for (i in 0...6) { diff --git a/src/Util.hx b/src/Util.hx index d68fc1f5..d34c9a15 100644 --- a/src/Util.hx +++ b/src/Util.hx @@ -1,5 +1,7 @@ package src; +import h2d.Tile; +import h3d.mat.Texture; import hxd.BitmapData; import h3d.Vector; @@ -35,11 +37,44 @@ class Util { } public static function rotateImage(bitmap:BitmapData, angle:Float) { - // var bmp = new Bitmap(Tile.fromBitmap(bitmap)); - // bmp.rotate(angle); - // var output = new Texture(bitmap.width, bitmap.height, [TextureFlags.Target]); - // bmp.drawTo(output); - // var pixels = output.capturePixels(); - // bitmap.setPixels(pixels); + var curpixels = bitmap.getPixels().clone(); + bitmap.lock(); + if (angle == Math.PI / 2) + for (x in 0...curpixels.width) { + for (y in 0...curpixels.height) { + bitmap.setPixel(x, y, curpixels.getPixel(y, curpixels.height - x - 1)); + } + } + if (angle == -Math.PI / 2) + for (x in 0...curpixels.width) { + for (y in 0...curpixels.height) { + bitmap.setPixel(x, y, curpixels.getPixel(curpixels.width - y - 1, x)); + } + } + if (angle == Math.PI) + for (x in 0...curpixels.width) { + for (y in 0...curpixels.height) { + bitmap.setPixel(x, y, curpixels.getPixel(curpixels.width - x - 1, curpixels.height - y - 1)); + } + } + bitmap.unlock(); + } + + public static function flipImage(bitmap:BitmapData, hflip:Bool, vflip:Bool) { + var curpixels = bitmap.getPixels().clone(); + bitmap.lock(); + if (hflip) + for (x in 0...curpixels.width) { + for (y in 0...curpixels.height) { + bitmap.setPixel(x, y, curpixels.getPixel(curpixels.height - x - 1, y)); + } + } + if (vflip) + for (x in 0...curpixels.width) { + for (y in 0...curpixels.height) { + bitmap.setPixel(x, y, curpixels.getPixel(x, curpixels.width - y - 1)); + } + } + bitmap.unlock(); } }