demo功能:全景瀏覽 效果,可上下左右前後轉動瀏覽。
demo說明:項目中pano.jpg 是貼圖 。將這個圖貼到球型模型上,攝像機設定為球的中心點,在內向球外觀看貼圖。
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
demo:http://download.csdn.net/detail/donny_zhang/5552467