Book Image

Augmented Reality for Developers

By : Jonathan Linowes, Krystian Babilinski
Book Image

Augmented Reality for Developers

By: Jonathan Linowes, Krystian Babilinski

Overview of this book

Augmented Reality brings with it a set of challenges that are unseen and unheard of for traditional web and mobile developers. This book is your gateway to Augmented Reality development—not a theoretical showpiece for your bookshelf, but a handbook you will keep by your desk while coding and architecting your first AR app and for years to come. The book opens with an introduction to Augmented Reality, including markets, technologies, and development tools. You will begin by setting up your development machine for Android, iOS, and Windows development, learning the basics of using Unity and the Vuforia AR platform as well as the open source ARToolKit and Microsoft Mixed Reality Toolkit. You will also receive an introduction to Apple's ARKit and Google's ARCore! You will then focus on building AR applications, exploring a variety of recognition targeting methods. You will go through multiple complete projects illustrating key market sectors including business marketing, education, industrial training, and gaming. By the end of the book, you will have gained the necessary knowledge to make quality content appropriate for a range of AR devices, platforms, and intended uses.
Table of Contents (16 chapters)
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Animating the moon orbit


OK, back to work. With that short explanation of Unity programming, we're better armed to write more code. Let's get the moon moving; it should be orbiting the earth.

Adding the moon orbit

Let's write a script called Orbit that rotates one object, the moon, around another object, the earth. We want to be able to specify its orbital period as the number of earth days for one complete orbit. For the moon, that's 27.3 days. And, like our Spin script, we'll also provide a scalar that converts earth days into game time seconds as shown ahead:

  1. In Hierarchy, select Moon and Add Component, New Script (C-Sharp). Name it Orbit, then press Create and Add.
  2. Double-click on the new script to open it in your code editor.

Write the Orbit class as follows:

File: Orbit.cs 
using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
 
public class Orbit : MonoBehaviour { 
    public Transform aroundBody; 
    public float orbitalPeriod = 27.3f; // earth days for one...