use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TestBatchNodeTower method simpleInitApp.
@Override
public void simpleInitApp() {
timer = new NanoTimer();
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
// bulletAppState.setEnabled(false);
stateManager.attach(bulletAppState);
bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(0.4f);
brick = new Box(brickWidth, brickHeight, brickDepth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
//bulletAppState.getPhysicsSpace().enableDebug(assetManager);
initMaterial();
initTower();
initFloor();
initCrossHairs();
this.cam.setLocation(new Vector3f(0, 25f, 8f));
cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
cam.setFrustumFar(80);
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, "shoot");
rootNode.setShadowMode(ShadowMode.Off);
batchNode.batch();
batchNode.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(batchNode);
shadowRenderer = new DirectionalLightShadowFilter(assetManager, 1024, 2);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
shadowRenderer.setLight(dl);
shadowRenderer.setLambda(0.55f);
shadowRenderer.setShadowIntensity(0.6f);
shadowRenderer.setShadowCompareMode(CompareMode.Hardware);
shadowRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(shadowRenderer);
viewPort.addProcessor(fpp);
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TestBrickWall method initFloor.
public void initFloor() {
Box floorBox = new Box(10f, 0.1f, 5f);
floorBox.scaleTextureCoordinates(new Vector2f(3, 6));
Geometry floor = new Geometry("floor", floorBox);
floor.setMaterial(mat3);
floor.setShadowMode(ShadowMode.Receive);
floor.setLocalTranslation(0, -0.1f, 0);
floor.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(10f, 0.1f, 5f)), 0));
this.rootNode.attachChild(floor);
this.getPhysicsSpace().add(floor);
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class AndroidTouchInput method onTouch.
public boolean onTouch(MotionEvent event) {
if (!isInitialized()) {
return false;
}
boolean bWasHandled = false;
TouchEvent touch = null;
// System.out.println("native : " + event.getAction());
int action = getAction(event);
int pointerIndex = getPointerIndex(event);
int pointerId = getPointerId(event);
Vector2f lastPos = lastPositions.get(pointerId);
float jmeX;
float jmeY;
numPointers = event.getPointerCount();
//final int pointerCount = event.getPointerCount();
switch(getAction(event)) {
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_DOWN:
jmeX = getJmeX(event.getX(pointerIndex));
jmeY = invertY(getJmeY(event.getY(pointerIndex)));
touch = getFreeTouchEvent();
touch.set(TouchEvent.Type.DOWN, jmeX, jmeY, 0, 0);
touch.setPointerId(pointerId);
touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure(pointerIndex));
lastPos = new Vector2f(jmeX, jmeY);
lastPositions.put(pointerId, lastPos);
addEvent(touch);
addEvent(generateMouseEvent(touch));
bWasHandled = true;
break;
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
jmeX = getJmeX(event.getX(pointerIndex));
jmeY = invertY(getJmeY(event.getY(pointerIndex)));
touch = getFreeTouchEvent();
touch.set(TouchEvent.Type.UP, jmeX, jmeY, 0, 0);
touch.setPointerId(pointerId);
touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure(pointerIndex));
lastPositions.remove(pointerId);
addEvent(touch);
addEvent(generateMouseEvent(touch));
bWasHandled = true;
break;
case MotionEvent.ACTION_MOVE:
// Convert all pointers into events
for (int p = 0; p < event.getPointerCount(); p++) {
jmeX = getJmeX(event.getX(p));
jmeY = invertY(getJmeY(event.getY(p)));
lastPos = lastPositions.get(event.getPointerId(p));
if (lastPos == null) {
lastPos = new Vector2f(jmeX, jmeY);
lastPositions.put(event.getPointerId(p), lastPos);
}
float dX = jmeX - lastPos.x;
float dY = jmeY - lastPos.y;
if (dX != 0 || dY != 0) {
touch = getFreeTouchEvent();
touch.set(TouchEvent.Type.MOVE, jmeX, jmeY, dX, dY);
touch.setPointerId(event.getPointerId(p));
touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure(p));
lastPos.set(jmeX, jmeY);
addEvent(touch);
addEvent(generateMouseEvent(touch));
bWasHandled = true;
}
}
break;
case MotionEvent.ACTION_OUTSIDE:
break;
}
// Try to detect gestures
if (gestureDetector != null) {
gestureDetector.onTouchEvent(event);
}
if (scaleDetector != null) {
scaleDetector.onTouchEvent(event);
}
return bWasHandled;
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class AndroidTouchInput14 method onHover.
public boolean onHover(MotionEvent event) {
boolean consumed = false;
int action = getAction(event);
int pointerId = getPointerId(event);
int pointerIndex = getPointerIndex(event);
Vector2f lastPos = lastHoverPositions.get(pointerId);
float jmeX;
float jmeY;
numPointers = event.getPointerCount();
// logger.log(Level.INFO, "onHover pointerId: {0}, action: {1}, x: {2}, y: {3}, numPointers: {4}",
// new Object[]{pointerId, action, event.getX(), event.getY(), event.getPointerCount()});
TouchEvent touchEvent;
switch(action) {
case MotionEvent.ACTION_HOVER_ENTER:
jmeX = getJmeX(event.getX(pointerIndex));
jmeY = invertY(getJmeY(event.getY(pointerIndex)));
touchEvent = getFreeTouchEvent();
touchEvent.set(TouchEvent.Type.HOVER_START, jmeX, jmeY, 0, 0);
touchEvent.setPointerId(pointerId);
touchEvent.setTime(event.getEventTime());
touchEvent.setPressure(event.getPressure(pointerIndex));
lastPos = new Vector2f(jmeX, jmeY);
lastHoverPositions.put(pointerId, lastPos);
addEvent(touchEvent);
consumed = true;
break;
case MotionEvent.ACTION_HOVER_MOVE:
// Convert all pointers into events
for (int p = 0; p < event.getPointerCount(); p++) {
jmeX = getJmeX(event.getX(p));
jmeY = invertY(getJmeY(event.getY(p)));
lastPos = lastHoverPositions.get(event.getPointerId(p));
if (lastPos == null) {
lastPos = new Vector2f(jmeX, jmeY);
lastHoverPositions.put(event.getPointerId(p), lastPos);
}
float dX = jmeX - lastPos.x;
float dY = jmeY - lastPos.y;
if (dX != 0 || dY != 0) {
touchEvent = getFreeTouchEvent();
touchEvent.set(TouchEvent.Type.HOVER_MOVE, jmeX, jmeY, dX, dY);
touchEvent.setPointerId(event.getPointerId(p));
touchEvent.setTime(event.getEventTime());
touchEvent.setPressure(event.getPressure(p));
lastPos.set(jmeX, jmeY);
addEvent(touchEvent);
}
}
consumed = true;
break;
case MotionEvent.ACTION_HOVER_EXIT:
jmeX = getJmeX(event.getX(pointerIndex));
jmeY = invertY(getJmeY(event.getY(pointerIndex)));
touchEvent = getFreeTouchEvent();
touchEvent.set(TouchEvent.Type.HOVER_END, jmeX, jmeY, 0, 0);
touchEvent.setPointerId(pointerId);
touchEvent.setTime(event.getEventTime());
touchEvent.setPressure(event.getPressure(pointerIndex));
lastHoverPositions.remove(pointerId);
addEvent(touchEvent);
consumed = true;
break;
default:
consumed = false;
break;
}
return consumed;
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class HDRRenderer method createLumShader.
private Material createLumShader(int srcW, int srcH, int bufW, int bufH, int mode, int iters, Texture tex) {
Material mat = new Material(manager, "Common/MatDefs/Hdr/LogLum.j3md");
Vector2f blockSize = new Vector2f(1f / bufW, 1f / bufH);
Vector2f pixelSize = new Vector2f(1f / srcW, 1f / srcH);
Vector2f blocks = new Vector2f();
float numPixels = Float.POSITIVE_INFINITY;
if (iters != -1) {
do {
pixelSize.multLocal(2);
blocks.set(blockSize.x / pixelSize.x, blockSize.y / pixelSize.y);
numPixels = blocks.x * blocks.y;
} while (numPixels > iters);
} else {
blocks.set(blockSize.x / pixelSize.x, blockSize.y / pixelSize.y);
numPixels = blocks.x * blocks.y;
}
mat.setBoolean("Blocks", true);
if (mode == LUMMODE_ENCODE_LUM)
mat.setBoolean("EncodeLum", true);
else if (mode == LUMMODE_DECODE_LUM)
mat.setBoolean("DecodeLum", true);
mat.setTexture("Texture", tex);
mat.setVector2("BlockSize", blockSize);
mat.setVector2("PixelSize", pixelSize);
mat.setFloat("NumPixels", numPixels);
return mat;
}
Aggregations