From The Blog: Corona Roadmap 2018

Considering the release notes of the latest daily builds, it seems that Corona team will try to release them all at once.

Please consider developing android camera overlays as a priority.  Augmented Reality is about to become super hot commodity, and we are going to need it badly… I understand its complicated, but we really need it and I would rather be able to develop AR solutions within corona.

public class MMCC extends Activity {
Preview mPreview;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Hide the window title.
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

// Create our Preview view and set it as the content of our activity.
mPreview = new Preview(this);
GuideBox guideBox = new GuideBox(this); 

//camera preview
setContentView(mPreview);
//overlay guide box
addContentView(guideBox, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

public class GuideBox extends View {
public GuideBox(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub

Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.GREEN);

//center
int x0=canvas.getWidth()/2;
int y0=canvas.getHeight()/2;
int dx=canvas.getHeight()/3;
int dy=canvas.getHeight()/3;

//draw guide box
canvas.drawRect(x0-dx, y0-dy, x0+dx, y0+dy, paint);

super.onDraw(canvas);

Looking at that code, it’s looks simple, but it may not be that straight forward. Corona’s main display system is an OpenGL window. We would need to provide a video feed to an OpenGL object that can be put inside that window.  I suspect the use of the word canvas above isn’t referencing our OpenGL window.

If this was feasible, we would have done it.  I’ll ask engineering again, but I’m not sure if I will get a different answer.

Rob

Thanks for the feedback Rob,

Stuff like this is never easy but wow… what a feature set would be opened up to corona developers!

Here’s a bit more java/xml that does it… basically take the 

<?xml version=“1.0” encoding=“utf-8”?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width=“fill_parent”
android:layout_height=“fill_parent” >

<android.view.SurfaceView
android:id="@+id/surface"
android:layout_width=“fill_parent”
android:layout_height=“fill_parent” />

<ImageView
android:id = “@+id/header”
android:layout_width = “wrap_content”
android:layout_height = “wrap_content” />

</FrameLayout>

and for the java code you should extend SurfaceHolder.Callback in your activity and then attach the camera to the surface view like this,its my full code please be careful with bitmaps and canvas that is the tricky part :

public class MainActivity extends Activity implements SurfaceHolder.Callback
{
private Camera camera = null;
private SurfaceView cameraSurfaceView = null;
private SurfaceHolder cameraSurfaceHolder = null;
private boolean previewing = false;
RelativeLayout relativeLayout;

private Button btnCapture = null;
private Button btnsave = null;
private Button btnshare = null;
private boolean isSaved=false;
private boolean isCaptured=false;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

getWindow().setFormat(PixelFormat.TRANSLUCENT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main);

relativeLayout=(RelativeLayout) findViewById(R.id.containerImg);
relativeLayout.setDrawingCacheEnabled(true);
cameraSurfaceView = (SurfaceView)
findViewById(R.id.surfaceView1);
// cameraSurfaceView.setLayoutParams(new FrameLayout.LayoutParams(640, 480));
cameraSurfaceHolder = cameraSurfaceView.getHolder();
cameraSurfaceHolder.addCallback(this);
// cameraSurfaceHolder.setType(SurfaceHolder.
// SURFACE_TYPE_PUSH_BUFFERS);

btnCapture = (Button)findViewById(R.id.capturebtn);
btnCapture.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
camera.takePicture(cameraShutterCallback,
cameraPictureCallbackRaw,
cameraPictureCallbackJpeg);
isCaptured=true;
}
});
btnsave = (Button)findViewById(R.id.savebtn);
btnsave.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
FrameLayout frm = (FrameLayout)findViewById(R.id.frameLayout1);
frm.setDrawingCacheEnabled(true);
frm.buildDrawingCache();
Bitmap bitmap = frm.getDrawingCache();
try {
File rootFile=new File(Environment.getExternalStorageDirectory().toString()+"/MYCAMERAOVERLAY");
rootFile.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = “Image-”+ n +".png";

File resultingfile = new File(rootFile, fname);

if (resultingfile.exists ()) resultingfile.delete ();
try {
FileOutputStream Fout = new FileOutputStream(resultingfile);
bitmap.compress(CompressFormat.PNG, 100, Fout);
Fout.flush();
Fout.close();

} catch (FileNotFoundException e) {
Log.d(“In Saving File”, e + “”);
}
} catch(IOException e){
Log.d(“In Saving File”, e + “”);
}
isSaved=true;
}
});
btnshare = (Button)findViewById(R.id.sharebtn);
btnshare.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if((isSaved)&&(isCaptured)){
// TODO sharing what ever we saved
// take the path

}

}
});
}

ShutterCallback cameraShutterCallback = new ShutterCallback()
{
@Override
public void onShutter()
{
// TODO Auto-generated method stub
}
};

PictureCallback cameraPictureCallbackRaw = new PictureCallback()
{
@Override
public void onPictureTaken(byte[] data, Camera camera)
{
// TODO Auto-generated method stub
}
};

PictureCallback cameraPictureCallbackJpeg = new PictureCallback()
{
@Override
public void onPictureTaken(byte[] data, Camera camera)
{
// TODO Auto-generated method stub
Bitmap cameraBitmap = BitmapFactory.decodeByteArray
(data, 0, data.length);

int wid = cameraBitmap.getWidth();
int hgt = cameraBitmap.getHeight();

// Toast.makeText(getApplicationContext(), wid+""+hgt, Toast.LENGTH_SHORT).show();
Bitmap newImage = Bitmap.createBitmap
(wid, hgt, Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(newImage);

canvas.drawBitmap(cameraBitmap, 0f, 0f, null);

camera.startPreview();

newImage.recycle();
newImage = null;

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);

startActivity(intent);

}
};

@Override
public void surfaceChanged(SurfaceHolder holder,
int format, int width, int height)
{
// TODO Auto-generated method stub

if(previewing)
{
camera.stopPreview();
previewing = false;
}
try
{
Camera.Parameters parameters = camera.getParameters();
parameters.setPreviewSize(640, 480);
parameters.setPictureSize(640, 480);
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
camera.setDisplayOrientation(-90);

}

// parameters.setRotation(90);
camera.setParameters(parameters);

camera.setPreviewDisplay(cameraSurfaceHolder);
camera.startPreview();
previewing = true;
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Override
public void surfaceCreated(SurfaceHolder holder)
{
// TODO Auto-generated method stub
try
{
camera = Camera.open();
}
catch(RuntimeException e)
{
Toast.makeText(getApplicationContext(), “Device camera is not working properly, please try after sometime.”, Toast.LENGTH_LONG).show();
}
}

@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
// TODO Auto-generated method stub
try{

camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}catch(Exception e){
e.printStackTrace();
}
}

Eh… Am I missing something here?

Why exactly is this difficult seen as Corona can already fill a rect with the camera?

https://docs.coronalabs.com/api/type/ShapeObject/fill.html#camera-source-fill

Making sense of that is an entirely different conversation!

Hi, I think Greg is looking for support for camera source fill …on Android.  Higher up in that doc https://docs.coronalabs.com/api/type/ShapeObject/fill.html#camera-source-fill it states “Camera Source — used to fill an object with the device camera source (iOS-only).”

I’d love to see it working on Android too. Augmented Reality was featured a the very top of the Google Play Store (Android) last week (or maybe the week before). I agree it’s going to be real hot. Would love to see support on Android too via Corona. With the speed that technology progresses I’m a little worried that over time 2D games will become less popular, Augmented Reality is a step in the right direction!!

I guess 3D is way out of scope (?) but I’d love to see that supported eventually too.  Doesn’t have to be 3D photorealistic worlds, just 3D geometry like in the apps Hocus (over 5 million installs) and Monument Valley (over 1 million installs). Hopefully might be a possibility in the long term?  I guess with enough math it might be a possibility now, but we love Corona for its ease of use and speed of development!

Ah I missed iOS only - that’s crap…

Agreed this should be cross platform at the very least - after all Android devices have had cameras for like as long as iOS devices.

Link real time camera view with Google maps API/GPS and then the combo is very powerful!

I agree AR is a powerful incentive for future development.

It’s just a shame that Corona is resource-constrained… 

Yes we need this for Android, I think the Android API has matured alot since this was last looked at, and that there is more of a chance of getting it done now from a technical perspective.  iOS cameras are easier to subclass, so camera source fill has been working on iOS for a long time.  Of all the things that would help Corona gain wider use, I think this is the biggest one… Ready Player One is out this coming weeked!

