Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean isTapOnSetColor(float x, float y) {
- Vec3F intersection, lineStart, lineEnd;
- DisplayMetrics metrics = new DisplayMetrics();
- mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- for ( Map.Entry<String, Matrix44F> entry : modelViewMatrix_colors.entrySet()) {
- String key = entry.getKey();
- Matrix44F matrix44F = entry.getValue();
- intersection = SampleMath.getPointToPlaneIntersection(
- SampleMath.Matrix44FInverse(vuforiaAppSession.getProjectionMatrix()),
- matrix44F, metrics.widthPixels, metrics.heightPixels,
- new Vec2F(x, y), new Vec3F(0, 0, 0), new Vec3F(0, 0, 1));
- lineStart = SampleMath.getPointToPlaneLineStart(
- SampleMath.Matrix44FInverse(vuforiaAppSession.getProjectionMatrix()),
- matrix44F, metrics.widthPixels, metrics.heightPixels,
- new Vec2F(x, y), new Vec3F(0, 0, 0), new Vec3F(0, 0, 1));
- lineEnd = SampleMath.getPointToPlaneLineEnd(
- SampleMath.Matrix44FInverse(vuforiaAppSession.getProjectionMatrix()),
- matrix44F, metrics.widthPixels, metrics.heightPixels,
- new Vec2F(x, y), new Vec3F(0, 0, 0), new Vec3F(0, 0, 1));
- boolean bool = checkIntersectionLine(matrix44F, lineStart, lineEnd);
- if (bool) {
- String[] ids = key.split("_");
- Realm realm = Realm.getDefaultInstance();
- Colors color = realm.where(Colors.class).equalTo("id", Integer.parseInt(ids[1])).findFirst();
- Log.d(Constants.TAG, "CLICKED!!!!!!!!!!!!!!!!!! " + key + " / " + color.getName_ru());
- return true;
- }
- }
- return false;
- }
- boolean checkIntersectionLine(Matrix44F transformA2, Vec3F pointA, Vec3F pointB) {
- Matrix44F transformA = SampleMath.Matrix44FTranspose(transformA2);
- Vec3F lineDir = SampleMath.Vec3FSub(pointB, pointA);
- List<Vec3F> dominoTransformedVertices = new ArrayList<>();
- for (int i = 0; i < Verts_colors.size()/3; i++) {
- dominoTransformedVertices.add(SampleMath.Vec3FTransform(new Vec3F(Verts_colors.get(i*3).floatValue(), Verts_colors.get(i*3+1).floatValue(), Verts_colors.get(i*3+2).floatValue()), transformA));
- }
- for(int i=0; i<Normals_colors.size()/3; i++) {
- Vec3F normal = SampleMath.Vec3FTransformNormal(new Vec3F(Normals_colors.get(i*3).floatValue(), Normals_colors.get(i*3+1).floatValue(), Normals_colors.get(i*3+2).floatValue()), transformA);
- Vec3F cross = SampleMath.Vec3FCross(normal, lineDir);
- if (isSeparatingAxisLine(dominoTransformedVertices, normal, pointA, pointB))
- return false;
- if (isSeparatingAxisLine(dominoTransformedVertices, cross, pointA, pointB))
- return false;
- }
- return true;
- }
- boolean isSeparatingAxisLine(List<Vec3F> dominoTransformedVertices, Vec3F axis, Vec3F pointA, Vec3F pointB) {
- float magnitude = axis.getData()[0] * axis.getData()[0] + axis.getData()[1] * axis.getData()[1] + axis.getData()[2] * axis.getData()[2];
- if (magnitude < 0.00001) return false;
- float minA, maxA, minB, maxB;
- minA = maxA = SampleMath.Vec3FDot(dominoTransformedVertices.toArray(new Vec3F[dominoTransformedVertices.size()])[0], axis);
- float p;
- for (int i = 1; i < dominoTransformedVertices.size(); i++) {
- p = SampleMath.Vec3FDot(dominoTransformedVertices.toArray(new Vec3F[dominoTransformedVertices.size()])[i], axis);
- if (p < minA) minA = p;
- if (p > maxA) maxA = p;
- }
- minB = maxB = SampleMath.Vec3FDot(pointA, axis);
- p = SampleMath.Vec3FDot(pointB, axis);
- if (p < minB) minB = p;
- if (p > maxB) maxB = p;
- if (maxA < minB) return true;
- if (minA > maxB) return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement