/** Normalizes the up vector by first calculating the right vector via a cross product between direction and up, and then * recalculating the up vector via a cross product between right and direction. */ public void normalizeUp () { tmpVec.set(direction).crs(up).nor(); up.set(tmpVec).crs(direction).nor(); }
/** Normalizes the up vector by first calculating the right vector via a cross product between direction and up, and then * recalculating the up vector via a cross product between right and direction. */ public void normalizeUp () { tmpVec.set(direction).crs(up).nor(); up.set(tmpVec).crs(direction).nor(); }
/** Sets the rotation of this decal based on the (normalized) direction and up vector. * @param dir the direction vector * @param up the up vector */ public void setRotation (Vector3 dir, Vector3 up) { tmp.set(up).crs(dir).nor(); tmp2.set(dir).crs(tmp).nor(); rotation.setFromAxes(tmp.x, tmp2.x, dir.x, tmp.y, tmp2.y, dir.y, tmp.z, tmp2.z, dir.z); updated = false; }
/** Sets the rotation of this decal based on the (normalized) direction and up vector. * @param dir the direction vector * @param up the up vector */ public void setRotation (Vector3 dir, Vector3 up) { tmp.set(up).crs(dir).nor(); tmp2.set(dir).crs(tmp).nor(); rotation.setFromAxes(tmp.x, tmp2.x, dir.x, tmp.y, tmp2.y, dir.y, tmp.z, tmp2.z, dir.z); updated = false; }
@Override public void update () { for (int i = 0, accelOffset = 0, c = i + controller.particles.size * rotationChannel.strideSize; i < c; i += rotationChannel.strideSize, accelOffset += accellerationChannel.strideSize) { Vector3 axisZ = TMP_V1.set(accellerationChannel.data[accelOffset + ParticleChannels.XOffset], accellerationChannel.data[accelOffset + ParticleChannels.YOffset], accellerationChannel.data[accelOffset + ParticleChannels.ZOffset]).nor(), axisY = TMP_V2.set(TMP_V1) .crs(Vector3.Y).nor().crs(TMP_V1).nor(), axisX = TMP_V3.set(axisY).crs(axisZ).nor(); TMP_Q.setFromAxes(false, axisX.x, axisY.x, axisZ.x, axisX.y, axisY.y, axisZ.y, axisX.z, axisY.z, axisZ.z); rotationChannel.data[i + ParticleChannels.XOffset] = TMP_Q.x; rotationChannel.data[i + ParticleChannels.YOffset] = TMP_Q.y; rotationChannel.data[i + ParticleChannels.ZOffset] = TMP_Q.z; rotationChannel.data[i + ParticleChannels.WOffset] = TMP_Q.w; } }
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { shader.set(inputID, TMP_VECTOR3.set(shader.camera.direction).crs(shader.camera.up).nor()); } };
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { shader.set(inputID, TMP_VECTOR3.set(shader.camera.direction).crs(shader.camera.up).nor()); } };
/** Build an ellipse */ public static void build (MeshPartBuilder builder, float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float angleFrom, float angleTo) { tmpV1.set(normalX, normalY, normalZ).crs(0, 0, 1); tmpV2.set(normalX, normalY, normalZ).crs(0, 1, 0); if (tmpV2.len2() > tmpV1.len2()) tmpV1.set(tmpV2); tmpV2.set(tmpV1.nor()).crs(normalX, normalY, normalZ).nor(); build(builder, width, height, innerWidth, innerHeight, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, tmpV1.x, tmpV1.y, tmpV1.z, tmpV2.x, tmpV2.y, tmpV2.z, angleFrom, angleTo); }
/** Build an ellipse */ public static void build (MeshPartBuilder builder, float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float angleFrom, float angleTo) { tmpV1.set(normalX, normalY, normalZ).crs(0, 0, 1); tmpV2.set(normalX, normalY, normalZ).crs(0, 1, 0); if (tmpV2.len2() > tmpV1.len2()) tmpV1.set(tmpV2); tmpV2.set(tmpV1.nor()).crs(normalX, normalY, normalZ).nor(); build(builder, width, height, innerWidth, innerHeight, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, tmpV1.x, tmpV1.y, tmpV1.z, tmpV2.x, tmpV2.y, tmpV2.z, angleFrom, angleTo); }
@Override public void update () { for (int i = 0, accelOffset = 0, c = i + controller.particles.size * rotationChannel.strideSize; i < c; i += rotationChannel.strideSize, accelOffset += accellerationChannel.strideSize) { Vector3 axisZ = TMP_V1.set(accellerationChannel.data[accelOffset + ParticleChannels.XOffset], accellerationChannel.data[accelOffset + ParticleChannels.YOffset], accellerationChannel.data[accelOffset + ParticleChannels.ZOffset]).nor(), axisY = TMP_V2.set(TMP_V1) .crs(Vector3.Y).nor().crs(TMP_V1).nor(), axisX = TMP_V3.set(axisY).crs(axisZ).nor(); TMP_Q.setFromAxes(false, axisX.x, axisY.x, axisZ.x, axisX.y, axisY.y, axisZ.y, axisX.z, axisY.z, axisZ.z); rotationChannel.data[i + ParticleChannels.XOffset] = TMP_Q.x; rotationChannel.data[i + ParticleChannels.YOffset] = TMP_Q.y; rotationChannel.data[i + ParticleChannels.ZOffset] = TMP_Q.z; rotationChannel.data[i + ParticleChannels.WOffset] = TMP_Q.w; } }
/** Sets the plane normal and distance to the origin based on the three given points which are considered to be on the plane. * The normal is calculated via a cross product between (point1-point2)x(point2-point3) * * @param point1 * @param point2 * @param point3 */ public void set (Vector3 point1, Vector3 point2, Vector3 point3) { normal.set(point1).sub(point2).crs(point2.x-point3.x, point2.y-point3.y, point2.z-point3.z).nor(); d = -point1.dot(normal); }
/** Sets the plane normal and distance to the origin based on the three given points which are considered to be on the plane. * The normal is calculated via a cross product between (point1-point2)x(point2-point3) * * @param point1 * @param point2 * @param point3 */ public void set (Vector3 point1, Vector3 point2, Vector3 point3) { normal.set(point1).sub(point2).crs(point2.x-point3.x, point2.y-point3.y, point2.z-point3.z).nor(); d = -point1.dot(normal); }
/** Sets the matrix to a look at matrix with a direction and an up vector. Multiply with a translation matrix to get a camera * model view matrix. * * @param direction The direction vector * @param up The up vector * @return This matrix for the purpose of chaining methods together. */ public Matrix4 setToLookAt (Vector3 direction, Vector3 up) { l_vez.set(direction).nor(); l_vex.set(direction).nor(); l_vex.crs(up).nor(); l_vey.set(l_vex).crs(l_vez).nor(); idt(); val[M00] = l_vex.x; val[M01] = l_vex.y; val[M02] = l_vex.z; val[M10] = l_vey.x; val[M11] = l_vey.y; val[M12] = l_vey.z; val[M20] = -l_vez.x; val[M21] = -l_vez.y; val[M22] = -l_vez.z; return this; }
@Override public boolean touchDragged (int screenX, int screenY, int pointer) { float deltaX = -Gdx.input.getDeltaX() * degreesPerPixel; float deltaY = -Gdx.input.getDeltaY() * degreesPerPixel; camera.direction.rotate(camera.up, deltaX); tmp.set(camera.direction).crs(camera.up).nor(); camera.direction.rotate(tmp, deltaY); // camera.up.rotate(tmp, deltaY); return true; }
@Override public boolean touchDragged (int screenX, int screenY, int pointer) { float deltaX = -Gdx.input.getDeltaX() * degreesPerPixel; float deltaY = -Gdx.input.getDeltaY() * degreesPerPixel; camera.direction.rotate(camera.up, deltaX); tmp.set(camera.direction).crs(camera.up).nor(); camera.direction.rotate(tmp, deltaY); // camera.up.rotate(tmp, deltaY); return true; }
protected boolean process (float deltaX, float deltaY, int button) { if (button == rotateButton) { tmpV1.set(camera.direction).crs(camera.up).y = 0f; camera.rotateAround(target, tmpV1.nor(), deltaY * rotateAngle); camera.rotateAround(target, Vector3.Y, deltaX * -rotateAngle); } else if (button == translateButton) { camera.translate(tmpV1.set(camera.direction).crs(camera.up).nor().scl(-deltaX * translateUnits)); camera.translate(tmpV2.set(camera.up).scl(-deltaY * translateUnits)); if (translateTarget) target.add(tmpV1).add(tmpV2); } else if (button == forwardButton) { camera.translate(tmpV1.set(camera.direction).scl(deltaY * translateUnits)); if (forwardTarget) target.add(tmpV1); } if (autoUpdate) camera.update(); return true; }
protected boolean process (float deltaX, float deltaY, int button) { if (button == rotateButton) { tmpV1.set(camera.direction).crs(camera.up).y = 0f; camera.rotateAround(target, tmpV1.nor(), deltaY * rotateAngle); camera.rotateAround(target, Vector3.Y, deltaX * -rotateAngle); } else if (button == translateButton) { camera.translate(tmpV1.set(camera.direction).crs(camera.up).nor().scl(-deltaX * translateUnits)); camera.translate(tmpV2.set(camera.up).scl(-deltaY * translateUnits)); if (translateTarget) target.add(tmpV1).add(tmpV2); } else if (button == forwardButton) { camera.translate(tmpV1.set(camera.direction).scl(deltaY * translateUnits)); if (forwardTarget) target.add(tmpV1); } if (autoUpdate) camera.update(); return true; }
@Override public void update () { super.update(); // Transform the frustum camera if ((state & PAUSE_FRUSTUM_CAM) == PAUSE_FRUSTUM_CAM) return; final float dt = Gdx.graphics.getDeltaTime(); frustumInstance.transform.idt().rotate(Vector3.Y, frustumCamAngleY = (frustumCamAngleY + dt * FRUSTUM_ANG_SPEED) % 360); frustumCam.direction.set(0, 0, -1); frustumCam.up.set(Vector3.Y); frustumCam.position.set(Vector3.Zero); frustumCam.rotate(frustumInstance.transform); float frustumCamPosY = frustumCamPos.y; frustumCamPos.add(tmpV1.set(Vector3.Y).crs(tmpV2.set(frustumCamPos).nor()).scl(dt * FRUSTUM_LIN_SPEED)).nor() .scl(FRUSTUM_MOVE_RADIUS); frustumCamPos.y = frustumCamPosY; frustumCam.position.set(frustumCamPos); frustumInstance.transform.setTranslation(frustumCamPos); frustumCam.update(); }