Comments (1)
I Got the solution so..... am closing this isuue
import 'dart:ffi';
import 'package:arcore_flutter_plugin/arcore_flutter_plugin.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:vector_math/vector_math_64.dart' as vector;
import 'package:vector_math/vector_math_64.dart';
import "dart:math";
class HomePage extends StatefulWidget {
@OverRide
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State {
ArCoreController arCoreController;
ArCoreNode node;
double distance;
int count = 1;
var objectPosition1, objectPosition2, finalResult;
@OverRide
void dispose() {
super.dispose();
arCoreController.dispose();
}
void onTapHandler(String name) {
print("Flutter: onNodeTap");
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
content: FlatButton(
onPressed: () {
arCoreController.removeNode(nodeName: name);
setState(() {
count--;
});
Navigator.pop(context);
},
child: Text("Remove Selected Node ?"),
)),
);
}
var getPose0, getPose1, gettranslation, getNodeName;
var nodePosition;
Future _addSphere(ArCoreHitTestResult hit) async {
final ByteData textureBytes = await rootBundle.load('assets/eartha.jpg');
final earthMaterial = ArCoreMaterial(
color: Color.fromARGB(120, 66, 134, 244),
textureBytes: textureBytes.buffer.asUint8List());
final earthShape = ArCoreSphere(
materials: [earthMaterial],
radius: 0.03,
);
final earth = ArCoreNode(
shape: earthShape,
position: hit.pose.translation,
// position: hit.pose.translation + vector.Vector3(0.0, 1.0, 0.0),
rotation: hit.pose.rotation);
setState(() {
if (count == 1) {
objectPosition1 = hit.pose.translation;
} else if (count == 2) {
objectPosition2 = hit.pose.translation;
finalResult = getDistanceBetween(objectPosition1, objectPosition2);
}
});
count++;
arCoreController.addArCoreNodeWithAnchor(earth);
}
void _handleOnPlaneTap(List hits) {
final hit = hits.first;
if (count <= 2) {
_addSphere(hit);
}
}
void _onArCoreViewCreated(ArCoreController controller) {
arCoreController = controller;
arCoreController.onNodeTap = (name) => onTapHandler(name);
arCoreController.onPlaneTap = _handleOnPlaneTap;
}
getDistanceBetween(to, from) {
var dx = to.x - from.x;
var dy = to.y - from.y;
var dz = to.z - from.z;
var distance = sqrt(dx * dx + dy * dy + dz * dz);
print("------------------------------------$distance");
return distance;
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 800,
child: Column(
children: [
Container(
height: 700,
child: ArCoreView(
onArCoreViewCreated: _onArCoreViewCreated,
enableTapRecognizer: true,
// enablePlaneRenderer: true,
enableUpdateListener: true,
),
),
// Text("Distance:$distance"),
Text("Counter:$count"),
Text("Final Result:$finalResult"),
],
),
),
),
);
}
}
from learn_ar_flutter.
Related Issues (14)
- Implement a GridView on the start screen
- Replace placeholder images
- Fix onTap functionality
- Add coming soon dialog box
- Fix bottom navigation bar color
- Modals from anywhere HOT 1
- Add a splash screen to the app HOT 3
- app never recognise the plan
- Typo
- Add theme settings to a ThemeData widget HOT 2
- Add a model to the app
- Add about button
- Update README HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learn_ar_flutter.