/** * Internally rotates this vector around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @return this vector for chaining */ public Vector2 rotateAroundOriginLocal(double angle, final boolean clockwise) { if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return set(newX, newY); }
/** * Internally rotates this vector around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @return this vector for chaining */ public Vector2 rotateAroundOriginLocal(double angle, final boolean clockwise) { if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return set(newX, newY); }
/** * Creates a new vector representing this vector rotated around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return the new rotated vector */ @Override public Vector2 rotateAroundOrigin(double angle, final boolean clockwise, final Vector2 store) { Vector2 result = store; if (result == null) { result = new Vector2(); } if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return result.set(newX, newY); }
/** * Sets the values of this quaternion to the values represented by a given angle and unit length axis of rotation. * If axis == 0,0,0 the quaternion is set to identity. * * @param angle * the angle to rotate (in radians). * @param axis * the axis of rotation (already normalized - unit length). * @throws NullPointerException * if axis is null */ public Quaternion fromAngleNormalAxis(final double angle, final ReadOnlyVector3 axis) { if (axis.equals(Vector3.ZERO)) { return setIdentity(); } final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double w = MathUtils.cos(halfAngle); final double x = sin * axis.getX(); final double y = sin * axis.getY(); final double z = sin * axis.getZ(); return set(x, y, z, w); }
/** * Creates a new vector representing this vector rotated around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return the new rotated vector */ @Override public Vector2 rotateAroundOrigin(double angle, final boolean clockwise, final Vector2 store) { Vector2 result = store; if (result == null) { result = new Vector2(); } if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return result.set(newX, newY); }
/** * Sets the values of this quaternion to the values represented by a given angle and unit length axis of rotation. * If axis == 0,0,0 the quaternion is set to identity. * * @param angle * the angle to rotate (in radians). * @param axis * the axis of rotation (already normalized - unit length). * @throws NullPointerException * if axis is null */ public Quaternion fromAngleNormalAxis(final double angle, final ReadOnlyVector3 axis) { if (axis.equals(Vector3.ZERO)) { return setIdentity(); } final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double w = MathUtils.cos(halfAngle); final double x = sin * axis.getX(); final double y = sin * axis.getY(); final double z = sin * axis.getZ(); return set(x, y, z, w); }
/** * Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores the results in the * store var. * * @param sphereCoords * (Radius, Azimuth, Polar) * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 sphericalToCartesianZ(final ReadOnlyVector3 sphereCoords, final Vector3 store) { final double a = sphereCoords.getX() * cos(sphereCoords.getZ()); final double x = a * cos(sphereCoords.getY()); final double y = a * sin(sphereCoords.getY()); final double z = sphereCoords.getX() * sin(sphereCoords.getZ()); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores the results in the * store var. * * @param sphereCoords * (Radius, Azimuth, Polar) * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 sphericalToCartesianZ(final ReadOnlyVector3 sphereCoords, final Vector3 store) { final double a = sphereCoords.getX() * cos(sphereCoords.getZ()); final double x = a * cos(sphereCoords.getY()); final double y = a * sin(sphereCoords.getY()); final double z = sphereCoords.getX() * sin(sphereCoords.getZ()); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Converts a point from Spherical coordinates to Cartesian (using positive Y as up) and stores the results in the * store var. * * @param sphereCoords * (Radius, Azimuth, Polar) * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 sphericalToCartesian(final ReadOnlyVector3 sphereCoords, final Vector3 store) { final double a = sphereCoords.getX() * cos(sphereCoords.getZ()); final double x = a * cos(sphereCoords.getY()); final double y = sphereCoords.getX() * sin(sphereCoords.getZ()); final double z = a * sin(sphereCoords.getY()); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Converts a point from Spherical coordinates to Cartesian (using positive Y as up) and stores the results in the * store var. * * @param sphereCoords * (Radius, Azimuth, Polar) * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 sphericalToCartesian(final ReadOnlyVector3 sphereCoords, final Vector3 store) { final double a = sphereCoords.getX() * cos(sphereCoords.getZ()); final double x = a * cos(sphereCoords.getY()); final double y = sphereCoords.getX() * sin(sphereCoords.getZ()); final double z = a * sin(sphereCoords.getY()); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
private void setGeometryData(final int shellLess) { // generate geometry // center of disk _meshData.getVertexBuffer().put(0).put(0).put(0); for (int x = 0; x < _meshData.getVertexCount(); x++) { _meshData.getNormalBuffer().put(0).put(0).put(1); } _meshData.getTextureCoords(0).getBuffer().put(.5f).put(.5f); final double inverseShellLess = 1.0 / shellLess; final double inverseRadial = 1.0 / _radialSamples; final Vector3 radialFraction = new Vector3(); final Vector2 texCoord = new Vector2(); for (int radialCount = 0; radialCount < _radialSamples; radialCount++) { final double angle = MathUtils.TWO_PI * inverseRadial * radialCount; final double cos = MathUtils.cos(angle); final double sin = MathUtils.sin(angle); final Vector3 radial = new Vector3(cos, sin, 0); for (int shellCount = 1; shellCount < _shellSamples; shellCount++) { final double fraction = inverseShellLess * shellCount; // in (0,R] radialFraction.set(radial).multiplyLocal(fraction); final int i = shellCount + shellLess * radialCount; texCoord.setX(0.5 * (1.0 + radialFraction.getX())); texCoord.setY(0.5 * (1.0 + radialFraction.getY())); BufferUtils.setInBuffer(texCoord, _meshData.getTextureCoords(0).getBuffer(), i); radialFraction.multiplyLocal(_radius); BufferUtils.setInBuffer(radialFraction, _meshData.getVertexBuffer(), i); } } }
/** * Generate a random velocity within the parameters of max angle and the rotation matrix. * * @param store * a vector to store the results in. */ protected Vector3 getRandomVelocity(final Vector3 store) { final double randDir = MathUtils.TWO_PI * MathUtils.nextRandomFloat(); final double randAngle = getRandomAngle(); Vector3 result = store; if (result == null) { result = new Vector3(); } result.setX(MathUtils.cos(randDir) * MathUtils.sin(randAngle)); result.setY(MathUtils.cos(randAngle)); result.setZ(MathUtils.sin(randDir) * MathUtils.sin(randAngle)); rotateVectorSpeed(result); result.multiplyLocal(getInitialVelocity()); return result; }
/** * Generate a random velocity within the parameters of max angle and the rotation matrix. * * @param store * a vector to store the results in. */ protected Vector3 getRandomVelocity(final Vector3 store) { final double randDir = MathUtils.TWO_PI * MathUtils.nextRandomFloat(); final double randAngle = getRandomAngle(); Vector3 result = store; if (result == null) { result = new Vector3(); } result.setX(MathUtils.cos(randDir) * MathUtils.sin(randAngle)); result.setY(MathUtils.cos(randAngle)); result.setZ(MathUtils.sin(randDir) * MathUtils.sin(randAngle)); rotateVectorSpeed(result); result.multiplyLocal(getInitialVelocity()); return result; }
/** * Apply rotation around Z * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationZ(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos + getY() * sin; final double newY = -getX() * sin + getY() * cos; final double newZ = getZ() * cos + getW() * sin; final double newW = -getZ() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around Z * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationZ(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos + getY() * sin; final double newY = -getX() * sin + getY() * cos; final double newZ = getZ() * cos + getW() * sin; final double newW = -getZ() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around Y * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationY(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos - getZ() * sin; final double newY = getY() * cos + getW() * sin; final double newZ = getX() * sin + getZ() * cos; final double newW = -getY() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around X * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationX(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos + getW() * sin; final double newY = getY() * cos + getZ() * sin; final double newZ = -getY() * sin + getZ() * cos; final double newW = -getX() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around X * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationX(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos + getW() * sin; final double newY = getY() * cos + getZ() * sin; final double newZ = -getY() * sin + getZ() * cos; final double newW = -getX() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around Y * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationY(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos - getZ() * sin; final double newY = getY() * cos + getW() * sin; final double newZ = getX() * sin + getZ() * cos; final double newW = -getY() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
final double fCos = MathUtils.cos(angle); final double fSin = MathUtils.sin(angle); final double fOneMinusCos = 1.0 - fCos;