-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathphysics_page.dart
71 lines (62 loc) · 1.97 KB
/
physics_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import 'dart:math' as math;
import 'package:arkit_plugin/arkit_plugin.dart';
import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart' as vector;
class PhysicsPage extends StatefulWidget {
@override
_PhysicsPageState createState() => _PhysicsPageState();
}
class _PhysicsPageState extends State<PhysicsPage> {
late ARKitController arkitController;
@override
void dispose() {
arkitController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Physics Sample')),
body: Container(
child: ARKitSceneView(onARKitViewCreated: onARKitViewCreated)));
void onARKitViewCreated(ARKitController arkitController) {
this.arkitController = arkitController;
_addPlane(this.arkitController);
_addSphere(this.arkitController);
}
void _addSphere(ARKitController controller) {
final material =
ARKitMaterial(diffuse: ARKitMaterialProperty.color(Colors.blue));
final sphere = ARKitSphere(materials: [material], radius: 0.1);
final node = ARKitNode(
geometry: sphere,
physicsBody: ARKitPhysicsBody(
ARKitPhysicsBodyType.dynamicType,
categoryBitMask: BodyType.sphere.index + 1,
),
position: vector.Vector3(0, 1, -1));
controller.add(node);
}
void _addPlane(ARKitController controller) {
final plane = ARKitPlane(
width: 2,
height: 2,
materials: [
ARKitMaterial(
diffuse: ARKitMaterialProperty.color(Colors.green),
)
],
);
final node = ARKitNode(
geometry: plane,
physicsBody: ARKitPhysicsBody(
ARKitPhysicsBodyType.staticType,
shape: ARKitPhysicsShape(plane),
categoryBitMask: BodyType.plane.index + 1,
),
rotation: vector.Vector4(1, 0, 0, -math.pi / 2),
position: vector.Vector3(0, -0.5, -1),
);
controller.add(node);
}
}
enum BodyType { sphere, plane }