Search in sources :

Example 1 with OctreeWrapper

use of gaiasky.scenegraph.octreewrapper.OctreeWrapper in project gaiasky by langurmonkey.

the class NaturalCamera method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    switch(event) {
        case FOCUS_CHANGE_CMD:
            setTrackingObject(null, null);
            // Check the type of the parameter: IFocus or String
            IFocus focus = null;
            // Center focus or not
            boolean centerFocus = !Settings.settings.runtime.openVr;
            if (data.length > 1)
                centerFocus = (Boolean) data[1];
            if (data[0] instanceof String) {
                SceneGraphNode sgn = GaiaSky.instance.sceneGraph.getNode((String) data[0]);
                if (sgn instanceof IFocus) {
                    focus = (IFocus) sgn;
                    diverted = !centerFocus;
                }
            } else if (data[0] instanceof IFocus) {
                focus = (IFocus) data[0];
                diverted = !centerFocus;
            }
            setFocus(focus);
            checkFocus();
            break;
        case FOV_CHANGED_CMD:
            boolean checkMax = source instanceof Actor;
            float fov = MathUtilsd.clamp((float) data[0], Constants.MIN_FOV, checkMax ? Constants.MAX_FOV : 179f);
            for (PerspectiveCamera cam : cameras) {
                cam.fieldOfView = fov;
            }
            fovFactor = camera.fieldOfView / 40f;
            if (parent.current == this) {
                EventManager.publish(Event.FOV_CHANGE_NOTIFICATION, this, fov, fovFactor);
            }
            break;
        case CUBEMAP_CMD:
            boolean state = (boolean) data[0];
            CubemapProjection p = (CubemapProjection) data[1];
            if (p.isPlanetarium() && state && !Settings.settings.runtime.openVr) {
                fovBackup = GaiaSky.instance.cameraManager.getCamera().fieldOfView;
            }
            break;
        case CAMERA_POS_CMD:
            synchronized (updateLock) {
                pos.set((double[]) data[0]);
                posinv.set(pos).scl(-1d);
            }
            break;
        case CAMERA_DIR_CMD:
            synchronized (updateLock) {
                direction.set((double[]) data[0]).nor();
            }
            break;
        case CAMERA_UP_CMD:
            synchronized (updateLock) {
                up.set((double[]) data[0]).nor();
            }
            break;
        case CAMERA_PROJECTION_CMD:
            synchronized (updateLock) {
                // Position
                pos.set((double[]) data[0]);
                posinv.set(pos).scl(-1d);
                // Direction
                direction.set((double[]) data[1]).nor();
                // Up
                up.set((double[]) data[2]).nor();
                // Change projection flag
                projectionFlag = true;
            }
            break;
        case CAMERA_FWD:
            synchronized (updateLock) {
                addForwardForce((double) data[0]);
            }
            break;
        case CAMERA_ROTATE:
            synchronized (updateLock) {
                addRotateMovement((double) data[0], (double) data[1], false, true);
            }
            break;
        case CAMERA_TURN:
            synchronized (updateLock) {
                addRotateMovement((double) data[0], (double) data[1], true, true);
            }
            break;
        case CAMERA_PAN:
            break;
        case CAMERA_ROLL:
            synchronized (updateLock) {
                addRoll((double) data[0], Settings.settings.scene.camera.cinematic);
            }
            break;
        case CAMERA_STOP:
            synchronized (updateLock) {
                stopTotalMovement();
            }
            break;
        case CAMERA_CENTER:
            synchronized (updateLock) {
                diverted = false;
            }
            break;
        case GO_TO_OBJECT_CMD:
            if (this.focus != null) {
                final IFocus f = this.focus;
                GaiaSky.postRunnable(() -> {
                    setTrackingObject(null, null);
                    // Position camera near focus
                    stopTotalMovement();
                    f.getAbsolutePosition(aux1b);
                    pos.set(aux1b);
                    double dx = 0d;
                    double dy = f.getSize() / 4d;
                    double dz = -f.getSize() * 4d;
                    if (Settings.settings.runtime.openVr) {
                        dz = -dz;
                    }
                    pos.add(dx, dy, dz);
                    posinv.set(pos).scl(-1d);
                    direction.set(aux1b).sub(pos).nor();
                    up.set(direction.x, direction.z, -direction.y).nor();
                    rotate(up, 0.01);
                    updatePerspectiveCamera();
                });
            }
            break;
        case ORIENTATION_LOCK_CMD:
            synchronized (updateLock) {
                previousOrientationAngle = 0;
            }
            break;
        case FREE_MODE_COORD_CMD:
            synchronized (updateLock) {
                double ra = (Double) data[0];
                double dec = (Double) data[1];
                double dist = 1e12d * Constants.PC_TO_U;
                aux1.set(MathUtilsd.degRad * ra, MathUtilsd.degRad * dec, dist);
                Coordinates.sphericalToCartesian(aux1, aux2);
                freeTargetPos.set(aux2);
                facingFocus = false;
                freeTargetOn = true;
            }
            break;
        case FOCUS_NOT_AVAILABLE:
            if (getMode().isFocus()) {
                boolean found = false;
                if (data[0] instanceof IFocus) {
                    focus = (IFocus) data[0];
                    found = isFocus(focus);
                } else if (data[0] instanceof OctreeWrapper) {
                    OctreeWrapper octree = (OctreeWrapper) data[0];
                    OctreeNode octant = this.focus.getOctant();
                    if (octant != null && octant.getRoot() == octree.root) {
                        found = true;
                    }
                } else if (data[0] instanceof GenericCatalog) {
                    GenericCatalog gc = (GenericCatalog) data[0];
                    if (gc.children != null && gc.children.contains((SceneGraphNode) this.focus, true)) {
                        found = true;
                    }
                }
                if (found) {
                    // Set camera  free
                    EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FREE_MODE);
                }
            }
            break;
        case TOGGLE_VISIBILITY_CMD:
            if (getMode().isFocus()) {
                ComponentType ct = ComponentType.getFromKey((String) data[0]);
                if (this.focus != null && ct != null && this.focus.getCt().isEnabled(ct)) {
                    // Set camera  free
                    EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FREE_MODE);
                }
            }
            break;
        case CAMERA_CENTER_FOCUS_CMD:
            synchronized (updateLock) {
                setCenterFocus((Boolean) data[0]);
            }
            break;
        case CONTROLLER_CONNECTED_INFO:
            Settings.settings.controls.gamepad.addControllerListener(controllerListener, (String) data[0]);
            break;
        case CONTROLLER_DISCONNECTED_INFO:
            // Nothing
            break;
        case NEW_DISTANCE_SCALE_FACTOR:
            synchronized (updateLock) {
                DIST_A = 0.1 * Constants.PC_TO_U;
                DIST_B = 5.0 * Constants.KPC_TO_U;
                DIST_C = 5000.0 * Constants.MPC_TO_U;
            }
            break;
        case CAMERA_TRACKING_OBJECT_CMD:
            final IFocus newTrackingObject = (IFocus) data[0];
            final String newTrackingName = (String) data[1];
            synchronized (updateLock) {
                this.setTrackingObject(newTrackingObject, newTrackingName != null ? newTrackingName.toLowerCase() : null);
            }
            break;
        default:
            break;
    }
}
Also used : ComponentType(gaiasky.render.ComponentTypes.ComponentType) OctreeNode(gaiasky.util.tree.OctreeNode) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) Actor(com.badlogic.gdx.scenes.scene2d.Actor) CubemapProjection(gaiasky.util.gdx.contrib.postprocess.effects.CubemapProjections.CubemapProjection) OctreeWrapper(gaiasky.scenegraph.octreewrapper.OctreeWrapper)

