public boolean isRenderable() { return actualContext != null && actualContext.isRenderable(); }
if (context != null && context.isCreated()){ logger.warning("start() called when application already created!"); return; context.setSettings(settings); } else if (contextType == Type.OffscreenSurface){ context = new LwjglOffscreenBufferVR(); context.setSettings(settings); } else { logger.severe("Unsupported context type \""+contextType+"\". Supported are \"Display\" and \"OffscreenSurface\""); context.setSystemListener(this); context.create(waitFor);
/** * Internal use only. */ public void requestClose(boolean esc){ context.destroy(false); }
private void initDisplay(){ // aquire important objects // from the context settings = context.getSettings(); // Only reset the timer if a user has not already provided one if (timer == null) { timer = context.getTimer(); } renderer = context.getRenderer(); }
/** * Restarts the context, applying any changed settings. * <p> * Changes to the {@link AppSettings} of this Application are not * applied immediately; calling this method forces the context * to restart, applying the new settings. */ public void restart(){ context.setSettings(settings); context.restart(); }
public void create(boolean waitFor) { if (actualContext != null){ throw new IllegalStateException("Already created"); } actualContext = JmeSystem.newContext(settings, Type.OffscreenSurface); actualContext.setSystemListener(new AwtPanelsListener()); actualContext.create(waitFor); }
/** * Starts the application. * Creating a rendering context and executing * the main loop in a separate thread. */ public void start(JmeContext.Type contextType, boolean waitFor){ if (context != null && context.isCreated()){ logger.warning("start() called when application already created!"); return; } if (settings == null){ settings = new AppSettings(true); } logger.log(Level.FINE, "Starting application: {0}", getClass().getName()); context = JmeSystem.newContext(settings, contextType); context.setSystemListener(this); context.create(waitFor); }
/** * Initializes mouse and keyboard input. Also * initializes joystick input if joysticks are enabled in the * AppSettings. */ private void initInput(){ mouseInput = context.getMouseInput(); if (mouseInput != null) mouseInput.initialize(); keyInput = context.getKeyInput(); if (keyInput != null) keyInput.initialize(); touchInput = context.getTouchInput(); if (touchInput != null) touchInput.initialize(); if (!settings.getBoolean("DisableJoysticks")){ joyInput = context.getJoyInput(); if (joyInput != null) joyInput.initialize(); } inputManager = new InputManager(mouseInput, keyInput, joyInput, touchInput); }
/** * Get the ratio between the {@link #getCanvasSize() GUI canvas size} and the application main windows (if available) or the screen size. * @return the ratio between the {@link #getCanvasSize() GUI canvas size} and the application main windows (if available). * @see #getCanvasSize() */ public Vector2f getCanvasToWindowRatio() { if (environment != null){ if (environment.getApplication() != null){ if( ratio == null ) { ratio = new Vector2f(); Vector2f canvas = getCanvasSize(); int width = Integer.min(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth(), environment.getApplication().getContext().getSettings().getWidth()); int height = Integer.min(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight(), environment.getApplication().getContext().getSettings().getHeight()); ratio.x = Float.max(1f, canvas.x / width); ratio.y = Float.max(1f, canvas.y / height); } return ratio; } else { throw new IllegalStateException("VR GUI manager underlying environment is not attached to any application."); } } else { throw new IllegalStateException("VR GUI manager is not attached to any environment."); } }
/** * Initializes the application's canvas for use. * <p> * After calling this method, cast the {@link #getContext() context} to * {@link JmeCanvasContext}, * then acquire the canvas with {@link JmeCanvasContext#getCanvas() } * and attach it to an AWT/Swing Frame. * The rendering thread will start when the canvas becomes visible on * screen, however if you wish to start the context immediately you * may call {@link #startCanvas() } to force the rendering thread * to start. * * @see JmeCanvasContext * @see Type#Canvas */ public void createCanvas(){ if (context != null && context.isCreated()){ logger.warning("createCanvas() called when application already created!"); return; } if (settings == null){ settings = new AppSettings(true); } logger.log(Level.FINE, "Starting application: {0}", getClass().getName()); context = JmeSystem.newContext(settings, JmeContext.Type.Canvas); context.setSystemListener(this); }
public void setSettings(AppSettings settings) { this.settings.copyFrom(settings); this.settings.setRenderer(AppSettings.LWJGL_OPENGL2); if (actualContext != null){ actualContext.setSettings(settings); } }
public boolean isCreated() { return actualContext != null && actualContext.isCreated(); }
public Renderer getRenderer() { return actualContext.getRenderer(); }
public Timer getTimer() { return actualContext.getTimer(); }
@Override public void centerMouse() { if (environment != null){ if (environment.getApplication() != null){ // set mouse in center of the screen if newly added Vector2f size = environment.getVRGUIManager().getCanvasSize(); MouseInput mi = environment.getApplication().getContext().getMouseInput(); AppSettings as = environment.getApplication().getContext().getSettings(); if( mi instanceof GlfwMouseInputVR ) ((GlfwMouseInputVR)mi).setCursorPosition((int)(as.getWidth() / 2f), (int)(as.getHeight() / 2f)); if( environment.isInVR() ) { cursorPos.x = size.x / 2f; cursorPos.y = size.y / 2f; recentCenterCount = 2; } } else { throw new IllegalStateException("This VR environment is not attached to any application."); } } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
/** * Starts the rendering thread after createCanvas() has been called. * <p> * Calling this method is optional, the canvas will start automatically * when it becomes visible. * * @param waitFor If true, the current thread will block until the * rendering thread is running */ public void startCanvas(boolean waitFor){ context.create(waitFor); }
@Override public void gainFocus() { logger.fine("gainFocus"); if (view != null) { view.onResume(); } if (app != null) { //resume the audio AudioRenderer audioRenderer = app.getAudioRenderer(); if (audioRenderer != null) { audioRenderer.resumeAll(); } //resume the sensors (aka joysticks) if (app.getContext() != null) { JoyInput joyInput = app.getContext().getJoyInput(); if (joyInput != null) { if (joyInput instanceof AndroidSensorJoyInput) { AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; androidJoyInput.resumeSensors(); } } } } if (app != null) { app.gainFocus(); } }
private void initDisplay(){ // aquire important objects // from the context settings = context.getSettings(); // Only reset the timer if a user has not already provided one if (timer == null) { timer = context.getTimer(); } renderer = context.getRenderer(); }
/** * Starts the application. * Creating a rendering context and executing * the main loop in a separate thread. */ public void start(JmeContext.Type contextType){ if (context != null && context.isCreated()){ logger.warning("start() called when application already created!"); return; } if (settings == null){ settings = new AppSettings(true); } logger.log(Level.FINE, "Starting application: {0}", getClass().getName()); context = JmeSystem.newContext(settings, contextType); context.setSystemListener(this); context.create(false); }
/** * Initializes mouse and keyboard input. Also * initializes joystick input if joysticks are enabled in the * AppSettings. */ private void initInput(){ mouseInput = context.getMouseInput(); if (mouseInput != null) mouseInput.initialize(); keyInput = context.getKeyInput(); if (keyInput != null) keyInput.initialize(); touchInput = context.getTouchInput(); if (touchInput != null) touchInput.initialize(); if (!settings.getBoolean("DisableJoysticks")){ joyInput = context.getJoyInput(); if (joyInput != null) joyInput.initialize(); } inputManager = new InputManager(mouseInput, keyInput, joyInput, touchInput); }