2017-03-24 17:40:05 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
|
|
|
* Copyright (C) 2016-2017 malte0811
|
|
|
|
*
|
|
|
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Industrial Wires is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package malte0811.industrialWires.client;
|
|
|
|
|
2017-05-03 18:08:52 +02:00
|
|
|
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import org.lwjgl.util.vector.Vector3f;
|
|
|
|
|
2017-06-27 16:15:45 +02:00
|
|
|
import javax.annotation.Nullable;
|
2017-03-24 17:40:05 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2017-06-27 16:15:45 +02:00
|
|
|
import static org.lwjgl.util.vector.Vector3f.cross;
|
|
|
|
import static org.lwjgl.util.vector.Vector3f.sub;
|
|
|
|
|
2017-03-24 17:40:05 +01:00
|
|
|
public class RawQuad {
|
|
|
|
public final Vector3f[] vertices = new Vector3f[4];
|
|
|
|
public final EnumFacing facing;
|
|
|
|
public final TextureAtlasSprite tex;
|
|
|
|
public final float[] colorA;
|
|
|
|
public final Vector3f normal;
|
2017-06-27 16:15:45 +02:00
|
|
|
public final float[][] uvs;
|
2017-05-11 16:39:20 +02:00
|
|
|
public int light;
|
|
|
|
|
2017-03-24 17:40:05 +01:00
|
|
|
public RawQuad(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3,
|
|
|
|
EnumFacing facing, TextureAtlasSprite tex, float[] colorA,
|
|
|
|
Vector3f normal, float[] uvs) {
|
2017-05-11 16:39:20 +02:00
|
|
|
this(v0, v1, v2, v3, facing, tex, colorA, normal, uvs, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public RawQuad(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3,
|
|
|
|
EnumFacing facing, TextureAtlasSprite tex, float[] colorA,
|
|
|
|
Vector3f normal, float[] uvs, int light) {
|
2017-06-27 16:15:45 +02:00
|
|
|
this(v0, v1, v2, v3, facing, tex, colorA, normal, new float[][]{
|
|
|
|
{uvs[0], uvs[1]}, {uvs[0], uvs[3]},
|
|
|
|
{uvs[2], uvs[3]}, {uvs[2], uvs[1]}
|
|
|
|
}, light);
|
|
|
|
}
|
|
|
|
|
|
|
|
public RawQuad(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3,
|
|
|
|
EnumFacing facing, TextureAtlasSprite tex, float[] colorA,
|
|
|
|
@Nullable Vector3f normal, float[][] uvs, int light) {
|
2017-03-24 17:40:05 +01:00
|
|
|
vertices[0] = v0;
|
|
|
|
vertices[1] = v1;
|
|
|
|
vertices[2] = v2;
|
|
|
|
vertices[3] = v3;
|
|
|
|
this.facing = facing;
|
|
|
|
this.tex = tex;
|
2017-05-11 16:39:20 +02:00
|
|
|
if (colorA.length == 3) {
|
2017-03-24 17:40:05 +01:00
|
|
|
this.colorA = Arrays.copyOf(colorA, 4);
|
|
|
|
this.colorA[3] = 1;
|
|
|
|
} else {
|
|
|
|
this.colorA = colorA;
|
|
|
|
}
|
2017-06-27 16:15:45 +02:00
|
|
|
if (normal != null) {
|
|
|
|
this.normal = normal;
|
|
|
|
} else {
|
2017-06-30 21:04:02 +02:00
|
|
|
this.normal = cross(sub(v1, v3, null), sub(v2, v0, null), null);
|
2017-06-27 16:15:45 +02:00
|
|
|
this.normal.normalise(this.normal);
|
|
|
|
}
|
2017-03-24 17:40:05 +01:00
|
|
|
this.uvs = uvs;
|
2017-05-11 16:39:20 +02:00
|
|
|
this.light = light;
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-05-03 18:08:52 +02:00
|
|
|
public RawQuad apply(Matrix4 mat) {
|
|
|
|
Matrix4 matNormal = mat.copy().transpose();
|
|
|
|
matNormal.invert();
|
|
|
|
return new RawQuad(mat.apply(vertices[0]), mat.apply(vertices[1]), mat.apply(vertices[2]), mat.apply(vertices[3]),
|
2017-06-27 16:15:45 +02:00
|
|
|
facing, tex, colorA, matNormal.apply(normal), uvs, light);
|
2017-05-03 18:08:52 +02:00
|
|
|
}
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|