2013-07-25 17:48:22 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-05-11 12:14:17 +08:00
|
|
|
|
2013-07-25 17:48:22 +08:00
|
|
|
http://www.cocos2d-x.org
|
2014-05-11 12:14:17 +08:00
|
|
|
|
2013-07-25 17:48:22 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2014-05-11 12:14:17 +08:00
|
|
|
|
2013-07-25 17:48:22 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2014-05-11 12:14:17 +08:00
|
|
|
|
2013-07-25 17:48:22 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2016-04-18 15:09:21 +08:00
|
|
|
#include "deprecated/CCDeprecated.h"
|
|
|
|
|
|
|
|
#include "platform/CCPlatformMacros.h"
|
|
|
|
#include "math/Vec2.h"
|
|
|
|
#include "math/CCGeometry.h"
|
|
|
|
#include "base/ccTypes.h"
|
|
|
|
#include "renderer/CCGLProgram.h"
|
|
|
|
#include "2d/CCDrawingPrimitives.h"
|
|
|
|
#include "base/CCDirector.h"
|
2013-07-25 17:48:22 +08:00
|
|
|
|
|
|
|
|
2014-05-11 12:14:17 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
|
2013-07-25 17:48:22 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2015-04-20 01:40:52 +08:00
|
|
|
const Vec2 CCPointZero;
|
2013-07-25 17:48:22 +08:00
|
|
|
|
|
|
|
/* The "zero" size -- equivalent to Size(0, 0). */
|
|
|
|
const Size CCSizeZero = Size::ZERO;
|
|
|
|
|
|
|
|
/* The "zero" rectangle -- equivalent to Rect(0, 0, 0, 0). */
|
|
|
|
const Rect CCRectZero = Rect::ZERO;
|
|
|
|
|
|
|
|
|
|
|
|
const Color3B ccWHITE = Color3B::WHITE;
|
|
|
|
const Color3B ccYELLOW = Color3B::YELLOW;
|
|
|
|
const Color3B ccGREEN = Color3B::GREEN;
|
|
|
|
const Color3B ccBLUE = Color3B::BLUE;
|
|
|
|
const Color3B ccRED = Color3B::RED;
|
|
|
|
const Color3B ccMAGENTA = Color3B::MAGENTA;
|
|
|
|
const Color3B ccBLACK = Color3B::BLACK;
|
|
|
|
const Color3B ccORANGE = Color3B::ORANGE;
|
|
|
|
const Color3B ccGRAY = Color3B::GRAY;
|
|
|
|
|
2013-07-26 04:36:19 +08:00
|
|
|
const BlendFunc kCCBlendFuncDisable = BlendFunc::DISABLE;
|
2013-07-25 17:48:22 +08:00
|
|
|
|
|
|
|
const char* kCCShader_PositionTextureColor = GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR;
|
|
|
|
const char* kCCShader_PositionTextureColorAlphaTest = GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST;
|
|
|
|
const char* kCCShader_PositionColor = GLProgram::SHADER_NAME_POSITION_COLOR;
|
|
|
|
const char* kCCShader_PositionTexture = GLProgram::SHADER_NAME_POSITION_TEXTURE;
|
|
|
|
const char* kCCShader_PositionTexture_uColor = GLProgram::SHADER_NAME_POSITION_TEXTURE_U_COLOR;
|
|
|
|
const char* kCCShader_PositionTextureA8Color = GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR;
|
|
|
|
const char* kCCShader_Position_uColor = GLProgram::SHADER_NAME_POSITION_U_COLOR;
|
|
|
|
const char* kCCShader_PositionLengthTexureColor = GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR;
|
|
|
|
|
|
|
|
// uniform names
|
|
|
|
const char* kCCUniformPMatrix_s = GLProgram::UNIFORM_NAME_P_MATRIX;
|
|
|
|
const char* kCCUniformMVMatrix_s = GLProgram::UNIFORM_NAME_MV_MATRIX;
|
|
|
|
const char* kCCUniformMVPMatrix_s = GLProgram::UNIFORM_NAME_MVP_MATRIX;
|
|
|
|
const char* kCCUniformTime_s = GLProgram::UNIFORM_NAME_TIME;
|
|
|
|
const char* kCCUniformSinTime_s = GLProgram::UNIFORM_NAME_SIN_TIME;
|
|
|
|
const char* kCCUniformCosTime_s = GLProgram::UNIFORM_NAME_COS_TIME;
|
|
|
|
const char* kCCUniformRandom01_s = GLProgram::UNIFORM_NAME_RANDOM01;
|
2014-05-14 09:12:58 +08:00
|
|
|
const char* kCCUniformSampler_s = GLProgram::UNIFORM_NAME_SAMPLER0;
|
2013-07-25 17:48:22 +08:00
|
|
|
const char* kCCUniformAlphaTestValue = GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE;
|
|
|
|
|
|
|
|
// Attribute names
|
2013-07-26 08:47:42 +08:00
|
|
|
const char* kCCAttributeNameColor = GLProgram::ATTRIBUTE_NAME_COLOR;
|
|
|
|
const char* kCCAttributeNamePosition = GLProgram::ATTRIBUTE_NAME_POSITION;
|
|
|
|
const char* kCCAttributeNameTexCoord = GLProgram::ATTRIBUTE_NAME_TEX_COORD;
|
2013-07-25 17:48:22 +08:00
|
|
|
|
2013-07-25 22:38:55 +08:00
|
|
|
void ccDrawInit()
|
|
|
|
{
|
|
|
|
DrawPrimitives::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ccDrawFree()
|
|
|
|
{
|
2015-01-06 19:45:10 +08:00
|
|
|
//it will crash clang static analyzer so hide it if __clang_analyzer__ defined
|
2014-12-11 17:10:43 +08:00
|
|
|
#ifndef __clang_analyzer__
|
2013-07-25 22:38:55 +08:00
|
|
|
DrawPrimitives::free();
|
2014-12-11 17:10:43 +08:00
|
|
|
#endif
|
2013-07-25 22:38:55 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawPoint( const Vec2& point )
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawPoint(point);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawPoints( const Vec2 *points, unsigned int numberOfPoints )
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawPoints(points, numberOfPoints);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawLine( const Vec2& origin, const Vec2& destination )
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawLine(origin, destination);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawRect( Vec2 origin, Vec2 destination )
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawRect(origin, destination);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawSolidRect( Vec2 origin, Vec2 destination, Color4F color )
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawSolidRect(origin, destination, color);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawPoly( const Vec2 *vertices, unsigned int numOfVertices, bool closePolygon )
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawPoly(vertices, numOfVertices, closePolygon);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawSolidPoly( const Vec2 *poli, unsigned int numberOfPoints, Color4F color )
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawSolidPoly(poli, numberOfPoints, color);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawCircle( const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY)
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawCircle(center, radius, angle, segments, drawLineToCenter, scaleX, scaleY);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawCircle( const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter)
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawCircle(center, radius, angle, segments, drawLineToCenter);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawSolidCircle( const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY)
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawSolidCircle(center, radius, angle, segments, scaleX, scaleY);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawSolidCircle( const Vec2& center, float radius, float angle, unsigned int segments)
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawSolidCircle(center, radius, angle, segments);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawQuadBezier(const Vec2& origin, const Vec2& control, const Vec2& destination, unsigned int segments)
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawQuadBezier(origin, control, destination, segments);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ccDrawCubicBezier(const Vec2& origin, const Vec2& control1, const Vec2& control2, const Vec2& destination, unsigned int segments)
|
2013-07-25 22:38:55 +08:00
|
|
|
{
|
|
|
|
DrawPrimitives::drawCubicBezier(origin, control1, control2, destination, segments);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ccDrawCatmullRom( PointArray *arrayOfControlPoints, unsigned int segments )
|
|
|
|
{
|
|
|
|
DrawPrimitives::drawCatmullRom(arrayOfControlPoints, segments);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ccDrawCardinalSpline( PointArray *config, float tension, unsigned int segments )
|
|
|
|
{
|
|
|
|
DrawPrimitives::drawCardinalSpline(config, tension, segments);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ccDrawColor4B( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
|
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::setDrawColor4B(r, g, b, a);
|
2013-07-25 22:38:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ccDrawColor4F( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
|
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::setDrawColor4F(r, g, b, a);
|
2013-07-25 22:38:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ccPointSize( GLfloat pointSize )
|
|
|
|
{
|
|
|
|
DrawPrimitives::setPointSize(pointSize);
|
|
|
|
}
|
|
|
|
|
2014-04-21 17:37:52 +08:00
|
|
|
MATRIX_STACK_TYPE currentActiveStackType = MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW;
|
|
|
|
|
|
|
|
void CC_DLL kmGLFreeAll(void)
|
|
|
|
{
|
|
|
|
Director::getInstance()->resetMatrixStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CC_DLL kmGLPushMatrix(void)
|
|
|
|
{
|
|
|
|
Director::getInstance()->pushMatrix(currentActiveStackType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CC_DLL kmGLPopMatrix(void)
|
|
|
|
{
|
|
|
|
Director::getInstance()->popMatrix(currentActiveStackType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CC_DLL kmGLMatrixMode(unsigned int mode)
|
|
|
|
{
|
|
|
|
if(KM_GL_MODELVIEW == mode)
|
|
|
|
currentActiveStackType = MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW;
|
|
|
|
else if(KM_GL_PROJECTION == mode)
|
|
|
|
currentActiveStackType = MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION;
|
|
|
|
else if(KM_GL_TEXTURE == mode)
|
|
|
|
currentActiveStackType = MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CC_DLL kmGLLoadIdentity(void)
|
|
|
|
{
|
|
|
|
Director::getInstance()->loadIdentityMatrix(currentActiveStackType);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void CC_DLL kmGLLoadMatrix(const Mat4* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
Director::getInstance()->loadMatrix(currentActiveStackType, *pIn);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void CC_DLL kmGLMultMatrix(const Mat4* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
Director::getInstance()->multiplyMatrix(currentActiveStackType, *pIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CC_DLL kmGLTranslatef(float x, float y, float z)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 mat;
|
|
|
|
Mat4::createTranslation(Vec3(x, y, z), &mat);
|
2014-04-21 17:37:52 +08:00
|
|
|
Director::getInstance()->multiplyMatrix(currentActiveStackType, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CC_DLL kmGLRotatef(float angle, float x, float y, float z)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 mat;
|
|
|
|
Mat4::createRotation(Vec3(x, y, z), angle, &mat);
|
2014-04-21 17:37:52 +08:00
|
|
|
Director::getInstance()->multiplyMatrix(currentActiveStackType, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CC_DLL kmGLScalef(float x, float y, float z)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 mat;
|
|
|
|
Mat4::createScale(x, y, z, &mat);
|
2014-04-21 17:37:52 +08:00
|
|
|
Director::getInstance()->multiplyMatrix(currentActiveStackType, mat);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void CC_DLL kmGLGetMatrix(unsigned int mode, Mat4* pOut)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
if(KM_GL_MODELVIEW == mode)
|
|
|
|
*pOut = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
else if(KM_GL_PROJECTION == mode)
|
|
|
|
*pOut = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
|
|
|
|
else if(KM_GL_TEXTURE == mode)
|
|
|
|
*pOut = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4Fill(Mat4* pOut, const float* pMat)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pOut->set(pMat);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4Assign(Mat4* pOut, const Mat4* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pOut->set(pIn->m);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4Identity(Mat4* pOut)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
*pOut = Mat4::IDENTITY;
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4Inverse(Mat4* pOut, const Mat4* pM)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-01 01:59:36 +08:00
|
|
|
*pOut = pM->getInversed();
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4Transpose(Mat4* pOut, const Mat4* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-01 01:59:36 +08:00
|
|
|
*pOut = pIn->getTransposed();
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4Multiply(Mat4* pOut, const Mat4* pM1, const Mat4* pM2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
*pOut = (*pM1) * (*pM2);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4Translation(Mat4* pOut, const float x, const float y, const float z)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4::createTranslation(x, y, z, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4RotationX(Mat4* pOut, const float radians)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4::createRotationX(radians, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4RotationY(Mat4* pOut, const float radians)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4::createRotationY(radians, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4RotationZ(Mat4* pOut, const float radians)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4::createRotationZ(radians, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4RotationAxisAngle(Mat4* pOut, const Vec3* axis, float radians)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4::createRotation(*axis, radians, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4Scaling(Mat4* pOut, const float x, const float y, const float z)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4::createScale(x, y, z, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4PerspectiveProjection(Mat4* pOut, float fovY, float aspect, float zNear, float zFar)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4::createPerspective(fovY, aspect, zNear, zFar, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4OrthographicProjection(Mat4* pOut, float left, float right, float bottom, float top, float nearVal, float farVal)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4::createOrthographicOffCenter(left, right, bottom, top, nearVal, farVal, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4* kmMat4LookAt(Mat4* pOut, const Vec3* pEye, const Vec3* pCenter, const Vec3* pUp)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4::createLookAt(*pEye, *pCenter, *pUp, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3Fill(Vec3* pOut, float x, float y, float z)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pOut->x = x;
|
|
|
|
pOut->y = y;
|
|
|
|
pOut->z = z;
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
float kmVec3Length(const Vec3* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
return pIn->length();
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
float kmVec3LengthSq(const Vec3* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
return pIn->lengthSquared();
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
CC_DLL Vec3* kmVec3Lerp(Vec3* pOut, const Vec3* pV1, const Vec3* pV2, float t)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pOut->x = pV1->x + t * ( pV2->x - pV1->x );
|
|
|
|
pOut->y = pV1->y + t * ( pV2->y - pV1->y );
|
|
|
|
pOut->z = pV1->z + t * ( pV2->z - pV1->z );
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3Normalize(Vec3* pOut, const Vec3* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-01 01:10:18 +08:00
|
|
|
*pOut = pIn->getNormalized();
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3Cross(Vec3* pOut, const Vec3* pV1, const Vec3* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3::cross(*pV1, *pV2, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
float kmVec3Dot(const Vec3* pV1, const Vec3* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
return Vec3::dot(*pV1, *pV2);
|
2014-04-21 17:37:52 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3Add(Vec3* pOut, const Vec3* pV1, const Vec3* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3::add(*pV1, *pV2, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3Subtract(Vec3* pOut, const Vec3* pV1, const Vec3* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3::subtract(*pV1, *pV2, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3Transform(Vec3* pOut, const Vec3* pV1, const Mat4* pM)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pM->transformPoint(*pV1, pOut);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3TransformNormal(Vec3* pOut, const Vec3* pV, const Mat4* pM)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pM->transformVector(*pV, pOut);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3TransformCoord(Vec3* pOut, const Vec3* pV, const Mat4* pM)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4 v(pV->x, pV->y, pV->z, 1);
|
2014-04-21 17:37:52 +08:00
|
|
|
pM->transformVector(&v);
|
|
|
|
v = v * (1/v.w);
|
|
|
|
pOut->set(v.x, v.y, v.z);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3Scale(Vec3* pOut, const Vec3* pIn, const float s)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
*pOut = *pIn * s;
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3Assign(Vec3* pOut, const Vec3* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
*pOut = *pIn;
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3* kmVec3Zero(Vec3* pOut)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pOut->set(0, 0, 0);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2* kmVec2Fill(Vec2* pOut, float x, float y)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pOut->set(x, y);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
float kmVec2Length(const Vec2* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
return pIn->length();
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
float kmVec2LengthSq(const Vec2* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
return pIn->lengthSquared();
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2* kmVec2Normalize(Vec2* pOut, const Vec2* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-01 01:10:18 +08:00
|
|
|
*pOut = pIn->getNormalized();
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2* kmVec2Lerp(Vec2* pOut, const Vec2* pV1, const Vec2* pV2, float t)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pOut->x = pV1->x + t * ( pV2->x - pV1->x );
|
|
|
|
pOut->y = pV1->y + t * ( pV2->y - pV1->y );
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2* kmVec2Add(Vec2* pOut, const Vec2* pV1, const Vec2* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2::add(*pV1, *pV2, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
float kmVec2Dot(const Vec2* pV1, const Vec2* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
return Vec2::dot(*pV1, *pV2);
|
2014-04-21 17:37:52 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2* kmVec2Subtract(Vec2* pOut, const Vec2* pV1, const Vec2* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2::subtract(*pV1, *pV2, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2* kmVec2Scale(Vec2* pOut, const Vec2* pIn, const float s)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
*pOut = *pIn * s;
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2* kmVec2Assign(Vec2* pOut, const Vec2* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
*pOut = *pIn;
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4* kmVec4Fill(Vec4* pOut, float x, float y, float z, float w)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pOut->set(x, y, z, w);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4* kmVec4Add(Vec4* pOut, const Vec4* pV1, const Vec4* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4::add(*pV1, *pV2, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
float kmVec4Dot(const Vec4* pV1, const Vec4* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
return Vec4::dot(*pV1, *pV2);
|
2014-04-21 17:37:52 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
float kmVec4Length(const Vec4* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
return pIn->length();
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
float kmVec4LengthSq(const Vec4* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
return pIn->lengthSquared();
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4* kmVec4Lerp(Vec4* pOut, const Vec4* pV1, const Vec4* pV2, float t)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pOut->x = pV1->x + t * ( pV2->x - pV1->x );
|
|
|
|
pOut->y = pV1->y + t * ( pV2->y - pV1->y );
|
|
|
|
pOut->z = pV1->z + t * ( pV2->z - pV1->z );
|
|
|
|
pOut->w = pV1->w + t * ( pV2->w - pV1->w );
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4* kmVec4Normalize(Vec4* pOut, const Vec4* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-01 01:10:18 +08:00
|
|
|
*pOut = pIn->getNormalized();
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4* kmVec4Scale(Vec4* pOut, const Vec4* pIn, const float s)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
*pOut = *pIn * s;
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4* kmVec4Subtract(Vec4* pOut, const Vec4* pV1, const Vec4* pV2)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4::subtract(*pV1, *pV2, pOut);
|
2014-04-21 17:37:52 +08:00
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4* kmVec4Assign(Vec4* pOut, const Vec4* pIn)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
*pOut = *pIn;
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4* kmVec4MultiplyMat4(Vec4* pOut, const Vec4* pV, const Mat4* pM)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pM->transformVector(*pV, pOut);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec4* kmVec4Transform(Vec4* pOut, const Vec4* pV, const Mat4* pM)
|
2014-04-21 17:37:52 +08:00
|
|
|
{
|
|
|
|
pM->transformVector(*pV, pOut);
|
|
|
|
return pOut;
|
|
|
|
}
|
|
|
|
|
Optimize Vec3
small function Vec3 move to Vec3.inl
Added:
add(float xx, float yy, float zz);
setZero();
Change all code:
_vec3 = Vec3(x, y, z); -> _vec3.set(x, y, z);
Vec3 vec3 = Vec3(x, y, z); -> Vec3 vec3(x, y, z);
_vec3 += Vec3(x, y, z); -> _vec3.add(x, y, z);
_vec3 = Vec3::ZERO; -> _vec3.setZero();
2015-04-05 18:09:50 +08:00
|
|
|
const Vec3 KM_VEC3_NEG_Z(0, 0, -1);
|
|
|
|
const Vec3 KM_VEC3_POS_Z(0, 0, 1);
|
|
|
|
const Vec3 KM_VEC3_POS_Y(0, 1, 0);
|
|
|
|
const Vec3 KM_VEC3_NEG_Y(0, -1, 0);
|
|
|
|
const Vec3 KM_VEC3_NEG_X(-1, 0, 0);
|
|
|
|
const Vec3 KM_VEC3_POS_X(1, 0, 0);
|
|
|
|
const Vec3 KM_VEC3_ZERO(0, 0, 0);
|
|
|
|
|
|
|
|
const Vec2 KM_VEC2_POS_Y(0, 1);
|
|
|
|
const Vec2 KM_VEC2_NEG_Y(0, -1);
|
|
|
|
const Vec2 KM_VEC2_NEG_X(-1, 0);
|
|
|
|
const Vec2 KM_VEC2_POS_X(1, 0);
|
|
|
|
const Vec2 KM_VEC2_ZERO(0, 0);
|
2014-05-11 12:14:17 +08:00
|
|
|
|
2013-07-26 17:29:06 +08:00
|
|
|
NS_CC_END
|
2014-05-11 12:14:17 +08:00
|
|
|
|
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|