private Vector3f parsePosition(JsonObject object, String memberName) { JsonArray jsonarray = JsonUtils.getJsonArray(object, memberName); if (jsonarray.size() != 3) { throw new JsonParseException("Expected 3 " + memberName + " values, found: " + jsonarray.size()); } else { float[] afloat = new float[3]; for (int i = 0; i < afloat.length; ++i) { afloat[i] = JsonUtils.getFloat(jsonarray.get(i), memberName + "[" + i + "]"); } return new Vector3f(afloat[0], afloat[1], afloat[2]); } }
protected Vector3f getViewVector(Entity entityIn, double partialTicks) { float f = (float)((double)entityIn.prevRotationPitch + (double)(entityIn.rotationPitch - entityIn.prevRotationPitch) * partialTicks); float f1 = (float)((double)entityIn.prevRotationYaw + (double)(entityIn.rotationYaw - entityIn.prevRotationYaw) * partialTicks); if (Minecraft.getMinecraft().gameSettings.thirdPersonView == 2) { f += 180.0F; } float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI); float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI); float f4 = -MathHelper.cos(-f * 0.017453292F); float f5 = MathHelper.sin(-f * 0.017453292F); return new Vector3f(f3 * f4, f5, f2 * f4); }
private BlockPartRotation parseRotation(JsonObject p_178256_1_) { BlockPartRotation blockpartrotation = null; if (p_178256_1_.has("rotation")) { JsonObject jsonobject = JsonUtils.getJsonObject(p_178256_1_, "rotation"); Vector3f vector3f = this.parsePosition(jsonobject, "origin"); vector3f.scale(0.0625F); EnumFacing.Axis enumfacing$axis = this.parseAxis(jsonobject); float f = this.parseAngle(jsonobject); boolean flag = JsonUtils.getBoolean(jsonobject, "rescale", false); blockpartrotation = new BlockPartRotation(vector3f, enumfacing$axis, f, flag); } return blockpartrotation; }
public BakedQuad makeBakedQuad(Vector3f posFrom, Vector3f posTo, BlockPartFace face, TextureAtlasSprite sprite, EnumFacing facing, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade) { int[] aint = this.makeQuadVertexData(face, sprite, facing, this.getPositionsDiv16(posFrom, posTo), modelRotationIn, partRotation, uvLocked, shade); EnumFacing enumfacing = getFacingFromVertexData(aint); if (uvLocked) { this.func_178409_a(aint, enumfacing, face.blockFaceUV, sprite); } if (partRotation == null) { this.func_178408_a(aint, enumfacing); } return new BakedQuad(aint, face.tintIndex, enumfacing); }
public BlockPart deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { JsonObject jsonobject = p_deserialize_1_.getAsJsonObject(); Vector3f vector3f = this.parsePositionFrom(jsonobject); Vector3f vector3f1 = this.parsePositionTo(jsonobject); BlockPartRotation blockpartrotation = this.parseRotation(jsonobject); Map<EnumFacing, BlockPartFace> map = this.parseFacesCheck(p_deserialize_3_, jsonobject); if (jsonobject.has("shade") && !JsonUtils.isBoolean(jsonobject, "shade")) { throw new JsonParseException("Expected shade to be a Boolean"); } else { boolean flag = JsonUtils.getBoolean(jsonobject, "shade", true); return new BlockPart(vector3f, vector3f1, map, blockpartrotation, flag); } }
private static float convertDataToArrays(List<Vertex> vertices, List<Vector2f> textures, List<Vector3f> normals, float[] verticesArray, float[] texturesArray, float[] normalsArray) { float furthestPoint = 0; for (int i = 0; i < vertices.size(); i++) { Vertex currentVertex = vertices.get(i); if (currentVertex.getLength() > furthestPoint) { furthestPoint = currentVertex.getLength(); } Vector3f position = currentVertex.getPosition(); Vector2f textureCoord = textures.get(currentVertex.getTextureIndex()); Vector3f normalVector = normals.get(currentVertex.getNormalIndex()); verticesArray[i * 3] = position.x; verticesArray[i * 3 + 1] = position.y; verticesArray[i * 3 + 2] = position.z; texturesArray[i * 2] = textureCoord.x; texturesArray[i * 2 + 1] = 1 - textureCoord.y; normalsArray[i * 3] = normalVector.x; normalsArray[i * 3 + 1] = normalVector.y; normalsArray[i * 3 + 2] = normalVector.z; } return furthestPoint; }
public BakedQuad makeBakedQuad(Vector3f posFrom, Vector3f posTo, BlockPartFace face, TextureAtlasSprite sprite, EnumFacing facing, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade) { int[] aint = this.makeQuadVertexData(face, sprite, facing, this.getPositionsDiv16(posFrom, posTo), modelRotationIn, partRotation, uvLocked, shade); EnumFacing enumfacing = getFacingFromVertexData(aint); if (uvLocked) { this.func_178409_a(aint, enumfacing, face.blockFaceUV, sprite); } if (partRotation == null) { this.func_178408_a(aint, enumfacing); } return new BakedQuad(aint, face.tintIndex, enumfacing, sprite); }
private Vector3f parsePosition(JsonObject p_178251_1_, String p_178251_2_) { JsonArray jsonarray = JsonUtils.getJsonArray(p_178251_1_, p_178251_2_); if (jsonarray.size() != 3) { throw new JsonParseException("Expected 3 " + p_178251_2_ + " values, found: " + jsonarray.size()); } else { float[] afloat = new float[3]; for (int i = 0; i < afloat.length; ++i) { afloat[i] = JsonUtils.getFloat(jsonarray.get(i), p_178251_2_ + "[" + i + "]"); } return new Vector3f(afloat[0], afloat[1], afloat[2]); } }
public static Colour sub(Colour colLeft, Colour colRight, Colour dest) { if (dest == null) { return new Colour(Vector3f.sub(colLeft.col, colRight.col, null)); } else { Vector3f.sub(colLeft.col, colRight.col, dest.col); return dest; } }
public static Matrix4f createViewMatrix(Camera camera) { Matrix4f viewMatrix = new Matrix4f(); viewMatrix.setIdentity(); Matrix4f.rotate((float) Math.toRadians(camera.getPitch()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix); Matrix4f.rotate((float) Math.toRadians(camera.getYaw()), new Vector3f(0, 1, 0), viewMatrix, viewMatrix); Vector3f cameraPos = camera.getPosition(); Vector3f negativeCameraPos = new Vector3f(-cameraPos.x, -cameraPos.y, -cameraPos.z); Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix); return viewMatrix; }
private static void processVertex(String[] vertexData, List<Integer> indices, List<Vector2f> textures, List<Vector3f> normals, float[] textureArray, float[] normalsArray) { int currentVertexPointer = Integer.parseInt(vertexData[0]) - 1; // obj file starts index at 1 and not 0 indices.add(currentVertexPointer); Vector2f currentTex = textures.get(Integer.parseInt(vertexData[1]) - 1); textureArray[currentVertexPointer * 2] = currentTex.x; textureArray[currentVertexPointer * 2 + 1] = 1 - currentTex.y; // OpenGL starts at top left and blender at bottom left Vector3f currentNorm = normals.get(Integer.parseInt(vertexData[2]) - 1); normalsArray[currentVertexPointer * 3] = currentNorm.x; normalsArray[currentVertexPointer * 3 + 1] = currentNorm.y; normalsArray[currentVertexPointer * 3 + 2] = currentNorm.z; }
private Vector3f parsePositionTo(JsonObject object) { Vector3f vector3f = this.parsePosition(object, "to"); if (vector3f.x >= -16.0F && vector3f.y >= -16.0F && vector3f.z >= -16.0F && vector3f.x <= 32.0F && vector3f.y <= 32.0F && vector3f.z <= 32.0F) { return vector3f; } else { throw new JsonParseException("\'to\' specifier exceeds the allowed boundaries: " + vector3f); } }
private List<BlockPart> func_178394_a(int p_178394_1_, String p_178394_2_, TextureAtlasSprite p_178394_3_) { Map<EnumFacing, BlockPartFace> map = Maps.<EnumFacing, BlockPartFace>newHashMap(); map.put(EnumFacing.SOUTH, new BlockPartFace((EnumFacing)null, p_178394_1_, p_178394_2_, new BlockFaceUV(new float[] {0.0F, 0.0F, 16.0F, 16.0F}, 0))); map.put(EnumFacing.NORTH, new BlockPartFace((EnumFacing)null, p_178394_1_, p_178394_2_, new BlockFaceUV(new float[] {16.0F, 0.0F, 0.0F, 16.0F}, 0))); List<BlockPart> list = Lists.<BlockPart>newArrayList(); list.add(new BlockPart(new Vector3f(0.0F, 0.0F, 7.5F), new Vector3f(16.0F, 16.0F, 8.5F), map, (BlockPartRotation)null, true)); list.addAll(this.func_178397_a(p_178394_3_, p_178394_2_, p_178394_1_)); return list; }
private void rotateScale(Vector3f position, Vector3f rotationOrigin, Matrix4f rotationMatrix, Vector3f scale) { Vector4f vector4f = new Vector4f(position.x - rotationOrigin.x, position.y - rotationOrigin.y, position.z - rotationOrigin.z, 1.0F); Matrix4f.transform(rotationMatrix, vector4f, vector4f); vector4f.x *= scale.x; vector4f.y *= scale.y; vector4f.z *= scale.z; position.set(vector4f.x + rotationOrigin.x, vector4f.y + rotationOrigin.y, vector4f.z + rotationOrigin.z); }
public void bakeGeometry(List<Vector3f> faces, List<Vector3f> vertexData, List<Vector2f> uvData, List<Vector3f> normalData) { for (Vector3f faceData : faces) { int vertexIndex = (int) (faceData.getX() - 1); int uvIndex = (int) (faceData.getY() - 1); int normalIndex = (int) (faceData.getZ() - 1); this.vertices.add(new Vertex(vertexData.get(vertexIndex), uvData.get(uvIndex), normalData.get(normalIndex))); } }
public int rotateVertex(Vector3f position, EnumFacing facing, int vertexIndex, ModelRotation modelRotationIn, boolean uvLocked) { if (modelRotationIn == ModelRotation.X0_Y0) { return vertexIndex; } else { this.rotateScale(position, new Vector3f(0.5F, 0.5F, 0.5F), modelRotationIn.getMatrix4d(), new Vector3f(1.0F, 1.0F, 1.0F)); return modelRotationIn.rotateVertex(facing, vertexIndex); } }
private boolean intersectionInRange(float start, float finish, Vector3f ray) { Vector3f startPoint = getPointOnRay(ray, start); Vector3f endPoint = getPointOnRay(ray, finish); if (!isUnderGround(startPoint) && isUnderGround(endPoint)) { return true; } else { return false; } }
public void averageTangents(){ if(tangents.isEmpty()){ return; } for(Vector3f tangent : tangents){ Vector3f.add(averagedTangent, tangent, averagedTangent); } averagedTangent.normalise(); }
public static float getDistance(Vector3f point1, Vector3f point2) { float distance = 0; Vector3f temp = new Vector3f(); temp.x = Math.abs(point2.x - point1.x); temp.y = Math.abs(point2.y - point1.y); temp.z = Math.abs(point2.z - point1.z); distance = (float) Math.sqrt((temp.x * temp.x) + (temp.y * temp.y) + (temp.z * temp.z)); return distance; }
/** * Creates a water region at the specified x and z coordinates. Scaled to the size of a region. * @param x * @param z */ public WaterRegion(float x, float z) { transformation = new Matrix4f().translate(new Vector3f(x, WATER_HEIGHT, z)); if(shader == null) { try { shader = new WaterShader("water"); shader.setUniform("reflection_texture", 0); shader.setUniform("dudv_texture", 1); shader.setUniform("normal_texture", 2); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } if(dudvTexture == null) { dudvTexture = new Texture("waterdudv.png"); } if(normalTexture == null) { normalTexture = new Texture("waternormal.png"); } framebuffer = new FrameBuffer(REFLECTION_WIDTH, REFLECTION_HEIGHT); framebuffer.attachTexture(); framebuffer.attachDepthBuffer(); framebuffer.verifyIntegrity(); }
/** * Calculates the normals per face. * @param vertices */ private void calculateNormals(Vertex[] vertices, float[][] heightMap) { // Calculates the normal to each face. int idx = 0; for(int j = 0; j < SIZE; j++) { for(int i = 0; i < SIZE; i++) { Vector3f v = new Vector3f(i, heightMap[i][j], j); Vector3f v1 = new Vector3f(i + 1, heightMap[i + 1][j], j); Vector3f v2 = new Vector3f(i, heightMap[i][j + 1], j + 1); calculateNormal(vertices[idx++], v, v1, v2); v.y = heightMap[i + 1][j]; v1.y = heightMap[i + 2][j]; v2.y = heightMap[i + 1][j + 1]; calculateNormal(vertices[idx++], v, v1, v2); v.y = heightMap[i + 1][j + 1]; v1.y = heightMap[i + 2][j + 1]; v2.y = heightMap[i + 1][j + 2]; calculateNormal(vertices[idx++], v, v1, v2); v.y = heightMap[i][j + 1]; v1.y = heightMap[i + 1][j + 1]; v2.y = heightMap[i][j + 2]; calculateNormal(vertices[idx++], v, v1, v2); } } }
/** * Initiates the display, OpenGL, and any other non-loop lines * to run before loop */ public static void init() { DisplayManager.createDisplay(); // Display loader = new Loader(); create = new Creation(loader); renderer = new MasterRenderer(); player = create.createPlayer("bunny", "white", new Vector3f(0, 0, 0), 0, 180, 0, 1f); camera = new Camera(player, new Vector3f(), 0, 0, 0, true); List<Entity> tempBatch = create.createScatterEntity("lowPolyTree", "lowPolyTree", 0, 0, 0, 1f, 800, 160, true); entities.addAll(tempBatch); sun = new Light(new Vector3f(-2000, 2000, 2000), new Vector3f(1, 1, 1)); String[] texturePack = {"grassy", "dirt", "path", "pinkFlowers", "blendMap"}; Terrain terrain = create.createTerrain(texturePack, 0, -1); terrains.add(terrain); WorldReader.loader = loader; //world stuff goes here demoWorld = new DemoWorld("demoWorld"); demoWorld.initWorld(); mousePicker = new MousePicker(camera, renderer.getProjectionMatrix(), terrain); }
private Vector3f parsePositionTo(JsonObject p_178247_1_) { Vector3f vector3f = this.parsePosition(p_178247_1_, "to"); if (vector3f.x >= -16.0F && vector3f.y >= -16.0F && vector3f.z >= -16.0F && vector3f.x <= 32.0F && vector3f.y <= 32.0F && vector3f.z <= 32.0F) { return vector3f; } else { throw new JsonParseException("\'to\' specifier exceeds the allowed boundaries: " + vector3f); } }
private Vector3f parsePositionFrom(JsonObject p_178249_1_) { Vector3f vector3f = this.parsePosition(p_178249_1_, "from"); if (vector3f.x >= -16.0F && vector3f.y >= -16.0F && vector3f.z >= -16.0F && vector3f.x <= 32.0F && vector3f.y <= 32.0F && vector3f.z <= 32.0F) { return vector3f; } else { throw new JsonParseException("\'from\' specifier exceeds the allowed boundaries: " + vector3f); } }
public ItemTransformVec3f deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { JsonObject jsonobject = p_deserialize_1_.getAsJsonObject(); Vector3f vector3f = this.parseVector3f(jsonobject, "rotation", ROTATION_DEFAULT); Vector3f vector3f1 = this.parseVector3f(jsonobject, "translation", TRANSLATION_DEFAULT); vector3f1.scale(0.0625F); vector3f1.x = MathHelper.clamp_float(vector3f1.x, -1.5F, 1.5F); vector3f1.y = MathHelper.clamp_float(vector3f1.y, -1.5F, 1.5F); vector3f1.z = MathHelper.clamp_float(vector3f1.z, -1.5F, 1.5F); Vector3f vector3f2 = this.parseVector3f(jsonobject, "scale", SCALE_DEFAULT); vector3f2.x = MathHelper.clamp_float(vector3f2.x, -4.0F, 4.0F); vector3f2.y = MathHelper.clamp_float(vector3f2.y, -4.0F, 4.0F); vector3f2.z = MathHelper.clamp_float(vector3f2.z, -4.0F, 4.0F); return new ItemTransformVec3f(vector3f, vector3f1, vector3f2); }
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale) { Matrix4f matrix = new Matrix4f(); matrix.setIdentity(); Matrix4f.translate(translation, matrix, matrix); Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1, 0, 0), matrix, matrix); Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0, 1, 0), matrix, matrix); Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0, 0, 1), matrix, matrix); Matrix4f.scale(new Vector3f(scale, scale, scale), matrix, matrix); return matrix; }
public static void main(String[] args) { DisplayManager.createDisplay(); Loader loader = new Loader(); RawModel model = OBJLoader.loadObjModel("tree", loader); TexturedModel texturedModel = new TexturedModel(model, new ModelTexture(loader.loadTexture("tree"))); List<Entity> entities = new ArrayList<Entity>(); Random random = new Random(); for(int i = 0; i < 500; i++){ entities.add(new Entity(texturedModel, new Vector3f(random.nextFloat()*800 - 400, 0, random.nextFloat() * -600), 0, 0, 0, 3)); } Light light = new Light(new Vector3f(20000, 20000, 2000), new Vector3f(1, 1, 1)); Terrain terrain1 = new Terrain(-1, -1, loader, new ModelTexture(loader.loadTexture("grass"))); Terrain terrain2 = new Terrain(0, -1, loader, new ModelTexture(loader.loadTexture("grass"))); Camera camera = new Camera(); MasterRenderer renderer = new MasterRenderer(); while(!Display.isCloseRequested()) { camera.move(); renderer.processTerrain(terrain1); renderer.processTerrain(terrain2); for(Entity entity:entities){ renderer.processEntity(entity); } renderer.render(light, camera); // render model DisplayManager.updateDisplay(); } renderer.cleanUp(); loader.cleanUp(); // delete all VBOs and VAOs DisplayManager.closeDisplay(); }
/** * Calculates the normal of the triangle made from the 3 vertices. The vertices must be specified in counter-clockwise order. * @param vertex0 * @param vertex1 * @param vertex2 * @return */ public static Vector3f calcNormal(Vector3f vertex0, Vector3f vertex1, Vector3f vertex2) { Vector3f tangentA = Vector3f.sub(vertex1, vertex0, null); Vector3f tangentB = Vector3f.sub(vertex2, vertex0, null); Vector3f normal = Vector3f.cross(tangentA, tangentB, null); normal.normalise(); return normal; }
public static Vector3f[][] generateNormals(float[][] heights) { Vector3f[][] normals = new Vector3f[heights.length][heights.length]; for (int z = 0; z < normals.length; z++) { for (int x = 0; x < normals[z].length; x++) { normals[z][x] = calculateNormal(x, z, heights); } } return normals; }
private Vector3f[] calculateCornerPositions(int col, int row, float[][] heights) { Vector3f[] vertices = new Vector3f[4]; vertices[0] = new Vector3f(col, heights[row][col], row); vertices[1] = new Vector3f(col, heights[row + 1][col], row + 1); vertices[2] = new Vector3f(col + 1, heights[row][col + 1], row); vertices[3] = new Vector3f(col + 1, heights[row + 1][col + 1], row + 1); return vertices; }
public BakedQuad makeBakedQuad(Vector3f p_makeBakedQuad_1_, Vector3f p_makeBakedQuad_2_, BlockPartFace p_makeBakedQuad_3_, TextureAtlasSprite p_makeBakedQuad_4_, EnumFacing p_makeBakedQuad_5_, ITransformation p_makeBakedQuad_6_, BlockPartRotation p_makeBakedQuad_7_, boolean p_makeBakedQuad_8_, boolean p_makeBakedQuad_9_) { BlockFaceUV blockfaceuv = p_makeBakedQuad_3_.blockFaceUV; if (p_makeBakedQuad_8_) { if (Reflector.ForgeHooksClient_applyUVLock.exists()) { blockfaceuv = (BlockFaceUV)Reflector.call(Reflector.ForgeHooksClient_applyUVLock, new Object[] {p_makeBakedQuad_3_.blockFaceUV, p_makeBakedQuad_5_, p_makeBakedQuad_6_}); } else { blockfaceuv = this.applyUVLock(p_makeBakedQuad_3_.blockFaceUV, p_makeBakedQuad_5_, (ModelRotation)p_makeBakedQuad_6_); } } boolean flag = p_makeBakedQuad_9_ && !Reflector.ForgeHooksClient_fillNormal.exists(); int[] aint = this.makeQuadVertexData(blockfaceuv, p_makeBakedQuad_4_, p_makeBakedQuad_5_, this.getPositionsDiv16(p_makeBakedQuad_1_, p_makeBakedQuad_2_), p_makeBakedQuad_6_, p_makeBakedQuad_7_, flag); EnumFacing enumfacing = getFacingFromVertexData(aint); if (p_makeBakedQuad_7_ == null) { this.applyFacing(aint, enumfacing); } if (Reflector.ForgeHooksClient_fillNormal.exists()) { Reflector.call(Reflector.ForgeHooksClient_fillNormal, new Object[] {aint, enumfacing}); return new BakedQuad(aint, p_makeBakedQuad_3_.tintIndex, enumfacing, p_makeBakedQuad_4_, p_makeBakedQuad_9_, DefaultVertexFormats.ITEM); } else { return new BakedQuad(aint, p_makeBakedQuad_3_.tintIndex, enumfacing, p_makeBakedQuad_4_); } }
private static Vector3f calculateNormal(int x, int z, float[][] heights) { float heightL = getHeight(x - 1, z, heights); float heightR = getHeight(x + 1, z, heights); float heightD = getHeight(x, z - 1, heights); float heightU = getHeight(x, z + 1, heights); Vector3f normal = new Vector3f(heightL - heightR, 2f, heightD - heightU); normal.normalise(); return normal; }
public Camera(Player player, Vector3f pos, float pitch, float yaw, float roll, boolean isFP) { this.player = player; this.pitch = pitch; this.yaw = yaw; this.roll = roll; this.position = pos; this.isFirstPerson = isFP; }
private boolean isUnderGround(Vector3f testPoint) { Terrain terrain = getTerrain(testPoint.getX(), testPoint.getZ()); float height = 0; if (terrain != null) { //height = terrain.getHeightTerrain(testPoint.getX(), testPoint.getZ()); } if (testPoint.y < height) { return true; } else { return false; } }
public static Vector3f getVectorFromPoints(Vector3f point1, Vector3f point2) { Vector3f temp = new Vector3f(); temp.x = point2.x - point1.x; temp.y = point2.y - point1.y; temp.z = point2.z - point1.z; return temp; }