360°全景图展示

首先,感谢一下这位哥们的文章        http://blog.csdn.net/weiming8517/article/details/8793968

   官方例子:http://code.google.com/p/panoramagl-android/downloads/list

因为公司最近有这个需求,所以就研究了下这玩意。

其实很简单的,就一个类,仔细看看就会了.......

先上图:                 

1.首先看看结构   

2.然后是Manactivity类,我在之前那位哥们基础上加了几段代码,实现了 “旋转手机,自动浏览360°全景”

package com.example.panoramagldemo;


import javax.microedition.khronos.opengles.GL10;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

import com.panoramagl.PLCylindricalPanorama;
import com.panoramagl.PLIPanorama;
import com.panoramagl.PLImage;
import com.panoramagl.PLSphericalPanorama;
import com.panoramagl.PLView;
import com.panoramagl.utils.PLUtils;

public class MainActivity extends PLView
{	
	/**
	 * 控制全景图 是否可以自动旋转
	 * 	true  可以选择      false 不可以旋转
	 */
	private boolean sign=true; 
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        //调用加载全景图方法
        this.loadPanorama(0);
    }

	/**
     * This event is fired when OpenGL renderer was created
     * @param gl Current OpenGL context
     */
    @Override
	protected void onGLContextCreated(GL10 gl)
	{
    	super.onGLContextCreated(gl);
    	
    	//Add layout
    	View mainView = this.getLayoutInflater().inflate(R.layout.activity_main, null);
        this.addContentView(mainView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        
        //重要  官方这里没有给出使用示例    控制垂直方向观看角度 默认为getCamera().setPitchRange(-90,90); 
        //可设定getCamera().setPitchRange(-30,30);等有一定仰俯视角度的观看效果  这里设置为上下不可滑动
       // getCamera().setPitchRange(0,0); 
      //取消放大缩小
		//getCamera().setFovEnabled(false);
        
      
        
        /*//Zoom controls  缩放控制
        ZoomControls zoomControls = (ZoomControls)mainView.findViewById(R.id.zoomControls);
        zoomControls.setOnZoomInClickListener(new OnClickListener()
        {	
			@Override
			public void onClick(View view)
			{
				getCamera().zoomIn(true);
			}
		});
        zoomControls.setOnZoomOutClickListener(new OnClickListener()
        {	
			@Override
			public void onClick(View view)
			{
				getCamera().zoomOut(true);
			}
		});*/
	}
    
    /**load methods*/
    
    /**
     * Load panorama image manually
     * @param index Spinner position where 0 = spherical, 1 = spherical2, 2 = cubic, 3 = cylindrical
     */
    private void loadPanorama(int index)
    {
    	GL10 gl = this.getCurrentGL();
    	PLIPanorama panorama = null;
    	//Lock panoramic view
    	this.setBlocked(true);
    	//Spherical panorama example (supports up 1024x512 texture)  球体全景例子 1024*512贴图
        if(index == 0)
        {
        	//gl.glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
            panorama = new PLSphericalPanorama();
            ((PLSphericalPanorama)panorama).setImage(gl, PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.drawable.a), false));
            
        }
        //Spherical2 panorama example (only support 2048x1024 texture)  球体全景例子  2048*1024贴图
       /*
        else if(index == 1)
        {
        	panorama = new PLSpherical2Panorama();
            ((PLSpherical2Panorama)panorama).setImage(gl, PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.pano_sphere2), false));
        }
        //Cubic panorama example (supports up 1024x1024 texture per face)  立方体全景例子  需每个面的贴图都是1024*1024
        else if(index == 2)
        {
        	PLCubicPanorama cubicPanorama = new PLCubicPanorama();
        	cubicPanorama.setImage(gl, PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.pano_f), false), PLCubeFaceOrientation.PLCubeFaceOrientationFront);
        	cubicPanorama.setImage(gl, PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.pano_b), false), PLCubeFaceOrientation.PLCubeFaceOrientationBack);
        	cubicPanorama.setImage(gl, PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.pano_l), false), PLCubeFaceOrientation.PLCubeFaceOrientationLeft);
        	cubicPanorama.setImage(gl, PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.pano_r), false), PLCubeFaceOrientation.PLCubeFaceOrientationRight);
        	cubicPanorama.setImage(gl, PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.pano_u), false), PLCubeFaceOrientation.PLCubeFaceOrientationUp);
        	cubicPanorama.setImage(gl, PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.pano_d), false), PLCubeFaceOrientation.PLCubeFaceOrientationDown);
            panorama = cubicPanorama;
        }*/
        //Cylindrical panorama example (supports up 1024x1024 texture)  柱形全景例子 需提供1024*1024贴图
        else if(index == 3)
        {
        	PLCylindricalPanorama cylindricalPanorama = new PLCylindricalPanorama();
        	cylindricalPanorama.setHeightCalculated(false);
        	cylindricalPanorama.getCamera().setPitchRange(0.0f, 0.0f);
        	cylindricalPanorama.setImage(gl, PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.a), false));
            panorama = cylindricalPanorama;
        }
        
        //Add a hotspot  添加热点
       // panorama.addHotspot(new PLHotspot((kHotspotIdMin + Math.abs(random.nextInt()) % ((kHotspotIdMax + 1) - kHotspotIdMin)), PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.hotspot), false), 0.0f, 0.0f, 0.08f, 0.08f));
        //Load panorama
        this.reset();
        this.setPanorama(panorama);
        //为True的时候可以自动旋转
        if(sign){
	        this.startSensorialRotation();        
	//        this.activateOrientation();
	        this.activateAccelerometer();
	//        this.activateMagnetometer();
	//        this.activateGyroscope();
			this.setAccelerometerEnabled(true);
	    	this.setAccelerometerInterval(0.033f);
	    	this.setAccelerometerSensitivity(10.0f);
	    	this.setAccelerometerLeftRightEnabled(true);
	    	this.setAccelerometerUpDownEnabled(false);
    	}else{
    		this.setAccelerometerEnabled(false);
    	}
        //Unlock panoramic view  
        this.setBlocked(false);
    }
}


 

 再次感谢那位哥......

Demo下载地址点击打开链接

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值