Git Product home page Git Product logo

Comments (1)

Madanraj1 avatar Madanraj1 commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.