当前位置: 首页 > 工具软件 > PanoramaGL > 使用案例 >

android com.panoramagl应用示例,增加俯仰视角控制

金阳曜
2023-12-01

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

package com.shaoming.pano1;

import java.util.Random;

import javax.microedition.khronos.opengles.GL10;

import com.panoramagl.PLCubicPanorama;
import com.panoramagl.PLCylindricalPanorama;
import com.panoramagl.PLILoader;
import com.panoramagl.PLIPanorama;
import com.panoramagl.PLIView;
import com.panoramagl.PLImage;
import com.panoramagl.PLJSONLoader;
import com.panoramagl.PLSpherical2Panorama;
import com.panoramagl.PLSphericalPanorama;
import com.panoramagl.PLView;
import com.panoramagl.PLViewEventListener;
import com.panoramagl.enumeration.PLCubeFaceOrientation;
import com.panoramagl.hotspots.PLHotspot;
import com.panoramagl.ios.structs.CGPoint;
import com.panoramagl.structs.PLPosition;
import com.panoramagl.utils.PLUtils;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.ZoomControls;
import android.widget.AdapterView.OnItemSelectedListener;
import android.view.View.OnClickListener;

public class PanoramaActivity extends PLView
{
	/**constants*/
	
	private static final int kHotspotIdMin = 1;
	private static final int kHotspotIdMax = 1000;
	
	/**member variables*/
	
	private Random random = new Random();
	
	/**init methods*/
	
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.loadPanorama(0);
        
        this.setListener(new PLViewEventListener()
        {
        	@Override
    		public void onDidClickHotspot(PLIView pView, PLHotspot hotspot, CGPoint screenPoint, PLPosition scene3DPoint)
        	{
        		Toast.makeText(pView.getActivity(), String.format("You select the hotspot with ID %d", hotspot.getIdentifier()), Toast.LENGTH_SHORT).show();
        	}
		});
    }

	/**
     * 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.panorama_layout, null);
        this.addContentView(mainView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        
        //重要  官方这里没有给出使用示例    控制垂直方向观看角度 默认为getCamera().setPitchRange(-90,90); 
        //可设定getCamera().setPitchRange(-30,30);等有一定仰俯视角度的观看效果  这里设置为上下不可滑动
        getCamera().setPitchRange(0,0); 
        
        
        Button backButton = (Button)mainView.findViewById(R.id.panorama_back);
        backButton.setOnClickListener(new OnClickListener()
		{
			
			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				
			}
		});
        
        //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.raw.pano_sphere), 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.pano_sphere3333), 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);
        //Unlock panoramic view  
        this.setBlocked(false);
    }
}


//重要  官方这里没有给出使用示例    控制垂直方向观看角度 
        getCamera().setPitchRange(0,0);

 类似资料: