Demo function: provides a panoramic view, which allows you to browse the page from top to bottom, right to back, and right.
Demo Description: In the project, pano.jpg is a texture. Place the image on the Ball Model, set the camera to the center of the ball, and view the texture on the inside ball.
Demo screenshot:
Demo main code: plview. m (display panoramic 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 sensiti.pdf: camera. rotatesensiti.pdf];
[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 sensiti.pdf: camera. rotatesensiti.pdf];
[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