Created
October 20, 2014 04:37
-
-
Save powderly/8074483408144a47e53c to your computer and use it in GitHub Desktop.
AR_View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.monyetmabuk.rajawali.tutorials.examples.general; | |
import javax.microedition.khronos.opengles.GL10; | |
import rajawali.Object3D; | |
import rajawali.animation.Animation; | |
import rajawali.animation.EllipticalOrbitAnimation3D; | |
import rajawali.lights.DirectionalLight; | |
import rajawali.materials.Material; | |
import rajawali.materials.textures.ATexture.TextureException; | |
import rajawali.materials.textures.AlphaMapTexture; | |
import rajawali.materials.textures.AnimatedGIFTexture; | |
import rajawali.materials.textures.Texture; | |
import rajawali.materials.textures.VideoTexture; | |
import rajawali.math.vector.Vector3; | |
import rajawali.primitives.Plane; | |
import rajawali.primitives.Sphere; | |
import android.content.Context; | |
import android.graphics.BitmapFactory; | |
import android.hardware.Sensor; | |
import android.hardware.SensorEventListener; | |
import android.hardware.SensorManager; | |
import android.media.MediaPlayer; | |
import android.os.Handler; | |
import android.util.Log; | |
import android.view.Gravity; | |
import android.widget.TextView; | |
import com.monyetmabuk.rajawali.tutorials.R; | |
import com.monyetmabuk.rajawali.tutorials.examples.AExampleFragment; | |
public class SkyboxFragment extends AExampleFragment{ | |
static final String TAG = "rotateDiag"; | |
private DirectionalLight mLight; | |
private Object3D mSphere; | |
private Object3D mPlane1; | |
private Object3D mPlane2; | |
private Object3D mPlane3; | |
private Object3D mPlane4; | |
private Object3D plane; | |
private Object3D video_plane; | |
public AnimatedGIFTexture mGifTexture; | |
private MediaPlayer mMediaPlayer; | |
private VideoTexture mVideoTexture; | |
@Override | |
protected AExampleRenderer createRenderer() { | |
return new SkyboxRenderer(getActivity()); | |
} | |
private final class SkyboxRenderer extends AExampleRenderer { | |
public SkyboxRenderer(Context context) { | |
super(context); | |
} | |
protected void initScene() { | |
mLight = new DirectionalLight(1f, 0.2f, -1.0f); // set the direction | |
mLight.setColor(1.0f, 1.0f, 1.0f); | |
mLight.setPower(2); | |
getCurrentScene().addLight(mLight); | |
getCurrentCamera().setFarPlane(3000); | |
try { | |
getCurrentScene().setSkybox(R.drawable.posx1, R.drawable.negx1, | |
R.drawable.posy1, R.drawable.negy1, R.drawable.posz1, | |
R.drawable.negz1); | |
} catch (TextureException e) { | |
e.printStackTrace(); | |
} | |
l //jpg textures on object3D planes | |
double[] loc2 = {0f, -.3f, -100.5f}; //midnight | |
double[] loc3 = {-50f,-.3f,-100.5f}; //l o'clock | |
double[] loc4 = {50f,-.3f,-100.5f}; // 11 o'clock | |
mPlane1=initIcon(mPlane1, loc4, "paris", R.drawable.paris); | |
mPlane2=initIcon(mPlane2, loc2, "seoul", R.drawable.seoul); | |
mPlane3=initIcon(mPlane3, loc3, "lisbon", R.drawable.lisbon); | |
mMediaPlayer = MediaPlayer.create(getContext(), | |
R.raw.melbourne); | |
mMediaPlayer.setLooping(true); | |
/*VIDEO TEXTURE*/ | |
Material video_material = new Material(); | |
video_plane = new Plane(24, 24, 6, 6, Vector3.Axis.Z); | |
video_plane.setMaterial(video_material); | |
video_plane.setRotY(-180); | |
getCurrentScene().addChild(video_plane); | |
video_plane.setPosition(0f, -.3f, 50f); | |
video_plane.setDoubleSided(true); | |
mVideoTexture = new VideoTexture("melbourne_weather", mMediaPlayer); | |
video_material.setColorInfluence(0); | |
try { | |
video_material.addTexture(mVideoTexture); | |
} catch (TextureException e) { | |
e.printStackTrace(); | |
} | |
mMediaPlayer.start(); | |
/*GIPHY TEXTURE*/ | |
Material material = new Material(); | |
plane = new Plane(24, 24, 6, 6, Vector3.Axis.Z); | |
plane.setMaterial(material); | |
plane.setRotY(-180); | |
getCurrentScene().addChild(plane); | |
plane.isTransparent(); | |
plane.setPosition(50f, -.3f, 50f); | |
plane.setDoubleSided(true); | |
try { | |
mGifTexture = new AnimatedGIFTexture("giphy_1", R.drawable.giphy_1); | |
material.addTexture(mGifTexture); | |
material.setColorInfluence(0); | |
mGifTexture.rewind(); | |
plane.setScaleX((float) mGifTexture.getWidth() / (float) mGifTexture.getHeight()); | |
} catch (TextureException e) { | |
e.printStackTrace(); | |
} | |
} | |
public Object3D initIcon(Object3D obj, double[] loc, String name, int resourceId ){ | |
try { | |
Material material = new Material(); | |
material.addTexture(new AlphaMapTexture(name, resourceId)); | |
material.setColor(0xFFFFFFFF); | |
obj = new Plane(24, 24, 6, 6, Vector3.Axis.Z); | |
obj.setMaterial(material); | |
getCurrentScene().addChild(obj); | |
} catch (TextureException e) { | |
e.printStackTrace(); | |
} | |
obj.setPosition(loc[0],loc[1],loc[2]); | |
obj.isTransparent(); | |
obj.setDoubleSided(true); | |
return obj; | |
} | |
public void onDrawFrame(GL10 glUnused) { | |
super.onDrawFrame(glUnused); | |
Log.d(TAG, "rotation=" + result[0]); | |
mPlane1.setRotY(-180); | |
mPlane2.setRotY(-180); | |
mPlane3.setRotY(mPlane3.getRotY()+.5); | |
//plane.setRotY(-180); | |
mVideoTexture.update(); | |
if(result[0]> -70 && result[0] < 70) { | |
getCurrentCamera().setRotY(result[0]); | |
getCurrentCamera().setRotX(result[1]); | |
}else if (result[0]> 70 || result[0] < -70){ | |
getCurrentCamera().setRotY(result[0]); | |
getCurrentCamera().setRotX(-result[1]); | |
} | |
if(result[0]>-1 && result[0]<10){ | |
mPlane2.setZ(-75f); | |
plane.setColor(0xFFFFFFFF); | |
}else{ | |
mPlane2.setZ(-100f); | |
plane.setColor(0xFFFF0000); | |
} | |
if(result[0]>25 && result[0]<45){ | |
mPlane1.setZ(-75f); | |
}else{ | |
mPlane1.setZ(-100f); | |
} | |
if(result[0]>-25 && result[0]<-15){ | |
mPlane3.setRotY(mPlane3.getRotY()+55);; | |
}else{ | |
mPlane3.setRotY(mPlane3.getRotY()+.5); | |
} | |
if (mGifTexture != null) { | |
try { | |
mGifTexture.update(); | |
} catch (TextureException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
public void onVisibilityChanged(boolean visible) { | |
super.onVisibilityChanged(visible); | |
if (!visible) | |
if (mMediaPlayer != null) | |
mMediaPlayer.pause(); | |
else if (mMediaPlayer != null) | |
mMediaPlayer.start(); | |
} | |
public void onSurfaceDestroyed() { | |
super.onSurfaceDestroyed(); | |
mMediaPlayer.stop(); | |
mMediaPlayer.release(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment