com.badlogic.gdx.math.Matrix4.setToTranslation()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(103)

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

Matrix4.setToTranslation介绍

[英]Sets this matrix to a translation matrix, overwriting it first by an identity matrix and then setting the 4th column to the translation vector.
[中]将此矩阵设置为转换矩阵,首先用单位矩阵覆盖它,然后将第四列设置为转换向量。

代码示例

代码示例来源:origin: libgdx/libgdx

/** Constructs a new ModelInstance at the specified position. */
public ModelInstance (final Model model, float x, float y, float z) {
  this(model);
  this.transform.setToTranslation(x, y, z);
}

代码示例来源:origin: libgdx/libgdx

/** Constructs a new ModelInstance at the specified position. */
public ModelInstance (final Model model, Vector3 position) {
  this(model);
  this.transform.setToTranslation(position);
}

代码示例来源:origin: libgdx/libgdx

/** Constructs a new ModelInstance at the specified position. */
public ModelInstance (final Model model, Vector3 position) {
  this(model);
  this.transform.setToTranslation(position);
}

代码示例来源:origin: libgdx/libgdx

/** Constructs a new ModelInstance at the specified position. */
public ModelInstance (final Model model, float x, float y, float z) {
  this(model);
  this.transform.setToTranslation(x, y, z);
}

代码示例来源:origin: libgdx/libgdx

public BulletEntity (final Model model, final btCollisionObject body, final float x, final float y, final float z) {
  this(model, body, tmpM.setToTranslation(x, y, z));
}

代码示例来源:origin: libgdx/libgdx

public void update (float deltaTime) {
    vy += -30f * deltaTime;
    position.y += vy * deltaTime;
    position.x += vx * deltaTime;
    position.z += vz * deltaTime;
    if (position.y < 0.1f) {
      vy *= -0.70f;
      position.y = 0.1f;
    }
    if (position.x < -5) {
      vx = -vx;
      position.x = -5;
    }
    if (position.x > 5) {
      vx = -vx;
      position.x = 5;
    }
    if (position.z < -5) {
      vz = -vz;
      position.z = -5;
    }
    if (position.z > 5) {
      vz = -vz;
      position.z = 5;
    }
    lightInstance.transform.setToTranslation(position);
  }
}

代码示例来源:origin: libgdx/libgdx

public static void build (MeshPartBuilder builder, float radius, float height, int divisions) {
    if (height < 2f * radius) throw new GdxRuntimeException("Height must be at least twice the radius");
    final float d = 2f * radius;
    CylinderShapeBuilder.build(builder, d, height - d, d, divisions, 0, 360, false);
    SphereShapeBuilder.build(builder, matTmp1.setToTranslation(0, .5f * (height - d), 0), d, d, d, divisions, divisions, 0,
      360, 0, 90);
    SphereShapeBuilder.build(builder, matTmp1.setToTranslation(0, -.5f * (height - d), 0), d, d, d, divisions, divisions, 0,
      360, 90, 180);
  }
}

代码示例来源:origin: libgdx/libgdx

public static void build (MeshPartBuilder builder, float radius, float height, int divisions) {
    if (height < 2f * radius) throw new GdxRuntimeException("Height must be at least twice the radius");
    final float d = 2f * radius;
    CylinderShapeBuilder.build(builder, d, height - d, d, divisions, 0, 360, false);
    SphereShapeBuilder.build(builder, matTmp1.setToTranslation(0, .5f * (height - d), 0), d, d, d, divisions, divisions, 0,
      360, 0, 90);
    SphereShapeBuilder.build(builder, matTmp1.setToTranslation(0, -.5f * (height - d), 0), d, d, d, divisions, divisions, 0,
      360, 90, 180);
  }
}

代码示例来源:origin: libgdx/libgdx

/** Sets this matrix to a look at matrix with the given position, target and up vector.
 * 
 * @param position the position
 * @param target the target
 * @param up the up vector
 * @return This matrix */
public Matrix4 setToLookAt (Vector3 position, Vector3 target, Vector3 up) {
  tmpVec.set(target).sub(position);
  setToLookAt(tmpVec, up);
  this.mul(tmpMat.setToTranslation(-position.x, -position.y, -position.z));
  return this;
}

