Tabnine Logo
Vector4
Code IndexAdd Tabnine to your IDE (free)

How to use
Vector4
in
com.ardor3d.math

Best Java code snippets using com.ardor3d.math.Vector4 (Showing top 20 results out of 315)

origin: com.ardor3d/ardor3d-math

/**
 * Divides the values of this vector by the given scalar value and returns the result in store.
 * 
 * @param scalar
 * @param store
 *            the vector to store the result in for return. If null, a new vector object is created and returned.
 * @return a new vector (this.x / scalar, this.y / scalar, this.z / scalar, this.w / scalar)
 */
@Override
public Vector4 divide(final double scalar, final Vector4 store) {
  Vector4 result = store;
  if (result == null) {
    result = new Vector4();
  }
  return result.set(getX() / scalar, getY() / scalar, getZ() / scalar, getW() / scalar);
}
origin: com.ardor3d/ardor3d-math

/**
 * Increments the values of this vector with the given x, y, z and w values.
 * 
 * @param x
 * @param y
 * @param z
 * @param w
 * @return this vector for chaining
 */
public Vector4 addLocal(final double x, final double y, final double z, final double w) {
  return set(getX() + x, getY() + y, getZ() + z, getW() + w);
}
origin: com.ardor3d/ardor3d-core

public void setEnvPlaneR(final ReadOnlyVector4 plane) {
  if (plane == null) {
    _envPlaneR = null;
    return;
  } else if (_envPlaneR == null) {
    _envPlaneR = new Vector4(plane);
  } else {
    _envPlaneR.set(plane);
  }
}
origin: com.ardor3d/ardor3d-math

/**
 * Creates a new unit length vector from this one by dividing by length. If the length is 0, (ie, if the vector is
 * 0, 0, 0, 0) then a new vector (0, 0, 0, 0) is returned.
 * 
 * @param store
 *            the vector to store the result in for return. If null, a new vector object is created and returned.
 * @return a new unit vector (or 0, 0, 0, 0 if this unit is 0 length)
 */
@Override
public Vector4 normalize(final Vector4 store) {
  final double lengthSq = lengthSquared();
  if (Math.abs(lengthSq) > MathUtils.EPSILON) {
    return multiply(MathUtils.inverseSqrt(lengthSq), store);
  }
  return store != null ? store.set(Vector4.ZERO) : new Vector4(Vector4.ZERO);
}
origin: Renanse/Ardor3D

