Public Member Functions | Static Public Member Functions | Properties

CC3ViewportManager Class Reference

CC3ViewportManager manages the GL viewport and device orientation for the 3D scene, 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 <CC3Scene.h>

Collaboration diagram for CC3ViewportManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Static Public Member Functions

(id) + viewportManagerOnScene:
(id) + viewportManagerOnWorld:

Properties

CC3MatrixdeviceRotationMatrix
BOOL isFullView: 1
CGRect layerBounds
CGRect layerBoundsLocal
CC3Viewport viewport

Detailed Description

CC3ViewportManager manages the GL viewport and device orientation for the 3D scene, 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 the 3D scene. 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 scene expects. In general, the 2D and 3D scenes 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) initOnScene: (CC3Scene *)  aCC3Scene

Initializes this instance on the specified CC3Scene.

- (id) initOnWorld: (CC3Scene *)  DEPRECATED_ATTRIBUTE
Deprecated:
Renamed to initOnScene:.
- (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 scene does not extend beyond the layer bounds.

- (void) populateFrom: (CC3ViewportManager *)  another

Template method that populates this instance from the specified other instance.

This method is invoked automatically during object copying via the copy or copyWithZone: method. In most situations, the application should use the copy method, and should never need to invoke this method directly.

Subclasses that add additional instance state (instance variables) should extend copying by overriding this method to copy that additional state. Superclass that override this method should be sure to invoke the superclass implementation to ensure that superclass state is copied as well.

- (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) viewportManagerOnScene: (CC3Scene *)  aCC3Scene

Allocates and initializes an autoreleased instance on the specified CC3Scene.

+ (id) viewportManagerOnWorld: (CC3Scene *)  DEPRECATED_ATTRIBUTE
Deprecated:
Renamed to viewportManagerOnScene:.

Property Documentation

- (CC3Matrix *) 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) isFullView [read, assign]

Returns whether the viewport covers the full UIView.

- (CGRect) layerBounds [read, assign]

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

- (CGRect) layerBoundsLocal [read, assign]

The bounding box of the CC3Layer the scene 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 scene.


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