public Vector3f vector3f() { return new Vector3f((float)x, (float)y, (float)z); }
/** * Normalise this vector and place the result in another vector. * @param dest The destination vector, or null if a new vector is to be created * @return the normalised vector */ public Vector3f normalise(Vector3f dest) { float l = length(); if (dest == null) dest = new Vector3f(x / l, y / l, z / l); else dest.set(x / l, y / l, z / l); return dest; }
/** * Called to update the entity's position/logic. */ public void onUpdate() { this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; if (this.particleAge++ >= this.particleMaxAge) { this.setExpired(); } float percent = (float) this.particleAge / (float) this.particleMaxAge; Vector3f dir = Vector3f.sub(to, from, null); Vector3f spiralDir = Vector3f.cross(dir.normalise(null), up, null); spiralDir.scale((float) Math.sin((particleAge + startTime) * 0.5) * orbitRadius); Vector3f up = new Vector3f(this.up); up.scale((float) Math.cos((particleAge + startTime) * 0.5) * orbitRadius); Vector3f.add(spiralDir, up, spiralDir); dir.scale(percent); Vector3f posOnPath = Vector3f.add(from, dir, null); setPosition(posOnPath.x + spiralDir.x, posOnPath.y + spiralDir.y, posOnPath.z + spiralDir.z); } }
private static void addNormalCover(List<BakedQuad> quads, TextureAtlasSprite sprite, EnumFacing coverSide, boolean hasUp, boolean hasDown, boolean hasEast, boolean hasWest, boolean handle) { AxisAlignedBB bounds = ConstantsCable.getCoverBounds(coverSide); Vector3f from = new Vector3f((float) bounds.minX * 16, (float) bounds.minY * 16, (float) bounds.minZ * 16); Vector3f to = new Vector3f((float) bounds.maxX * 16, (float) bounds.maxY * 16, (float) bounds.maxZ * 16); from.setX(2); to.setX(14); from.setX(2); to.setX(14); from.setY(2); to.setY(14); quads.addAll(new CubeBuilder().from(from.getX(), from.getY(), from.getZ()).to(to.getX(), to.getY(), to.getZ()).addFaces(face -> new CubeBuilder.Face(face, sprite)).bake()); from = new Vector3f((float) bounds.minX * 16, (float) bounds.minY * 16, (float) bounds.minZ * 16); to = new Vector3f((float) bounds.maxX * 16, (float) bounds.maxY * 16, (float) bounds.maxZ * 16); quads.addAll(new CubeBuilder().from(from.getX(), from.getY(), from.getZ()).to(to.getX(), to.getY(), to.getZ()).addFaces(face -> new CubeBuilder.Face(face, BORDER_SPRITE)).bake());
@SideOnly(Side.CLIENT) public void SpawnReplicateParticles(int startTime) { double time = (double) (startTime) / (double) (REPLICATION_ANIMATION_TIME); double gravity = MOMathHelper.easeIn(time, 0.02, 0.2, 1); int age = (int) Math.round(MOMathHelper.easeIn(time, 2, 10, 1)); int count = (int) Math.round(MOMathHelper.easeIn(time, 1, 20, 1)); for (int i = 0; i < count; i++) { float speed = 0.05f; Vector3f pos = MOMathHelper.randomSpherePoint(this.getPos().getX() + 0.5D, this.getPos().getY() + 0.5D, this.getPos().getZ() + 0.5D, new Vec3d(0.5, 0.5, 0.5), this.world.rand); Vector3f dir = new Vector3f(random.nextFloat() * 2 - 1, (random.nextFloat() * 2 - 1) * 0.05f, random.nextFloat() * 2 - 1); dir.scale(speed); ReplicatorParticle replicatorParticle = new ReplicatorParticle(this.world, pos.getX(), pos.getY(), pos.getZ(), dir.getX(), dir.getY(), dir.getZ()); replicatorParticle.setCenter(this.getPos().getX() + 0.5D, this.getPos().getY() + 0.5D, this.getPos().getZ() + 0.5D); replicatorParticle.setParticleAge(age); replicatorParticle.setPointGravityScale(gravity); Minecraft.getMinecraft().effectRenderer.addEffect(replicatorParticle); } }
Vector3f source = new Vector3f(stabilizer.getPos().getX(), stabilizer.getPos().getY(), stabilizer.getPos().getZ()); Vector3f destination = new Vector3f((float) hit.hitVec.x, (float) hit.hitVec.y, (float) hit.hitVec.z); Vector3f dir = Vector3f.sub(destination, source, null); Vector3f dirC = Vector3f.cross(dir, new Vector3f(1, 0, 1), null); float distance = dir.length(); dir.normalise(dir); Vector3f front = new Vector3f(0, 0, -1); Vector3f c = Vector3f.cross(dir, front, null); double omega = Math.acos(Vector3f.dot(dir, front)); GlStateManager.enableBlend(); GlStateManager.disableCull();
/** * Add a vector to another vector and place the result in a destination * vector. * @param left The LHS vector * @param right The RHS vector * @param dest The destination vector, or null if a new vector is to be created * @return the sum of left and right in dest */ public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) { if (dest == null) return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z); else { dest.set(left.x + right.x, left.y + right.y, left.z + right.z); return dest; } }
private void renderAttack(Vector3f dir, float percent) { GlStateManager.pushMatrix(); Vector3f front = new Vector3f(1, 0, 0); Vector3f c = Vector3f.cross(dir, front, null); double omega = Math.acos(Vector3f.dot(dir, front)); GlStateManager.rotate((float) (omega * (180 / Math.PI)), c.x, c.y, c.z); RenderUtils.applyColorWithMultipy(Reference.COLOR_HOLO, 1 * percent); Minecraft.getMinecraft().renderEngine.bindTexture(forcefield_damage_tex); //normal_sphere.renderAll(); GlStateManager.popMatrix(); } }
@SideOnly(Side.CLIENT) public void SpawnReplicateParticles(Entity entity, Vector3f p) { double entityRadius = entity.width; double entityArea = Math.max(entityRadius * entity.height, 0.3); double radiusX = entityRadius + random.nextDouble() * 0.2f; double radiusZ = entityRadius + random.nextDouble() * 0.2f; double time = Math.min((double) (transportTimer) / (double) (getTransportDelay()), 1); double gravity = 0.015f; int age = (int) Math.round(MOMathHelper.easeIn(time, 5, 15, 1)); int count = (int) Math.round(MOMathHelper.easeIn(time, 2, entityArea * 15, 1)); for (int i = 0; i < count; i++) { float speed = random.nextFloat() * 0.05f + 0.15f; float height = p.y + 1 + random.nextFloat() * entity.height; Vector3f origin = new Vector3f(p.x, height, p.z); Vector3f pos = MOMathHelper.randomSpherePoint(origin.x, origin.y, origin.z, new Vec3d(radiusX, 0, radiusZ), random); Vector3f dir = Vector3f.cross(Vector3f.sub(origin, pos, null), new Vector3f(0, 1, 0), null); dir.scale(speed); ReplicatorParticle replicatorParticle = new ReplicatorParticle(this.world, pos.x, pos.y, pos.z, dir.x, dir.y, dir.z); replicatorParticle.setCenter(origin.x, origin.y, origin.z); replicatorParticle.setParticleAge(age); replicatorParticle.setPointGravityScale(gravity); Minecraft.getMinecraft().effectRenderer.addEffect(replicatorParticle); } }
public Matrix3f rotationMatrix(float angle, float x, float y, float z) { angle *= (float) Math.PI / 180.0F; Vector3f axis = new Vector3f(x, y, z); axis.normalise(); float s = (float) Math.sin(angle); float c = (float) Math.cos(angle); float oc = 1.0f - c; Matrix3f mat = new Matrix3f(); mat.m00 = oc * axis.x * axis.x + c; mat.m01 = oc * axis.x * axis.y - axis.z * s; mat.m02 = oc * axis.z * axis.x + axis.y * s; mat.m10 = oc * axis.x * axis.y + axis.z * s; mat.m11 = oc * axis.y * axis.y + c; mat.m12 = oc * axis.y * axis.z - axis.x * s; mat.m20 = oc * axis.z * axis.x - axis.y * s; mat.m21 = oc * axis.y * axis.z + axis.x * s; mat.m22 = oc * axis.z * axis.z + c; return mat; }
for (int i = 0; i < count; i++) { Matrix4f rotation = new Matrix4f(); Vector3f offset = new Vector3f(); rotation.rotate((float) Math.PI / 2f, new Vector3f(0, 0, 1)); offset = new Vector3f(0.5f, 0.7f, 0.5f); } else if (side == EnumFacing.WEST) { rotation.rotate((float) Math.PI / 2f, new Vector3f(0, 0, 1)); offset = new Vector3f(-0.2f, 0.5f, 0.5f); } else if (side == EnumFacing.EAST) { rotation.rotate((float) Math.PI / 2f, new Vector3f(0, 0, -1)); offset = new Vector3f(1.2f, 0.5f, 0.5f); } else if (side == EnumFacing.SOUTH) { rotation.rotate((float) Math.PI / 2f, new Vector3f(1, 0, 0)); offset = new Vector3f(0.5f, 0.5f, 1.2f); } else if (side == EnumFacing.NORTH) { rotation.rotate((float) Math.PI / 2f, new Vector3f(-1, 0, 0)); offset = new Vector3f(0.5f, 0.5f, -0.2f); circle.scale(0.4f); Vector4f circleTransformed = new Vector4f(circle.x, circle.y, circle.z, 1); Matrix4f.transform(rotation, circleTransformed, circleTransformed);
private Matrix4f getTransform(float mouseX, float mouseY) { Preconditions.checkNotNull(dragStart, "Draging not started"); Vector3f current = calculateSpherePoint(mouseX, mouseY); float dot = Vector3f.dot(dragStart, current); if (Math.abs(dot - 1) < 0.0001) return lastTransform; Vector3f axis = Vector3f.cross(dragStart, current, null); try { axis.normalise(); } catch (IllegalStateException e) { // Zero length vector return lastTransform; } float angle = 2 * (float)(Math.acos(dot)); Matrix4f rotation = new Matrix4f(); rotation.rotate(angle, axis); return Matrix4f.mul(rotation, lastTransform, null); }
/** * Calculate the angle between two vectors, in radians * @param a A vector * @param b The other vector * @return the angle between the two vectors, in radians */ public static float angle(Vector3f a, Vector3f b) { float dls = dot(a, b) / (a.length() * b.length()); if (dls < -1f) dls = -1f; else if (dls > 1.0f) dls = 1.0f; return (float)Math.acos(dls); }
Vector3f.sub(part.positionFrom, trimTranslation, part.positionFrom); Vector3f.sub(part.positionTo, trimTranslation, part.positionTo); Vector3f.sub(part.positionTo, trimTranslation, part.positionTo); elements.add(part); Vector3f.add(part.positionTo, backTranslation, part.positionTo); BlockPartFace face; if(backIndex!=-1) {
public void translate(Vector3f translationVector) { for (Vertex vertex : this.vertexList) { Vector3f.add(vertex.getPosition(), translationVector, vertex.getPosition()); } }
Vector3f from = new Vector3f((float) bounds.minX * 16, (float) bounds.minY * 16, (float) bounds.minZ * 16); Vector3f to = new Vector3f((float) bounds.maxX * 16, (float) bounds.maxY * 16, (float) bounds.maxZ * 16); from.setY(2); to.setY(14); from.setX(2); } else { from.setX(0); to.setX(size); } else if (coverSide == EnumFacing.SOUTH) { if (hasEast) { to.setX(14); } else { to.setX(16); from.setX(16 - size); } else if (coverSide == EnumFacing.EAST) { from.setZ(0); to.setZ(size); } else if (coverSide == EnumFacing.WEST) { from.setZ(16 - size); to.setZ(16); } else if (coverSide == EnumFacing.DOWN || coverSide == EnumFacing.UP) { from.setZ(16 - size); to.setZ(16);
/** * Subtract a vector from another vector and place the result in a destination * vector. * @param left The LHS vector * @param right The RHS vector * @param dest The destination vector, or null if a new vector is to be created * @return left minus right in dest */ public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) { if (dest == null) return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z); else { dest.set(left.x - right.x, left.y - right.y, left.z - right.z); return dest; } }