@Test
public void testGetSet() {
  final Vector4 vec1 = new Vector4();
  vec1.setX(0);
  assertTrue(vec1.getX() == 0.0);
  vec1.setX(Double.POSITIVE_INFINITY);
  assertTrue(vec1.getX() == Double.POSITIVE_INFINITY);
  vec1.setX(Double.NEGATIVE_INFINITY);
  assertTrue(vec1.getX() == Double.NEGATIVE_INFINITY);
  assertTrue(vec1.getValue(0) == Double.NEGATIVE_INFINITY);
  vec1.setY(0);
  assertTrue(vec1.getY() == 0.0);
  vec1.setY(Double.POSITIVE_INFINITY);
  assertTrue(vec1.getY() == Double.POSITIVE_INFINITY);
  vec1.setY(Double.NEGATIVE_INFINITY);
  assertTrue(vec1.getY() == Double.NEGATIVE_INFINITY);
  assertTrue(vec1.getValue(1) == Double.NEGATIVE_INFINITY);
  vec1.setZ(0);
  assertTrue(vec1.getZ() == 0.0);
  vec1.setZ(Double.POSITIVE_INFINITY);
  assertTrue(vec1.getZ() == Double.POSITIVE_INFINITY);
  vec1.setZ(Double.NEGATIVE_INFINITY);
  assertTrue(vec1.getZ() == Double.NEGATIVE_INFINITY);
  assertTrue(vec1.getValue(2) == Double.NEGATIVE_INFINITY);
  vec1.setW(0);
  assertTrue(vec1.getW() == 0.0);
  vec1.setW(Double.POSITIVE_INFINITY);
origin: com.ardor3d/ardor3d-effects

final double dv = 1.0f / (double) (sizeY - 1);
final Vector4 pointTop = Vector4.fetchTempInstance();
final Vector4 pointFinal = Vector4.fetchTempInstance();
final Vector4 pointBottom = Vector4.fetchTempInstance();
for (int y = smallerFrom; y < biggerTo; y++) {
  for (int x = 0; x < sizeX; x++) {
    pointTop.lerpLocal(intersectTopLeft, intersectTopRight, u);
    pointBottom.lerpLocal(intersectBottomLeft, intersectBottomRight, u);
    pointFinal.lerpLocal(pointTop, pointBottom, v);
    pointFinal.setX(pointFinal.getX() / pointFinal.getW());
    pointFinal.setZ(pointFinal.getZ() / pointFinal.getW());
    pointFinal.setY(heightGenerator.getHeight(pointFinal.getX(), pointFinal.getZ(), time));
    vertBufArray[index++] = pointFinal.getXf();
    vertBufArray[index++] = pointFinal.getYf();
    vertBufArray[index++] = pointFinal.getZf();
Vector4.releaseTempInstance(pointTop);
Vector4.releaseTempInstance(pointFinal);
Vector4.releaseTempInstance(pointBottom);
origin: com.ardor3d/ardor3d-core

public Vector3 getNormalizedDeviceCoordinates(final ReadOnlyVector3 worldPosition, Vector3 store) {
  if (store == null) {
    store = new Vector3();
  }
  checkModelViewProjection();
  final Vector4 position = Vector4.fetchTempInstance();
  position.set(worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), 1);
  _modelViewProjection.applyPre(position, position);
  position.multiplyLocal(1.0 / position.getW());
  store.setX(position.getX());
  store.setY(position.getY());
  store.setZ(position.getZ());
  Vector4.releaseTempInstance(position);
  return store;
}
origin: Renanse/Ardor3D

private void setTextureData() {
  // x = left, y = top, z = right, w = bottom
  final FloatBuffer coords = _meshData.getTextureBuffer(0);
  coords.rewind();
  coords.put(0).put(0);
  coords.put(_textureBorderOffsets.getXf()).put(0);
  coords.put(1f - _textureBorderOffsets.getZf()).put(0);
  coords.put(1).put(0);
  coords.put(0).put(_textureBorderOffsets.getWf());
  coords.put(_textureBorderOffsets.getXf()).put(_textureBorderOffsets.getWf());
  coords.put(1f - _textureBorderOffsets.getZf()).put(_textureBorderOffsets.getWf());
  coords.put(1).put(_textureBorderOffsets.getWf());
  coords.put(0).put(1f - _textureBorderOffsets.getYf());
  coords.put(_textureBorderOffsets.getXf()).put(1f - _textureBorderOffsets.getYf());
  coords.put(1f - _textureBorderOffsets.getZf()).put(1f - _textureBorderOffsets.getYf());
  coords.put(1).put(1f - _textureBorderOffsets.getYf());
  coords.put(0).put(1);
  coords.put(_textureBorderOffsets.getXf()).put(1);
  coords.put(1f - _textureBorderOffsets.getZf()).put(1);
  coords.put(1).put(1);
  _meshData.markBufferDirty(MeshData.KEY_TextureCoords0);
}
origin: Renanse/Ardor3D

if (value instanceof Vector4) {
  final Vector4 vec = (Vector4) value;
  return stack.mallocDouble(4).put(vec.getX()).put(vec.getY()).put(vec.getZ()).put(vec.getW()).flip();
if (value instanceof Vector4) {
  final Vector4 vec = (Vector4) value;
  return stack.mallocFloat(4).put(vec.getXf()).put(vec.getYf()).put(vec.getZf()).put(vec.getWf())
      .flip();
origin: com.ardor3d/ardor3d-effects

private void calculateIntersection(final double planeHeight, final ReadOnlyVector2 screenPosition,
    final ReadOnlyMatrix4 modelViewProjectionInverseMatrix) {
  origin.set(screenPosition.getX() * 2 - 1, screenPosition.getY() * 2 - 1, -1, 1);
  direction.set(screenPosition.getX() * 2 - 1, screenPosition.getY() * 2 - 1, 1, 1);
  modelViewProjectionInverseMatrix.applyPre(origin, origin);
  modelViewProjectionInverseMatrix.applyPre(direction, direction);
  direction.subtractLocal(origin);
  // final double t = (planeHeight * origin.getW() - origin.getY())
  // / (direction.getY() - planeHeight * direction.getW());
  if (Math.abs(direction.getY()) > MathUtils.EPSILON) {
    final double t = (planeHeight - origin.getY()) / direction.getY();
    direction.multiplyLocal(t);
  } else {
    direction.normalizeLocal();
    direction.multiplyLocal(mainCamera.getFrustumFar());
  }
  origin.addLocal(direction);
}
origin: Renanse/Ardor3D

/**
 * Sets the value of this vector to (0, 0, 0, 0)
 * 
 * @return this vector for chaining
 */
public Vector4 zero() {
  return set(0, 0, 0, 0);
}
origin: com.ardor3d/ardor3d-math

@Override
public Vector4 clone() {
  return new Vector4(this);
}
origin: Renanse/Ardor3D

@Test
public void testApplyVector4() {
  final Matrix4 mat4 = new Matrix4().applyRotationX(MathUtils.HALF_PI);
  final Vector4 vec4 = new Vector4(0, 1, 0, 1);
  final Vector4 result = mat4.applyPost(vec4, null);
  assertTrue(Math.abs(new Vector4(0, 0, 1, 1).distance(result)) <= MathUtils.EPSILON);
  vec4.set(0, 1, 1, 1);
  mat4.applyPost(vec4, result);
  assertTrue(Math.abs(new Vector4(0, -1, 1, 1).distance(result)) <= MathUtils.EPSILON);
  vec4.set(0, 1, 1, 1);
  mat4.applyPre(vec4, result);
  assertTrue(Math.abs(new Vector4(0, 1, -1, 1).distance(result)) <= MathUtils.EPSILON);
  vec4.set(1, 1, 1, 1);
  assertTrue(Math.abs(new Vector4(1, 1, -1, 1).distance(mat4.applyPre(vec4, null))) <= MathUtils.EPSILON);
}
origin: Renanse/Ardor3D

@Test
public void testAdd() {
  final Vector4 vec1 = new Vector4();
  final Vector4 vec2 = new Vector4(Vector4.ONE);
  vec1.addLocal(1, 2, 3, 4);
  assertEquals(new Vector4(1, 2, 3, 4), vec1);
  vec1.addLocal(-1, -2, -3, -4);
  assertEquals(Vector4.ZERO, vec1);
  vec1.zero();
  vec1.addLocal(vec2);
  assertEquals(Vector4.ONE, vec1);
  vec1.zero();
  final Vector4 vec3 = vec1.add(vec2, new Vector4());
  assertEquals(Vector4.ZERO, vec1);
  assertEquals(Vector4.ONE, vec3);
  final Vector4 vec4 = vec1.add(0, 0, 0, 1, null);
  assertEquals(Vector4.ZERO, vec1);
  assertEquals(Vector4.UNIT_W, vec4);
}
origin: Renanse/Ardor3D

@Test
public void testNormalize() {
  final Vector4 vec1 = new Vector4(2, 1, 3, -1);
  assertTrue(vec1.length() == Math.sqrt(15));
  final Vector4 vec2 = vec1.normalize(null);
  final double invLength = MathUtils.inverseSqrt(2 * 2 + 1 * 1 + 3 * 3 + -1 * -1);
  assertEquals(new Vector4(2 * invLength, 1 * invLength, 3 * invLength, -1 * invLength), vec2);
  vec1.normalizeLocal();
  assertEquals(new Vector4(2 * invLength, 1 * invLength, 3 * invLength, -1 * invLength), vec1);
  vec1.zero();
  vec1.normalize(vec2);
  assertEquals(vec1, vec2);
  // ensure no exception thrown
  vec1.normalizeLocal();
  vec1.normalize(null);
}
origin: com.ardor3d/ardor3d-core

/**
 * Add to a Vector4 in-buffer.
 * 
 * @param toAdd
 *            the vector to add from
 * @param buf
 *            the buffer to find the Vector4 within
 * @param index
 *            the position (in terms of vectors, not floats) of the vector to add to
 */
public static void addInBuffer(final ReadOnlyVector4 toAdd, final FloatBuffer buf, final int index) {
  final Vector4 temp = Vector4.fetchTempInstance();
  populateFromBuffer(temp, buf, index);
  temp.addLocal(toAdd);
  setInBuffer(temp, buf, index);
  Vector4.releaseTempInstance(temp);
}
origin: Renanse/Ardor3D

@Test
public void testDot() {
  final Vector4 vec1 = new Vector4(7, 2, 5, -1);
  assertTrue(35.0 == vec1.dot(3, 1, 2, -2));
  assertTrue(-11.0 == vec1.dot(new Vector4(-1, 1, -1, 1)));
}
origin: Renanse/Ardor3D

@Test
public void testScaleAdd() {
  final Vector4 vec1 = new Vector4(1, 1, 1, 1);
  final Vector4 vec2 = vec1.scaleAdd(2.0, new Vector4(1, 2, 3, 4), null);
  final Vector4 vec2B = vec1.scaleAdd(2.0, new Vector4(1, 2, 3, 4), new Vector4());
  assertEquals(new Vector4(3.0, 4.0, 5.0, 6.0), vec2);
  assertEquals(new Vector4(3.0, 4.0, 5.0, 6.0), vec2B);
  vec1.scaleAddLocal(2.0, new Vector4(1, 2, 3, 4));
  assertEquals(vec2, vec1);
}
origin: Renanse/Ardor3D

@Test
public void testNegate() {
  final Vector4 vec1 = new Vector4(3, 2, -1, 1);
  final Vector4 vec2 = vec1.negate(null);
  assertEquals(new Vector4(-3, -2, 1, -1), vec2);
  vec1.negateLocal();
  assertEquals(vec2, vec1);
}
origin: Renanse/Ardor3D

  @Test
  public void testSimpleHash() {
    // Just a simple sanity check.
    final Vector4 vec1 = new Vector4(1, 2, 3, 4);
    final Vector4 vec2 = new Vector4(1, 2, 3, 4);
    final Vector4 vec3 = new Vector4(2, 2, 2, 2);

    assertTrue(vec1.hashCode() == vec2.hashCode());
    assertTrue(vec1.hashCode() != vec3.hashCode());
  }
}
com.ardor3d.mathVector4

Javadoc

Vector4 represents a point or vector in a four dimensional system. This implementation stores its data in double-precision.

Most used methods

  • <init>
    Constructs a new vector set to the (x, y, z, w) values of the given source vector.
  • set
    Sets the value of this vector to the (x, y, z, w) values of the provided source vector.
  • getW
  • getX
  • getY
  • getZ
  • addLocal
    Increments the values of this vector with the x, y, z and w values of the given vector.
  • getXf
  • getYf
  • getZf
  • multiplyLocal
    Internally modifies the values of this vector by multiplying them each by the given scale values.
  • setW
    Sets the fourth component of this vector to the given double value.
  • multiplyLocal,
  • setW,
  • setX,
  • setY,
  • setZ,
  • dot,
  • fetchTempInstance,
  • getWf,
  • multiply,
  • normalizeLocal

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSupportFragmentManager (FragmentActivity)
  • setContentView (Activity)
  • scheduleAtFixedRate (Timer)
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Collectors (java.util.stream)
  • JFileChooser (javax.swing)
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now