Thanks @roaminggamer. I fear you’re right about GPS accuracy in that regard. We’ll have to wait a few more years still, perhaps.
AR doesn’t need to use GPS. Visual image targets can be used instead which is an image in the real world that the device app uses to motion track content. Here is an example of a flat 2d object but a shape that does adjust to the tilts and zooms of the device to track onto an image target. Check last part of the video: https://www.youtube.com/watch?v=GDF-D-kGhjA
As far as I can tell, Corona out of the box cannot interpret image targets in its camera view. But Vuforia can. So I am thinking the solution is using Vuforia via Corona Enterprise, correct?
So if anyone has had experience with Vuforia in Enterprise, it would be great to hear about it. I did find Walter responding in Vuforia to some specific questions so someone in Corona land is doing it: https://developer.vuforia.com/forum/ios/using-vuforia-without-eaglview
Hi
I am fairly new to Coronasdk. I am intrigued about AR and want to do similar things with CoronaSDK for Android. I know that CoronaSDK can do it for IOS. I can’t afford the enterprise version since I am just playing around with coding and most of the projects I do is free.
I read in Rob’s post somewhere here that we can put a sticker on top of the camera. This would be so cool too. I can think of so many things that can be done with this AR feature (if only available on Andriod as well).
Anyone has done this sticker on top of camera?
Thanks
Rgds
TH
Hi All
So I’m not the best coder in the world, but I managed to make a little PokemonGo AR clone in Corona in less than 100 lines of code.
You can see the video here https://www.youtube.com/watch?v=SRVgbjwYeGo
You can download and use the code(however you like) here - https://bitbucket.org/sskenth/coronaopensource.git
Hope that helps you on your journey with Augmented Reality and CoronaSDK.
Good luck, and if I can answer any specific question on it, let me know
-Sat
P.S. can anyone tell me how to embed a video into a forum post, as you can see above I clearly dont know how to do it ahaha [SOLVED - Thanks Rob]
Nice tutorial.
Have you tried just putting in the URL? It might be smart enough to detect youtube links.
It couldn’t have been any easier and I still got it wrong, I feel so silly right now :unsure:
Thanks Rob
By the way, great tutorial!
Thank you Rob, its a great compliment especially coming from a legend like yourself 
AR is definitely possible in Corona, check out my Corona app Stickar. Though I eventually switched my AR code from lua to native for pixel perfect movement.
Here’s some really helpful code I’ve written in my year long exploration into AR. Haven’t tested in a while, changed some variable names around, but it should be a good starting point. Note: does not adjust to Landscape orientation.
Augmented Reality tracking in <100 lines of code
0: Quick setup
system.setAccelerometerInterval( 100 ) -- 100hz for best effect, higher battery drain local ar = {degrees = 0,height = 0,startDegrees = 0,startHeight = 0} -- degrees comes from the compass (for x AR movement) -- height comes from the accelerometer (for y AR movement) -- startDegrees is an offset for x AR movement (default is 0) -- startHeight is an offset for y AR movement (default is 0) -- AR camera local background = display.newRect(display.contentWidth\*.5,display.contentHeight\*.5,display.contentWidth,display.contentHeight) background.fill = {type = "camera"} -- gives you a fullscreen camera view background.width = display.contentHeight\*(3/4) -- get proper aspect ratio for camera
1: Augmented Reality tracking
local track\_degrees = nil local track\_degrees\_last = nil local track\_group = display.newGroup() -- group that moves with device orientation changes local test = display.newRect(track\_group,display.contentWidth\*.5,display.contentHeight\*.5,64,64) track = function (event) if not track\_degrees then track\_degrees = ar.degrees track\_degrees\_last = ar.degrees end -- flip tracking for full 360 deg rotation if ar.degrees-track\_degrees\_last \>= 180 then track\_degrees\_last = track\_degrees\_last + 360 elseif ar.degrees-track\_degrees\_last \<= -180 then track\_degrees\_last = track\_degrees\_last - 360 end track\_degrees = track\_degrees + (ar.degrees-track\_degrees\_last) track\_degrees\_last = ar.degrees local easex = 0 local easey = ar.height\*display.contentHeight if ar.startDegrees then easex = -(vt.track\_degrees-ar.startDegrees)\*16-(display.contentWidth\*.5) end if ar.startHeight then easey = (ar.height\*display.contentHeight)-(ar.startHeight\*display.contentHeight)-display.contentHeight\*.5 end local track\_speed = 3 -- lower value = faster tracking, more jittery track\_group:translate(((easex-track\_group.x)/track\_speed),((easey-track\_group.y)/track\_speed)) end Runtime:addEventListener("enterFrame",track)
2: Get ar.degrees
local compass = function( event ) if \_G.device == "Android" or event.geographic == nil then ar.degrees = event.magnetic else ar.degrees = event.geographic end if ar.degrees \< 0 then ar.degrees = ar.degrees + 360 elseif ar.degrees \>= 360 then ar.degrees = ar.degrees - 360 end end Runtime:addEventListener( "heading", compass )
3: Get ar.height
accelerometer = function ( event ) ar.height = event.zGravity end Runtime:addEventListener( "accelerometer", accelerometer )
4: insert AR object
local create\_AR\_object = function (obj) local xc,yc = obj:localToContent(0,0 ) track\_group:insert(obj) obj.x = -track\_group.x+(xc-W\*.5) obj.y = -track\_group.y+(yc-H\*.5) end local myObject = display.newCircle(0,0,64) create\_AR\_object(myObject)
Here are some other helpful pieces of code if you’re planning on making an AR/GPS game like Pokemon Go
1: Distance between two map coordinates, accurate whether you’re in China or the North Pole
Important because latitude and longitude distances change as you move away from the equator
local map\_distance = function (lat1,long1,lat2,long2) local R = 6371000; -- metres local x1 = math.rad(lat1); local x2 = math.rad(lat2); local deltax = math.rad(lat2-lat1); local deltalambda = math.rad(lon2-lon1); local a = math.sin(deltax/2) \* math.sin(deltax/2) + math.cos(x1) \* math.cos(x2) \* math.sin(deltalambda/2) \* math.sin(deltalambda/2); local c = 2 \* math.atan2(math.sqrt(a), math.sqrt(1-a)); local d = R \* c; return d end
2: Plot a point on a map using distance and angle
Simple, but a big time saver
local plotter = function (lat,lon,ang,dist) if lat and lon then local x = lat + dist\*math.deg(math.cos(math.rad(ang))) local y = lon + dist\*math.deg(math.sin(math.rad(ang))) return x,y end
I also have code for translating latitude and longitude to screen pixels (for AR camera) if anyone is interested.
Hope I helped and got someone started on a new Corona AR project!
Hi @AidanWolf, great tutorial. You also mention that you have some code for translating latitude and longitude to screen screen pixels ? Would you be open to share some of it please ?
regards.
Nick
Stickar looks interesting. Would like to try It but keep getting: “not compatible with this iPad” message on multiple iPads we’ve tried.
@nmichaud yes I do, though its currently a mess because it was for a specific app. I’ll make it “copy and paste ready” soon, and post it here.
@kilopop Stickar is an iPhone only app, but unknowingly the iTunes Store made it compatible for every device. This will be fixed once I figure out why haha.
Stickar doesn’t download on iPhone 5s iOS 9.3.2