com.ardor3d.math.Transform类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中com.ardor3d.math.Transform类的一些代码示例,展示了Transform类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transform类的具体详情如下:
包路径:com.ardor3d.math.Transform
类名称:Transform

Transform介绍

[英]Transform models a transformation in 3d space as: Y = MX+T, with M being a Matrix3 and T is a Vector3. Generally M will be a rotation only matrix in which case it is represented by the matrix and scale fields as RS, where S is a positive scale vector. For non-uniform scales and reflections, use setMatrix, which will consider M as being a general 3x3 matrix and disregard anything set in scale.
[中]变换将三维空间中的变换建模为:Y=MX+T,其中M是矩阵3,T是向量3。通常,M是一个仅旋转的矩阵,在这种情况下,它由矩阵和比例场表示为RS,其中S是正比例向量。对于非均匀的尺度和反射,使用StMatrix,它将M作为一般的3x3矩阵,忽略任何在尺度上设置的任何东西。

代码示例

代码示例来源:origin: com.ardor3d/ardor3d-core

/**
 * Sets the world transform.
 * 
 * @param transform
 *            the new world transform
 */
public void setWorldTransform(final ReadOnlyTransform transform) {
  _worldTransform.set(transform);
}

代码示例来源:origin: com.ardor3d/ardor3d-animation

public void applyTo(final Transform transform) {
  transform.setIdentity();
  transform.setRotation(getRotation());
  transform.setScale(getScale());
  transform.setTranslation(getTranslation());
}

代码示例来源:origin: Renanse/Ardor3D

/**
 * @return An instance of Transform that is intended for temporary use in calculations and so forth. Multiple calls
 *         to the method should return instances of this class that are not currently in use.
 */
public final static Transform fetchTempInstance() {
  if (MathConstants.useMathPools) {
    return Transform.TRANS_POOL.fetch();
  } else {
    return new Transform();
  }
}

代码示例来源:origin: Renanse/Ardor3D

@Override
public Transform multiply(final ReadOnlyTransform transformBy, final Transform store) {
  final Transform transform = super.multiply(transformBy, store);
  if (!Transform.isValid(transform)) {
    throw new InvalidTransformException("Transform is invalid");
  }
  return transform;
}

代码示例来源:origin: com.ardor3d/ardor3d-core

/**
 * Updates the worldTransform.
 * 
 * @param recurse
 *            usually false when updating the tree. Set to true when you just want to update the world transforms
 *            for a branch without updating geometric state.
 */
public void updateWorldTransform(final boolean recurse) {
  if (_parent != null) {
    _parent._worldTransform.multiply(_localTransform, _worldTransform);
  } else {
    _worldTransform.set(_localTransform);
  }
  clearDirty(DirtyType.Transform);
}

代码示例来源:origin: Renanse/Ardor3D

@Test
public void testMultiply() {
  final Transform trans1 = new Transform();
  final Transform trans2 = new Transform();
  assertEquals(Transform.IDENTITY, trans1.multiply(trans2, null));
  trans1.setTranslation(1, 2, 3);
  final Transform trans3 = trans1.multiply(trans2, null);
  assertEquals(trans1, trans3);
  trans2.setTranslation(-1, -2, -3);
  trans1.multiply(trans2, trans3);
  assertEquals(Transform.IDENTITY, trans3);
  assertTrue(trans3.isRotationMatrix());
  assertTrue(trans3.isIdentity());
  assertTrue(trans3.isUniformScale());
  trans2.setScale(1, 2, 1);
  trans1.multiply(trans2, trans3);
  assertEquals(new Transform().setScale(1, 2, 1), trans3);
  assertTrue(trans3.isRotationMatrix());
  assertFalse(trans3.isIdentity());
  assertFalse(trans3.isUniformScale());
  trans1.setScale(1, 2, 1);
  trans1.multiply(trans2, trans3);
  assertEquals(new Transform().setRotation(new Matrix3(1, 0, 0, 0, 4, 0, 0, 0, 1)).setTranslation(0, -2, 0),
      trans3);
  assertFalse(trans3.isRotationMatrix());
  assertFalse(trans3.isIdentity());
  assertFalse(trans3.isUniformScale());
}

代码示例来源:origin: com.ardor3d/ardor3d-terrain

@Override
  public void drawTo(final BufferedImage image, final ReadOnlyTransform localTransform, final int clipmapLevel) {
    // apply the two transforms together and then use result to scale/translate and rotate image
    final Transform trans = new Transform();
    localTransform.multiply(getTransform(), trans);

    // grab a copy of the graphics so we don't bleed state to next image
    final Graphics2D g2d = (Graphics2D) image.getGraphics().create();

    // apply hints
    for (final RenderingHints.Key key : hints.keySet()) {
      g2d.setRenderingHint(key, hints.get(key));
    }

    // set transform
    g2d.translate(trans.getTranslation().getX(), trans.getTranslation().getY());
    g2d.rotate(trans.getMatrix().toAngles(null)[2]); // rotation about z
    g2d.scale(trans.getScale().getX(), trans.getScale().getY());

    // set composite
    if (_compositeOverride != null) {
      g2d.setComposite(_compositeOverride);
    }

    // draw the image
    g2d.drawImage(_image, 0, 0, null);
  }
}

代码示例来源:origin: Renanse/Ardor3D

public ReadOnlyTransform getValue() {
  final Transform t = new Transform();
  t.setTranslation(_translationX.getDoubleValue(), _translationY.getDoubleValue(), 0);
  final double val = _rotation.getDoubleValue() * MathUtils.DEG_TO_RAD;
  final Matrix3 mat = Matrix3.fetchTempInstance().fromAngles(0, 0, val);
  t.setRotation(mat);
  Matrix3.releaseTempInstance(mat);
  t.setScale(_scale.getDoubleValue());
  return t;
}

代码示例来源:origin: com.ardor3d/ardor3d-animation

final Transform temp = Transform.fetchTempInstance();
    _globalTransforms[parentIndex].multiply(_localTransforms[index], _globalTransforms[index]);
  } else {
    _globalTransforms[index].set(_localTransforms[index]);
  _globalTransforms[index].multiply(_skeleton.getJoints()[index].getInverseBindPose(), temp);
  temp.getHomogeneousMatrix(_matrixPalette[index]);
Transform.releaseTempInstance(temp);
firePoseUpdated();

代码示例来源:origin: Renanse/Ardor3D

@Test
public void testInvert() {
  final Transform trans1 = new Transform();
  trans1.setRotation(new Matrix3().applyRotationZ(3 * MathUtils.QUARTER_PI));
  final Transform trans2 = trans1.invert(null);
  assertEquals(Transform.IDENTITY, trans1.multiply(trans2, null));
  trans1.setIdentity().invert(trans1);
  assertEquals(Transform.IDENTITY, trans1);
}

代码示例来源:origin: Renanse/Ardor3D

@Test(expected = IllegalArgumentException.class)
public void testFailScale1B() {
  final Transform trans = new Transform();
  trans.setScale(Vector3.ZERO);
}

代码示例来源:origin: com.ardor3d/ardor3d-core

/**
 * 
 * @param cam
 */
public void correctTransform(final Camera cam) {
  updateWorldTransform(false);
  if (_autoRotate) {
    // Billboard rotation
    _look.set(cam.getDirection());
    _left.set(cam.getLeft()).negateLocal();
    _rot.fromAxes(_left, _look, cam.getUp());
    _worldTransform.setRotation(_rot);
  }
  _worldTransform.setScale(_localTransform.getScale());
}

代码示例来源:origin: Renanse/Ardor3D

@Override
public ResultSample doTransformMultTest(final int count, final int maxCount, final long timeOutMS) {
  final ReadOnlyMatrix4 m1 = new Matrix4().fromAngleAxis(MathUtils.nextRandomDouble(),
      new Vector3(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble()));
  final ReadOnlyMatrix4 m2 = new Matrix4().fromAngleAxis(MathUtils.nextRandomDouble(),
      new Vector3(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble()));
  final Transform a = new Transform().fromHomogeneousMatrix(m1);
  final Transform b = new Transform();
  final Transform by = new Transform().fromHomogeneousMatrix(m2);
  final long start = System.currentTimeMillis();
  int loopCount = 0;
  while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) {
    ++loopCount;
    for (int i = 0; i < count; ++i) {
      if (i % 2 == 0) {
        a.multiply(by, b);
      } else {
        b.multiply(by, a);
      }
    }
  }
  return populateResult(System.currentTimeMillis() - start, loopCount, a.getHomogeneousMatrix(null).toArray(null));
}

