-
Notifications
You must be signed in to change notification settings - Fork 0
Chaance Graves Project 3
This app will track the position of the Moon via a 3D rendering and would be able to update information to the User such as (Ecliptic Latitude and Longitude, Phase, and distance in km). A Javascript based program was written in conjuction with obtaining the aforementionded values. From there it will be able to allow the user to open the camera screen to get an accurate representation of the location of the moon basesd's on the calculator's results. This app would be useful for any astronomy enthusiast or anybody wanting to get a sense of where the Moon can be agorithmatically.
- Augmented Reality with Camera API and OpenGL ES2.
- WebView application.
- GPS location of the device.
- Orientation sensor API.
Below is the classes used for CameraView and CameraProjectActivity. These classes in particualar were responsible for handling the the Surface view rendering of the Sphere when the camera is open.
package com.test;
import java.io.IOException;
import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.SurfaceHolder.Callback;
public class CameraView extends SurfaceView implements Callback {
private Camera camera;
public CameraView( Context context ) {
super( context );
// We're implementing the Callback interface and want to get notified
// about certain surface events.
getHolder().addCallback( this );
// We're changing the surface to a PUSH surface, meaning we're receiving
// all buffer data from another component - the camera, in this case.
getHolder().setType( SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS );
}
public void surfaceCreated( SurfaceHolder holder ) {
// Once the surface is created, simply open a handle to the camera hardware.
camera = Camera.open();
}
public void surfaceChanged( SurfaceHolder holder, int format, int width, int height ) {
// This method is called when the surface changes, e.g. when it's size is set.
// We use the opportunity to initialize the camera preview display dimensions.
Camera.Parameters p = camera.getParameters();
p.setPreviewSize( width, height );
camera.setParameters( p );
// We also assign the preview display to this surface...
try {
camera.setPreviewDisplay( holder );
} catch( IOException e ) {
e.printStackTrace();
}
// ...and start previewing. From now on, the camera keeps pushing preview
// images to the surface.
camera.startPreview();
}
public void surfaceDestroyed( SurfaceHolder holder ) {
// Once the surface gets destroyed, we stop the preview mode and release
// the whole camera since we no longer need it.
camera.stopPreview();
camera.release();
camera = null;
}
}package com.test;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View;
import android.content.Intent;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.content.Context;
import android.view.MotionEvent;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class CameraProjectActivity extends Activity{
/** Called when the activity is first created. */
//@Override
private TextView text, text1, text2,text3, text4, text5;
public void onCreate( Bundle savedInstanceState ) {
// Next, we disable the application's title bar...
requestWindowFeature( Window.FEATURE_NO_TITLE );
// ...and the notification bar. That way, we can use the full screen.
getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN );
super.onCreate(savedInstanceState);
setContentView(R.layout.cameraview);
// Now let's create an OpenGL surface.
GLSurfaceView glView = new GLSurfaceView( this );
// To see the camera preview, the OpenGL surface has to be created translucently.
// See link above.
glView.setEGLConfigChooser( 8, 8, 8, 8, 16, 0 );
glView.getHolder().setFormat( PixelFormat.TRANSLUCENT );
// The renderer will be implemented in a separate class, GLView, which I'll show next.
glView.setRenderer( new GLClearRenderer() );
// Now set this as the main view.
setContentView( glView );
// Now also create a view which contains the camera preview...
CameraView cameraView = new CameraView( this );
// ...and add it, wrapping the full screen size.
addContentView( cameraView, new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT ) );
// You can use a Framelayout to hold the surfaceview
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(glView);
// Here we declare the parameters to be seen on the screen with the 3D rendered model.
//text = (TextView) findViewById(R.id.distance);
//text1 = (TextView) findViewById(R.id.ecliptic_lat);
//text2 = (TextView) findViewById(R.id.ecliptic_long);
//text3 = (TextView) findViewById(R.id.distance);
//text4 = (TextView) findViewById(R.id.distance);
//text5 = (TextView) findViewById(R.id.distance);
// Then create a layout to hold everything, for example a RelativeLayout
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.addView(frameLayout);
relativeLayout.addView(text); // show the distance in km
relativeLayout.addView(text1); // show the Ecliptic latitude of the moon.
relativeLayout.addView(text2); // show the Ecliptic longitude of the moon.
//relativeLayout.addView(text3); // Yaw?
//relativeLayout.addView(text4); // Pitch?
//relativeLayout.addView(text5); // Roll?
}
public void openCamera(View view){
Intent intent = new Intent(this, CameraProjectActivity.class);
}
- Framework for Augmented reality activity and Simple two button interface was created.
- 3D rendered sphere model was successfully created on placed on the Surfaceview of the phone screen.
- The Javascript application for calculating the defined Moon data was successfully utilized to return values.
- 2D image wrapping of sphere indicating the phases from the calculator - 8 phases can be rendered with a switch/case statement on top of the the Sphere.
- Save the data to a .txt file for the user to access in a later time.
- A more defined robust method to convert ecliptic coordinates to phone orientation data parameters. (yaw, pitch, roll)