use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class HelloCollision method simpleInitApp.
public void simpleInitApp() {
/** Set up Physics */
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
//bulletAppState.getPhysicsSpace().enableDebug(assetManager);
// We re-use the flyby camera for rotation, while positioning is handled by physics
viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
flyCam.setMoveSpeed(100);
setUpKeys();
setUpLight();
// We load the scene from the zip file and adjust its size.
assetManager.registerLocator("town.zip", ZipLocator.class);
sceneModel = assetManager.loadModel("main.scene");
sceneModel.setLocalScale(2f);
// We set up collision detection for the scene by creating a
// compound collision shape and a static RigidBodyControl with mass zero.
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);
landscape = new RigidBodyControl(sceneShape, 0);
sceneModel.addControl(landscape);
// We set up collision detection for the player by creating
// a capsule collision shape and a CharacterControl.
// The CharacterControl offers extra settings for
// size, stepheight, jumping, falling, and gravity.
// We also put the player in its starting position.
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(0, 10, 0));
// We attach the scene and the player to the rootnode and the physics space,
// to make them appear in the game world.
rootNode.attachChild(sceneModel);
bulletAppState.getPhysicsSpace().add(landscape);
bulletAppState.getPhysicsSpace().add(player);
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class TestChaseCamera method simpleInitApp.
public void simpleInitApp() {
// Load a teapot model
teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
teaGeom.setMaterial(mat_tea);
rootNode.attachChild(teaGeom);
// Load a floor model
Material mat_ground = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Geometry ground = new Geometry("ground", new Quad(50, 50));
ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
ground.setLocalTranslation(-25, -1, 25);
ground.setMaterial(mat_ground);
rootNode.attachChild(ground);
// Disable the default first-person cam!
flyCam.setEnabled(false);
// Enable a chase cam
chaseCam = new ChaseCamera(cam, teaGeom, inputManager);
//Uncomment this to invert the camera's vertical rotation Axis
//chaseCam.setInvertVerticalAxis(true);
//Uncomment this to invert the camera's horizontal rotation Axis
//chaseCam.setInvertHorizontalAxis(true);
//Comment this to disable smooth camera motion
chaseCam.setSmoothMotion(true);
//Uncomment this to disable trailing of the camera
//WARNING, trailing only works with smooth motion enabled. It is true by default.
//chaseCam.setTrailingEnabled(false);
//Uncomment this to look 3 world units above the target
//chaseCam.setLookAtOffset(Vector3f.UNIT_Y.mult(3));
//Uncomment this to enable rotation when the middle mouse button is pressed (like Blender)
//WARNING : setting this trigger disable the rotation on right and left mouse button click
//chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
//Uncomment this to set mutiple triggers to enable rotation of the cam
//Here spade bar and middle mouse button
//chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE));
//registering inputs for target's movement
registerInput();
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class OSVR method getHMDMatrixProjectionLeftEye.
@Override
public Matrix4f getHMDMatrixProjectionLeftEye(Camera cam) {
if (eyeLeftInfo == null)
return cam.getProjectionMatrix();
if (eyeMatrix[EYE_LEFT] == null) {
FloatBuffer tfb = FloatBuffer.allocate(16);
com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.osvrClientGetViewerEyeSurfaceProjectionMatrixf(displayConfig, 0, (byte) EYE_LEFT, 0, cam.getFrustumNear(), cam.getFrustumFar(), (short) 0, tfb);
eyeMatrix[EYE_LEFT] = new Matrix4f();
eyeMatrix[EYE_LEFT].set(tfb.get(0), tfb.get(4), tfb.get(8), tfb.get(12), tfb.get(1), tfb.get(5), tfb.get(9), tfb.get(13), tfb.get(2), tfb.get(6), tfb.get(10), tfb.get(14), tfb.get(3), tfb.get(7), tfb.get(11), tfb.get(15));
}
return eyeMatrix[EYE_LEFT];
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class OSVRInput method getFinalObserverPosition.
@Override
public Vector3f getFinalObserverPosition(int index) {
VRViewManagerOSVR vrvm = (VRViewManagerOSVR) environment.getVRViewManager();
if (vrvm == null || isInputDeviceTracking(index) == false)
return null;
Object obs = environment.getObserver();
Vector3f pos = getPosition(index);
if (obs instanceof Camera) {
((Camera) obs).getRotation().mult(pos, pos);
return pos.addLocal(((Camera) obs).getLocation());
} else {
((Spatial) obs).getWorldRotation().mult(pos, pos);
return pos.addLocal(((Spatial) obs).getWorldTranslation());
}
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class OpenVRInput method getFinalObserverPosition.
@Override
public Vector3f getFinalObserverPosition(int index) {
if (environment != null) {
VRViewManagerOpenVR vrvm = (VRViewManagerOpenVR) environment.getVRViewManager();
if (vrvm != null) {
if (isInputDeviceTracking(index) == false) {
return null;
}
Object obs = environment.getObserver();
Vector3f pos = getPosition(index);
if (obs instanceof Camera) {
((Camera) obs).getRotation().mult(pos, pos);
return pos.addLocal(((Camera) obs).getLocation());
} else {
((Spatial) obs).getWorldRotation().mult(pos, pos);
return pos.addLocal(((Spatial) obs).getWorldTranslation());
}
} else {
throw new IllegalStateException("VR environment has no valid view manager.");
}
} else {
throw new IllegalStateException("VR input is not attached to a VR environment.");
}
}
Aggregations