image
Creating Sphere

Contents

Augmented Reality in iOS

The course is part of this learning path

Start course
Difficulty
Intermediate
Duration
43m
Students
19
Description

This course explores augmented reality and how to use it to bring some visuals into our lives, into our living rooms. For example, at the end of this section, we're going to build an app that we can show the Earth, the Mars, and the Venus inside of our living room just like it's real. So, we're going to learn how to do that in this section. If you're ready, let's get started.

Learning Objectives

  • Understand what augmented reality is
  • Learn how to create moving views
  • Learn how to create cubs and spheres
  • Learn how to create an augmented app

Intended Audience

This course is intended for anyone who wants to learn how to develop apps on iOS.

Prerequisites

To get the most out of this course, some basic knowledge of iOS development would be beneficial. We recommend that you take this course as part of the Developing Mobile Apps for iOS learning path.

Transcript

Hi, within this lecture we're going to see how we can create a sphere rather than a box, so that we can create our worlds, create our planet, so that we can build our Solar System App. So, it's easy, I'm going to comment this out and rather than creating an SCNBox, I'm going to go for SCNSphere, okay? So, I'm going to call this mySphere, okay, and this will be an SCNSphere, and if you open parentheses it will ask you for one radius because the radius will be okay to create a sphere. And again, I'm going to go for something small like 0.1, and of course, we have to make sure we change this myBox to be mySphere in order to add this to our sceneView. So, this is myShere. Here we go, now we can test this, and we will see wood.jpg wrapped around our sphere so that we will get a wood sphere, okay? So, let's see, here we go. Now I believe this is good, right? We can do something with that. As you can see we have this round image that looks like a planet but it's like a wooden planet. And it's okay. And of course we're going to find some textures to wrap around our spheres later on like a world texture or Venus texture. But for right now we're good to go with that. So, what I'm going to do, I'm going to create a function in order to create some spheres later on because we will add more than one and it will be not efficient to copy and paste everything over here. It's better to do that with code, better to do that with functions, okay? So, I'm going to take everything from here and I'm going to cut them with command X. And I'm going to create a function called createSphere, okay? And under that function, I'm going to paste in everything and I'm going to get some inputs over here. First of all, I need a radius, right? And our radius will be a CGFloat type. And rather than saying radius, we're going to say radius over here and we need a content name, right? Like a wood.jpg. So, I'm going to call this content and it would be a string. And finally we will need a vector and this will be an SCNVector tree. So, if we give these inputs, we can easily create some spheres later on. So, rather than saying wood.jpg, I'm going to open a parenthesis here with a, say, reverse slash and, say, content, and let me see where the radius is, yes, it's here. So, rather than saying 0.1, I'm going to go for radius, okay? And rather than giving this SCNVector, I'm just going to give the vector over here. So, this function will return some SCNNode to me. Okay, so I'm going to make it return an SCNNode, and I'm going to return the node over here that we have created so that we can assign this node to be a variable over here. For example, let me say, let mySphere, is a createSphere function and it returns a node. And over here it will have 0.1 radius, and a content of wall.png, and a vector of SCNVector tree, and open parenthesis and I will give the same numbers one more time, like a 0, 0.1 or/and -0.5. And I believe we test this with 0.5 all the time. So, I'm going to change this to be -1, and let me do this something like 0.2 so we can see how it looks like. And rather than saying node, of course we have to say mySphere to make this work. And now I'm going to run this on my simulator, on my iPhone actually, not simulator, on my real device to see if we can see the sphere with wall.png. So, let me open my phone and here we go, we see wall.png wrapped around our sphere. So, it's looking good, it looks like star walls planet over here. So, I believe that's good. Now we can find some other textures to work on with it, but before we do that I'm just going to show you one more thing. In order to work with shadows more efficiently, you can come over here and say sceneView.automaticallyUpdatesLighting, and this will be true. And when I run this, it will be much better in terms of lighting and in terms of shadows. So, maybe you cannot see the difference at this point because it was already looking good, but in other cases you will see the difference. When you do this, it will take care of lighting and shadows by itself. So, it would be much more realistic. It will be much more lively, okay? So, I believe we can stop here, and in the next lecture we're going to find some planet textures and we're going to finalize our Solar System App.

 

About the Author
Students
1675
Courses
55
Learning Paths
3

Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.

Covered Topics