Search in sources :

Example 11 with IFocus

use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.

the class AbstractOctreeWrapper method updateLocal.

public void updateLocal(ITimeFrameProvider time, ICamera camera) {
    super.updateLocal(time, camera);
    // Fade node visibility applies here
    if (this.isVisible()) {
        // Update octants
        if (!copy) {
            // Compute observed octants and fill roulette list
            OctreeNode.nOctantsObserved = 0;
            OctreeNode.nObjectsObserved = 0;
            root.update(translation, camera, roulette, opacity);
            if (OctreeNode.nObjectsObserved != lastNumberObjects) {
                // Need to update the points in renderer
                EventManager.publish(Event.STAR_POINT_UPDATE_FLAG, this, true);
                lastNumberObjects = OctreeNode.nObjectsObserved;
            }
            // Call the update method of all entities in the roulette list. This
            // is implemented in the subclass.
            updateOctreeObjects(time, translation, camera);
            addToRenderLists(camera, root);
            // Reset mask
            roulette.clear();
            // Update focus, just in case
            IFocus focus = camera.getFocus();
            if (focus != null) {
                SceneGraphNode star = focus.getFirstStarAncestor();
                OctreeNode parent = parenthood.get(star);
                if (parent != null && !parent.isObserved()) {
                    star.update(time, star.parent.translation, camera);
                }
            }
        } else {
            // Just update children
            for (SceneGraphNode node : children) {
                node.update(time, translation, camera);
            }
        }
    }
}
Also used : SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) OctreeNode(gaiasky.util.tree.OctreeNode) IFocus(gaiasky.scenegraph.IFocus)

Example 12 with IFocus

use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.

the class ConsoleLogger method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    switch(event) {
        case POST_NOTIFICATION:
            LoggerLevel level = (LoggerLevel) data[0];
            Object[] dat = (Object[]) data[1];
            StringBuilder message = new StringBuilder();
            for (int i = 0; i < dat.length; i++) {
                if (i != dat.length - 1 || !(dat[i] instanceof Boolean)) {
                    message.append(dat[i].toString());
                    if (i < dat.length - 1 && !(i == dat.length - 2 && dat[data.length - 1] instanceof Boolean)) {
                        message.append(TAG_SEPARATOR);
                    }
                }
            }
            addMessage(message.toString(), level);
            break;
        case FOCUS_CHANGED:
            if (data[0] != null) {
                IFocus sgn = null;
                if (data[0] instanceof String) {
                    sgn = GaiaSky.instance.sceneGraph.findFocus((String) data[0]);
                } else {
                    sgn = (IFocus) data[0];
                }
                addMessage(I18n.txt("notif.camerafocus", sgn.getName()));
            }
            break;
        case TIME_STATE_CMD:
            Boolean bool = (Boolean) data[0];
            if (bool == null) {
                addMessage(I18n.txt("notif.toggle", I18n.txt("gui.time")));
            } else {
                addMessage(I18n.txt("notif.simulation." + (bool ? "resume" : "pause")));
            }
            break;
        case TOGGLE_VISIBILITY_CMD:
            if (data.length == 2)
                addMessage(I18n.txt("notif.visibility." + (((Boolean) data[1]) ? "on" : "off"), I18n.txt((String) data[0])));
            else
                addMessage(I18n.txt("notif.visibility.toggle", I18n.txt((String) data[0])));
            break;
        case FOCUS_LOCK_CMD:
        case ORIENTATION_LOCK_CMD:
        case TOGGLE_AMBIENT_LIGHT:
        case OCTREE_PARTICLE_FADE_CMD:
            addMessage(data[0] + (((Boolean) data[1]) ? " on" : " off"));
            break;
        case CAMERA_MODE_CMD:
            CameraMode cm = (CameraMode) data[0];
            if (cm != CameraMode.FOCUS_MODE)
                addMessage(I18n.txt("notif.cameramode.change", data[0]));
            break;
        case TIME_WARP_CHANGED_INFO:
            addMessage(I18n.txt("notif.timepace.change", data[0]));
            break;
        case FOV_CHANGE_NOTIFICATION:
            // addMessage("Field of view changed to " + (float) data[0]);
            break;
        case JAVA_EXCEPTION:
            Throwable t = (Throwable) data[0];
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            t.printStackTrace(pw);
            String stackTrace = sw.toString();
            if (data.length == 1) {
                if (I18n.bundle != null)
                    addMessage(I18n.txt("notif.error", stackTrace));
                else
                    addMessage("Error: " + stackTrace);
            } else {
                if (I18n.bundle != null)
                    addMessage(I18n.txt("notif.error", data[1] + TAG_SEPARATOR + stackTrace));
                else
                    addMessage("Error: " + data[1] + TAG_SEPARATOR + stackTrace);
            }
            break;
        case ORBIT_DATA_LOADED:
            addMessage(I18n.txt("notif.orbitdata.loaded", data[1], ((PointCloudData) data[0]).getNumPoints()), LoggerLevel.DEBUG);
            break;
        case SCREENSHOT_INFO:
            addMessage(I18n.txt("notif.screenshot", data[0]));
            break;
        case STEREOSCOPIC_CMD:
            addMessage(I18n.txt("notif.toggle", I18n.txt("notif.stereoscopic")));
            break;
        case DISPLAY_GUI_CMD:
            boolean displayGui = (Boolean) data[0];
            addMessage(I18n.txt("notif." + (!displayGui ? "activated" : "deactivated"), data[1]));
            break;
        case STEREO_PROFILE_CMD:
            addMessage(I18n.txt("notif.stereoscopic.profile", Settings.StereoProfile.values()[(Integer) data[0]].toString()));
            break;
        case FRAME_OUTPUT_CMD:
            boolean activated = (Boolean) data[0];
            if (activated) {
                addMessage(I18n.txt("notif.activated", I18n.txt("element.frameoutput")));
            } else {
                addMessage(I18n.txt("notif.deactivated", I18n.txt("element.frameoutput")));
            }
            break;
        default:
            break;
    }
}
Also used : PointCloudData(gaiasky.data.util.PointCloudData) CameraMode(gaiasky.scenegraph.camera.CameraManager.CameraMode) LoggerLevel(gaiasky.util.Logger.LoggerLevel) IFocus(gaiasky.scenegraph.IFocus) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 13 with IFocus

