Search in sources :

Example 11 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class RecursiveGrid method initialize.

@Override
public void initialize() {
    transformName = Settings.settings.scene.visibility.get(ComponentType.Galactic.toString()) ? "galacticToEquatorial" : (Settings.settings.scene.visibility.get(ComponentType.Ecliptic.toString()) ? "eclipticToEquatorial" : null);
    coordinateSystem = new Matrix4();
    coordinateSystemd = new Matrix4d();
    mat4daux = new Matrix4d();
    scalingFading = new Pair<>(0d, 0d);
    updateCoordinateSystem();
    nf = NumberFormatFactory.getFormatter("0.###E0");
    cc = Settings.settings.scene.visibility.get(ComponentType.Galactic.toString()) ? ccGal : (Settings.settings.scene.visibility.get(ComponentType.Ecliptic.toString()) ? ccEcl : ccEq);
    labelcolor = cc;
    label = true;
    labelPosition = new Vector3b();
    localTransform = new Matrix4();
    p01 = new Vector3d();
    p02 = new Vector3d();
    d01 = -1;
    d02 = -1;
    a = new Vector3d();
    b = new Vector3d();
    c = new Vector3d();
    d = new Vector3d();
    // Init billboard model
    mc = new ModelComponent();
    mc.setType("twofacedbillboard");
    Map<String, Object> p = new HashMap<>();
    p.put("diameter", 1d);
    mc.setParams(p);
    mc.forceInit = true;
    mc.initialize(null);
    mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, cc[0], cc[1], cc[2], cc[3]));
    // Depth reads, no depth writes
    mc.setDepthTest(GL20.GL_LEQUAL, false);
    // Initialize annotations vectorR
    initAnnotations();
}
Also used : Matrix4d(gaiasky.util.math.Matrix4d) Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d) ModelComponent(gaiasky.scenegraph.component.ModelComponent) HashMap(java.util.HashMap) ColorAttribute(gaiasky.util.gdx.shader.attribute.ColorAttribute) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 12 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class Spacecraft method computeDirectionUp.

public double computeDirectionUp(double dt, Pair<Vector3d, Vector3d> pair) {
    // Yaw, pitch and roll
    yawf = yawp * responsiveness;
    pitchf = pitchp * responsiveness;
    rollf = rollp * responsiveness;
    // Friction
    double friction = (drag * 2e7) * dt;
    yawf -= yawv * friction;
    pitchf -= pitchv * friction;
    rollf -= rollv * friction;
    // accel
    yawa = yawf / mass;
    pitcha = pitchf / mass;
    rolla = rollf / mass;
    // vel
    yawv += yawa * dt;
    pitchv += pitcha * dt;
    rollv += rolla * dt;
    // pos
    double yawDiff = (yawv * dt) % 360d;
    double pitchDiff = (pitchv * dt) % 360d;
    double rollDiff = (rollv * dt) % 360d;
    Vector3d direction = pair.getFirst();
    Vector3d up = pair.getSecond();
    // apply yaw
    direction.rotate(up, yawDiff);
    // apply pitch
    Vector3d aux1 = D31.get().set(direction).crs(up);
    direction.rotate(aux1, pitchDiff);
    up.rotate(aux1, pitchDiff);
    // apply roll
    up.rotate(direction, -rollDiff);
    return rollDiff;
}
Also used : Vector3d(gaiasky.util.math.Vector3d)

Example 13 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class Spacecraft method render.

@Override
public void render(LineRenderSystem renderer, ICamera camera, float alpha) {
    // Direction
    Vector3d d = D31.get().set(direction);
    d.nor().scl(.5e-4);
    renderer.addLine(this, posf.x, posf.y, posf.z, posf.x + d.x, posf.y + d.y, posf.z + d.z, 1, 0, 0, 1);
    // Up
    Vector3d u = D31.get().set(up);
    u.nor().scl(.2e-4);
    renderer.addLine(this, posf.x, posf.y, posf.z, posf.x + u.x, posf.y + u.y, posf.z + u.z, 0, 0, 1, 1);
}
Also used : Vector3d(gaiasky.util.math.Vector3d)

Example 14 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class ChangeOfBasisTest method main.

public static void main(String[] args) {
    System.out.println("==========================");
    Matrix4d c = Matrix4d.changeOfBasis(new double[] { 0, 0, -1 }, new double[] { 0, 1, 0 }, new double[] { 1, 0, 0 });
    Vector3d v = new Vector3d(1, 0, 0);
    System.out.println(v + " -> " + (new Vector3d(v)).mul(c));
    v = new Vector3d(0, 1, 0);
    System.out.println(v + " -> " + (new Vector3d(v)).mul(c));
    v = new Vector3d(0, 0, 1);
    System.out.println(v + " -> " + (new Vector3d(v)).mul(c));
    System.out.println("==========================");
    c = Matrix4d.changeOfBasis(new double[] { 0.5, 0, 0 }, new double[] { -1, 2, 0 }, new double[] { 0, 0, 1 });
    v = new Vector3d(4, 1, 0);
    System.out.println(v + " -> " + (new Vector3d(v)).mul(c));
    v = new Vector3d(0, 1, 0);
    System.out.println(v + " -> " + (new Vector3d(v)).mul(c));
}
Also used : Matrix4d(gaiasky.util.math.Matrix4d) Vector3d(gaiasky.util.math.Vector3d)

Example 15 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class OctreeNode method computeObservedFast.

/**
 * Simplification to compute octant visibility. Angle between camera direction and octant centre
 * must be smaller than fov/2 plus a correction (approximates octants to spheres)
 *
 * @param cam The camera
 * @return Whether the octant is observed
 */
private boolean computeObservedFast(ICamera cam) {
    // vector from camera to center of box
    Vector3d cpospos = auxD1.set(centre).sub(cam.getPos());
    // auxD2 rotation axis
    Vector3d axis = auxD2.set(cam.getDirection()).crs(centre);
    Vector3d edge = auxD3.set(cam.getDirection()).rotate(axis, cam.getCamera().fieldOfView / 2d);
    // get angle at edge (when far side is radius)
    double angle1 = FastMath.toDegrees(FastMath.atan(radius / cpospos.len()));
    // get actual angle
    double angle2 = edge.angle(cpospos);
    // We're in the containing sphere or centre is in front of us
    return distToCamera <= radius || angle2 < angle1;
}
Also used : Vector3d(gaiasky.util.math.Vector3d)

Aggregations

Vector3d (gaiasky.util.math.Vector3d)120 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)11 Array (com.badlogic.gdx.utils.Array)10 Vector3 (com.badlogic.gdx.math.Vector3)8 Vector3b (gaiasky.util.math.Vector3b)8 PointCloudData (gaiasky.data.util.PointCloudData)7 Keyframe (gaiasky.desktop.util.camera.Keyframe)5 Matrix4d (gaiasky.util.math.Matrix4d)5 Quaterniond (gaiasky.util.math.Quaterniond)5 ArrayList (java.util.ArrayList)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)3 Vector2d (gaiasky.util.math.Vector2d)3 Path (java.nio.file.Path)3 Date (java.util.Date)3 Matrix4 (com.badlogic.gdx.math.Matrix4)2 OrbitComponent (gaiasky.scenegraph.component.OrbitComponent)2 ParticleRecord (gaiasky.scenegraph.particle.ParticleRecord)2