mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 05:01:38 +00:00
Perfect skybox
This commit is contained in:
parent
eab4f32a25
commit
8d679e7f04
2 changed files with 53 additions and 7 deletions
13
src/Sky.hx
13
src/Sky.hx
|
|
@ -35,6 +35,8 @@ class Sky extends Object {
|
||||||
var lines = dmlFile.split('\n').map(x -> x.toLowerCase());
|
var lines = dmlFile.split('\n').map(x -> x.toLowerCase());
|
||||||
var skyboxImages = [];
|
var skyboxImages = [];
|
||||||
|
|
||||||
|
// 5: bottom, to be rotated/flipped
|
||||||
|
// 0: front
|
||||||
var skyboxIndices = [3, 1, 2, 0, 4, 5];
|
var skyboxIndices = [3, 1, 2, 0, 4, 5];
|
||||||
|
|
||||||
for (i in 0...6) {
|
for (i in 0...6) {
|
||||||
|
|
@ -56,7 +58,16 @@ class Sky extends Object {
|
||||||
maxwidth = texture.width;
|
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]);
|
var cubemaptexture = new Texture(maxheight, maxwidth, [Cube]);
|
||||||
for (i in 0...6) {
|
for (i in 0...6) {
|
||||||
|
|
|
||||||
47
src/Util.hx
47
src/Util.hx
|
|
@ -1,5 +1,7 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import h2d.Tile;
|
||||||
|
import h3d.mat.Texture;
|
||||||
import hxd.BitmapData;
|
import hxd.BitmapData;
|
||||||
import h3d.Vector;
|
import h3d.Vector;
|
||||||
|
|
||||||
|
|
@ -35,11 +37,44 @@ class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function rotateImage(bitmap:BitmapData, angle:Float) {
|
public static function rotateImage(bitmap:BitmapData, angle:Float) {
|
||||||
// var bmp = new Bitmap(Tile.fromBitmap(bitmap));
|
var curpixels = bitmap.getPixels().clone();
|
||||||
// bmp.rotate(angle);
|
bitmap.lock();
|
||||||
// var output = new Texture(bitmap.width, bitmap.height, [TextureFlags.Target]);
|
if (angle == Math.PI / 2)
|
||||||
// bmp.drawTo(output);
|
for (x in 0...curpixels.width) {
|
||||||
// var pixels = output.capturePixels();
|
for (y in 0...curpixels.height) {
|
||||||
// bitmap.setPixels(pixels);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue