remove kmMat4 in Director.cpp

This commit is contained in:
Huabing.Xu 2014-04-10 17:36:47 +08:00
parent 4e0be639a2
commit 84cf5ca895
1 changed files with 33 additions and 33 deletions

View File

@ -288,8 +288,7 @@ void Director::drawScene()
pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
// global identity matrix is needed... come on kazmath! // global identity matrix is needed... come on kazmath!
kmMat4 identity; Matrix identity = Matrix::identity();
kmMat4Identity(&identity);
// draw the scene // draw the scene
if (_runningScene) if (_runningScene)
@ -606,6 +605,7 @@ void Director::setProjection(Projection projection)
switch (projection) switch (projection)
{ {
case Projection::_2D: case Projection::_2D:
{
loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 #if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
if(getOpenGLView() != nullptr) if(getOpenGLView() != nullptr)
@ -613,17 +613,18 @@ void Director::setProjection(Projection projection)
multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, getOpenGLView()->getOrientationMatrix()); multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, getOpenGLView()->getOrientationMatrix());
} }
#endif #endif
kmMat4 orthoMatrix; Matrix orthoMatrix;
kmMat4OrthographicProjection(&orthoMatrix, 0, size.width, 0, size.height, -1024, 1024); Matrix::createOrthographicOffCenter(0, size.width, 0, size.height, -1024, 1024, &orthoMatrix);
multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix); multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix);
loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
break; break;
}
case Projection::_3D: case Projection::_3D:
{ {
float zeye = this->getZEye(); float zeye = this->getZEye();
kmMat4 matrixPerspective, matrixLookup; Matrix matrixPerspective, matrixLookup;
loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
@ -636,16 +637,12 @@ void Director::setProjection(Projection projection)
} }
#endif #endif
// issue #1334 // issue #1334
kmMat4PerspectiveProjection(&matrixPerspective, 60, (GLfloat)size.width/size.height, 10, zeye+size.height/2); Matrix::createPerspective(60, (GLfloat)size.width/size.height, 10, zeye+size.height/2, &matrixPerspective);
// kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, 0.1f, 1500);
multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, matrixPerspective); multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, matrixPerspective);
kmVec3 eye, center, up; Vector3 eye(size.width/2, size.height/2, zeye), center(size.width/2, size.height/2, 0.0f), up(0.0f, 1.0f, 0.0f);
kmVec3Fill(&eye, size.width/2, size.height/2, zeye); Matrix::createLookAt(eye, center, up, &matrixLookup);
kmVec3Fill(&center, size.width/2, size.height/2, 0.0f);
kmVec3Fill(&up, 0.0f, 1.0f, 0.0f);
kmMat4LookAt(&matrixLookup, &eye, &center, &up);
multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, matrixLookup); multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, matrixLookup);
loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
@ -720,12 +717,14 @@ void Director::setDepthTest(bool on)
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
} }
static void GLToClipTransform(kmMat4 *transformOut) static void GLToClipTransform(Matrix *transformOut)
{ {
if(nullptr == transformOut) return;
Director* director = Director::getInstance(); Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
kmMat4 projection; Matrix projection;
projection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); projection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 #if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
@ -733,43 +732,45 @@ static void GLToClipTransform(kmMat4 *transformOut)
kmMat4Multiply(&projection, Director::getInstance()->getOpenGLView()->getReverseOrientationMatrix(), &projection); kmMat4Multiply(&projection, Director::getInstance()->getOpenGLView()->getReverseOrientationMatrix(), &projection);
#endif #endif
kmMat4 modelview; Matrix modelview;
modelview = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); modelview = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmMat4Multiply(transformOut, &projection, &modelview); *transformOut = projection * modelview;
} }
Point Director::convertToGL(const Point& uiPoint) Point Director::convertToGL(const Point& uiPoint)
{ {
kmMat4 transform; Matrix transform;
GLToClipTransform(&transform); GLToClipTransform(&transform);
kmMat4 transformInv; Matrix transformInv;
kmMat4Inverse(&transformInv, &transform); transform.invert(&transformInv);
// Calculate z=0 using -> transform*[0, 0, 0, 1]/w // Calculate z=0 using -> transform*[0, 0, 0, 1]/w
kmScalar zClip = transform.mat[14]/transform.mat[15]; float zClip = transform.m[14]/transform.m[15];
Size glSize = _openGLView->getDesignResolutionSize(); Size glSize = _openGLView->getDesignResolutionSize();
kmVec3 clipCoord = {2.0f*uiPoint.x/glSize.width - 1.0f, 1.0f - 2.0f*uiPoint.y/glSize.height, zClip}; Vector4 clipCoord(2.0f*uiPoint.x/glSize.width - 1.0f, 1.0f - 2.0f*uiPoint.y/glSize.height, zClip, 1);
kmVec3 glCoord; Vector4 glCoord;
kmVec3TransformCoord(&glCoord, &clipCoord, &transformInv); //transformInv.transformPoint(clipCoord, &glCoord);
transformInv.transformVector(clipCoord, &glCoord);
return Point(glCoord.x, glCoord.y); float factor = 1.0/glCoord.w;
return Point(glCoord.x * factor, glCoord.y * factor);
} }
Point Director::convertToUI(const Point& glPoint) Point Director::convertToUI(const Point& glPoint)
{ {
kmMat4 transform; Matrix transform;
GLToClipTransform(&transform); GLToClipTransform(&transform);
kmVec3 clipCoord; Vector4 clipCoord;
// Need to calculate the zero depth from the transform. // Need to calculate the zero depth from the transform.
kmVec3 glCoord = {glPoint.x, glPoint.y, 0.0}; Vector4 glCoord(glPoint.x, glPoint.y, 0.0, 1);
kmVec3TransformCoord(&clipCoord, &glCoord, &transform); transform.transformVector(glCoord, &clipCoord);
Size glSize = _openGLView->getDesignResolutionSize(); Size glSize = _openGLView->getDesignResolutionSize();
return Point(glSize.width*(clipCoord.x*0.5 + 0.5), glSize.height*(-clipCoord.y*0.5 + 0.5)); float factor = 1.0/glCoord.w;
return Point(glSize.width*(clipCoord.x*0.5 + 0.5) * factor, glSize.height*(-clipCoord.y*0.5 + 0.5) * factor);
} }
const Size& Director::getWinSize(void) const const Size& Director::getWinSize(void) const
@ -1074,8 +1075,7 @@ void Director::showStats()
} }
// global identity matrix is needed... come on kazmath! // global identity matrix is needed... come on kazmath!
kmMat4 identity; Matrix identity = Matrix::identity();
kmMat4Identity(&identity);
_drawnVerticesLabel->visit(_renderer, identity, false); _drawnVerticesLabel->visit(_renderer, identity, false);
_drawnBatchesLabel->visit(_renderer, identity, false); _drawnBatchesLabel->visit(_renderer, identity, false);