Example 2 with OctreeWrapper

use of gaiasky.scenegraph.octreewrapper.OctreeWrapper in project gaiasky by langurmonkey.

the class OctreeGroupLoader method loadOctreeData.

@Override
protected AbstractOctreeWrapper loadOctreeData() {
    /*
         * LOAD METADATA
         */
    logger.info(I18n.txt("notif.loading", metadata));
    MetadataBinaryIO metadataReader = new MetadataBinaryIO();
    OctreeNode root = metadataReader.readMetadataMapped(metadata);
    if (root != null) {
        logger.info(I18n.txt("notif.nodeloader", root.numNodesRec(), metadata));
        logger.info(I18n.txt("notif.loading", particles));
        /*
             * CREATE OCTREE WRAPPER WITH ROOT NODE - particle group is by default
             * parallel, so we never use OctreeWrapperConcurrent
             */
        AbstractOctreeWrapper octreeWrapper = new OctreeWrapper("Universe", root);
        octreeWrapper.setFadeout(new double[] { 8e3, 5e5 });
        // Catalog info
        String name = this.name != null ? this.name : "LOD data";
        String description = this.description != null ? this.description : "Octree-based LOD dataset";
        CatalogInfo ci = new CatalogInfo(name, description, null, CatalogInfoSource.LOD, 1.5f, octreeWrapper);
        ci.nParticles = params.containsKey("nobjects") ? (Long) params.get("nobjects") : -1;
        ci.sizeBytes = params.containsKey("size") ? (Long) params.get("size") : -1;
        EventManager.publish(Event.CATALOG_ADD, this, ci, false);
        dataVersionHint = name.contains("DR2") || name.contains("dr2") || description.contains("DR2") || description.contains("dr2") ? 0 : 1;
        /*
             * LOAD LOD LEVELS - LOAD PARTICLE DATA
             */
        try {
            int depthLevel = Math.min(OctreeNode.maxDepth, PRELOAD_DEPTH);
            loadLod(depthLevel, octreeWrapper);
            flushLoadedIds();
        } catch (IOException e) {
            logger.error(e);
        }
        return octreeWrapper;
    } else {
        logger.info("Dataset not found: " + metadata + " - " + particles);
        return null;
    }
}
Also used : MetadataBinaryIO(gaiasky.data.octreegen.MetadataBinaryIO) OctreeNode(gaiasky.util.tree.OctreeNode) CatalogInfo(gaiasky.util.CatalogInfo) IOException(java.io.IOException) AbstractOctreeWrapper(gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper) OctreeWrapper(gaiasky.scenegraph.octreewrapper.OctreeWrapper) AbstractOctreeWrapper(gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)

