public Quaternion() { w = 1; vec = new Vector3(); }
@Override public Vector3 toVector3() { return new Vector3(x, y, 0); }
public SimplePhysic(float radius, float mass) { this(radius, mass, new Vector3()); }
public MatrixCache(ProjectionMatrix pro) { view = new ViewMatrix(); view.loadIdentity(); projektion = pro; listener = new LinkedList<>(); AABB scene = new AABB(new Vector3(), new Vector3()); // sutil = new ShadowUtil(scene); // addListener(sutil); // sutil.changeOccured(new MatrixEvent(this, VIEW)); }
public Vector3 cross(ImmutableVector<Vector3> b) { Vector3 mul = b.clone(); return new Vector3(y * mul.z - z * mul.y, z * mul.x - x * mul.z, x * mul.y - y * mul.x); }
/** * @return a axis vector of the object space represented by this matrix (not * normalized). */ public Vector3 getAxis(Axis a) { float[] mat = getArray(); float[] vec = new float[3]; System.arraycopy(mat, a.offset, vec, 0, 3); return new Vector3(mat[a.offset], mat[a.offset + 1], mat[a.offset + 2]); }
@Override public Vector3 toVector3() { return new Vector3(coords[0], coords[1], getDimension() > 2 ? coords[2] : 0); }
/** * @return total translation of matrix space relativ to world space. Can be * used as position of the matrix in world space. */ public Vector3 getTranslation() { float[] mat = getArray(); return new Vector3(mat[12], mat[13], mat[14]); }
public Quaternion mult(Quaternion q) { float[] q1 = vec.getCoords(); float[] q2 = q.vec.getCoords(); float ww = w * q.w - q1[0] * q.w - q1[1] * q2[1] - q1[2] * q2[2]; float x = w * q2[0] + q1[0] * q.w + q1[1] * q2[2] - q1[2] * q2[1]; float y = w * q2[1] + q1[1] * q.w + q1[2] * q2[0] - q1[0] * q2[2]; float z = w * q2[2] + q1[2] * q.w + q1[0] * q2[1] - q1[1] * q2[0]; return new Quaternion(ww, new Vector3(x, y, z)); }
/** * 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); }
private Vector3 getPosition(Vertex v) { float[] pos = getFloat(v.getAttribute(position)); return new Vector3(pos[0], pos[1], pos[2]); }
private Vector3 getNormal(Vertex v) { float[] pos = getFloat(v.getAttribute(normal)); return new Vector3(pos[0], pos[1], pos[2]); }
public Vector3[] getCorners() { float[] c = dimension.getCoords(); Vector3[] corners = new Vector3[8]; for (int i = 0; i < 8; i++) { int ii = i % 4; corners[i] = start.clone().add(new Vector3( (ii == 1 || ii == 2) ? c[0] : 0, ii < 2 ? 0 : c[1], i < 4 ? 0 : c[2])); } return corners; }
public Vector3 getViewDirection() { float[] f = inverse().getColumn(2).getCoords(); return new Vector3(f[0], f[1], f[2]); }
public Vector3 fastMult(Tupel3 vec) { float[] data = getArray(); float x, y, z; x = data[0]; x += data[1]; x += data[2]; x += data[3]; y = data[4]; y += data[5]; y += data[6]; y += data[7]; z = data[8]; z += data[9]; z += data[10]; z += data[11]; return new Vector3(x * vec.getX(), y * vec.getY(), z * vec.getZ()); }
private void updateLight(ImmutableVector<Vector3> lightdir) { getMatrices().setLight(lightdir.clone()); Vector3 light = matrices.getView().fastMult(lightdir.clone()); light.normalize(); Vector3 halfvector = new Vector3(0, 0, 1).add(light).normalize(); setLightUniforms(light, halfvector); }
/** * 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()); }