360°全景影像移動端類庫--PanoramaGL

傳送門 ☞ 輪子的專欄 ☞ 轉載請註明 ☞ http://blog.csdn.net/leverage_1229

介紹

        本指南將介紹一個PanoramaGL 0.1類庫的簡單用法,更多的細節請簽出HelloPanoramaGL示例查看。

細節

1如何導入PanoramaGL類庫?

1.1從源代碼中導入

(1)下載PanoramaGL_0.1.zip或從代碼倉庫下載源代碼
(2)如果你下載zip文件然後解壓該文件
(3)在Eclipse中導入PanoramaGL項目:
    點擊“File”選擇“Import”菜單;
    選擇“General”目錄中的“Existing Projects into Workspace”,點擊“Next”按鈕;
    點擊“Browse”按鈕,選擇PanoramaGL項目文件夾
    點擊“Finish”按鈕。
(4)右鍵單擊你的項目並選擇“Properties”選項
(5)選擇左側面板“Android”選項
(6)找到右側面板“Library”部分,點擊“Add...”按鈕
(7)選擇“PanoramaGL”類庫,點擊“OK”按鈕
(8)在屬性窗口的右下角選擇“OK”按鈕表示接受更改

1.2從編譯後的文件中導入

(1)下載libglues.zip
(2)解壓zip文件並複製到你的項目的“libs”文件夾中
(3)下載PanoramaGL 0.1.jar
(4)複製jar文件到你的項目的“libs”文件夾中
(5)在你的項目中導入jar文件:
    右鍵單擊你的項目並選擇“Properties”選項;
    選擇左側面板“Java Build Path”選項;
    選擇“Libraries”選項卡;
    點擊“Add JARs”按鈕;
    在你的項目中選擇“libs/PanoramaGL_0.1.jar”文件;
    點擊“OK”按鈕;
    在屬性窗口的右下角選擇“OK”按鈕表示接受更改。

2在應用程序中如何使用PanoramaGL?

(1)如前面描述那樣導入類庫
(2)在“res/raw”文件夾中導入一個球面圖像(如:pano_sphere.jpg)
(3)在Activity中,你需要構建一個全景圖像的查看器,具體做法如下:
繼承PLView類
public class YourActivity extends PLView
在onCreate()方法中加載全景圖像
 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PLSphericalPanorama panorama = new PLSphericalPanorama();
    panorama.setImage(this.getCurrentGL(), PLImage.imageWithBitmap(PLUtils.getBitmap(this, R.raw.pano_sphere)));
    this.setPanorama(panorama);
}
注意:如果有必要的話,你也可以從其他方法中加載全景圖像或事件。

3簡單JSON協議

同樣,你可以使用JSON協議加載全景圖像。
注意:在該版本中,JSON協議被限制只處理本地文件。

3.1源代碼

this.load(new PLJSONLoader(this, "res://raw/json_spherical"));
注意:在我的應用程序的“res/raw”文件夾中有一個名爲“json_spherical.data”的文件,可以使用這段代碼加載。或
this.load(new PLJSONLoader(this, "file:///sdcard/files/json_spherical.data"));
注意:在Android設備的“/sdcard/files”文件夾中有一個名爲“json_spherical.data”的文件,可以使用這段代碼加載。

3.2JSON協議

{
    "urlBase": "file:///sdcard/files",  //URL base where the files are
                                        //The options are res:// for application resources and file:// for file system (this feature will be improved to support the http protocol)
    "type": "spherical",                //Panorama type: [spherical, spherical2, cubic, cylindrical]
    "sensorialRotation": false,         //Automatic rotation using sensors [true, false] <Optional>
    "scrolling":                        //Scrolling section <Optional>
    {
        "enabled": false                //Enable scrolling feature [true, false] <Optional>
    },
    "inertia":                          //Inertia section <Optional>
    {
        "enabled": false,               //Enable inertia feature [true, false] <Optional>
        "interval": 3                   //Inertia's interval in seconds <Optional>
    },
    "accelerometer":                    //Accelerometer section <Optional>
    {
        "enabled": false,               //Enable the accelerometer feature [true, false] <Optional>
        "interval": 0.033,              //Update interval of accelerometer (this value must be calculated as 1/frequency) <Optional>
        "sensitivity": 10.0,            //Sensitivity of the accelerometer <Optional>
        "leftRightEnabled": true,       //Enable the direction of movement with the accelerometer (left/right) <Optional>
        "upDownEnabled": false          //Enable the direction of movement with the accelerometer (up/down) <Optional>
    },
    "images":                           //Panoramic images section
                                        //A property can be a name e.g. preview.jpg, preview or URL e.g. file:///sdcard/files/preview.jpg, res://raw/preview
                                        //if a property only have a name, the real path will be the urlBase + image name
    {
        "preview": "preview.jpg",       //Preview image name or URL (this option will be used with http protocol) <Optional>
        "image": "pano.jpg"             //Panoramic image name or URL for spherical, spherical2 and cylindrical panoramas
        "front": "front.jpg",           //Front image name or URL for cubic panorama (only use with cubic panorama)
        "back": "back.jpg",             //Back image name or URL for cubic panorama (only use with cubic panorama)
        "left": "left.jpg",             //Left image name or URL for cubic panorama (only use with cubic panorama)
        "right": "right.jpg",           //Right image name or URL for cubic panorama (only use with cubic panorama)
        "up": "up.jpg",                 //Up image name or URL for cubic panorama (only use with cubic panorama)
        "down": "down.jpg"              //Down image name or URL for cubic panorama (only use with cubic panorama)
    },
    "camera":                           //Camera settings section <Optional>
    {
        "vlookat": 0,                   //Initial vertical position [-90, 90]
        "hlookat": 0,                   //Initial horizontal position [-180, 180]
        "atvmin": -90,                  //Min vertical position [-90, 90]
        "atvmax": 90,                   //Max vertical position [-90, 90]
        "athmin": -180,                 //Min horizontal position [-180, 180]
        "athmax": 180                   //Max horizontal position [-180, 180]
    },
    "hotspots": [                       //Hotspots section (this section is an array of hotspots) <Optional>
                 {
                 "id": 1,               //Hotspot identifier (long)
                 "atv": 0,              //Vertical position [-90, 90]
                 "ath": 0,              //Horizontal position [-180, 180]
                 "width": 0.08,         //Width
                 "height": 0.08,        //Height
                 "image": "hotspot.png" //Image name or URL
                 }
                ]
}

3.3看到

PLJSONLoader類和PLView加載方法。
json_spherical.data、json_spherical2、json_cylindrical.data和json_cubic.data都位於HelloPanoramaGL示例的“res/raw”文件夾中。

4更多信息

想獲得更多信息,請簽出HelloPanoramaGL示例,該示例運行在Android2.x或以上版本。

5效果圖

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章