代码示例来源:origin: libgdx/libgdx

/** Sets this matrix to a look at matrix with the given position, target and up vector.
 * 
 * @param position the position
 * @param target the target
 * @param up the up vector
 * @return This matrix */
public Matrix4 setToLookAt (Vector3 position, Vector3 target, Vector3 up) {
  tmpVec.set(target).sub(position);
  setToLookAt(tmpVec, up);
  this.mul(tmpMat.setToTranslation(-position.x, -position.y, -position.z));
  return this;
}

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  texture = new Texture(Gdx.files.internal("data/black_marked_0.png"));
  region = new TextureRegion(texture);
  batch = new SpriteBatch();
  batch.getTransformMatrix().setToTranslation(30.5f, 30.5f, 0);
}

代码示例来源:origin: libgdx/libgdx

private void renderBox (Body body, float halfWidth, float halfHeight) {
  // get the bodies center and angle in world coordinates
  Vector2 pos = body.getWorldCenter();
  float angle = body.getAngle();
  // set the translation and rotation matrix
  transform.setToTranslation(pos.x, pos.y, 0);
  transform.rotate(0, 0, 1, (float)Math.toDegrees(angle));
  // render the box
  renderer.begin(ShapeType.Line);
  renderer.setTransformMatrix(transform);
  renderer.setColor(1, 1, 1, 1);
  renderer.rect(-halfWidth, -halfHeight, halfWidth * 2, halfHeight * 2);
  renderer.end();
}

代码示例来源:origin: libgdx/libgdx

@Override
  public boolean keyUp (int keycode) {
    switch (keycode) {
    case Keys.DOWN:
      downPressed = false;
      break;
    case Keys.UP:
      upPressed = false;
      break;
    case Keys.LEFT:
      leftPressed = false;
      break;
    case Keys.RIGHT:
      rightPressed = false;
      break;
    case Keys.R:
      chassis.body.setWorldTransform(chassis.transform.setToTranslation(0, 5, 0));
      chassis.body.setInterpolationWorldTransform(chassis.transform);
      ((btRigidBody)(chassis.body)).setLinearVelocity(Vector3.Zero);
      ((btRigidBody)(chassis.body)).setAngularVelocity(Vector3.Zero);
      chassis.body.activate();
      break;
    }
    return super.keyUp(keycode);
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  super.create();
  final Model sphereModel = modelBuilder.createSphere(0.5f, 0.5f, 0.5f, 8, 8,
    new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE)), Usage.Position
      | Usage.Normal);
  disposables.add(sphereModel);
  final BulletConstructor sphereConstructor = new BulletConstructor(sphereModel, 0.25f, new btSphereShape(0.25f));
  sphereConstructor.bodyInfo.setRestitution(1f);
  world.addConstructor("sphere", sphereConstructor);
  final Model sceneModel = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
  disposables.add(sceneModel);
  final BulletConstructor sceneConstructor = new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(
    sceneModel.meshParts));
  sceneConstructor.bodyInfo.setRestitution(0.25f);
  world.addConstructor("scene", sceneConstructor);
  world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90)).setColor(
    0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
  world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
    0.25f + 0.5f * (float)Math.random(), 1f);
  for (float x = -3; x < 7; x++) {
    for (float z = -5; z < 5; z++) {
      world.add("sphere", x, 10f + (float)Math.random() * 0.1f, z).setColor(0.5f + 0.5f * (float)Math.random(),
        0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
    }
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
protected void onLoaded () {
  if (currentlyLoading == null || currentlyLoading.length() == 0) return;
  final ModelInstance instance = new ModelInstance(assets.get(currentlyLoading, Model.class));
  instance.transform = new Matrix4().idt();
  instance.transform.setToTranslation(MathUtils.random(-10, 10), MathUtils.random(-10, 10), MathUtils.random(-10, 10));
  instance.transform.rotate(Vector3.X, MathUtils.random(-180, 180));
  instance.transform.rotate(Vector3.Y, MathUtils.random(-180, 180));
  instance.transform.rotate(Vector3.Z, MathUtils.random(-180, 180));
  instances.add(instance);
}

代码示例来源:origin: libgdx/libgdx

world.addConstructor("scene", sceneConstructor);
final BulletEntity scene = world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90));
scene.setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
  0.25f + 0.5f * (float)Math.random(), 1f);

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  if (spriteBatch != null) return;
  spriteBatch = new SpriteBatch();
  Matrix4 transform = new Matrix4();
  transform.setToTranslation(0, Gdx.graphics.getHeight(), 0);
  transform.mul(new Matrix4().setToScaling(1, -1, 1));
  spriteBatch.setTransformMatrix(transform);
  pixS1 = new Pixmap(Gdx.files.getFileHandle("data/test4.png", Files.FileType.Internal));
  pixS2 = new Pixmap(Gdx.files.getFileHandle("data/test3.png", Files.FileType.Internal));
  pixD = new Pixmap(512, 1024, Pixmap.Format.RGBA8888);
  pixD.setBlending(Pixmap.Blending.SourceOver);
  pixD.setFilter(Pixmap.Filter.NearestNeighbour);
  pixD.drawPixmap(pixS1, 0, 0, 38, 76, 0, 0, 512, 1024);
  pixD.drawPixmap(pixS2, 0, 0, 38, 76, 0, 0, 512, 1024);
  logoSprite = new Sprite(new Texture(pixD));
  logoSprite.flip(false, true);
  pixS1.dispose();
  pixS2.dispose();
  pixD.dispose();
}

