您的位置:首页 > 移动开发 > Android开发

Android 360度全景图片 源码

2014-10-23 17:28 204 查看
先上张效果图



Google官方写了一个包,专门用来作全景图片的:PanoramaGL.jar。 可自己下载 http://download.csdn.net/detail/wuf1023/8073707

   设置显示图片有两种试,第一种是一整张鱼眼式的全景图片;第二种是6张图片合成

  不多说,直接上代码

public class HelloPanorama extends PLView
{
	@Override
	protected void onGLContextCreated(GL10 gl)
	{
        super.onGLContextCreated(gl);
      //If you want to use setDeviceOrientationEnabled(true), activity orientation only must be portrait. Eg. android:screenOrientation="portrait"
    	this.setDeviceOrientationEnabled(false);
    	
      //You can use accelerometer你可以用加速计
    	//this.setAccelerometerEnabled(true);
    	//this.setAccelerometerUpDownEnabled(true);
    	//this.setAccelerometerSensitivity(0.5f);
    	//this.setAccelerometerLeftRightEnabled(true);

    	//充许滚动
    	this.setScrollingEnabled(true);
    	//充许惯性
    	this.setInertiaEnabled(true);
    	//惯性灵敏度
    	this.setInertiaInterval(0.2f);

    	//旋转灵敏度
    	this.getCamera().setRotateSensitivity(100f);
    	//缩放灵敏度
    	this.getCamera().setFovSensitivity(2000);
    	//缩放范围
    	this.getCamera().setFovRange(PLRange.PLRangeMake(-5.0f, 5.0f));
    	//初始缩放
    	this.getCamera().setFov(-5f);
    	
        try
        {
        	/*
        	 * Important Note: You must edit AndroidManifest.xml and put android:configChanges="keyboardHidden|orientation" attribute in activity else you have memory problems
        	 */
	    	
	    	
	    	//Example with Sphere type (you need one image)
	    	this.setType(PLViewType.PLViewTypeSpherical);
	    	this.addTextureAndRelease(PLTexture.textureWithImage(this.getImageWithResouce(R.drawable.p01)));
	    	
	    	/*
	    	//Example with Cube Faces type (you need an image for each cube face)
	    	this.setType(PLViewType.PLViewTypeCubeFaces);
	    	this.addTextureAndRelease(PLTexture.textureWithImage(this.getImageWithResouce(R.drawable.front)));
	    	this.addTextureAndRelease(PLTexture.textureWithImage(this.getImageWithResouce(R.drawable.back)));
	    	this.addTextureAndRelease(PLTexture.textureWithImage(this.getImageWithResouce(R.drawable.left)));
	    	this.addTextureAndRelease(PLTexture.textureWithImage(this.getImageWithResouce(R.drawable.right)));
	    	this.addTextureAndRelease(PLTexture.textureWithImage(this.getImageWithResouce(R.drawable.top)));
	    	this.addTextureAndRelease(PLTexture.textureWithImage(this.getImageWithResouce(R.drawable.bottom)));
	    	*/
        }
        catch(Throwable ex)
        {
        	Log.e("HelloPanorama::onGLContextCreated", "Error:" + ex.getMessage());
        }
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: