use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class TestConeVSFrustum method simpleInitApp.
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
frustumCam = cam.clone();
frustumCam.setFrustumFar(25);
Vector3f[] points = new Vector3f[8];
for (int i = 0; i < 8; i++) {
points[i] = new Vector3f();
}
ShadowUtil.updateFrustumPoints2(frustumCam, points);
WireFrustum frustumShape = new WireFrustum(points);
Geometry frustum = new Geometry("frustum", frustumShape);
frustum.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
rootNode.attachChild(frustum);
rootNode.addLight(new DirectionalLight());
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.2f));
rootNode.addLight(al);
Grid grid = new Grid(50, 50, 5);
Geometry gridGeom = new Geometry("grid", grid);
gridGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
gridGeom.getMaterial().setColor("Color", ColorRGBA.Gray);
rootNode.attachChild(gridGeom);
gridGeom.setLocalTranslation(-125, -25, -125);
// flyCam.setMoveSpeed(30);
// flyCam.setDragToRotate(true);
// cam.setLocation(new Vector3f(56.182674f, 19.037334f, 7.093905f));
// cam.setRotation(new Quaternion(0.0816657f, -0.82228005f, 0.12213967f, 0.5497892f));
spotLight = new SpotLight();
spotLight.setSpotRange(25);
spotLight.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
float radius = FastMath.tan(spotLight.getSpotOuterAngle()) * spotLight.getSpotRange();
Cylinder cylinder = new Cylinder(5, 16, 0, radius, spotLight.getSpotRange(), true, false);
geom = new Geometry("light", cylinder);
geom.setMaterial(new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"));
geom.getMaterial().setColor("Diffuse", ColorRGBA.White);
geom.getMaterial().setColor("Ambient", ColorRGBA.DarkGray);
geom.getMaterial().setBoolean("UseMaterialColors", true);
final LightNode ln = new LightNode("lb", spotLight);
ln.attachChild(geom);
geom.setLocalTranslation(0, -spotLight.getSpotRange() / 2f, 0);
geom.rotate(-FastMath.HALF_PI, 0, 0);
rootNode.attachChild(ln);
// ln.rotate(FastMath.QUARTER_PI, 0, 0);
// ln.setLocalTranslation(0, 0, -16);
inputManager.addMapping("click", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addMapping("shift", new KeyTrigger(KeyInput.KEY_LSHIFT), new KeyTrigger(KeyInput.KEY_RSHIFT));
inputManager.addMapping("middleClick", new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
inputManager.addMapping("up", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
inputManager.addMapping("down", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
inputManager.addMapping("left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
inputManager.addMapping("right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
final Node camTarget = new Node("CamTarget");
rootNode.attachChild(camTarget);
ChaseCameraAppState chaser = new ChaseCameraAppState();
chaser.setTarget(camTarget);
chaser.setMaxDistance(150);
chaser.setDefaultDistance(70);
chaser.setDefaultHorizontalRotation(FastMath.HALF_PI);
chaser.setMinVerticalRotation(-FastMath.PI);
chaser.setMaxVerticalRotation(FastMath.PI * 2);
chaser.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
stateManager.attach(chaser);
flyCam.setEnabled(false);
inputManager.addListener(new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
Spatial s = null;
float mult = 1;
if (moving) {
s = ln;
}
if (panning) {
s = camTarget;
mult = -1;
}
if ((moving || panning) && s != null) {
if (shift) {
if (name.equals("left")) {
tmp.set(cam.getDirection());
s.rotate(tmpQuat.fromAngleAxis(value, tmp));
}
if (name.equals("right")) {
tmp.set(cam.getDirection());
s.rotate(tmpQuat.fromAngleAxis(-value, tmp));
}
} else {
value *= MOVE_SPEED * mult;
if (name.equals("up")) {
tmp.set(cam.getUp()).multLocal(value);
s.move(tmp);
}
if (name.equals("down")) {
tmp.set(cam.getUp()).multLocal(-value);
s.move(tmp);
}
if (name.equals("left")) {
tmp.set(cam.getLeft()).multLocal(value);
s.move(tmp);
}
if (name.equals("right")) {
tmp.set(cam.getLeft()).multLocal(-value);
s.move(tmp);
}
}
}
}
}, "up", "down", "left", "right");
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("click")) {
if (isPressed) {
moving = true;
} else {
moving = false;
}
}
if (name.equals("middleClick")) {
if (isPressed) {
panning = true;
} else {
panning = false;
}
}
if (name.equals("shift")) {
if (isPressed) {
shift = true;
} else {
shift = false;
}
}
}
}, "click", "middleClick", "shift");
/**
* An unshaded textured cube. // * Uses texture from jme3-test-data
* library!
*/
Box boxMesh = new Box(1f, 1f, 1f);
boxGeo = new Geometry("A Textured Box", boxMesh);
Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture monkeyTex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
boxMat.setTexture("ColorMap", monkeyTex);
boxGeo.setMaterial(boxMat);
// rootNode.attachChild(boxGeo);
//
//boxGeo2 = boxGeo.clone();
//rootNode.attachChild(boxGeo2);
System.err.println("light " + spotLight.getPosition());
}
use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class TestShadowsPerf method simpleInitApp.
@Override
public void simpleInitApp() {
Logger.getLogger("com.jme3").setLevel(Level.SEVERE);
flyCam.setMoveSpeed(50);
flyCam.setEnabled(false);
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
cam.setLocation(new Vector3f(-53.952988f, 27.15874f, -32.875023f));
cam.setRotation(new Quaternion(0.1564309f, 0.6910534f, -0.15713608f, 0.6879555f));
// cam.setLocation(new Vector3f(53.64627f, 130.56f, -11.247704f));
// cam.setRotation(new Quaternion(-6.5737107E-4f, 0.76819664f, -0.64021313f, -7.886125E-4f));
////
cam.setFrustumFar(500);
mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
Box b = new Box(800, 1, 700);
b.scaleTextureCoordinates(new Vector2f(50, 50));
Geometry ground = new Geometry("ground", b);
ground.setMaterial(mat);
rootNode.attachChild(ground);
ground.setShadowMode(ShadowMode.Receive);
Sphere sphMesh = new Sphere(32, 32, 1);
sphMesh.setTextureMode(Sphere.TextureMode.Projected);
sphMesh.updateGeometry(32, 32, 1, false, false);
TangentBinormalGenerator.generate(sphMesh);
sphere = new Geometry("Rock Ball", sphMesh);
sphere.setLocalTranslation(0, 5, 0);
sphere.setMaterial(mat);
sphere.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(sphere);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
dl.setColor(ColorRGBA.White);
rootNode.addLight(dl);
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.7f));
rootNode.addLight(al);
//rootNode.setShadowMode(ShadowMode.CastAndReceive);
createballs();
final DirectionalLightShadowRenderer pssmRenderer = new DirectionalLightShadowRenderer(assetManager, 1024, 4);
viewPort.addProcessor(pssmRenderer);
//
// final PssmShadowFilter pssmRenderer = new PssmShadowFilter(assetManager, 1024, 4);
// FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
// fpp.addFilter(pssmRenderer);
// viewPort.addProcessor(fpp);
pssmRenderer.setLight(dl);
pssmRenderer.setLambda(0.55f);
pssmRenderer.setShadowIntensity(0.55f);
pssmRenderer.setShadowCompareMode(com.jme3.shadow.CompareMode.Software);
pssmRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
//pssmRenderer.displayDebug();
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("display") && isPressed) {
//pssmRenderer.debugFrustrums();
System.out.println("tetetetet");
}
if (name.equals("add") && isPressed) {
createballs();
}
}
}, "display", "add");
inputManager.addMapping("display", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("add", new KeyTrigger(KeyInput.KEY_RETURN));
}
use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class TestMatParamOverride method simpleInitApp.
@Override
public void simpleInitApp() {
inputManager.setCursorVisible(true);
createBox(-3, ColorRGBA.Red);
createBox(0, ColorRGBA.Green);
createBox(3, ColorRGBA.Blue);
inputManager.addMapping("override", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("override") && isPressed) {
if (!rootNode.getLocalMatParamOverrides().isEmpty()) {
rootNode.clearMatParamOverrides();
} else {
rootNode.addMatParamOverride(override);
}
System.out.println(rootNode.getLocalMatParamOverrides());
}
}
}, "override");
}
use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class HelloPicking method initKeys.
/** Declaring the "Shoot" action and mapping to its triggers. */
private void initKeys() {
inputManager.addMapping("Shoot", // trigger 1: spacebar
new KeyTrigger(KeyInput.KEY_SPACE), // trigger 2: left-button click
new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, "Shoot");
}
use of com.jme3.input.controls.ActionListener in project jmonkeyengine by jMonkeyEngine.
the class TestTangentSpace method simpleInitApp.
@Override
public void simpleInitApp() {
renderManager.setSinglePassLightBatchSize(2);
renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
initView();
Spatial s = assetManager.loadModel("Models/Test/BasicCubeLow.obj");
rootNode.attachChild(s);
Material m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
m.setTexture("NormalMap", assetManager.loadTexture("Models/Test/Normal_pixel.png"));
Geometry g = (Geometry) s;
Geometry g2 = (Geometry) g.deepClone();
g2.move(5, 0, 0);
g.getParent().attachChild(g2);
g.setMaterial(m);
g2.setMaterial(m);
//Regular tangent generation (left geom)
TangentBinormalGenerator.generate(g2.getMesh(), true);
//MikkTSPace Tangent generation (right geom)
MikktspaceTangentGenerator.generate(g);
createDebugTangents(g2);
createDebugTangents(g);
inputManager.addListener(new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("toggleDebug") && isPressed) {
if (debugNode.getParent() == null) {
rootNode.attachChild(debugNode);
} else {
debugNode.removeFromParent();
}
}
}
}, "toggleDebug");
inputManager.addMapping("toggleDebug", new KeyTrigger(KeyInput.KEY_SPACE));
DirectionalLight dl = new DirectionalLight(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);
}
Aggregations