FREELessons: 13Length: 1.2 hours

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

3.3 Starting Measurement

In this lesson, we are going to start measuring points and rendering an indicator to the screen.

3.3 Starting Measurement

Hi, and welcome back to Get Started with Augmented Reality for iOS. In this lesson, we are going to start measuring from a point and also show it in the vault. We are going to do the screen interaction the same way we did last section. But this time, instead of touchesEnded, I'm using touchesBegan. So as soon as the user touches the screen, the market gets set. The first step is to perform a head test. Therefore, I need to convert the touch to the scene views location. And then perform a head test against a known feature point, which would find sense be a detected plane. Okay, what does Xcode not like? I see, there is an equals sign too many. Next up, we need to get the hint point. I have used the hint test that is specific to AR kit, so instead of an SCN hint test result, I'll receive an AR hint test result. This class doesn't have world cord in it, but only a world transform matrix. No problem for us as we know exactly how to extract the position from it. We just need the values from the last column, and fill them into SCNVector3. I want to be able to measure multiple points, so we need to match pairs. This means the app has to act differently when we already have a first point. Therefore, I'm going to introduce a variable called is measuring, which is either true, if you have an active starting point, or false, if you don't. So if we aren't measuring it, let's start a precision and a property called active starting point, and then set as measuring to true. Let me quickly add the indicator and initialize it to full. I'm also going to add active starting point. Which I'm going to forcefully unwrap, because it will only be accessed if we have a point. To find step is to display the point on the screen. I'll extract that into a separate function, so we can draw it multiple times, parsing in the precision. To show the measuring points, I'm using spheres. They're perfect because no matter where you look from, you will see a white dot if you keep the lighting as it is. This saves us from using more complicated ways to align the model to the few. Which we are re-using in the last lesson of this section. The radius will be two centimeters for now. Of course, we also need a node for the geometry, which receives the position we passed in. Finally, the node has to be added to the same. Let's spell the run and see what we have accomplished up until now. Okay, I've laid out some measuring points, so let's tap, that's not right. I have made a mistake when doing the hit test. Of course, I don't want to point at the touch location, I want it at the center point of the sceneView. Let's try this again. Now the point is where it should be. Of course, right now it only works once. I'm going to make one final edit before I'm finishing up the lesson. And that is reducing the radius to five millimeters. So the sphere is much smaller and doesn't have a diameter of four centimeters. In the next lesson, we'll finish the measurement of the second point and also calculate the distance between the two. See you there.

Back to the top