ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Follow publication

ARCore Cupcakes #3 — Understanding Vector3

Hari Vignesh Jayapalan
ProAndroidDev
Published in
4 min readAug 18, 2018

--

Image credits — :-P

ARCore Cupcakes is a blog series, intended to showcase quick hacks, pro-tips and concepts on ARCore and Sceneform development for Android Developers. The goal of this series is to provide necessary support for AndroidDevs to upgrade themselves to ARCoreDevs.

If you’re an AndroidDev, trying to become an ARCoreDev, start from the series below, which covers basic ARCore and Sceneform fundamentals.

Previous Episode — #2

Why you need to understand Vector3?

Before we dive in to the concept, you may ask why I should read this? Though Sceneform has provided us (or aimed to provide us) the same app writing experience for creating AR apps, there are few gaming/graphics concepts that will reflect. We need to understand them to become a better ARCoreDev.

Some of the topics are self-explanatory, but some are not. They all revolve around coordinate geometry concepts — which must have studied in your high school or UG. If you’re not great with Math like me, it’s worse!

Fear not, once we start playing with it, we’ll get a hang of it.

Where to use Vector3?

Vector3 is a common entity that is used to denote the position or translation or scaling for any 3D object in space or in our Augmented environment.

If you have read the previous episode, we provided the position of the 3D object as a Vector3 object — this is just one of the use-case. We also provide the scale factor for the cube using Vector3.

Vector3 usage example

Vector

What’s meant by a Vector? In simple words, a quantity which has both magnitude and direction.

Which means it will have a value and a direction where that value will be put to action.

Vector3

Now I feel you can guess what Vector3 is. It’s a vector with 3 values or coordinates, where each has it’s own direction and value.

Vector3(float x, float y, float z)

Every object in 3D space has it’s position represented in X,Y & Z coordinate system. Just like the image below

Image credits: https://www.reaconverter.com

Usually right direction is positive and left is negative. For Example, If you need to translate this cube or move this cube in 3D space, you need to provide the distance(magnitude) — how much to move and the direction — which way to move.

Which is nothing but a vector representing 3 axis values — Vector3. For example,

  • Consider the inital position of the cube as (0, 0, 0)
  • If you move along the x-axis to the right, then it is (2, 0, 0)
  • If you move along the x-axis to the left, then it is (-2, 0, 0)
  • This is the case for other axis — Y and Z

This can also be applied to scaling or resizing the cube as well. For example,

  • Consider the size of the cube in it’s initial positon as (1f, 1f, 1f) — Here the magnitude is a float value representing the size of the object in that particular direction.
  • In simple words, if you are seeing the cube image, x-axis wise it is length, z-axis wise it is width and y-axis wise it is height — this is just the perspective. it changes from the angle of perception.
  • If you make the scale factor as (5f, 1f, 1f), it becomes a cuboid along the x-axis with length 5 times more than other coordinates.

Other uses of Vector3 API

Not just for translation and scaling we use or represent it with Vector3. Vector3 of ARCore provides addition operations such as Vector calculations — dot product, cross product and so on. Check out the detailed API doc.

If you have understood the above concept, great! But if you’re still not clear, I’ve got a cool thing just for you! Vector playground!

Vector Playground

This is a simple app that I sketched for scaling the object dynamically. You’ll know how Vector3 is applied in terms of scaling an object.

Gif sample of the app — Vector3 playground

Project

Don’t forget to hit star if this repo has helped you in understanding Vector3.

Other implementations of the project

  • You get to see the usage of fragments for AR experience
  • You also get to see how to scale the objects at runtime

TL;DR — Project

To apply scale factors dynamically for a project, you need to approach Anchor and provide localScale value. AR Scene changes/updates the frame to look out for the new feature points and it updates the values automatically.

TL;DR — Vector3

  • Vector is a quantity which has both magnitude and direction
  • Vector3 is a representation of object’s position and size in 3D space
  • Translation and Scaling are some of the use-cases where we use Vector3
  • ARCore API provides other basic vector manipulation options
  • We also saw a basic Vector3-playground app — demonstrating scaling object dynamically

See you soon in another episode!

Follow me on Twitter, Facebook or LinkedIn, will post an update when I write new posts and feel free to come and say Hi :-)

Thank you for spending your precious time in reading this article. Loved it? Clap your 👏 to say “thanks!” and help others find this article.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Written by Hari Vignesh Jayapalan

Android Dev at WeTransfer| ex Backbase | #1 Google AAD | Public Speaker | Blogger | Creative Coder & Logical Designer

Responses (1)

Write a response