HelloPanorama是由国外一名老外写的,所以很久没有更新,最近开始做全景视图,开始使用他所提供的库,将遇到的问题说明一下
首先下载HelloPanorama项目,在gitHub可以搜索到,
https://github.com/heroims/HelloPanoramaGL
下载完成后,发现这个项目是用MRC写的,然而我习惯用ARC,所以将项目中的资源文件以及库导入到我的项目中,
导入之后,进入Build Phases,设置PanoramaGL的文件为-fno-objc-arc,这样就可以在ARC项目中编译MRC的文件了,
编译一下,会发现报错了,在PLPanoramaBase.h文件中报错,
改成这样就好了
@private
PLTexture *__unsafe_unretained*previewTextures;
PLTexture *__unsafe_unretained*textures;
}
修改完成后,就可以完成显示了,根据原来项目的代码,我们可以直接拷贝,将PLView显示出来
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.title = @"全景图片";
self.view.backgroundColor = [UIColor whiteColor];
NSArray * items = @[@"球体2048x1024",@"球体1024x512",@"6面体1024x1024",@"柱形1024x1024"];
self.plView = [[PLView alloc] init];
[self.plView setFrame:self.view.frame];
self.plView.delegate = self;
self.plView.isAccelerometerEnabled = NO;
self.plView.isScrollingEnabled = YES;
self.plView.isInertiaEnabled = YES;
[self.view addSubview:self.plView];
UISegmentedControl * segmented = [[UISegmentedControl alloc]initWithItems:items];
segmented.frame = CGRectMake(5, 74, self.view.frame.size.width - 10, 40);
segmented.tintColor = [UIColor lightGrayColor];
segmented.selectedSegmentIndex = 0;
[segmented addTarget:self action:@selector(clickSegmented:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmented];
}
当UISegmentedControl值改变时,响应
- (void)clickSegmented:(UISegmentedControl *)seg{
NSObject<PLIPanorama> *panorama = nil;
switch (seg.selectedSegmentIndex) {
case 0:
//Spherical2 panorama example (supports up 2048x1024 texture 全景图 球体)
panorama = [PLSpherical2Panorama panorama];
[(PLSpherical2Panorama *)panorama setImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"1" ofType:@"jpeg"]]];
break;
case 1:
//Spherical panorama example (supports up 1024x512 texture 全景图 球体)
panorama = [PLSphericalPanorama panorama];
[(PLSphericalPanorama *)panorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"pano_sphere" ofType:@"jpg"]]]];
break;
case 2:
//Cubic panorama example (supports up 1024x1024 texture per face 6张图 6面体)
panorama = [PLCubicPanorama panorama];
[(PLCubicPanorama *)panorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"pano_f" ofType:@"jpg"]]] face:PLCubeFaceOrientationFront];
[(PLCubicPanorama *)panorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"pano_b" ofType:@"jpg"]]] face:PLCubeFaceOrientationBack];
[(PLCubicPanorama *)panorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"pano_l" ofType:@"jpg"]]] face:PLCubeFaceOrientationLeft];
[(PLCubicPanorama *)panorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"pano_r" ofType:@"jpg"]]] face:PLCubeFaceOrientationRight];
[(PLCubicPanorama *)panorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"pano_u" ofType:@"jpg"]]] face:PLCubeFaceOrientationUp];
[(PLCubicPanorama *)panorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"pano_d" ofType:@"jpg"]]] face:PLCubeFaceOrientationDown];
// panorama = cubicPanorama;
break;
case 3:
//Cylindrical panorama example (supports up 1024x1024 texture 全景图 显示为柱形)
panorama = [PLCylindricalPanorama panorama];
((PLCylindricalPanorama *)panorama).isHeightCalculated = NO;
[(PLCylindricalPanorama *)panorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"pano_sphere" ofType:@"jpg"]]]];
break;
default:
break;
}
[self.plView setPanorama:panorama];
}
这就可以将简单的全景图添加到屏幕中并显示了
如果想了解一些具体的参数含义可以参考文档
http://www.codeproject.com/Articles/60635/Panorama-iPod-Touch-iPhone !
The supported features in version 0.1 Beta are:
- Supports OpenGLES 1.1
- Tested with SDK 3.0 to 3.2
- Supports cubic, spherical and cylindrical panoramic images
- Allows scrolling and continuous scrolling
- Supports scrolling left to right and from top to bottom using the accelerometer
- Allows to use the inertia to stop scrolling
- Supports zoom in and zoom out (moving two fingers on the screen)
- Supports reset (placing three fingers on the screen)
- Allows you to control the range of rotation in the x, y and z axis
- Supports Portrait, Portrait Upside Down, Landscape Left and Landscape Right orientation using the accelerometer
- Supports for events on view
Classes Documentation
Then proceed to explain briefly the operation of the classes used:
PLView
class, this class is a view (inherits from UIView) allowing a simple set of features for power display panoramic images. The properties and methods of this class are:
- BOOL isDeviceOrientationEnabled; //If the view allows you to enable orientation of the device supports (manually, typical of the Library)
- UIDeviceOrientation deviceOrientation; //lets see what orientation has this view, or set in that we want the view orientation appears. Eg. plView.deviceOrientation=UIDeviceOrientationLandscapeLeft;
- PLOrientationSupported deviceOrientationSupported; //This property allows you to tell the view that positions of orientation is enabled and running. Eg. PlView.deviceOrientationSupported = (PLOrientationSupportedPortrait | PLOrientationSupportedLandscapeLeft) <- in this case only allows for Portrait orientation and LandscapeLeft
- BOOL isAccelerometerEnabled; //This property enables the operation of the accelerometer
- BOOL isAccelerometerLeftRightEnabled; // This property activates the accelerometer operation only in the x-axis and depends on this active property isAccelerometerEnabled
- BOOL isAccelerometerUpDownEnabled; // This property activates the accelerometer operation only in the y-axis and depends on this active property isAccelerometerEnabled
- float accelerometerSensitivity; // Set the sensitivity with which to operate the accelerometer (motion sensing)
- NSTimeInterval accelerometerInterva;l // Sets the refresh time in seconds of accelerometer
- CGPoint startPoint; // This property tells us which position he made the first touch when the event occurs (Touch Begin event)
- CGPoint endPoint; // This property will be cooling while moving the finger on the screen (Touch Move event)
- BOOL isScrollingEnabled; // This property tells us if you could make a scrolling at the hearing, if not active, only move when the fingers moving on the screen
- NSUInteger minDistanceToEnableScrolling; // Minimum distance that must be traveled with the fingers to activate the scrolling
- BOOL isInertiaEnabled; / / Check the inertia that means that when someone performs a scroll inertia is activated to slow the scroll to stop the movement
- NSTimeInterval inertiaInterval; // Duration of inertia in seconds
- BOOL isResetEnabled; // Property that can be enabled to reset the view to its original position when placing three fingers on the screen
- PLViewType type; // Type of view to be used can be (PLViewTypeSpherical, PLViewTypeCubeFaces, PLViewTypeCylindrical)
- PLCamera * camera; / / Property allows us to change or take the parameters of the camera
- - (void) addTexture: (PLTexture *) texture; // Add a texture to be used, in the case of spherical and cylindrical single view to invoke this method once, in the case of cubic view use this method six times (one texture per face)
- - (void) removeTexture: (PLTexture *) texture; // Removes an object of type texture of the view
- - (void) removeTextureAtIndex: (NSUInteger) index; // Removes an object of type texture by index of the view
- - (void) removeAllTextures; // Removes all the textures that the view can use
PLTexture class allows us to load a texture that will be used by the view, its properties and methods are:
- GLuint textureId; // read-only property giving the identifier of an OpenGL texture
- int width, height; // read-only properties for the width and height of a texture loaded
- BOOL isValid; // Property to know if the texture failed to load
- - (id) init; // Default Constructor
- - (id) initWithImage: (UIImage *) image; // Constructor that receives an object of type UIImage where an image must be loaded
- - (id) initWithImage: (UIImage *) image rotate (int) angle; // Same as the previous method but can rotate the image 90, 180, 270 degrees
- - (id) initWithPath: (NSString *) path; // Constructor that receives the image path (jpeg, png)
- - (id) initWithPath: (NSString *) path rotate (int) angle; // Same as the previous method but can rotate the image 90, 180, 270 degrees
// Constructors static type that operate with the same parameters that the init equivalent functions
- + (id) textureWithImage: (UIImage *) image;
- + (id) textureWithPath: (NSString *) path;
- + (id) textureWithImage: (UIImage *) image rotate (int) angle;
- + (id) textureWithPath: (NSString *) path rotate (int) angle;
- - (BOOL) loadTextureWithImage: (UIImage *) image; // Load a texture from an image object
- - (BOOL) loadTextureWithImage: (UIImage *) image rotate (int) angle; / / Same as the previous method but can rotate the image 90, 180, 270 degrees
- - (BOOL) loadTextureWithPath: (NSString *) path, // Load a texture from image path (jpeg, png)
- - (BOOL) loadTextureWithPath: (NSString *) path rotate (int) angle; / / Same as the previous method but can rotate the image 90, 180, 270 degrees
PLCamera class allows us to change the display settings of the hearing, their properties are:
- BOOL IsFovEnabled; // Enable zoom in or zoom out eg. plView.camera.isFovEnabled = NO;
- float fov; // zoom level for the Hearing eg. plView.camera.fov = 10;
- float fovSensitivity; // sensitivity for the zoom when you place two fingers on the screen eg.plView.camera.fovSensitivity = 70;
- PLRange fovRange; // Range in values that will allow for the default zoom from -180 to 180 eg.plView.camera.fovRange = PLRangeMake (-10.10);
- PLRange fovFactorRange; // Range in which the zoom will work internaly (This range is for internal use with fovFactor property)
- BOOL isXAxisEnabled, isYAxisEnabled, isZAxisEnabled; // This properties enabled if the camera can move in the x, y, z eg. plView.camera.isXAxisEnabled = NO;
- PLPosition position; // property to place the camera in a position. PLPosition has the property x, y, z eg.plView.camera.x = 6;
- PLRange xRange, yRange, zRange; // Define the range in which it can move in the x, y, z eg.plView.camera.xRange = PLRangeMake (-100, 100);
- BOOL isPitchEnabled, isYawEnabled, isRollEnabled; // These properties enable that axes can rotate the camera x, y, z eg. plView.camera.isPitchEnabled = NO;
- BOOL IsReverseRotation; // Enable the rotation of the camera displacement is inversely related to the user to do with the touch or accelerometer. Eg. plView.camera.isReverseRotation = YES;
- PLRotation rotation; // angles of rotation (in degrees) of the camera x, y, z eg.plView.camera.rotation.pitch = 80;
- PLRange pitchRange, yawRange, rollRange; // Range in which the camera can rotate in x, y, z eg.plView.camera.pitchRange = PLRangeMake (-90, 90); <- on the x axis can only rotate the angle - 90 to 90
- float rotateSensitivity; // value of sensitivity in which the camera will rotate when the user moves the view eg . plView.camera.rotateSensitivity = 40;
- - (void) reset; / / Lets reset the camera settings back to the original position of the camera eg.[plView.camera reset];