当前位置:编程学习 > wap >>

ios 全景浏览效果demo

demo功能:全景浏览 效果,可上下左右前后转动浏览。

demo说明:项目中pano.jpg 是贴图 。将这个图贴到球型模型上,摄像机设定为球的中心点,在内向球外观看贴图。

demo截屏:

 

\\

 


demo主要代码:plview.m部分(显示全景的view)


[csharp]
#import "PLView.h"  
 
@interface PLView () 
 
- (void)initializeValues; 
 
@end 
 
@implementation PLView 
 
@synthesize type; 
@synthesize camera; 
 
#pragma mark - 
#pragma mark init methods  
 
- (void)allocAndInitVariables 

    [super allocAndInitVariables]; 
    scene = [PLScene scene]; 
    renderer = [PLRenderer rendererWithView:self scene:[scene retain]]; 
    camera = [PLCamera camera]; 

 
- (void)initializeValues 

    [super initializeValues]; 
    textures = [[NSMutableArray array] retain]; 
    type = PLViewTypeUnknown; 

 
- (void)reset 

    if(camera) 
        [camera reset]; 
    [super reset]; 

 
#pragma mark - 
#pragma mark property methods  
 
- (void)setType:(PLViewType)value 

    type = value; 
    if(sceneElement) 
        [sceneElement release]; 
     
    switch (value) { 
        case PLViewTypeCylindrical: 
            camera.fovFactorRange = PLRangeMake(kDefaultCylinderFovFactorMinValue, kDefaultCylinderFovFactorMaxValue); 
            sceneElement = [PLCylinder cylinder]; 
            break; 
        case PLViewTypeSpherical: 
            camera.fovFactorRange = PLRangeMake(kDefaultFovFactorMinValue, kDefaultFovFactorMaxValue); 
            sceneElement = [PLSphere sphere]; 
            break; 
        case PLViewTypeCubeFaces: 
            camera.fovFactorRange = PLRangeMake(kDefaultFovFactorMinValue, kDefaultFovFactorMaxValue); 
            sceneElement = [PLCube cube]; 
            break; 
        case PLViewTypeUnknown: 
            sceneElement = nil; 
            break; 
        default: 
            [NSException raise:@"Invalid panorama type" format:@"Type unknown", nil]; 
            break; 
    } 
     
    if(sceneElement) 
    { 
        sceneElement = [sceneElement retain]; 
        for(PLTexture * texture in textures) 
            [sceneElement addTexture:texture]; 
        [scene addElement:sceneElement]; 
    } 

 
#pragma mark - 
#pragma mark draw methods  
 
- (void)drawView  
{     
    [super drawView]; 
 
    [sceneElement clonePropertiesOf:camera]; 
    [scene.currentCamera cloneCameraProperties:camera]; 
    scene.currentCamera.rotation = PLRotationMake(0.0f, 0.0f, 0.0f); 
    scene.currentCamera.position = PLPositionMake(0.0f, 0.0f, 0.0f); 
     
    if(!isValidForFov && !isValidForOrientation) 
        [sceneElement rotateWithStartPoint:startPoint endPoint:endPoint sensitivity:camera.rotateSensitivity]; 
    [renderer render]; 
 
    camera.rotation = PLRotationMake(sceneElement.pitch, sceneElement.yaw, sceneElement.roll);   

 
#pragma mark - 
#pragma mark fov methods  
 
- (BOOL)calculateFov:(NSSet *)touches 

    if([super calculateFov:touches]) 
    { 
        [camera addFovWithDistance:fovDistance]; 
        [scene.currentCamera addFovWithDistance:fovDistance]; 
        return YES; 
    } 
    return NO; 

 
#pragma mark - 
#pragma mark texture methods  
 
- (void)addTexture:(PLTexture *)texture 

    [textures addObject:texture]; 
    if(sceneElement) 
        [sceneElement addTexture:texture]; 

                 
- (void)removeTexture:(PLTexture *)texture 

    [textures removeObject:texture]; 
    if(sceneElement) 
        [sceneElement removeTexture:texture]; 

                 
- (void)removeTextureAtIndex:(NSUInteger) index 

    [textures removeObjectAtIndex:index]; 
    if(sceneElement) 
        [sceneElement removeTextureAtIndex:index]; 

                 
- (void)removeAllTextures 

    [textures removeAllObjects]; 
    if(sceneElement) 
        [sceneElement removeAllTextures]; 

 
#pragma mark - 
#pragma mark orientation methods &n

补充:移动开发 , IOS ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,