/** * Internally modifies the values of this vector by dividing them each by the given scale values. * * @param x * @param y * @param z * @return this vector for chaining */ public Vector3 divideLocal(final double x, final double y, final double z) { return set(getX() / x, getY() / y, getZ() / z); }
public double eval(final double x, final double y, final double z) { final Vector3 temp = Vector3.fetchTempInstance(); temp.set(x, y, z); rotation.applyPost(temp, temp); final double val = source.eval(temp.getX(), temp.getY(), temp.getZ()); Vector3.releaseTempInstance(temp); return val; } };
/** * Compute the average of two vectors. * * @param a * first vector * @param b * second vector * @return the average of two points */ protected Vector3 createMidpoint(final Vector3 a, final Vector3 b) { return new Vector3((a.getX() + b.getX()) * 0.5, (a.getY() + b.getY()) * 0.5, (a.getZ() + b.getZ()) * 0.5); }
/** * 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; }
/** * 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(); }
private void put(final FloatBuffer fb, final FloatBuffer nb, final Vector3 vec) { fb.put((float) vec.getX()).put((float) vec.getY()).put((float) vec.getZ()); final Vector3 v = vec.normalize(Vector3.fetchTempInstance()); nb.put((float) v.getX()).put((float) v.getY()).put((float) v.getZ()); Vector3.releaseTempInstance(v); }
@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()); } } }
/** * Apply the rotation matrix to a given vector representing a particle velocity. * * @param pSpeed * the velocity vector to be modified. */ protected void rotateVectorSpeed(final Vector3 pSpeed) { final double x = pSpeed.getX(), y = pSpeed.getY(), z = pSpeed.getZ(); pSpeed.setX(-1 * ((_rotMatrix.getM00() * x) + (_rotMatrix.getM10() * y) + (_rotMatrix.getM20() * z))); pSpeed.setY((_rotMatrix.getM01() * x) + (_rotMatrix.getM11() * y) + (_rotMatrix.getM21() * z)); pSpeed.setZ(-1 * ((_rotMatrix.getM02() * x) + (_rotMatrix.getM12() * y) + (_rotMatrix.getM22() * z))); }
public Vector3 getPositiveEnd(final Vector3 store) { Vector3 result = store; if (result == null) { result = new Vector3(); } result.set(getDirection()).multiplyLocal(_extent); result.addLocal(getOrigin()); return result; }
private void addVert(final Md2GlCommand cmd, final Md2Frame frame, final int vertIndex, final FloatBufferData verts) { final int index = cmd.vertIndices[vertIndex]; final byte[] vertData = frame.vertData; calcVert.set(vertData[index * 4 + 0] & 0xFF, vertData[index * 4 + 1] & 0xFF, vertData[index * 4 + 2] & 0xFF); calcVert.multiplyLocal(frame.scale).addLocal(frame.translate); verts.getBuffer().put(calcVert.getXf()).put(calcVert.getYf()).put(calcVert.getZf()); }
public void startDrag(final int mouseX, final int mouseY) { final Vector3 vec = Vector3.fetchTempInstance(); vec.set(mouseX, mouseY, 0); _uiFrameStatusBar.getWorldTransform().applyInverseVector(vec); _initialX = Math.round(vec.getXf()); _initialY = Math.round(vec.getYf()); Vector3.releaseTempInstance(vec); final UIFrame frame = UIFrame.findParentFrame(_uiFrameStatusBar); _initialLocalComponentWidth = frame.getLocalComponentWidth(); _initialLocalComponentHeight = frame.getLocalComponentHeight(); _initFrameTransform.set(frame.getWorldTransform()); }
@Override public boolean intersectsBoundingBox(final BoundingBox bb) { if (!Vector3.isValid(_center) || !Vector3.isValid(bb._center)) { return false; } if (Math.abs(bb._center.getX() - getCenter().getX()) < getRadius() + bb.getXExtent() && Math.abs(bb._center.getY() - getCenter().getY()) < getRadius() + bb.getYExtent() && Math.abs(bb._center.getZ() - getCenter().getZ()) < getRadius() + bb.getZExtent()) { return true; } return false; }
private boolean getWorldIntersection(final double planeHeight, final Vector3 source, final Vector3 destination, final Vector3 store, final Vector3 tmpStorage) { final Vector3 origin = store.set(source); final Vector3 direction = tmpStorage.set(destination).subtractLocal(origin); final double t = (planeHeight - origin.getY()) / (direction.getY()); direction.multiplyLocal(t); origin.addLocal(direction); return t >= 0.0 && t <= 1.0; }
public void updateLeftRightCameraFrames() { // update camera frame final Vector3 rightDir = Vector3.fetchTempInstance(); final Vector3 work = Vector3.fetchTempInstance(); rightDir.set(getDirection()).crossLocal(getUp()).multiplyLocal(_eyeSeparation / 2.0); _leftCamera.setFrame(getLocation().subtract(rightDir, work), getLeft(), getUp(), getDirection()); _rightCamera.setFrame(getLocation().add(rightDir, work), getLeft(), getUp(), getDirection()); Vector3.releaseTempInstance(work); Vector3.releaseTempInstance(rightDir); }
public float getHeightAt(final double x, final double z) { final Vector3 heightCalc = new Vector3(x, 0, z); worldToLocal(heightCalc, heightCalc); final float height = getClipmaps().get(0).getCache().getSubHeight(heightCalc.getXf(), heightCalc.getZf()); heightCalc.set(x, height, z); localToWorld(heightCalc, heightCalc); return heightCalc.getYf(); }
@Override public double getRadius() { double radius = 0.0; radius = Math.max(radius, _xAxis.multiply(_extent.getX(), _compVect1).length()); radius = Math.max(radius, _yAxis.multiply(_extent.getY(), _compVect1).length()); radius = Math.max(radius, _zAxis.multiply(_extent.getZ(), _compVect1).length()); return radius; }
public ReadOnlyTransform getValue() { final Transform t = new Transform(); t.setTranslation(_translation.getValue()); final Vector3 val = _rotation.getValue().multiplyLocal(MathUtils.DEG_TO_RAD); final Matrix3 mat = Matrix3.fetchTempInstance().fromAngles(val.getX(), val.getY(), val.getZ()); t.setRotation(mat); Matrix3.releaseTempInstance(mat); t.setScale(_scale.getValue()); return t; }
/** * Computes the normal from the three vertices in the given array that are indexed by the edges. * * @param verts * The array containing the vertices */ public void computeNormal(final Vector3[] verts) { final int i0 = edges[0].i0; final int i1 = edges[1].i0; final int i2 = edges[2].i0; verts[i2].subtract(verts[i1], _compVect0); verts[i0].subtract(verts[i1], _compVect1); normal.set(_compVect0.crossLocal(_compVect1)).normalizeLocal(); }