Add Transform to DrawNode

This commit is contained in:
Nite Luo 2013-11-19 11:06:26 -08:00
parent abb011f0ef
commit 7ad64ece36
6 changed files with 58 additions and 2 deletions

View File

@ -102,6 +102,7 @@ DrawNode::DrawNode()
, _bufferCapacity(0)
, _bufferCount(0)
, _buffer(NULL)
, _finalBuffer(NULL)
, _dirty(false)
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
@ -111,6 +112,8 @@ DrawNode::~DrawNode()
{
free(_buffer);
_buffer = NULL;
free(_finalBuffer);
_finalBuffer = NULL;
glDeleteBuffers(1, &_vbo);
_vbo = 0;
@ -150,6 +153,7 @@ void DrawNode::ensureCapacity(long count)
{
_bufferCapacity += MAX(_bufferCapacity, count);
_buffer = (V2F_C4B_T2F*)realloc(_buffer, _bufferCapacity*sizeof(V2F_C4B_T2F));
_finalBuffer = (V2F_C4B_T2F*)realloc(_buffer, _bufferCapacity*sizeof(V2F_C4B_T2F));
}
}

View File

@ -108,6 +108,7 @@ protected:
long _bufferCapacity;
GLsizei _bufferCount;
V2F_C4B_T2F *_buffer;
V2F_C4B_T2F *_finalBuffer;
BlendFunc _blendFunc;

View File

@ -5,6 +5,7 @@
#include "CCNewDrawNode.h"
#include "QuadCommand.h"
#include "Renderer.h"
NS_CC_BEGIN
@ -38,11 +39,59 @@ bool NewDrawNode::init()
return DrawNode::init();
}
void NewDrawNode::updateTransform()
{
if(_dirty && _visible)
{
//TODO optimize this transformation, should use parent's transformation instead
AffineTransform _transformToBatch = getNodeToWorldTransform();
//
// calculate the Quad based on the Affine Matrix
//
Size size = _rect.size;
float x1 = _offsetPosition.x;
float y1 = _offsetPosition.y;
float x2 = x1 + size.width;
float y2 = y1 + size.height;
float x = _transformToBatch.tx;
float y = _transformToBatch.ty;
float cr = _transformToBatch.a;
float sr = _transformToBatch.b;
float cr2 = _transformToBatch.d;
float sr2 = -_transformToBatch.c;
float ax = x1 * cr - y1 * sr2 + x;
float ay = x1 * sr + y1 * cr2 + y;
float bx = x2 * cr - y1 * sr2 + x;
float by = x2 * sr + y1 * cr2 + y;
float cx = x2 * cr - y2 * sr2 + x;
float cy = x2 * sr + y2 * cr2 + y;
float dx = x1 * cr - y2 * sr2 + x;
float dy = x1 * sr + y2 * cr2 + y;
_quad.bl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), _vertexZ );
_quad.br.vertices = Vertex3F( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), _vertexZ );
_quad.tl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), _vertexZ );
_quad.tr.vertices = Vertex3F( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _vertexZ );
}
_recursiveDirty = false;
setDirty(false);
}
void NewDrawNode::draw()
{
updateTransform();
// QuadCommand* quadCommand = new QuadCommand(0, _vertexZ, 0, _shaderProgram, _blendFunc, )
// QuadCommand* quadCommand = new QuadCommand(0, _vertexZ, CC_NO_TEXTURE, _shaderProgram, _blendFunc, &_quads, _bufferCount);
// Renderer::getInstance()->
}
NS_CC_END

View File

@ -21,6 +21,7 @@ public:
virtual bool init();
void updateTransform();
void draw();
protected:

View File

@ -12,6 +12,7 @@
NS_CC_BEGIN
#define CC_NO_TEXTURE 0
class QuadCommand : public RenderCommand
{

View File

@ -283,9 +283,9 @@ NewClippingNodeTest::NewClippingNodeTest()
// stencil->drawPolygon(rectangle, 4, white, 1, white);
// clipper->setStencil(stencil);
//Test with alpha Test
clipper->setAlphaThreshold(0.05f);
auto stencil = NewSprite::create("Images/grossini.png");
stencil->setScale(2.0f);
stencil->setPosition(s.width/2, s.height/2);
clipper->setStencil(stencil);