diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 84ef1200e097..4d3fd83a38c2 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -37,65 +37,9 @@ NS_CC_BEGIN -// Vec2 == CGPoint in 32-bits, but not in 64-bits (OS X) -// that's why the "v2f" functions are needed -static Vec2 v2fzero(0.0f,0.0f); - -static inline Vec2 v2f(float x, float y) -{ - Vec2 ret(x, y); - return ret; -} - -static inline Vec2 v2fadd(const Vec2 &v0, const Vec2 &v1) -{ - return v2f(v0.x+v1.x, v0.y+v1.y); -} - -static inline Vec2 v2fsub(const Vec2 &v0, const Vec2 &v1) -{ - return v2f(v0.x-v1.x, v0.y-v1.y); -} - -static inline Vec2 v2fmult(const Vec2 &v, float s) +static inline Tex2F v2ToTex2F(const Vec2 &v) { - return v2f(v.x * s, v.y * s); -} - -static inline Vec2 v2fperp(const Vec2 &p0) -{ - return v2f(-p0.y, p0.x); -} - -static inline Vec2 v2fneg(const Vec2 &p0) -{ - return v2f(-p0.x, - p0.y); -} - -static inline float v2fdot(const Vec2 &p0, const Vec2 &p1) -{ - return p0.x * p1.x + p0.y * p1.y; -} - -static inline Vec2 v2fnormalize(const Vec2 &p) -{ - Vec2 r(p.x, p.y); - r.normalize(); - return v2f(r.x, r.y); -} - -static inline Vec2 __v2f(const Vec2 &v) -{ -//#ifdef __LP64__ - return v2f(v.x, v.y); -// #else -// return * ((Vec2*) &v); -// #endif -} - -static inline Tex2F __t(const Vec2 &v) -{ - return *(Tex2F*)&v; + return {v.x, v.y}; } // implementation of DrawNode @@ -318,9 +262,8 @@ void DrawNode::drawPoint(const Vec2& position, const float pointSize, const Colo { ensureCapacityGLPoint(1); - V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint); - V2F_C4B_T2F a = {position, Color4B(color), Tex2F(pointSize,0)}; - *point = a; + V2F_C4B_T2F *point = _bufferGLPoint + _bufferCountGLPoint; + *point = {position, Color4B(color), Tex2F(pointSize,0)}; _customCommandGLPoint.updateVertexBuffer(point, _bufferCountGLPoint*sizeof(V2F_C4B_T2F), sizeof(V2F_C4B_T2F)); _bufferCountGLPoint += 1; @@ -337,11 +280,10 @@ void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, con { ensureCapacityGLPoint(numberOfPoints); - V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint); + V2F_C4B_T2F *point = _bufferGLPoint + _bufferCountGLPoint; for(unsigned int i=0; i < numberOfPoints; i++) { - V2F_C4B_T2F a = {position[i], Color4B(color), Tex2F(pointSize,0)}; - *(point + i) = a; + *(point + i) = {position[i], Color4B(color), Tex2F(pointSize,0)}; } _customCommandGLPoint.updateVertexBuffer(point, _bufferCountGLPoint*sizeof(V2F_C4B_T2F), numberOfPoints*sizeof(V2F_C4B_T2F)); @@ -354,13 +296,10 @@ void DrawNode::drawLine(const Vec2 &origin, const Vec2 &destination, const Color { ensureCapacityGLLine(2); - V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLLine + _bufferCountGLLine); + V2F_C4B_T2F *point = _bufferGLLine + _bufferCountGLLine; - V2F_C4B_T2F a = {origin, Color4B(color), Tex2F(0.0, 0.0)}; - V2F_C4B_T2F b = {destination, Color4B(color), Tex2F(0.0, 0.0)}; - - *point = a; - *(point+1) = b; + *point = {origin, Color4B(color), Tex2F(0.0, 0.0)}; + *(point+1) = {destination, Color4B(color), Tex2F(0.0, 0.0)}; _customCommandGLLine.updateVertexBuffer(point, _bufferCountGLLine*sizeof(V2F_C4B_T2F), 2*sizeof(V2F_C4B_T2F)); _bufferCountGLLine += 2; @@ -370,10 +309,10 @@ void DrawNode::drawLine(const Vec2 &origin, const Vec2 &destination, const Color void DrawNode::drawRect(const Vec2 &origin, const Vec2 &destination, const Color4F &color) { - drawLine(Vec2(origin.x, origin.y), Vec2(destination.x, origin.y), color); - drawLine(Vec2(destination.x, origin.y), Vec2(destination.x, destination.y), color); - drawLine(Vec2(destination.x, destination.y), Vec2(origin.x, destination.y), color); - drawLine(Vec2(origin.x, destination.y), Vec2(origin.x, origin.y), color); + drawLine(origin, Vec2(destination.x, origin.y), color); + drawLine(Vec2(destination.x, origin.y), destination, color); + drawLine(destination, Vec2(origin.x, destination.y), color); + drawLine(Vec2(origin.x, destination.y), origin, color); } void DrawNode::drawPoly(const Vec2 *poli, unsigned int numberOfPoints, bool closePolygon, const Color4F &color) @@ -390,25 +329,20 @@ void DrawNode::drawPoly(const Vec2 *poli, unsigned int numberOfPoints, bool clos ensureCapacityGLLine(vertex_count); } - V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLLine + _bufferCountGLLine); + V2F_C4B_T2F *point = _bufferGLLine + _bufferCountGLLine; V2F_C4B_T2F *cursor = point; unsigned int i = 0; - for(; i