我正在开发一个增强现实应用程序。我需要在此应用程序上添加立体视觉以与纸板一起使用,但我没有在此代码上添加立体视觉。有人能帮我吗?我有三个班,我在其中放立体镜,怎么做?
public class ARSimpleApplication extends Application {
private static Application sInstance;
// Anywhere in the application where an instance is required, this method
// can be used to retrieve it.
public static Application getInstance() {
return sInstance;
}
@Override
public void onCreate() {
super.onCreate();
sInstance = this;
((ARSimpleApplication) sInstance).initializeInstance();
}
// Here we do one-off initialisation which should apply to all activities
// in the application.
protected void initializeInstance() {
// Unpack assets to cache directory so native library can read them.
// N.B.: If contents of assets folder changes, be sure to increment the
// versionCode integer in the AndroidManifest.xml file.
AssetHelper assetHelper = new AssetHelper(getAssets());
assetHelper.cacheAssetFolder(getInstance(), "Data");
}
}
public class ARSimple extends ARActivity {
private static final int MY_PERMISSIONS_REQUEST_CAMERA = 133;
/**
* A custom renderer is used to produce a new visual experience.
*/
private SimpleRenderer simpleRenderer = new SimpleRenderer();
/**
* The FrameLayout where the AR view is displayed.
*/
private FrameLayout mainLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainLayout = (FrameLayout)this.findViewById(R.id.mainLayout);
//if (!checkCameraPermission()) {
//if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { //ASK EVERY TIME - it's essential!
// ActivityCompat.requestPermissions(this,
// new String[]{Manifest.permission.CAMERA},
// MY_PERMISSIONS_REQUEST_CAMERA);
//}
// When the screen is tapped, inform the renderer and vibrate the phone
mainLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
simpleRenderer.click();
Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vib.vibrate(40);
}
});
}
/**
* Provide our own SimpleRenderer.
*/
@Override
protected ARRenderer supplyRenderer() {
if (!checkCameraPermission()) {
Toast.makeText(this, "No camera permission - restart the app", Toast.LENGTH_LONG).show();
return null;
}
return new SimpleRenderer();
}
/**
* Use the FrameLayout in this Activity's UI.
*/
@Override
protected FrameLayout supplyFrameLayout() {
return (FrameLayout)this.findViewById(R.id.mainLayout);
}
private boolean checkCameraPermission() {
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_CAMERA: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show();
return;
}
}
}
}
public class SimpleRenderer extends ARRenderer {
private int markerID = -1;
private Cube cube = new Cube(40.0f, 0.0f, 0.0f, 20.0f);
private float angle = 0.0f;
private boolean spinning = false;
@Override
public boolean configureARScene() {
markerID = ARToolKit.getInstance().addMarker("single;Data/patt.hiro;80");
if (markerID < 0) return false;
return true;
}
public void click() {
spinning = !spinning;
}
public void draw(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadMatrixf(ARToolKit.getInstance().getProjectionMatrix(), 0);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glFrontFace(GL10.GL_CW);
gl.glMatrixMode(GL10.GL_MODELVIEW);
if (ARToolKit.getInstance().queryMarkerVisible(markerID)) {
gl.glLoadMatrixf(ARToolKit.getInstance().queryMarkerTransformation(markerID), 0);
gl.glPushMatrix();
gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
cube.draw(gl);
gl.glPopMatrix();
if (spinning) angle += 5.0f;
}
}
}