Skip to content

Commit 66f0252

Browse files
committed
Fixing CCDirector.viewPort rect when using a 3D projection.
Former-commit-id: df3681d
1 parent 51f2d1c commit 66f0252

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

cocos2d/CCDirector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef NS_ENUM(NSUInteger, CCDirectorProjection) {
4848
CCDirectorProjectionCustom,
4949

5050
/// Detault projection is 3D projection
51-
CCDirectorProjectionDefault = CCDirectorProjection3D,
51+
CCDirectorProjectionDefault = CCDirectorProjection2D,
5252

5353
};
5454

cocos2d/CCDirector.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,22 +447,22 @@ -(CGSize)viewSizeInPixels
447447
-(CGRect)viewportRect
448448
{
449449
// TODO It's _possible_ that a user will use a non-axis aligned projection. Weird, but possible.
450-
kmMat4 projection;
451-
kmGLGetMatrix(KM_GL_PROJECTION, &projection);
452-
453-
kmMat4 projectionInv;
454-
kmMat4Inverse(&projectionInv, &projection);
450+
kmMat4 transform;
451+
GLToClipTransform(&transform);
452+
453+
kmMat4 transformInv;
454+
kmMat4Inverse(&transformInv, &transform);
455455

456456
// Calculate z=0 using -> transform*[0, 0, 0, 1]/w
457-
kmScalar zClip = projection.mat[14]/projection.mat[15];
457+
kmScalar zClip = transform.mat[14]/transform.mat[15];
458458

459459
// Bottom left and top right coordinates of viewport in clip coords.
460460
kmVec3 clipBL = {-1.0, -1.0, zClip};
461461
kmVec3 clipTR = { 1.0, 1.0, zClip};
462462

463463
kmVec3 glBL, glTR;
464-
kmVec3TransformCoord(&glBL, &clipBL, &projectionInv);
465-
kmVec3TransformCoord(&glTR, &clipTR, &projectionInv);
464+
kmVec3TransformCoord(&glBL, &clipBL, &transformInv);
465+
kmVec3TransformCoord(&glTR, &clipTR, &transformInv);
466466

467467
return CGRectMake(glBL.x, glBL.y, glTR.x - glBL.x, glTR.y - glBL.y);
468468
}

0 commit comments

Comments
 (0)