As 80% of my income comes from Android I can only agree.

Android is no longer the second best… it surpasses iOS in all metrics by some (considerable) margin.

I’ll watch Tomb Raider this week then next week is Player One for sure!

Is it possible to make that camera fill thing a plugin or is it something that can only be done by Corona team?

I do not believe it’s possible to push a video feed to an OpenGL texture from our current plugin structure.

Rob

Some time ago  kilopop mentioned Vuforia and every now and then I’ve thought about putting a binding together. (If I had seen this conversation a week ago I’d have hit up their booth at GDC.) It does seem to provide accessors that could be piped into an external texture, although that entails the cost of an upload. (On desktop this is enough to play a VLC stream without a hitch, even after swizzling the color components, but I can’t speak for mobile.) I don’t know if the price of the middleware would scare off too many users to be worth it, though (for similar reasons I held off on FMOD).

@bgmadclown I did make a proposal that I feel would open up such plugins. A bit rough now and I could probably iterate on what I wrote. The main trouble spot is the timing, i.e. when the rendering happens. Then again, in this case maybe it wouldn’t offer any advantage over the aforementioned upload.

@John_M I have a “basic 3D” plugin (also using external textures) but have basically sat on it for the last year and then some, since it flushes out a nasty simulator crash after some random number of relaunches on Windows 7. That said, perhaps I could just put a caveat for that environment and submit anyway. I was planning to finally send off something else, so I might be in the frame of mind for it soon.

Even though I was the one telling you about the pricing “problem” with FMOD i’d still love seeing this become a reality. Those with ambitions above 2 week sparetime projects may still qualify for the free FMOD license as you can’t develop many quality games in a year, well at least not if you’re a tiny team with no real budget. Hell even with smaller games it’s at least one a year. Some games may not benefit from any advances sound features but others might.

@Michael Flad
Aren’t the sounds in fmod only 99 cents each? Is there a different pricing problem with fmod? I guess we’d need a plugin for fmod though?

@StarCrunch
I’d love to see what the basic 3d plugin could do. If users would have simulator problems maybe we could just do live builds?

FMod ist not (primarily) about sounds but about the core code/engine you have to buy a license for. If you’re a small indie dev (<$500k a year) you can use FMOD for free for one game every 12 months, for each additional license in a year you’d have to pay $2000.

Some time ago (I have no idea when it changed, might be quite some years) they used to offer indie licenses at $100 which was a fantastic deal.

A hocus-clone wouldn’t need 3D, just isometric 2D.

I used it circa 2000 for a win32 title w the $100 indie license. the free-indie terms have changed over time too - iirc, at one time it was $100k/yr revenue cap, the current $500k/yr is a dev-budget cap

Yeah, I’ve still a project on my harddrive with a fsound.dll back from 1999 :slight_smile: That game actually also used Lua, iirc, 3.2 with it’s tag methods (which I quite liked back then). You’re right wrt to the dev budget but I’d say, once your in that dimensions it kind of doesn’t matter. You either need some advanced audio features and you’ll happily pay $2k for these or … well you’re probably just releasing low spec games anyway

agree completely - you’d likely have to be paying salaries to reach that point (fe, i’ve never seen a Corona-built app that looked like it had anywhere near $500k in “asset cost”), so you ought to be considered a “real business” at that point, another $2k for “tools” shouldn’t matter. (which i suspect matches fmod’s reasoning)

got you beat by 0.1!  :smiley:

(doubt any code still retrievable, only “proof” to offer was discovering a bug in 3.1’s math.random, fixed in 3.2, search for “bollinger” here:  https://github.com/lua/lua/blob/master/bugs))

Good point, I guess that would be considered isometric 2D. I’ll study up some more on that. I guess I had in mind a hocus-like world that you could rotate around to see from different sides by swiping on it or rotating it around with your fingers. Would that require 3D? Is that possible in Corona? I admit I don’t know enough about graphics rendering to pull that off without built-in functions :slight_smile:

Yes, the easiest way to do that would be with a 3D engine.  In theory, you could do all the calculations yourself and appropriately create/define the mesh or polygon, but that would slow and painful, as well as liable to display artifacts due to slight rounding errors.

https://docs.coronalabs.com/guide/graphics/path.html#paths