Perfect skybox

This commit is contained in:
RandomityGuy 2021-06-05 21:15:05 +05:30
parent eab4f32a25
commit 8d679e7f04
2 changed files with 53 additions and 7 deletions

View file

@ -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) {

View file

@ -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();
}
}