您的位置:首页 > 移动开发 > IOS开发

[置顶] ios 全景浏览效果demo

2013-06-09 20:15 351 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: