public Quaternion(float w, ImmutableVector<Vector3> vec) { this.w = w; this.vec = vec.clone().normalize(); }
/** * initializes a Quaternion with spherical rotation angles * <p/> * @param latitude * @param longitude * @param angle */ public void setSphericalAngles(double latitude, double longitude, double angle) { angle *= Matrix4.GRAD2RAD; double sin_a = sin(angle / 2); double cos_a = cos(angle / 2); double sin_lat = sin(latitude); double cos_lat = cos(latitude); double sin_long = sin(longitude); double cos_long = cos(longitude); double x = sin_a * cos_lat * sin_long; double y = sin_a * sin_lat; double z = sin_a * sin_lat * cos_long; vec = new Vector3((float) x, (float) y, (float) z).normalize(); w = (float) cos_a; }
/** * initializes the quaternion wiht Eular Angles * <p/> * @param pitch X axis angle in GRAD * @param yaw Y axis angle in GRAD * @param roll Z axis angle in GRAD */ public void setEularAngles(double pitch, double yaw, double roll) { //from http://etclab.mie.utoronto.ca/people/david_dir/GEMS/GEMS.html double pi = pitch * Matrix4.GRAD2RAD; double ya = yaw * Matrix4.GRAD2RAD; double ro = roll * Matrix4.GRAD2RAD; double sinPitch = sin(pi * 0.5); double cosPitch = cos(pi * 0.5F); double sinYaw = sin(ya * 0.5F); double cosYaw = cos(ya * 0.5F); double sinRoll = sin(ro * 0.5F); double cosRoll = cos(ro * 0.5F); double cosPitchCosYaw = cosPitch * cosYaw; double sinPitchSinYaw = sinPitch * sinYaw; double x = sinRoll * cosPitchCosYaw - cosRoll * sinPitchSinYaw; double y = cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw; double z = cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw; vec = new Vector3((float) x, (float) y, (float) z).normalize(); w = (float) (cosRoll * cosPitchCosYaw + sinRoll * sinPitchSinYaw); }
private void ini(ImmutableVector<Vector3> axis, float angle) { float[] c = axis.clone().normalize().getCoords(); float half = angle * 0.5f; float sin_a = (float) sin(half); float x = c[0] * sin_a; float y = c[1] * sin_a; float z = c[2] * sin_a; vec = new Vector3(x, y, z); w = (float) cos(half); }
/** * initializes a Quaternion which maps a Vector on another. * <p/> * @param old Source Vector which gets mapped. * @param map2 Destination Vector which the source Vector gets mapped to. */ public void mapVector(ImmutableVector<Vector3> old, ImmutableVector<Vector3> map2) { Vector3 o = old.clone().normalize(); Vector3 m = map2.clone().normalize(); float p = (float) acos(o.dot(m)); ini(o.cross(m), p); }
public Plane(ImmutableVector a, ImmutableVector normal) { this.a = a.toVector3(); this.normal = normal.toVector3().normalize(); nDot = -this.normal.dot(a); }
ImmutableVector<Vector3> normal = new Vector3(tmp[0] / 255f * 2f - 1f, tmp[1] / 255f * 2f - 1f, tmp[2] / 255f).normalize(); Vector3 dir = new Vector3(sx, sy, tmp[0]).sub(position); double lenSqrt = sqrt(dir.length()); double cosa = dir.normalize().dot(normal); if (cosa >= 0.) { sumOcclusion += cosa / lenSqrt;
public double distanceTo(Line<E> g) { if (isParallelTo(g)) { return distanceTo(g.a); } else { //TODO Vector3 n = dir.toVector3().cross(g.dir.toVector3()).normalize(); return Math.abs(a.clone().sub(g.a).toVector3().dot(n)); } }
/** * Builds a orthogonal Coordinate System, where the given Vector represents * the given Axis. Both other Axis are generated in a way that no gurantee * can be given how their orientation are. * <p/> * @param dir direction Vector of the given Axis * @param a Axis of the given Vektor */ public static Matrix4 createCoordinateSystem(ImmutableVector<Vector3> dir, Axis a) { Matrix4 res = new Matrix4(); res.loadIdentity(); Vector3 di = dir.clone().normalize(); res.setAxis(di, a); Vector3 dir2 = new Vector3(di.getY(), di.getZ(), -di.getX()); Vector3 dir3 = dir.clone().cross(dir2); Axis[] vals = Axis.values(); int a2 = a.ordinal(); a2 = (1 << a2) & 3; //(ordinal+1)%3 int a3 = (1 << a2) & 3;//(ordinal+2)%3 res.setAxis(dir2, vals[a2]); res.setAxis(dir3, vals[a3]); return res; }
private Float[] calculateTangent(Vertex v0, Vertex v1, Vertex v2) { Vector3 pos1 = getPosition(v0); Vector3 pos2 = getPosition(v1); Vector3 pos3 = getPosition(v2); Vector2 uv1 = getTexCoord(v0); Vector2 uv2 = getTexCoord(v1); Vector2 uv3 = getTexCoord(v2); Vector3 v2v1 = pos2.clone().sub(pos1); Vector3 v3v1 = pos3.clone().sub(pos1); float c2c1b = uv2.getY() - uv1.getY(); float c3c1b = uv3.getY() - uv1.getY(); Vector3 n = getNormal(v0); Vector3 t = new Vector3(c3c1b * v2v1.getX() - c2c1b * v3v1.getX(), c3c1b * v2v1.getY() - c2c1b * v3v1.getY(), c3c1b * v2v1.getZ() - c2c1b * v3v1.getZ()); Vector3 b = n.cross(t); Vector3 smoothTangent = b.cross(n).normalize(); return float2Float(smoothTangent.getCoords()); }