/** * Ensure our up, left and direction are unit-length vectors. */ public void normalize() { _left.normalizeLocal(); _up.normalizeLocal(); _direction.normalizeLocal(); onFrameChange(); }
/** * Ensure our up, left and direction are unit-length vectors. */ public void normalize() { _left.normalizeLocal(); _up.normalizeLocal(); _direction.normalizeLocal(); onFrameChange(); }
@Override public void prepare(final ParticleSystem system) { if (_wanderTargets.size() != system.getNumParticles()) { _wanderTargets = new ArrayList<Vector3>(system.getNumParticles()); for (int x = system.getNumParticles(); --x >= 0;) { _wanderTargets.add(new Vector3(system.getEmissionDirection()).normalizeLocal()); } } }
@Override public void prepare(final ParticleSystem system) { if (_wanderTargets.size() != system.getNumParticles()) { _wanderTargets = new ArrayList<Vector3>(system.getNumParticles()); for (int x = system.getNumParticles(); --x >= 0;) { _wanderTargets.add(new Vector3(system.getEmissionDirection()).normalizeLocal()); } } }
@Override public void apply(final double dt, final Particle particle, final int index) { if (_wanderRadius == 0 && _wanderDistance == 0 && _wanderJitter == 0) { return; } final Vector3 wanderTarget = _wanderTargets.get(index); wanderTarget.addLocal(calcNewJitter(), calcNewJitter(), calcNewJitter()); wanderTarget.normalizeLocal(); wanderTarget.multiplyLocal(_wanderRadius); _workVect.set(particle.getVelocity()).normalizeLocal().multiplyLocal(_wanderDistance); _workVect.addLocal(wanderTarget).normalizeLocal(); _workVect.multiplyLocal(particle.getVelocity().length()); particle.getVelocity().set(_workVect); }
private void setNormalData() { final Vector3 norm = new Vector3(); for (int i = 0; i < NUM_POINTS; i++) { BufferUtils.populateFromBuffer(norm, _meshData.getVertexBuffer(), i); norm.normalizeLocal(); BufferUtils.setInBuffer(norm, _meshData.getNormalBuffer(), i); } }
private void setNormalData() { final Vector3 norm = new Vector3(); for (int i = 0; i < NUM_POINTS; i++) { BufferUtils.populateFromBuffer(norm, _meshData.getVertexBuffer(), i); norm.normalizeLocal(); BufferUtils.setInBuffer(norm, _meshData.getNormalBuffer(), i); } }
private void setNormalData() { final Vector3 norm = new Vector3(); for (int i = 0; i < NUM_POINTS; i++) { BufferUtils.populateFromBuffer(norm, _meshData.getVertexBuffer(), i); norm.normalizeLocal(); BufferUtils.setInBuffer(norm, _meshData.getNormalBuffer(), i); } }
private void setNormalData() { final Vector3 norm = new Vector3(); for (int i = 0; i < NUM_POINTS; i++) { BufferUtils.populateFromBuffer(norm, _meshData.getVertexBuffer(), i); norm.normalizeLocal(); BufferUtils.setInBuffer(norm, _meshData.getNormalBuffer(), i); } }
private void setNormalData() { final Vector3 norm = new Vector3(); for (int i = 0; i < NUM_POINTS; i++) { BufferUtils.populateFromBuffer(norm, _meshData.getVertexBuffer(), i); norm.normalizeLocal(); BufferUtils.setInBuffer(norm, _meshData.getNormalBuffer(), i); } }
private void setNormalData() { final Vector3 norm = new Vector3(); for (int i = 0; i < NUM_POINTS; i++) { BufferUtils.populateFromBuffer(norm, _meshData.getVertexBuffer(), i); norm.normalizeLocal(); BufferUtils.setInBuffer(norm, _meshData.getNormalBuffer(), i); } }
public void transformNormals(final Transform transform, final boolean normalize) { final FloatBuffer normalBuffer = getNormalBuffer(); final Vector3 store = new Vector3(); for (int x = 0; x < _vertexCount; x++) { BufferUtils.populateFromBuffer(store, normalBuffer, x); transform.applyForwardVector(store, store); if (normalize) { store.normalizeLocal(); } BufferUtils.setInBuffer(store, normalBuffer, x); } }
public void transformNormals(final Transform transform, final boolean normalize) { final Vector3 store = new Vector3(); for (int x = 0; x < _vertexCount; x++) { BufferUtils.populateFromBuffer(store, _normalCoords.getBuffer(), x); transform.applyForwardVector(store, store); if (normalize) { store.normalizeLocal(); } BufferUtils.setInBuffer(store, _normalCoords.getBuffer(), x); } }
/** * Constructs a new segment segment using the supplied start and end points * * @param start * @param end */ public LineSegment3(final ReadOnlyVector3 start, final ReadOnlyVector3 end) { this(); _origin.set(start).addLocal(end).multiplyLocal(0.5); _direction.set(end).subtractLocal(start); _extent = 0.5 * _direction.length(); _direction.normalizeLocal(); }
/** * Constructs a new segment segment using the supplied start and end points * * @param start * @param end */ public LineSegment3(final ReadOnlyVector3 start, final ReadOnlyVector3 end) { this(); _origin.set(start).addLocal(end).multiplyLocal(0.5); _direction.set(end).subtractLocal(start); _extent = 0.5 * _direction.length(); _direction.normalizeLocal(); }
/** * Recalculates the surface normal of the triangle by crossing the vectors formed by BA and CA. */ protected void calculateNormal() { if (_normal == null) { _normal = _pointB.clone(); } else { _normal.set(_pointB); } _normal.subtractLocal(_pointA).crossLocal(_pointC.getX() - _pointA.getX(), _pointC.getY() - _pointA.getY(), _pointC.getZ() - _pointA.getZ()); _normal.normalizeLocal(); _dirtyNormal = false; }
/** * Recalculates the surface normal of the triangle by crossing the vectors formed by BA and CA. */ protected void calculateNormal() { if (_normal == null) { _normal = _pointB.clone(); } else { _normal.set(_pointB); } _normal.subtractLocal(_pointA).crossLocal(_pointC.getX() - _pointA.getX(), _pointC.getY() - _pointA.getY(), _pointC.getZ() - _pointA.getZ()); _normal.normalizeLocal(); _dirtyNormal = false; }
@Test public void testLookAt() { final Vector3 direction = new Vector3(-1, 0, 0); final Quaternion quat = new Quaternion().lookAt(direction, Vector3.UNIT_Y); assertTrue(Math.abs(direction.distance(quat.apply(Vector3.UNIT_Z, null))) <= Quaternion.ALLOWED_DEVIANCE); direction.set(1, 1, 1).normalizeLocal(); quat.lookAt(direction, Vector3.UNIT_Y); assertTrue(Math.abs(direction.distance(quat.apply(Vector3.UNIT_Z, null))) <= Quaternion.ALLOWED_DEVIANCE); direction.set(-1, 2, -1).normalizeLocal(); quat.lookAt(direction, Vector3.UNIT_Y); assertTrue(Math.abs(direction.distance(quat.apply(Vector3.UNIT_Z, null))) <= Quaternion.ALLOWED_DEVIANCE); }
private Matrix4 a3dMatrixRandom() { final Matrix4 mat = new Matrix4(); final Vector3 axis = new Vector3(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble()); axis.normalizeLocal(); mat.applyRotation(MathUtils.nextRandomDouble(), axis.getX(), axis.getY(), axis.getZ()); mat.applyTranslationPost(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble()); return mat; }
@Test public void testLookAt() { final Vector3 direction = new Vector3(-1, 0, 0); final Matrix3 mat3 = new Matrix3().lookAt(direction, Vector3.UNIT_Y); assertEquals(direction, mat3.applyPost(Vector3.UNIT_Z, null)); direction.set(1, 1, 1).normalizeLocal(); mat3.lookAt(direction, Vector3.UNIT_Y); assertEquals(direction, mat3.applyPost(Vector3.UNIT_Z, null)); direction.set(-1, 2, -1).normalizeLocal(); mat3.lookAt(direction, Vector3.UNIT_Y); assertEquals(direction, mat3.applyPost(Vector3.UNIT_Z, new Vector3())); } }