use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.

the class NaturalMouseKbdListener method touchUp.

@Override
public boolean touchUp(final int screenX, final int screenY, final int pointer, final int button) {
    EventManager.publish(Event.INPUT_EVENT, this, button);
    if (Settings.settings.runtime.inputEnabled) {
        touched &= ~(1 << pointer);
        multiTouch = !MathUtils.isPowerOfTwo(touched);
        if (button == this.button && button == leftMouseButton) {
            final long currentTime = TimeUtils.millis();
            final long lastLeftTime = lastClickTime;
            GaiaSky.postRunnable(() -> {
                // 5% of width pixels distance
                if (!Settings.settings.scene.camera.cinematic || gesture.dst(screenX, screenY) < MOVE_PX_DIST) {
                    boolean stopped = camera.stopMovement();
                    boolean focusRemoved = GaiaSky.instance.mainGui != null && GaiaSky.instance.mainGui.cancelTouchFocus();
                    boolean doubleClick = currentTime - lastLeftTime < doubleClickTime;
                    gesture.set(0, 0);
                    if (doubleClick && !stopped && !focusRemoved) {
                        // Select star, if any
                        IFocus hit = getBestHit(screenX, screenY);
                        if (hit != null) {
                            EventManager.publish(Event.FOCUS_CHANGE_CMD, this, hit);
                            EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE);
                        }
                    }
                }
            });
            dragDx = 0;
            dragDy = 0;
            lastClickTime = currentTime;
        } else if (button == this.button && button == rightMouseButton) {
            if (keyframeBeingDragged) {
                keyframeBeingDragged = false;
            } else if (gesture.dst(screenX, screenY) < MOVE_PX_DIST && getKeyframesPathObject() != null && getKeyframesPathObject().isSelected() && !anyPressed(Keys.CONTROL_LEFT, Keys.SHIFT_LEFT, Keys.ALT_LEFT)) {
                EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FREE_MODE);
                Objects.requireNonNull(getKeyframesPathObject()).unselect();
            } else {
                // Ensure Octants observed property is computed
                GaiaSky.postRunnable(() -> {
                    // 5% of width pixels distance
                    if (gesture.dst(screenX, screenY) < MOVE_PX_DIST && !Settings.settings.program.modeStereo.active) {
                        // Stop
                        camera.setYaw(0);
                        camera.setPitch(0);
                        // Right click, context menu
                        IFocus hit = getBestHit(screenX, screenY);
                        EventManager.publish(Event.POPUP_MENU_FOCUS, this, hit, screenX, screenY);
                    }
                });
                camera.setHorizontal(0);
                camera.setVertical(0);
            }
        }
        // Remove keyboard focus from GUI elements
        EventManager.instance.notify(Event.REMOVE_KEYBOARD_FOCUS, this);
        this.button = -1;
    }
    camera.setInputByController(false);
    return super.touchUp(screenX, screenY, pointer, button);
}
Also used : IFocus(gaiasky.scenegraph.IFocus)