代码示例来源:origin: libgdx/libgdx

public static btPairCachingGhostObject createFrustumObject (final Vector3... points) {
  final btPairCachingGhostObject result = new TestPairCachingGhostObject();
  final boolean USE_COMPOUND = true;
  // Using a compound shape is not necessary, but it's good practice to create shapes around the center.
  if (USE_COMPOUND) {
    final Vector3 centerNear = new Vector3(points[2]).sub(points[0]).scl(0.5f).add(points[0]);
    final Vector3 centerFar = new Vector3(points[6]).sub(points[4]).scl(0.5f).add(points[4]);
    final Vector3 center = new Vector3(centerFar).sub(centerNear).scl(0.5f).add(centerNear);
    final btConvexHullShape hullShape = new btConvexHullShape();
    for (int i = 0; i < points.length; i++)
      hullShape.addPoint(tmpV.set(points[i]).sub(center));
    final btCompoundShape shape = new btCompoundShape();
    shape.addChildShape(tmpM.setToTranslation(center), hullShape);
    result.setCollisionShape(shape);
  } else {
    final btConvexHullShape shape = new btConvexHullShape();
    for (int i = 0; i < points.length; i++)
      shape.addPoint(points[i]);
    result.setCollisionShape(shape);
  }
  result.setCollisionFlags(btCollisionObject.CollisionFlags.CF_NO_CONTACT_RESPONSE);
  return result;
}

代码示例来源:origin: libgdx/libgdx

mpb = modelBuilder.part("mesh", GL20.GL_TRIANGLES, mesh.getVertexAttributes(), material);
Matrix4 transform = new Matrix4();
mpb.setVertexTransform(transform.setToTranslation(0, 2, 0));
mpb.addMesh(mesh);
mpb.setColor(Color.BLUE);
mpb.setVertexTransform(transform.setToTranslation(1, 1, 0));
mpb.addMesh(mesh);
mpb.setColor(null);
mpb.setVertexTransform(transform.setToTranslation(-1, 1, 0).rotate(Vector3.X, 45));
mpb.addMesh(mesh);
mpb.setVertexTransform(transform.setToTranslation(0, 1, 1));
mpb.setUVRange(0.75f, 0.75f, 0.25f, 0.25f);
mpb.addMesh(mesh);

代码示例来源:origin: com.harium.etyl/etyl-gdx-util

/** Sets this matrix to a look at matrix with the given position, target and up vector.
 * 
 * @param position the position
 * @param target the target
 * @param up the up vector
 * @return This matrix */
public Matrix4 setToLookAt (Vector3 position, Vector3 target, Vector3 up) {
  tmpVec.set(target).sub(position);
  setToLookAt(tmpVec, up);
  
  this.set(this.mul(tmpMat.setToTranslation(-position.x, -position.y, -position.z)));
  return this;
}

相关文章