use of org.lwjgl.util.vector.Vector3f in project lwjgl by LWJGL.
the class Gears method init.
/**
*
*/
private void init() throws LWJGLException {
final int WIDTH = 640;
final int HEIGHT = 480;
Display.setLocation((Display.getDisplayMode().getWidth() - WIDTH) / 2, (Display.getDisplayMode().getHeight() - HEIGHT) / 2);
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
} catch (PowerManagementEventException e) {
e.printStackTrace();
}
Display.setTitle("Gears");
Display.create(new PixelFormat());
//glCoverageMaskNV(true);
// setup ogl
glViewport(0, 0, WIDTH, HEIGHT);
glFrontFace(GL_CCW);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
final Vector3f lp = new Vector3f(5.0f, 5.0f, 10.0f);
lp.normalise();
glLight(GL_LIGHT0, GL_POSITION, lp.getX(), lp.getY(), lp.getZ(), 0.0f);
/* make the gears */
gear1 = new Gear(gear(1.0f, 4.0f, 1.0f, 20, 0.7f), new float[] { 0.8f, 0.1f, 0.0f, 1.0f });
gear2 = new Gear(gear(0.5f, 2.0f, 2.0f, 10, 0.7f), new float[] { 0.0f, 0.8f, 0.2f, 1.0f });
gear3 = new Gear(gear(1.3f, 2.0f, 0.5f, 10, 0.7f), new float[] { 0.2f, 0.2f, 1.0f, 1.0f });
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
final float h = (float) 300 / (float) 300;
glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -40.0f);
vsh = new Shader(GL_VERTEX_SHADER, "uniform highp vec4 LIGHT_POS;\n" + "uniform highp mat4 MODEL_VIEW_PROJECTION_MATRIX;\n" + "uniform mediump mat3 NORMAL_MATRIX;\n" + "uniform lowp vec3 GEAR_COLOR;\n" + "attribute highp vec3 vPosition;\n" + "attribute mediump vec3 vNormal;\n" + "varying lowp vec3 color;\n" + "void main(void) {\n" + "\tgl_Position = MODEL_VIEW_PROJECTION_MATRIX * vec4(vPosition, 1.0);\n" + "\tvec3 normal = NORMAL_MATRIX * vNormal;\n" + "\tcolor = max(dot(normal, vec3(LIGHT_POS)), 0.0) * GEAR_COLOR + vec3(0.05);\n" + "}");
fsh = new Shader(GL_FRAGMENT_SHADER, "varying lowp vec3 color;\n" + "void main(void) {\n" + "\tgl_FragColor = vec4(color, 1.0);\n" + "}");
program = new ShaderProgram(vsh, fsh);
program.enable();
LIGHT_POS = program.getUniformLocation("LIGHT_POS");
MVP = program.getUniformLocation("MODEL_VIEW_PROJECTION_MATRIX");
NM = program.getUniformLocation("NORMAL_MATRIX");
GEAR_COLOR = program.getUniformLocation("GEAR_COLOR");
vPosition = program.getAttributeLocation("vPosition");
vNormal = program.getAttributeLocation("vNormal");
glEnableVertexAttribArray(vNormal);
glEnableVertexAttribArray(vPosition);
}
use of org.lwjgl.util.vector.Vector3f in project ImmersiveEngineering by BluSunrize.
the class ClientUtils method createBakedBox.
public static Set<BakedQuad> createBakedBox(Vector3f from, Vector3f to, Matrix4 matrix, EnumFacing facing, Function<Vector3f[], Vector3f[]> vertexTransformer, Function<EnumFacing, TextureAtlasSprite> textureGetter, float[] colour) {
HashSet quads = new HashSet();
if (vertexTransformer == null)
vertexTransformer = v -> v;
Vector3f[] vertices = { new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, from.y, to.z), new Vector3f(to.x, from.y, to.z), new Vector3f(to.x, from.y, from.z) };
TextureAtlasSprite sprite = textureGetter.apply(EnumFacing.DOWN);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.DOWN, facing), sprite, new double[] { from.x * 16, 16 - from.z * 16, to.x * 16, 16 - to.z * 16 }, colour, true));
for (Vector3f v : vertices) v.setY(to.y);
sprite = textureGetter.apply(EnumFacing.UP);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), sprite, new double[] { from.x * 16, from.z * 16, to.x * 16, to.z * 16 }, colour, false));
vertices = new Vector3f[] { new Vector3f(to.x, to.y, from.z), new Vector3f(to.x, from.y, from.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
sprite = textureGetter.apply(EnumFacing.NORTH);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.NORTH, facing), sprite, new double[] { from.x * 16, 16 - to.y * 16, to.x * 16, 16 - from.y * 16 }, colour, false));
for (Vector3f v : vertices) v.setZ(to.z);
sprite = textureGetter.apply(EnumFacing.SOUTH);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.SOUTH, facing), sprite, new double[] { to.x * 16, 16 - to.y * 16, from.x * 16, 16 - from.y * 16 }, colour, true));
vertices = new Vector3f[] { new Vector3f(from.x, to.y, to.z), new Vector3f(from.x, from.y, to.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
sprite = textureGetter.apply(EnumFacing.WEST);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), sprite, new double[] { to.z * 16, 16 - to.y * 16, from.z * 16, 16 - from.y * 16 }, colour, true));
for (Vector3f v : vertices) v.setX(to.x);
sprite = textureGetter.apply(EnumFacing.EAST);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), sprite, new double[] { from.z * 16, 16 - to.y * 16, to.z * 16, 16 - from.y * 16 }, colour, false));
return quads;
}
use of org.lwjgl.util.vector.Vector3f in project ImmersiveEngineering by BluSunrize.
the class ConveyorSplit method modifyQuads.
@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
TextureAtlasSprite tex_casing0 = ClientUtils.getSprite(texture_casing);
Matrix4 matrix = new Matrix4(facing);
float[] colour = { 1, 1, 1, 1 };
Vector3f[] vertices = { new Vector3f(.0625f, .1875f, 0), new Vector3f(.0625f, .1875f, 1), new Vector3f(.9375f, .1875f, 1), new Vector3f(.9375f, .1875f, 0) };
baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), EnumFacing.UP, tex_casing0, new double[] { 1, 16, 15, 0 }, colour, false));
vertices = new Vector3f[] { new Vector3f(.0625f, 0, 0), new Vector3f(.0625f, .1875f, 0), new Vector3f(.9375f, .1875f, 0), new Vector3f(.9375f, 0, 0) };
baseModel.set(15, ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing, ClientUtils.getSprite(ModelConveyor.rl_casing[1]), new double[] { 1, 16, 15, 13 }, colour, false));
vertices = new Vector3f[] { new Vector3f(.0625f, .125f, 0), new Vector3f(.0625f, .1875f, 0), new Vector3f(.9375f, .1875f, 0), new Vector3f(.9375f, .125f, 0) };
Vector3f[] vertices2 = new Vector3f[] { new Vector3f(.5f, .125f, 0), new Vector3f(.5f, .125f, .5f), new Vector3f(.5f, .1875f, .5f), new Vector3f(.5f, .1875f, 0) };
Vector3f[] vertices3 = new Vector3f[] { new Vector3f(.5f, .125f, 0), new Vector3f(.5f, .125f, .5f), new Vector3f(.5f, .1875f, .5f), new Vector3f(.5f, .1875f, 0) };
for (int i = 0; i < 8; i++) {
for (int iv = 0; iv < vertices.length; iv++) {
vertices[iv].setZ((i + 1) * .0625f);
vertices2[iv].setX(vertices2[iv].getX() + .0625f);
vertices3[iv].setX(vertices3[iv].getX() - .0625f);
}
double v = 16 - i;
baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing, tex_casing0, new double[] { 1, v - 1, 15, v }, colour, true));
if (i < 7) {
double u = 8 - i;
baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices2), facing, tex_casing0, new double[] { u - 1, 16, u, 8 }, colour, true));
baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices3), facing, tex_casing0, new double[] { u - 1, 16, u, 8 }, colour, false));
}
}
return baseModel;
}
use of org.lwjgl.util.vector.Vector3f in project Voxel_Game by ASasseCreations.
the class Chunk method save.
public final boolean save() {
if (operation == null || !operation.equals(ChunkOperation.SAVING)) {
if (!generated)
return true;
System.out.println("CANT SAVE");
return false;
}
if (modified.isEmpty())
return true;
final ADatabase database = new ADatabase("Chunk");
final List<Block> list = new ArrayList<>(Block.BLOCKS.values());
for (final Vector3f vector : modified.keySet()) {
final int x = (int) vector.x;
final int y = (int) vector.y;
final int z = (int) vector.z;
final BlockModeled block = blocks[x][y][z];
final Block texture;
int id;
if (block == null || block.preset == null || block.preset.texture == null)
id = -1;
else {
texture = block.preset;
id = list.indexOf(texture);
}
final AObject object = new AObject(x + ":" + y + ":" + z);
object.addField(AField.Integer("id", id));
database.addObject(object);
}
database.serializeToFile(Content.WORLD_FOLDER + "chunk_" + x + "_" + z + ".dat");
System.out.println("Saved chunk at [" + x + ", " + z + "]");
operation = null;
return true;
}
use of org.lwjgl.util.vector.Vector3f in project Voxel_Game by ASasseCreations.
the class Chunk method load.
public final void load() {
System.out.println("Loaded at [" + x + ", " + z + "]");
final ADatabase database = ADatabase.DeserializeFromFile(Content.WORLD_FOLDER + "chunk_" + x + "_" + z + ".dat");
final List<AObject> modifications = database.objects;
System.out.println(modifications.size());
final List<Block> list = new ArrayList<>(Block.BLOCKS.values());
for (final AObject object : modifications) {
final String[] parsed = object.getName().split(":");
final int x = Integer.parseInt(parsed[0]);
final int y = Integer.parseInt(parsed[1]);
final int z = Integer.parseInt(parsed[2]);
final int id = object.findField("id").getInt();
modified.put(new Vector3f(x, y, z), id);
if (id == -1)
blocks[x][y][z] = null;
else
blocks[x][y][z] = new BlockModeled(list.get(id));
}
System.out.println("Generated modifications chunk at [" + x + ", " + z + "]");
}
Aggregations