Public Member Functions | Static Public Member Functions | Properties

CC3ViewportManager Class Reference

CC3ViewportManager manages the GL viewport and device orientation for the 3D world, including handling coordinate system rotation based on the device orientation, and conversion of locations and points between the 3D and 2D coordinate systems. More...

#import <CC3World.h>

Collaboration diagram for CC3ViewportManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

(CGPoint) - cc2PointFromGLPoint:
(void) - closeViewport
(CGPoint) - glPointFromCC2Point:
(id) - initOnWorld:
(void) - openViewport
(void) - updateBounds:withDeviceOrientation:

Static Public Member Functions

(id) + viewportManagerOnWorld:

Properties

CC3GLMatrixdeviceRotationMatrix
BOOL isFullScreen
CGRect layerBounds
CGRect layerBoundsLocal
CC3Viewport viewport

Detailed Description

CC3ViewportManager manages the GL viewport and device orientation for the 3D world, including handling coordinate system rotation based on the device orientation, and conversion of locations and points between the 3D and 2D coordinate systems.


Member Function Documentation

- (CGPoint) cc2PointFromGLPoint: (CGPoint)  glPoint

Converts the specified point, which is in the coordinate system of the 3D GL environment, into the coordinate system used by the cocos2d layer, taking into consideration the size and position of the layer/viewport, and the orientation of the device.

The cocos2d layer coordinates are relative, and measured from the bottom-left corner of the layer, which might be rotated relative to the device orientation, and which might not be in the corner of the UIView or screen.

The GL cocordinates are absolute, relative to the bottom-left corner of the underlying UIView, which does not rotate with device orientation, is always in portait orientation, and is always in the corner of the screen.

One can think of the GL coordinates as absolute and fixed relative to the portrait screen, and the layer coordinates as relative to layer position and size, and device orientation.

- (void) closeViewport

Template method that closes the viewport for 3D drawing.

Default implementation does nothing. The GL viewport and scissor will automatically be reset to their 2D values when CC3OpenGLES11Engine is closed by 3D world. If that behaviour is changed by the application, it may be necessary to override this method to handle changing the viewport to what the 2D world expects. In general, the 2D and 3D worlds have different viewports only when the 3D layer does not cover the window.

- (CGPoint) glPointFromCC2Point: (CGPoint)  cc2Point

Converts the specified point, which is in the coordinate system of the cocos2d layer, into the coordinate system used by the 3D GL environment, taking into consideration the size and position of the layer/viewport, and the orientation of the device.

The cocos2d layer coordinates are relative, and measured from the bottom-left corner of the layer, which might be rotated relative to the device orientation, and which might not be in the corner of the UIView or screen.

The GL cocordinates are absolute, relative to the bottom-left corner of the underlying UIView, which does not rotate with device orientation, is always in portait orientation, and is always in the corner of the screen.

One can think of the GL coordinates as absolute and fixed relative to the portrait screen, and the layer coordinates as relative to layer position and size, and device orientation.

- (id) initOnWorld: (CC3World *)  aCC3World

Initializes this instance on the specified CC3World.

- (void) openViewport

Template method that opens the viewport for 3D drawing.

Sets the GL viewport to the contained viewport, and if the viewport does not cover the screen, applies GL scissors to the viewport so that GL drawing for this world does not extend beyond the layer bounds.

- (void) updateBounds: (CGRect)  bounds
withDeviceOrientation: (ccDeviceOrientation)  deviceOrientation 

Using the specified view bounds and deviceOrientation, updates the GL viewport and the device rotation matrix, and establishes conversion mappings between GL points and cocos2d points, in both directions.

These conversion mappings are used by the complimentary methods glPointFromCC2Point: and cc2PointFromGLPoint:.

The viewport is set to match the specified bounds.

The device rotation matrix is calculated from the angle of rotation associated with each device orientation.

This method is invoked automatically by the CC3Layer when the orientation of the device changes. Usually, the application never needs to invoke this method directly.

+ (id) viewportManagerOnWorld: (CC3World *)  aCC3World

Allocates and initializes an autoreleased instance on the specified CC3World.


Property Documentation

- (CC3GLMatrix *) deviceRotationMatrix [read, write, retain]

A rotation matrix to hold the transform required to align with the current device orientation.

The rotation matrix is updated automatically whenever the device orientation changes.

- (BOOL) isFullScreen [read, assign]

Returns whether the viewport covers the full screen.

- (CGRect) layerBounds [read, assign]

The bounding box of the CC3Layer the world is drawing within.

- (CGRect) layerBoundsLocal [read, assign]

The bounding box of the CC3Layer the world is drawing within, in coordinates local to the layer itself.

The origin of the returned rectangle will be {0, 0}, and the size will be the same as the rectangle returned by the layerBounds property.

- (CC3Viewport) viewport [read, assign]

The viewport used by the 3D world.


The documentation for this class was generated from the following file: