/** * Get the scene observer. If no observer has been set, this method return the application {@link #getCamera() camera}. * @return the scene observer. * @see #setObserver(Spatial) */ public Object getObserver() { if( observer == null ) { if (application != null){ return application.getCamera(); } else { throw new IllegalStateException("VR environment is not attached to any application."); } } return observer; }
@Override protected void initialize(Application app) { this.camera = app.getCamera(); this.listener = app.getListener(); }
/** * used internally * * @param stateManager the state manager * @param app the application */ public void initialize(AppStateManager stateManager, Application app) { initEvent(app, this); for (CinematicEvent cinematicEvent : cinematicEvents) { cinematicEvent.initEvent(app, this); } if(!cameras.isEmpty()){ for(CameraNode n : cameras.values()){ n.setCamera(app.getCamera()); } } initialized = true; }
public void onAction(String name, boolean value, float tpf) { if (!value) { return; } if (name.equals(INPUT_MAPPING_CAMERA_POS)) { Camera cam = app.getCamera(); if (cam != null) { Vector3f loc = cam.getLocation(); Quaternion rot = cam.getRotation(); System.out.println("Camera Position: (" + loc.x + ", " + loc.y + ", " + loc.z + ")"); System.out.println("Camera Rotation: " + rot); System.out.println("Camera Direction: " + cam.getDirection()); System.out.println("cam.setLocation(new Vector3f(" + loc.x + "f, " + loc.y + "f, " + loc.z + "f));"); System.out.println("cam.setRotation(new Quaternion(" + rot.getX() + "f, " +rot.getY()+ "f, " + rot.getZ() + "f, " + rot.getW() + "f));"); } } else if (name.equals(INPUT_MAPPING_MEMORY)) { BufferUtils.printCurrentDirectMemory(null); } } }
public Camera getDummyCamera(){ if (dummyCam == null){ if (application != null){ if (application.getCamera() != null){ dummyCam = application.getCamera().clone(); } else { if ((settings != null) && (settings.getWidth() != 0) && (settings.getHeight() != 0)){ dummyCam = new Camera(settings.getWidth(), settings.getHeight()); } else { dummyCam = new Camera(); } } } else { throw new IllegalStateException("VR environment is not attached to any application."); } } return dummyCam; }
@Override public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); this.inputManager = app.getInputManager(); target = new Node("ChaseCamTarget"); camNode.setCamera(app.getCamera()); camNode.setControlDir(CameraControl.ControlDirection.SpatialToCamera); target.attachChild(camNode); camNode.setLocalTranslation(0, 0, distance); upVector = app.getCamera().getUp().clone(); leftVector = app.getCamera().getLeft().clone(); registerWithInput(); rotateCamera(); }
@Override public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); this.app = app; if (app.getInputManager() != null) { if (flyCam == null) { flyCam = new FlyByCamera(app.getCamera()); } flyCam.registerWithInput(app.getInputManager()); } }
/** * Get the {@link Camera camera} used for rendering. * If the VR mode is {@link #isInVR() active}, this method return a dummy camera, otherwise, * this method return the camera of the attached application. * @return the camera attached used for rendering. */ public Camera getCamera() { if( isInVR() && getVRViewManager() != null && getVRViewManager().getLeftCamera() != null ) { return getDummyCamera(); } return application.getCamera(); }
CollisionResults results = new CollisionResults(); Vector3f click3d = app.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f, tmp); Vector3f dir = app.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f, tmp2).subtractLocal(click3d); Ray ray = new Ray(click3d, dir); debugNode.collideWith(ray, results);
public ArmatureDebugger addArmatureFrom(Armature armature, Spatial forSpatial) { ArmatureDebugger ad = armatures.get(armature); if(ad != null){ return ad; } JointInfoVisitor visitor = new JointInfoVisitor(armature); forSpatial.depthFirstTraversal(visitor); ad = new ArmatureDebugger(forSpatial.getName() + "_Armature", armature, visitor.deformingJoints); ad.setLocalTransform(forSpatial.getWorldTransform()); if (forSpatial instanceof Node) { List<Geometry> geoms = new ArrayList<>(); findGeoms((Node) forSpatial, geoms); if (geoms.size() == 1) { ad.setLocalTransform(geoms.get(0).getWorldTransform()); } } armatures.put(armature, ad); debugNode.attachChild(ad); if (isInitialized()) { ad.initialize(app.getAssetManager(), app.getCamera()); } return ad; }
@Override protected void onEnable() { // Set the number of visible frames to the current width of the screen setFrameCount(getApplication().getCamera().getWidth()); getApplication().setAppProfiler(profiler); Node gui = ((SimpleApplication)getApplication()).getGuiNode(); gui.attachChild(graph); gui.attachChild(background); }
/** * Initialize this state prior to its 1st update. Should be invoked only by * a subclass or by the AppStateManager. * * @param stateManager the manager for this state (not null) * @param app the application which owns this state (not null) */ @Override public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); this.app = app; this.rm = app.getRenderManager(); this.assetManager = app.getAssetManager(); setupMaterials(app); physicsDebugRootNode.setCullHint(Spatial.CullHint.Never); viewPort = rm.createMainView("Physics Debug Overlay", app.getCamera()); viewPort.setClearFlags(false, true, false); viewPort.attachScene(physicsDebugRootNode); }
/** * Initialize this state prior to its 1st update. Should be invoked only by * a subclass or by the AppStateManager. * * @param stateManager the manager for this state (not null) * @param app the application which owns this state (not null) */ @Override public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); this.app = app; this.rm = app.getRenderManager(); this.assetManager = app.getAssetManager(); setupMaterials(app); physicsDebugRootNode.setCullHint(Spatial.CullHint.Never); viewPort = rm.createMainView("Physics Debug Overlay", app.getCamera()); viewPort.setClearFlags(false, true, false); viewPort.attachScene(physicsDebugRootNode); }
public void onAction(String name, boolean keyPressed, float tpf) { Sphere bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); key2.setGenerateMips(true); Texture tex2 = app.getAssetManager().loadTexture(key2); mat2.setTexture("ColorMap", tex2); if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(app.getCamera().getLocation()); RigidBodyControl bulletControl = new RigidBodyControl(10); bulletg.addControl(bulletControl); bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25)); bulletg.addControl(bulletControl); rootNode.attachChild(bulletg); space.add(bulletControl); } } };
@Override protected void initialize(Application app) { vp = app.getRenderManager().createMainView("debug", app.getCamera()); vp.attachScene(debugNode); vp.setClearDepth(true); this.app = app; for (ArmatureDebugger armatureDebugger : armatures.values()) { armatureDebugger.initialize(app.getAssetManager(), app.getCamera()); } app.getInputManager().addListener(actionListener, "shoot", "toggleJoints"); app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT), new MouseButtonTrigger(MouseInput.BUTTON_RIGHT)); app.getInputManager().addMapping("toggleJoints", new KeyTrigger(KeyInput.KEY_F10)); debugNode.addLight(new DirectionalLight(new Vector3f(-1f, -1f, -1f).normalizeLocal())); debugNode.addLight(new DirectionalLight(new Vector3f(1f, 1f, 1f).normalizeLocal(), new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f))); vp.setEnabled(false); }
mat.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha); Geometry darkenStats = new Geometry("StatsDarken", new Quad(PANEL_WIDTH, app.getCamera().getHeight())); darkenStats.setMaterial(mat); darkenStats.setLocalTranslation(0, -app.getCamera().getHeight(), -1); ui.setLocalTranslation(app.getCamera().getWidth() - PANEL_WIDTH, app.getCamera().getHeight(), 0); font = app.getAssetManager().loadFont("Interface/Fonts/Console.fnt"); bigFont = app.getAssetManager().loadFont("Interface/Fonts/Default.fnt");
finalizeCamera(Vector3f.ZERO, objPos, environment.getApplication().getCamera());
@Override protected void initialize(Application app) { this.camera = app.getCamera(); this.listener = app.getListener(); }
@Override public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); this.app = app; this.rm = app.getRenderManager(); this.assetManager = app.getAssetManager(); setupMaterials(app); physicsDebugRootNode.setCullHint(Spatial.CullHint.Never); viewPort = rm.createMainView("Physics Debug Overlay", app.getCamera()); viewPort.setClearFlags(false, true, false); viewPort.attachScene(physicsDebugRootNode); }