public static Vector3f correctOffset(Vector3f offset) { return CORRECTION_QUATERNION.rotate(offset, new Vector3f()); }
public Vector3f getLocalDirection() { Vector3f result = Direction.FORWARD.getVector3f(); getLocalRotation().rotate(result, result); return result; }
public Vector3f getWorldDirection() { Vector3f result = Direction.FORWARD.getVector3f(); getWorldRotation().rotate(result, result); return result; }
public BlockMeshPart rotate(Quat4f rotation) { Vector3f[] newVertices = new Vector3f[vertices.length]; Vector3f[] newNormals = new Vector3f[normals.length]; for (int i = 0; i < newVertices.length; ++i) { newVertices[i] = rotation.rotate(vertices[i], new Vector3f()); newNormals[i] = rotation.rotate(normals[i], new Vector3f()); newNormals[i].normalize(); } return new BlockMeshPart(newVertices, newNormals, texCoords, indices); } }
public Vector3f getViewDirection() { Quat4f rot = getViewRotation(); // TODO: Put a generator for direction vectors in a util class somewhere // And just put quaternion -> vector somewhere too Vector3f dir = Direction.FORWARD.getVector3f(); return rot.rotate(dir, dir); }
public List<Vector3f> getVertexNormals(List<Vector3f> bonePositions, List<Quat4f> boneRotations) { List<Vector3f> results = Lists.newArrayListWithCapacity(getVertexCount()); for (int i = 0; i < vertexStartWeights.size(); ++i) { Vector3f vertexNorm = new Vector3f(); for (int weightIndexOffset = 0; weightIndexOffset < vertexWeightCounts.get(i); ++weightIndexOffset) { int weightIndex = vertexStartWeights.get(i) + weightIndexOffset; BoneWeight weight = weights.get(weightIndex); Vector3f current = boneRotations.get(weight.getBoneIndex()).rotate(weight.getNormal(), new Vector3f()); current.scale(weight.getBias()); vertexNorm.add(current); } results.add(vertexNorm); } return results; }
public List<Vector3f> getVertexPositions(List<Vector3f> bonePositions, List<Quat4f> boneRotations) { List<Vector3f> results = Lists.newArrayListWithCapacity(getVertexCount()); for (int i = 0; i < vertexStartWeights.size(); ++i) { Vector3f vertexPos = new Vector3f(); for (int weightIndexOffset = 0; weightIndexOffset < vertexWeightCounts.get(i); ++weightIndexOffset) { int weightIndex = vertexStartWeights.get(i) + weightIndexOffset; BoneWeight weight = weights.get(weightIndex); Vector3f current = boneRotations.get(weight.getBoneIndex()).rotate(weight.getPosition(), new Vector3f()); current.add(bonePositions.get(weight.getBoneIndex())); current.scale(weight.getBias()); vertexPos.add(current); } results.add(vertexPos); } return results; }
public Vector3f getLocalPosition() { Vector3f pos = new Vector3f(objectSpacePos); if (parent != null) { pos.sub(parent.getObjectPosition()); Quat4f inverseParentRot = new Quat4f(); inverseParentRot.inverse(parent.getObjectRotation()); inverseParentRot.rotate(pos, pos); } return pos; }
@Override public void updateListener(Vector3f position, Quat4f orientation, Vector3f velocity) { AL10.alListener3f(AL10.AL_VELOCITY, velocity.x, velocity.y, velocity.z); OpenALException.checkState("Setting listener velocity"); Vector3f dir = orientation.rotate(Direction.FORWARD.getVector3f(), new Vector3f()); Vector3f up = orientation.rotate(Direction.UP.getVector3f(), new Vector3f()); FloatBuffer listenerOri = BufferUtils.createFloatBuffer(6).put(new float[] {dir.x, dir.y, dir.z, up.x, up.y, up.z}); listenerOri.flip(); AL10.alListener(AL10.AL_ORIENTATION, listenerOri); OpenALException.checkState("Setting listener orientation"); this.listenerPosition.set(position); AL10.alListener3f(AL10.AL_POSITION, position.x, position.y, position.z); OpenALException.checkState("Setting listener position"); }
public Vector3f getWorldPosition(Vector3f output) { output.set(position); LocationComponent parentLoc = parent.getComponent(LocationComponent.class); while (parentLoc != null) { output.scale(parentLoc.scale); parentLoc.getLocalRotation().rotate(output, output); output.add(parentLoc.position); parentLoc = parentLoc.parent.getComponent(LocationComponent.class); } return output; }
@Override public Vector3f getCollisionOffset(Rotation rot) { Rotation simplifiedRot = applySymmetry(rot); if (simplifiedRot.equals(Rotation.none())) { return new Vector3f(baseCollisionOffset); } return simplifiedRot.getQuat4f().rotate(baseCollisionOffset, new Vector3f()); }
BoneWeight weight = weights.get(weightIndex + vertexStartWeights.get(vertIndex)); inverseRot.inverse(bones.get(weight.getBoneIndex()).getObjectRotation()); inverseRot.rotate(normal, norm); weight.setNormal(norm);
public void setWorldPosition(Vector3f value) { this.position.set(value); LocationComponent parentLoc = parent.getComponent(LocationComponent.class); if (parentLoc != null) { this.position.sub(parentLoc.getWorldPosition()); this.position.scale(1f / parentLoc.getWorldScale()); Quat4f rot = new Quat4f(0, 0, 0, 1); rot.inverse(parentLoc.getWorldRotation()); rot.rotate(this.position, this.position); } }
private void renderBoneOrientation(EntityRef boneEntity) { LocationComponent loc = boneEntity.getComponent(LocationComponent.class); if (loc == null) { return; } glPushMatrix(); Vector3f worldPosA = loc.getWorldPosition(); Quat4f worldRot = loc.getWorldRotation(); Vector3f offset = new Vector3f(0, 0, 0.1f); worldRot.rotate(offset, offset); offset.add(worldPosA); glBegin(GL11.GL_LINES); glVertex3f(worldPosA.x, worldPosA.y, worldPosA.z); glVertex3f(offset.x, offset.y, offset.z); glEnd(); loc.getChildren().forEach(this::renderBoneOrientation); glPopMatrix(); }
private void updateCamera(CharacterMovementComponent charMovementComp, Vector3f position, Quat4f rotation) { playerCamera.getPosition().set(position); Vector3f viewDir = Direction.FORWARD.getVector3f(); rotation.rotate(viewDir, playerCamera.getViewingDirection()); float stepDelta = charMovementComp.footstepDelta - lastStepDelta; if (stepDelta < 0) { stepDelta += 1; } bobFactor += stepDelta; lastStepDelta = charMovementComp.footstepDelta; if (playerCamera.isBobbingAllowed()) { if (config.getRendering().isCameraBobbing()) { ((PerspectiveCamera) playerCamera).setBobbingRotationOffsetFactor(calcBobbingOffset(0.0f, 0.01f, 2.5f)); ((PerspectiveCamera) playerCamera).setBobbingVerticalOffsetFactor(calcBobbingOffset((float) java.lang.Math.PI / 4f, 0.025f, 3f)); } else { ((PerspectiveCamera) playerCamera).setBobbingRotationOffsetFactor(0.0f); ((PerspectiveCamera) playerCamera).setBobbingVerticalOffsetFactor(0.0f); } } if (charMovementComp.mode == MovementMode.GHOSTING) { playerCamera.extendFov(24); } else { playerCamera.resetFov(); } }
@Test public void testRotateMixed() { Rotation rotation = Rotation.rotate(Yaw.CLOCKWISE_180, Pitch.CLOCKWISE_90, Roll.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), new Vector3f()); assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT)); }
@Test public void testRotateSidePitch() { Rotation rotation = Rotation.rotate(Pitch.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), new Vector3f()); assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT)); assertEquals(Side.TOP, Rotation.rotate(Pitch.CLOCKWISE_90).rotate(Side.FRONT)); assertEquals(Side.RIGHT, Rotation.rotate(Pitch.CLOCKWISE_90).rotate(Side.RIGHT)); }
@Test public void testRotateSideYaw() { Rotation rotation = Rotation.rotate(Yaw.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), new Vector3f()); assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT)); assertEquals(Side.LEFT, Rotation.rotate(Yaw.CLOCKWISE_90).rotate(Side.FRONT)); assertEquals(Side.TOP, Rotation.rotate(Yaw.CLOCKWISE_90).rotate(Side.TOP)); }
@Test public void testRotateSideRoll() { Rotation rotation = Rotation.rotate(Roll.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.TOP.toDirection().getVector3f(), new Vector3f()); assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.TOP)); assertEquals(Side.LEFT, Rotation.rotate(Roll.CLOCKWISE_90).rotate(Side.TOP)); assertEquals(Side.FRONT, Rotation.rotate(Roll.CLOCKWISE_90).rotate(Side.FRONT)); }