@Override public boolean onDown(MotionEvent event) { scrolling = false; synchronized (GlobalData.audioScene) { // determine transformed coordinate of touch point touchPoint[0] = event.getX(); touchPoint[1] = event.getY(); inverseViewportTransformation.mapPoints(touchPoint); GlobalData.audioScene.inverseMapPoint(touchPoint); // try to find nearest sound source lastTouchSoundSource = GlobalData.audioScene.getNearestSoundSource(touchPoint); if (lastTouchSoundSource != null) { // get distance (touch point to source) in pixels selectionOffset[0] = lastTouchSoundSource.getX(); selectionOffset[1] = lastTouchSoundSource.getY(); GlobalData.audioScene.mapPoint(selectionOffset); viewportTransformation.mapPoints(selectionOffset); selectionOffset[0] -= event.getX(); selectionOffset[1] -= event.getY(); float distance = FloatMath.sqrt( selectionOffset[0] * selectionOffset[0] + selectionOffset[1] * selectionOffset[1]); // select source? if (distance > SOURCE_SELECT_RADIUS) { lastTouchSoundSource = null; } } } return true; }
public float[][] getSceneBounds(Matrix viewportTransformation) { float[] point = {0.0f, 0.0f}; // map reference point to screen coordinate system viewportTransformation.mapPoints(point); // set min/max to reference position float[][] minMaxXY = { {point[0], point[1]}, {point[0], point[1]} }; // two points: minXY and maxXY synchronized (GlobalData.audioScene) { int numSources = GlobalData.audioScene.getNumSoundSources(); SoundSource s = null; for (int i = 0; i < numSources; i++) { s = GlobalData.audioScene.getSoundSource(i); point[0] = s.getX(); point[1] = s.getY(); // map to reference coordinate system GlobalData.audioScene.mapPoint(point); viewportTransformation.mapPoints(point); // check if point lies outwards current bounds if (point[0] < minMaxXY[0][0]) minMaxXY[0][0] = point[0]; if (point[0] > minMaxXY[1][0]) minMaxXY[1][0] = point[0]; if (point[1] < minMaxXY[0][1]) minMaxXY[0][1] = point[1]; if (point[1] > minMaxXY[1][1]) minMaxXY[1][1] = point[1]; } } return minMaxXY; }