private static Vector3f calculateSpherePoint(float x, float y) { Vector3f result = new Vector3f(x, y, 0); float sqrZ = 1 - Vector3f.dot(result, result); if (sqrZ > 0) result.z = (float)Math.sqrt(sqrZ); else result.normalise(); return result; }
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; }
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); }
/** * 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); } }
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);