use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.
the class StarGroup method updateMetadata.
/**
* Updates the additional information array, to use for sorting.
* In stars, we need to take into account the proper motion and the brightness.
*
* @param time The current time frame provider
* @param camera The camera
*/
public void updateMetadata(ITimeFrameProvider time, ICamera camera) {
Vector3d camPos = camera.getPos().tov3d(D34.get());
double deltaYears = AstroUtils.getMsSince(time.getTime(), epochJd) * Nature.MS_TO_Y;
if (pointData != null) {
int n = pointData.size();
for (int i = 0; i < n; i++) {
IParticleRecord d = pointData.get(i);
// Pm
Vector3d dx = D32.get().set(d.pmx(), d.pmy(), d.pmz()).scl(deltaYears);
// Pos
Vector3d x = D31.get().set(d.x(), d.y(), d.z()).add(dx);
metadata[i] = filter(i) ? (-(((d.size() * Constants.STAR_SIZE_FACTOR) / camPos.dst(x)) / camera.getFovFactor()) * Settings.settings.scene.star.brightness) : Double.MAX_VALUE;
}
}
}
use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.
the class StarGroup method render.
/**
* Proper motion rendering
*/
@Override
public void render(LineRenderSystem renderer, ICamera camera, float alpha) {
alpha *= GaiaSky.instance.sgr.alphas[ComponentTypes.ComponentType.VelocityVectors.ordinal()];
float thPointTimesFovFactor = (float) Settings.settings.scene.star.threshold.point * camera.getFovFactor();
int n = (int) getMaxProperMotionLines();
for (int i = n - 1; i >= 0; i--) {
IParticleRecord star = pointData.get(active[i]);
float radius = (float) (getSize(active[i]) * Constants.STAR_SIZE_FACTOR);
// Position
Vector3d lPos = fetchPosition(star, cPosD, D31.get(), currDeltaYears);
// Proper motion
Vector3d pm = D32.get().set(star.pmx(), star.pmy(), star.pmz()).scl(currDeltaYears);
// Rest of attributes
float distToCamera = (float) lPos.len();
float viewAngle = ((radius / distToCamera) / camera.getFovFactor()) * Settings.settings.scene.star.brightness;
if (viewAngle >= thPointTimesFovFactor / Settings.settings.scene.properMotion.number && (star.pmx() != 0 || star.pmy() != 0 || star.pmz() != 0)) {
Vector3d p1 = D31.get().set(star.x() + pm.x, star.y() + pm.y, star.z() + pm.z).sub(camera.getPos());
Vector3d ppm = D32.get().set(star.pmx(), star.pmy(), star.pmz()).scl(Settings.settings.scene.properMotion.length);
double p1p2len = ppm.len();
Vector3d p2 = D33.get().set(ppm).add(p1);
// Maximum speed in km/s, to normalize
float maxSpeedKms = 100;
float r, g, b;
switch(Settings.settings.scene.properMotion.colorMode) {
case 0:
default:
// DIRECTION
// Normalize, each component is in [-1:1], map to [0:1] and to a color channel
ppm.nor();
r = (float) (ppm.x + 1d) / 2f;
g = (float) (ppm.y + 1d) / 2f;
b = (float) (ppm.z + 1d) / 2f;
break;
case 1:
// LENGTH
ppm.set(star.pmx(), star.pmy(), star.pmz());
// Units/year to Km/s
ppm.scl(Constants.U_TO_KM / Nature.Y_TO_S);
double len = MathUtilsd.clamp(ppm.len(), 0d, maxSpeedKms) / maxSpeedKms;
ColorUtils.colormap_long_rainbow((float) (1 - len), rgba);
r = rgba[0];
g = rgba[1];
b = rgba[2];
break;
case 2:
// HAS RADIAL VELOCITY - blue: stars with RV, red: stars without RV
if (star.radvel() != 0) {
r = ColorUtils.gBlue[0] + 0.2f;
g = ColorUtils.gBlue[1] + 0.4f;
b = ColorUtils.gBlue[2] + 0.4f;
} else {
r = ColorUtils.gRed[0] + 0.4f;
g = ColorUtils.gRed[1] + 0.2f;
b = ColorUtils.gRed[2] + 0.2f;
}
break;
case 3:
// REDSHIFT from Sun - blue: -100 Km/s, red: 100 Km/s
float rav = star.radvel();
if (rav != 0) {
// rv in [0:1]
float rv = ((MathUtilsd.clamp(rav, -maxSpeedKms, maxSpeedKms) / maxSpeedKms) + 1) / 2;
ColorUtils.colormap_blue_white_red(rv, rgba);
r = rgba[0];
g = rgba[1];
b = rgba[2];
} else {
r = g = b = 1;
}
break;
case 4:
// REDSHIFT from Camera - blue: -100 Km/s, red: 100 Km/s
if (ppm.len2() != 0) {
ppm.set(star.pmx(), star.pmy(), star.pmz());
// Units/year to Km/s
ppm.scl(Constants.U_TO_KM / Nature.Y_TO_S);
Vector3d camStar = D34.get().set(p1);
double pr = ppm.dot(camStar.nor());
double projection = ((MathUtilsd.clamp(pr, -(double) maxSpeedKms, maxSpeedKms) / (double) maxSpeedKms) + 1) / 2;
ColorUtils.colormap_blue_white_red((float) projection, rgba);
r = rgba[0];
g = rgba[1];
b = rgba[2];
} else {
r = g = b = 1;
}
break;
case 5:
// SINGLE COLOR
r = ColorUtils.gBlue[0] + 0.2f;
g = ColorUtils.gBlue[1] + 0.4f;
b = ColorUtils.gBlue[2] + 0.4f;
break;
}
// Clamp
r = MathUtilsd.clamp(r, 0, 1);
g = MathUtilsd.clamp(g, 0, 1);
b = MathUtilsd.clamp(b, 0, 1);
renderer.addLine(this, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, r, g, b, alpha * this.opacity);
if (Settings.settings.scene.properMotion.arrowHeads) {
// Add Arrow cap
Vector3d p3 = D32.get().set(ppm).nor().scl(p1p2len * .86).add(p1);
p3.rotate(p2, 30);
renderer.addLine(this, p3.x, p3.y, p3.z, p2.x, p2.y, p2.z, r, g, b, alpha * this.opacity);
p3.rotate(p2, -60);
renderer.addLine(this, p3.x, p3.y, p3.z, p2.x, p2.y, p2.z, r, g, b, alpha * this.opacity);
}
}
}
}
use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.
the class GlobalResources method applyRelativisticAberration.
public static synchronized Vector3d applyRelativisticAberration(Vector3d pos, ICamera cam) {
// Relativistic aberration
if (Settings.settings.runtime.relativisticAberration) {
Vector3d cdir = aux;
if (cam.getVelocity() != null)
cdir.set(cam.getVelocity()).nor();
else
cdir.set(1, 0, 0);
double vc = cam.getSpeed() / Constants.C_KMH;
if (vc > 0) {
cdir.scl(-1);
double cosThS = cdir.dot(pos) / pos.len();
double th_s = Math.acos(cosThS);
double cosThO = (cosThS - vc) / (1 - vc * cosThS);
double th_o = Math.acos(cosThO);
pos.rotate(cdir.crs(pos).nor(), Math.toDegrees(th_o - th_s));
}
}
return pos;
}
use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.
the class KeyframesPathObject method renderKeyframeLabel.
private void renderKeyframeLabel(Keyframe kf, ExtSpriteBatch batch, ExtShaderProgram shader, FontRenderSystem sys, RenderingContext rc, ICamera camera) {
Vector3d pos = D31.get();
getTextPosition(camera, pos, kf);
float distToCam = (float) D32.get().set(kf.pos).add(camera.getInversePos()).len();
shader.setUniformf("u_viewAngle", 90f);
shader.setUniformf("u_viewAnglePow", 1);
shader.setUniformf("u_thOverFactor", 1);
shader.setUniformf("u_thOverFactorScl", 1);
shader.setUniform4fv("u_color", textColour(kf), 0, 4);
render3DLabel(batch, shader, sys.fontDistanceField, camera, rc, getText(kf), pos, distToCamera, textScale() * camera.getFovFactor(), textSize() * camera.getFovFactor() * distToCam, this.forceLabel);
}
use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.
the class Loc method renderText.
@Override
public boolean renderText() {
if (GaiaSky.instance.isOn(ct) && (viewAngle >= LOWER_LIMIT && viewAngle <= UPPER_LIMIT * Constants.DISTANCE_SCALE_FACTOR || forceLabel)) {
Vector3d aux = D31.get();
translation.put(aux).scl(-1);
double cosAlpha = aux.add(location3d.x, location3d.y, location3d.z).nor().dot(GaiaSky.instance.cameraManager.getDirection().nor());
return cosAlpha < -0.3f;
} else {
return false;
}
}
Aggregations