Example 3 with OctreeWrapper

use of gaiasky.scenegraph.octreewrapper.OctreeWrapper in project gaiasky by langurmonkey.

the class DatasetPreferencesWindow method generateFilterTable.

private void generateFilterTable(Filter filter) {
    float minSelectWidth = 160f;
    filterTable.clearChildren();
    if (filter != null && filter.hasRules()) {
        // Operation
        OwnSelectBox<String> operation = new OwnSelectBox<>(skin);
        operation.setWidth(minSelectWidth);
        operation.setItems("and", "or", "xor");
        operation.setSelected(filter.getOperationString().toLowerCase());
        operation.addListener(event -> {
            if (event instanceof ChangeEvent) {
                String newOp = operation.getSelected();
                filter.setOperation(newOp);
                filterEdited = true;
                return true;
            }
            return false;
        });
        filterTable.add(new OwnLabel(I18n.txt("gui.dataset.filter.operation"), skin)).left().padRight(pad10 * 2f).padBottom(pad10);
        filterTable.add(operation).left().expandX().padBottom(pad10).row();
        // Rules
        Array<FilterRule> rules = filter.getRules();
        Table rulesTable = new Table(skin);
        filterTable.add(rulesTable).colspan(2);
        for (FilterRule rule : rules) {
            // UNIT
            OwnLabel unit = new OwnLabel(rule.getAttribute().getUnit(), skin);
            // ATTRIBUTE
            boolean stars = ci.object instanceof StarGroup || ci.object instanceof OctreeWrapper;
            Array<AttributeComboBoxBean> attrs = new Array<>(false, stars ? 12 : 7);
            // Add particle attributes (dist, alpha, delta)
            attrs.add(new AttributeComboBoxBean(new AttributeDistance()));
            attrs.add(new AttributeComboBoxBean(new AttributeRA()));
            attrs.add(new AttributeComboBoxBean(new AttributeDEC()));
            attrs.add(new AttributeComboBoxBean(new AttributeEclLatitude()));
            attrs.add(new AttributeComboBoxBean(new AttributeEclLongitude()));
            attrs.add(new AttributeComboBoxBean(new AttributeGalLatitude()));
            attrs.add(new AttributeComboBoxBean(new AttributeGalLongitude()));
            if (stars) {
                // Star-only attributes (appmag, absmag, mualpha, mudelta, radvel)
                attrs.add(new AttributeComboBoxBean(new AttributeAppmag()));
                attrs.add(new AttributeComboBoxBean(new AttributeAbsmag()));
                attrs.add(new AttributeComboBoxBean(new AttributeMualpha()));
                attrs.add(new AttributeComboBoxBean(new AttributeMudelta()));
                attrs.add(new AttributeComboBoxBean(new AttributeRadvel()));
            }
            // Colors
            attrs.add(new AttributeComboBoxBean(new AttributeColorRed()));
            attrs.add(new AttributeComboBoxBean(new AttributeColorGreen()));
            attrs.add(new AttributeComboBoxBean(new AttributeColorBlue()));
            // Extra attributes
            if (ci.object instanceof ParticleGroup) {
                ParticleGroup pg = (ParticleGroup) ci.object;
                if (pg.size() > 0) {
                    IParticleRecord first = pg.get(0);
                    if (first.hasExtra()) {
                        ObjectDoubleMap.Keys<UCD> ucds = first.extraKeys();
                        for (UCD ucd : ucds) attrs.add(new AttributeComboBoxBean(new AttributeUCD(ucd)));
                    }
                }
            }
            OwnSelectBox<AttributeComboBoxBean> attribute = new OwnSelectBox<>(skin);
            attribute.setItems(attrs);
            attribute.setSelected(getAttributeBean(rule.getAttribute(), attrs));
            attribute.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    IAttribute newAttr = attribute.getSelected().attr;
                    rule.setAttribute(newAttr);
                    // Update unit
                    unit.setText(newAttr.getUnit());
                    filterEdited = true;
                    return true;
                }
                return false;
            });
            rulesTable.add(attribute).left().padRight(pad10).padBottom(pad5);
            // COMPARATOR
            String[] cmps = new String[] { "<", "<=", ">", ">=", "==", "!=" };
            OwnSelectBox<String> comparator = new OwnSelectBox<>(skin);
            comparator.setWidth(minSelectWidth);
            comparator.setItems(cmps);
            comparator.setSelected(rule.getComparator().toString());
            comparator.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    IComparator newComp = rule.getComparatorFromString(comparator.getSelected());
                    rule.setComparator(newComp);
                    filterEdited = true;
                    return true;
                }
                return false;
            });
            rulesTable.add(comparator).left().padRight(pad10).padBottom(pad5);
            // VALUE
            FloatValidator fval = new FloatValidator(-Float.MAX_VALUE, Float.MAX_VALUE);
            OwnTextField value = new OwnTextField(Double.toString(rule.getValue()), skin, fval);
            value.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    if (value.isValid()) {
                        try {
                            rule.setValue(Float.parseFloat(value.getText()));
                            filterEdited = true;
                            return true;
                        } catch (Exception e) {
                            logger.error(e);
                            return false;
                        }
                    }
                    return false;
                }
                return false;
            });
            rulesTable.add(value).left().padRight(pad10).padBottom(pad5);
            // UNIT
            rulesTable.add(unit).left().padRight(pad10 * 3f).padBottom(pad5);
            // RUBBISH
            OwnTextIconButton rubbish = new OwnTextIconButton("", skin, "rubbish");
            rubbish.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dataset.filter.rule.remove"), skin));
            rubbish.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    deleteRule(filter, rule);
                    filterEdited = true;
                    return true;
                }
                return false;
            });
            rulesTable.add(rubbish).left().padBottom(pad5).row();
        }
        // New rule button
        OwnTextIconButton addRule = new OwnTextIconButton(I18n.txt("gui.dataset.filter.rule.add"), skin, "add");
        addRule.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dataset.filter.rule.add"), skin));
        addRule.pad(pad10);
        rulesTable.add(addRule).left().padTop(pad10).row();
        addRule.addListener(event -> {
            if (event instanceof ChangeEvent) {
                dpw.addRule(filter);
                filterEdited = true;
                return true;
            }
            return false;
        });
    } else {
        // Add
        filterTable.add(new OwnLabel(I18n.txt("gui.dataset.filter.nofilters"), skin)).left().padBottom(pad10).row();
        OwnTextIconButton addFilter = new OwnTextIconButton(I18n.txt("gui.dataset.filter.add"), skin, "add");
        addFilter.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dataset.filter.add"), skin));
        addFilter.pad(pad10);
        filterTable.add(addFilter).left().padBottom(pad5).row();
        addFilter.addListener(event -> {
            if (event instanceof ChangeEvent) {
                dpw.addFilter();
                filterEdited = true;
                return true;
            }
            return false;
        });
    }
    pack();
}
Also used : FilterRule(gaiasky.util.filter.FilterRule) IComparator(gaiasky.util.filter.FilterRule.IComparator) AttributeComboBoxBean(gaiasky.interafce.beans.AttributeComboBoxBean) FloatValidator(gaiasky.util.validator.FloatValidator) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ParticleGroup(gaiasky.scenegraph.ParticleGroup) Array(com.badlogic.gdx.utils.Array) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) StarGroup(gaiasky.scenegraph.StarGroup) UCD(gaiasky.util.ucd.UCD) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) OctreeWrapper(gaiasky.scenegraph.octreewrapper.OctreeWrapper)

Aggregations

OctreeWrapper (gaiasky.scenegraph.octreewrapper.OctreeWrapper)3 OctreeNode (gaiasky.util.tree.OctreeNode)2 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)1 Array (com.badlogic.gdx.utils.Array)1 MetadataBinaryIO (gaiasky.data.octreegen.MetadataBinaryIO)1 AttributeComboBoxBean (gaiasky.interafce.beans.AttributeComboBoxBean)1 ComponentType (gaiasky.render.ComponentTypes.ComponentType)1 ParticleGroup (gaiasky.scenegraph.ParticleGroup)1 StarGroup (gaiasky.scenegraph.StarGroup)1 AbstractOctreeWrapper (gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)1 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)1 CatalogInfo (gaiasky.util.CatalogInfo)1 FilterRule (gaiasky.util.filter.FilterRule)1 IComparator (gaiasky.util.filter.FilterRule.IComparator)1 CubemapProjection (gaiasky.util.gdx.contrib.postprocess.effects.CubemapProjections.CubemapProjection)1 UCD (gaiasky.util.ucd.UCD)1 FloatValidator (gaiasky.util.validator.FloatValidator)1