Example 14 with IFocus

use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.

the class NaturalMouseKbdListener method touchDown.

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    if (Settings.settings.runtime.inputEnabled) {
        touched |= (1 << pointer);
        multiTouch = !MathUtils.isPowerOfTwo(touched);
        if (multiTouch)
            this.button = -1;
        else if (this.button < 0) {
            startX = screenX;
            startY = screenY;
            gesture.set(startX, startY);
            this.button = button;
        }
        if (button == Buttons.RIGHT) {
            // Select keyframes
            if (!(anyPressed(Keys.ALT_LEFT, Keys.SHIFT_LEFT, Keys.CONTROL_LEFT) && getKeyframesPathObject() != null && getKeyframesPathObject().isSelected())) {
                IFocus hit;
                keyframeBeingDragged = ((hit = getKeyframeCollision(screenX, screenY)) != null);
                if (keyframeBeingDragged) {
                    // FOCUS_MODE, do not center
                    EventManager.publish(Event.FOCUS_CHANGE_CMD, this, hit, false);
                    EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE, false);
                }
            }
        }
    }
    camera.setInputByController(false);
    return super.touchDown(screenX, screenY, pointer, button);
}
Also used : IFocus(gaiasky.scenegraph.IFocus)

Example 15 with IFocus

use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.

the class OpenVRListener method getHits.

private Array<IFocus> getHits(Vector3d p0, Vector3d p1) {
    Array<IFocus> l = GaiaSky.instance.getFocusableEntities();
    Array<IFocus> hits = new Array<>();
    Iterator<IFocus> it = l.iterator();
    // Add all hits
    while (it.hasNext()) {
        IFocus s = it.next();
        s.addHit(p0, p1, cam, hits);
    }
    return hits;
}
Also used : Array(com.badlogic.gdx.utils.Array) IFocus(gaiasky.scenegraph.IFocus)

Aggregations

IFocus (gaiasky.scenegraph.IFocus)16 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)6 Array (com.badlogic.gdx.utils.Array)3 CameraMode (gaiasky.scenegraph.camera.CameraManager.CameraMode)3 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)2 PointCloudData (gaiasky.data.util.PointCloudData)2 ParticleGroup (gaiasky.scenegraph.ParticleGroup)2 NaturalCamera (gaiasky.scenegraph.camera.NaturalCamera)2 LoggerLevel (gaiasky.util.Logger.LoggerLevel)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 com.badlogic.gdx.scenes.scene2d.ui (com.badlogic.gdx.scenes.scene2d.ui)1 StringBuilder (com.badlogic.gdx.utils.StringBuilder)1 BookmarkNode (gaiasky.interafce.BookmarksManager.BookmarkNode)1 NewBookmarkFolderDialog (gaiasky.interafce.NewBookmarkFolderDialog)1 Invisible (gaiasky.scenegraph.Invisible)1 StubModel (gaiasky.scenegraph.StubModel)1 CatalogInfo (gaiasky.util.CatalogInfo)1