你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> IOS全景浏覽效果demo

IOS全景浏覽效果demo

編輯:關於IOS

demo功能:全景浏覽 效果,可上下左右前後轉動浏覽。

demo說明:項目中pano.jpg 是貼圖 。將這個圖貼到球型模型上,攝像機設定為球的中心點,在內向球外觀看貼圖。

demo截屏:

 

IOS全景浏覽效果demoIOS全景浏覽效果demo

 

 

 

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


#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  
 
- (void)orientationChanged:(UIDeviceOrientation)orientation 
{ 
    if(camera && sceneElement) 
    { 
        camera.orientation = orientation; 
        sceneElement.orientation = orientation; 
        camera.pitchRange = sceneElement.pitchRange; 
        camera.yawRange = sceneElement.yawRange; 
        camera.rollRange = sceneElement.rollRange; 
        camera.rotation = PLRotationMake(sceneElement.pitch, sceneElement.yaw, sceneElement.roll); 
    } 
} 
 
#pragma mark - 
#pragma mark dealloc methods  
 
- (void)dealloc  
{     
    if(textures) 
        [textures release]; 
    if(camera) 
        [camera release]; 
    if(sceneElement) 
        [sceneElement release]; 
    if(scene) 
        [scene release]; 
    if(renderer) 
        [renderer release]; 
    [super dealloc]; 
} 
                 
@end 

#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

- (void)orientationChanged:(UIDeviceOrientation)orientation
{
 if(camera && sceneElement)
 {
  camera.orientation = orientation;
  sceneElement.orientation = orientation;
  camera.pitchRange = sceneElement.pitchRange;
  camera.yawRange = sceneElement.yawRange;
  camera.rollRange = sceneElement.rollRange;
  camera.rotation = PLRotationMake(sceneElement.pitch, sceneElement.yaw, sceneElement.roll);
 }
}

#pragma mark -
#pragma mark dealloc methods

- (void)dealloc
{   
 if(textures)
  [textures release];
 if(camera)
  [camera release];
 if(sceneElement)
  [sceneElement release];
 if(scene)
  [scene release];
    if(renderer)
  [renderer release];
 [super dealloc];
}
    
@end
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved