@Override public String toString() { return "Camera[location=" + location + "\n, direction=" + getDirection() + "\n" + "res=" + width + "x" + height + ", parallel=" + parallelProjection + "\n" + "near=" + frustumNear + ", far=" + frustumFar + "]"; }
@Override public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("rup") && isPressed) { roughness = FastMath.clamp(roughness + 0.1f, 0.0f, 1.0f); m.setFloat("Roughness", roughness); } if (name.equals("rdown") && isPressed) { roughness = FastMath.clamp(roughness - 0.1f, 0.0f, 1.0f); m.setFloat("Roughness", roughness); } if (name.equals("light") && isPressed) { dl.setDirection(cam.getDirection().normalize()); } } }, "light", "rup", "rdown");
@Override public void simpleUpdate(float tpf) { super.simpleUpdate(tpf); sl.setDirection(cam.getDirection()); sl.setPosition(cam.getLocation()); }
@Override public void simpleUpdate(float tpf) { float rayLength = 50f; Vector3f start = cam.getLocation(); Vector3f end = cam.getDirection().scaleAdd(rayLength, start); List<PhysicsRayTestResult> rayTest = bulletAppState.getPhysicsSpace().rayTest(start, end); if (rayTest.size() > 0) { PhysicsRayTestResult get = rayTest.get(0); PhysicsCollisionObject collisionObject = get.getCollisionObject(); // Display the name of the 1st object in place of FPS. fpsText.setText(collisionObject.getUserObject().toString()); } else { // Provide prompt feedback that no collision object was hit. fpsText.setText("MISSING"); } }
public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(cam.getLocation()); SphereCollisionShape bulletCollisionShape = new SphereCollisionShape(0.4f); RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1); // RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1); bulletNode.setLinearVelocity(cam.getDirection().mult(25)); bulletg.addControl(bulletNode); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletNode); } if (name.equals("gc") && !keyPressed) { System.gc(); } } };
public float distanceToCam(Geometry spat){ if (spat == null) return Float.NEGATIVE_INFINITY; if (spat.queueDistance != Float.NEGATIVE_INFINITY) return spat.queueDistance; Vector3f camPosition = cam.getLocation(); Vector3f viewVector = cam.getDirection(tempVec2); Vector3f spatPosition = null; if (spat.getWorldBound() != null){ spatPosition = spat.getWorldBound().getCenter(); }else{ spatPosition = spat.getWorldTranslation(); } spatPosition.subtract(camPosition, tempVec); spat.queueDistance = tempVec.dot(viewVector); return spat.queueDistance; }
public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(cam.getLocation()); RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1); // RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1); bulletNode.setLinearVelocity(cam.getDirection().mult(25)); bulletg.addControl(bulletNode); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletNode); } } };
public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(cam.getLocation()); RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1); // RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1); bulletNode.setLinearVelocity(cam.getDirection().mult(25)); bulletg.addControl(bulletNode); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletNode); } } };
public void setCamera(Camera cam, Matrix4f viewMatrix, Matrix4f projMatrix, Matrix4f viewProjMatrix) { this.viewMatrix.set(viewMatrix); this.projMatrix.set(projMatrix); this.viewProjMatrix.set(viewProjMatrix); camLoc.set(cam.getLocation()); cam.getLeft(camLeft); cam.getUp(camUp); cam.getDirection(camDir); near = cam.getFrustumNear(); far = cam.getFrustumFar(); }
private void bulletControl() { shootingChannel.setAnim("Dodge", 0.1f); shootingChannel.setLoopMode(LoopMode.DontLoop); Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(matBullet); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(character.getPhysicsLocation().add(cam.getDirection().mult(5))); RigidBodyControl bulletControl = new BombControl(bulletCollisionShape, 1); bulletControl.setCcdMotionThreshold(0.1f); bulletControl.setLinearVelocity(cam.getDirection().mult(80)); bulletg.addControl(bulletControl); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletControl); }
/** * Translate the camera left or forward by the specified amount. * * @param value translation amount * @param sideways true→left, false→forward */ protected void moveCamera(float value, boolean sideways){ Vector3f vel = new Vector3f(); Vector3f pos = cam.getLocation().clone(); if (sideways){ cam.getLeft(vel); }else{ cam.getDirection(vel); } vel.multLocal(value * moveSpeed); if (motionAllowed != null) motionAllowed.checkMotionAllowed(pos, vel); else pos.addLocal(vel); cam.setLocation(pos); }
@Override public void simpleUpdate(float tpf) { if (!done) { done = true; batch.attachChild(cube2); batch.batch(); } updateBoindPoints(points); frustum.update(points); time += tpf; dl.setDirection(cam.getDirection()); cube2.setLocalTranslation(FastMath.sin(-time) * 3, FastMath.cos(time) * 3, 0); cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); cube2.setLocalScale(Math.max(FastMath.sin(time), 0.5f)); // batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); } //
/** This method creates one individual physical cannon ball. * By defaul, the ball is accelerated and flies * from the camera position in the camera direction.*/ public void makeCannonBall() { /** Create a cannon ball geometry and attach to scene graph. */ Geometry ball_geo = new Geometry("cannon ball", sphere); ball_geo.setMaterial(stone_mat); rootNode.attachChild(ball_geo); /** Position the cannon ball */ ball_geo.setLocalTranslation(cam.getLocation()); /** Make the ball physical with a mass > 0.0f */ ball_phy = new RigidBodyControl(1f); /** Add physical ball to physics space. */ ball_geo.addControl(ball_phy); bulletAppState.getPhysicsSpace().add(ball_phy); /** Accelerate the physical ball to shoot it. */ ball_phy.setLinearVelocity(cam.getDirection().mult(25)); }
public void onAction(String binding, boolean value, float tpf) { if (binding.equals("shoot") && !value) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat); bulletg.setName("bullet"); bulletg.setLocalTranslation(cam.getLocation()); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1)); bulletg.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f); bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40)); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletg); } else if (binding.equals("shoot2") && !value) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setName("bullet"); bulletg.setLocalTranslation(cam.getLocation()); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1)); bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40)); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletg); } } }
@Override public void simpleUpdate(float tpf) { Vector3f camDir = cam.getDirection().clone().multLocal(0.6f); Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f); walkDirection.set(0,0,0); if(left) walkDirection.addLocal(camLeft); if(right) walkDirection.addLocal(camLeft.negate()); if(up) walkDirection.addLocal(camDir); if(down) walkDirection.addLocal(camDir.negate()); player.setWalkDirection(walkDirection); cam.setLocation(player.getPhysicsLocation()); }
@Override public void simpleUpdate(final float tpf) { Vector3f camDir = this.cam.getDirection().clone().multLocal(0.6f); Vector3f camLeft = this.cam.getLeft().clone().multLocal(0.4f); this.walkDirection.set(0, 0, 0); if (this.left) { this.walkDirection.addLocal(camLeft); } if (this.right) { this.walkDirection.addLocal(camLeft.negate()); } if (this.up) { this.walkDirection.addLocal(camDir); } if (this.down) { this.walkDirection.addLocal(camDir.negate()); } if (usePhysics) { this.player3.setWalkDirection(this.walkDirection); this.cam.setLocation(this.player3.getPhysicsLocation()); } } }
@Override public void simpleUpdate(final float tpf) { Vector3f camDir = this.cam.getDirection().clone().multLocal(0.6f); Vector3f camLeft = this.cam.getLeft().clone().multLocal(0.4f); this.walkDirection.set(0, 0, 0); if (this.left) { this.walkDirection.addLocal(camLeft); } if (this.right) { this.walkDirection.addLocal(camLeft.negate()); } if (this.up) { this.walkDirection.addLocal(camDir); } if (this.down) { this.walkDirection.addLocal(camDir.negate()); } if (usePhysics) { this.player3.setWalkDirection(this.walkDirection); this.cam.setLocation(this.player3.getPhysicsLocation()); } } }
/** * Rotate the billboard so it points directly opposite the direction the * camera's facing * * @param camera * Camera */ private void rotateScreenAligned(Camera camera) { // coopt diff for our in direction: look.set(camera.getDirection()).negateLocal(); // coopt loc for our left direction: left.set(camera.getLeft()).negateLocal(); orient.fromAxes(left, camera.getUp(), look); Node parent = spatial.getParent(); Quaternion rot=new Quaternion().fromRotationMatrix(orient); if ( parent != null ) { rot = parent.getWorldRotation().inverse().multLocal(rot); rot.normalizeLocal(); } spatial.setLocalRotation(rot); fixRefreshFlags(); }
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 public void simpleInitApp() { makeTerrain(); flyCam.setMoveSpeed(50); sl = new SpotLight(); sl.setSpotRange(100); sl.setSpotOuterAngle(20 * FastMath.DEG_TO_RAD); sl.setSpotInnerAngle(15 * FastMath.DEG_TO_RAD); sl.setDirection(new Vector3f(-0.39820394f, -0.73094344f, 0.55421597f)); sl.setPosition(new Vector3f(-64.61567f, -87.615425f, -202.41328f)); rootNode.addLight(sl); AmbientLight ambLight = new AmbientLight(); ambLight.setColor(ColorRGBA.Black); rootNode.addLight(ambLight); cam.setLocation(new Vector3f(-41.219646f, 0.8363f, -171.67267f)); cam.setRotation(new Quaternion(-0.04562731f, 0.89917684f, -0.09668826f, -0.4243236f)); sl.setDirection(cam.getDirection()); sl.setPosition(cam.getLocation()); }