代码示例来源:origin: Renanse/Ardor3D

/**
 * Sets the world translation vector.
 *
 * @param translation
 *            the new world translation
 */
public void setWorldTranslation(final ReadOnlyVector3 translation) {
  _worldTransform.setTranslation(translation);
}

代码示例来源:origin: Renanse/Ardor3D

@Test
public void testSimpleHash() {
  // Just a simple sanity check.
  final Transform trans1 = new Transform().setTranslation(1, 2, 3);
  final Transform trans2 = new Transform().setTranslation(1, 2, 3);
  final Transform trans3 = new Transform().setTranslation(1, 2, 0);
  assertTrue(trans1.hashCode() == trans2.hashCode());
  assertTrue(trans1.hashCode() != trans3.hashCode());
}

代码示例来源:origin: Renanse/Ardor3D

/**
 * Convert a vector (in) from this spatial's local coordinate space to world coordinate space.
 *
 * @param in
 *            vector to read from
 * @param store
 *            where to write the result (null to create a new vector, may be same as in)
 * @return the result (store)
 */
public Vector3 localToWorld(final ReadOnlyVector3 in, Vector3 store) {
  if (store == null) {
    store = new Vector3();
  }
  return _worldTransform.applyForward(in, store);
}

代码示例来源:origin: Renanse/Ardor3D

/**
 * Aligns this Billboard Node so that it points to the camera position.
 */
private void rotateCameraAligned() {
  final Camera camera = Camera.getCurrentCamera();
  _look.set(camera.getLocation()).subtractLocal(_worldTransform.getTranslation()).normalizeLocal();
  _left.set(camera.getUp()).crossLocal(_look);
  final Vector3 up = Vector3.fetchTempInstance();
  up.set(_look).crossLocal(_left);
  _orient.fromAxes(_left, up, _look);
  if(_localRot != null)
    _orient.multiplyLocal(_localRot);
  _worldTransform.setRotation(_orient);
  Vector3.releaseTempInstance(up);
}

代码示例来源:origin: Renanse/Ardor3D

/**
 * Draw a single Joint using the given world-space joint transform.
 *
 * @param jntTransform
 *                         our joint transform
 * @param scene
 * @param renderer
 *                         the Renderer to draw with.
 */
private static void drawJoint(final Transform jntTransform, final Spatial scene, final Renderer renderer) {
  final BoundingVolume vol = scene.getWorldBound();
  double size = 1.0;
  if (vol != null) {
    SkeletalDebugger.measureSphere.setCenter(vol.getCenter());
    SkeletalDebugger.measureSphere.setRadius(0);
    SkeletalDebugger.measureSphere.mergeLocal(vol);
    size = SkeletalDebugger.BONE_RATIO * SkeletalDebugger.measureSphere.getRadius();
  }
  scene.getWorldTransform().multiply(jntTransform, SkeletalDebugger.spTransform);
  SkeletalDebugger.spTransform.getMatrix().scale(new Vector3(size, size, size), SkeletalDebugger.spMatrix);
  SkeletalDebugger.spTransform.setRotation(SkeletalDebugger.spMatrix);
  SkeletalDebugger.joint.setWorldTransform(SkeletalDebugger.spTransform);
  SkeletalDebugger.joint.draw(renderer);
}

代码示例来源:origin: Renanse/Ardor3D

@Test
public void testTranslate() {
  final Transform trans = new Transform();
  trans.translate(1, 3, 5);
  assertEquals(new Vector3(1, 3, 5), trans.getTranslation());
  trans.translate(trans.getTranslation().negate(null));
  assertEquals(Vector3.ZERO, trans.getTranslation());
  trans.translate(new Vector3(1, 3, 5));
  assertEquals(new Vector3(1, 3, 5), trans.getTranslation());
  trans.translate(-1, -3, -5);
  assertEquals(Vector3.ZERO, trans.getTranslation());
}

代码示例来源:origin: com.ardor3d/ardor3d-core

/**
 * Sets the rotation of this spatial. This marks the spatial as DirtyType.Transform.
 * 
 * @param rotation
 *            the new rotation of this spatial
 * @see Transform#setRotation(Matrix3)
 */
public void setRotation(final ReadOnlyMatrix3 rotation) {
  _localTransform.setRotation(rotation);
  markDirty(DirtyType.Transform);
}

相关文章