mirror of https://github.com/axmolengine/axmol.git
parent
7751762893
commit
e6f055f3fd
|
@ -23,10 +23,12 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "3d/CCBillBoard.h"
|
#include "3d/CCBillBoard.h"
|
||||||
|
#include "3d/CCMeshVertexIndexData.h"
|
||||||
#include "2d/CCSpriteFrameCache.h"
|
#include "2d/CCSpriteFrameCache.h"
|
||||||
#include "base/CCDirector.h"
|
#include "base/CCDirector.h"
|
||||||
#include "base/CCCamera.h"
|
#include "base/CCCamera.h"
|
||||||
#include "renderer/CCRenderer.h"
|
#include "renderer/CCRenderer.h"
|
||||||
|
#include "renderer/CCGLProgramCache.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -37,7 +39,6 @@ BillBorad::BillBorad()
|
||||||
|
|
||||||
BillBorad::~BillBorad()
|
BillBorad::~BillBorad()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BillBorad* BillBorad::createWithTexture(Texture2D *texture)
|
BillBorad* BillBorad::createWithTexture(Texture2D *texture)
|
||||||
|
@ -91,27 +92,30 @@ BillBorad* BillBorad::create()
|
||||||
|
|
||||||
void BillBorad::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
void BillBorad::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||||
{
|
{
|
||||||
calculateBillBoradMatrix(_BillBoradMat);
|
auto camera = Camera::getVisitingCamera();
|
||||||
|
Mat4 viewInverseMat = camera->getViewMatrix().getInversed();
|
||||||
|
viewInverseMat.m[12] = viewInverseMat.m[13] = viewInverseMat.m[14] = 0;
|
||||||
|
|
||||||
Mat4 transMat = transform;
|
Mat4 transMat = transform;
|
||||||
transMat *= _BillBoradMat;
|
transMat *= viewInverseMat;
|
||||||
// Don't do calculate the culling if the transform was not updated
|
// Don't do calculate the culling if the transform was not updated
|
||||||
_insideBounds = (flags & FLAGS_TRANSFORM_DIRTY) ? renderer->checkVisibility(transMat, _contentSize) : _insideBounds;
|
_insideBounds = (flags & FLAGS_TRANSFORM_DIRTY) ? renderer->checkVisibility(transMat, _contentSize) : _insideBounds;
|
||||||
|
|
||||||
if(_insideBounds)
|
if(_insideBounds)
|
||||||
|
{
|
||||||
|
if (_displayedOpacity < 255)
|
||||||
|
{
|
||||||
|
Mat4 modelViewMat = camera->getViewMatrix() * transMat;
|
||||||
|
_quadCommand.init(-modelViewMat.m[14], _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, transMat);
|
||||||
|
renderer->addTransparentCommand(&_quadCommand);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, transMat);
|
_quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, transMat);
|
||||||
renderer->addCommand(&_quadCommand);
|
renderer->addCommand(&_quadCommand);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void BillBorad::calculateBillBoradMatrix(Mat4 &dst)
|
}
|
||||||
{
|
|
||||||
auto camera = Camera::getVisitingCamera();
|
|
||||||
dst = camera->getViewMatrix().getInversed();
|
|
||||||
|
|
||||||
dst.m[12]=0;
|
|
||||||
dst.m[13]=0;
|
|
||||||
dst.m[14]=0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -26,9 +26,11 @@
|
||||||
#define __CCBILLBOARD_H__
|
#define __CCBILLBOARD_H__
|
||||||
|
|
||||||
#include "2d/CCSprite.h"
|
#include "2d/CCSprite.h"
|
||||||
|
#include "renderer/CCMeshCommand.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class MeshIndexData;
|
||||||
/**
|
/**
|
||||||
* Inherit from Sprite, achieve BillBorad.
|
* Inherit from Sprite, achieve BillBorad.
|
||||||
*/
|
*/
|
||||||
|
@ -84,11 +86,6 @@ CC_CONSTRUCTOR_ACCESS:
|
||||||
BillBorad();
|
BillBorad();
|
||||||
virtual ~BillBorad();
|
virtual ~BillBorad();
|
||||||
|
|
||||||
protected:
|
|
||||||
Mat4 _BillBoradMat;
|
|
||||||
|
|
||||||
void calculateBillBoradMatrix(Mat4 &dst);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(BillBorad);
|
CC_DISALLOW_COPY_AND_ASSIGN(BillBorad);
|
||||||
|
|
||||||
|
|
|
@ -396,6 +396,7 @@ void Renderer::visitTransparentRenderQueue(const TransparentRenderQueue& queue)
|
||||||
auto cmd = static_cast<QuadCommand*>(command);
|
auto cmd = static_cast<QuadCommand*>(command);
|
||||||
|
|
||||||
_batchedQuadCommands.push_back(cmd);
|
_batchedQuadCommands.push_back(cmd);
|
||||||
|
_numQuads = cmd->getQuadCount();
|
||||||
memcpy(_quads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmd->getQuadCount());
|
memcpy(_quads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmd->getQuadCount());
|
||||||
convertToWorldCoordinates(_quads, cmd->getQuadCount(), cmd->getModelView());
|
convertToWorldCoordinates(_quads, cmd->getQuadCount(), cmd->getModelView());
|
||||||
drawBatchedQuads();
|
drawBatchedQuads();
|
||||||
|
@ -459,7 +460,9 @@ void Renderer::render()
|
||||||
if (_transparentRenderGroups.size())
|
if (_transparentRenderGroups.size())
|
||||||
{
|
{
|
||||||
_transparentRenderGroups.sort();
|
_transparentRenderGroups.sort();
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
visitTransparentRenderQueue(_transparentRenderGroups);
|
visitTransparentRenderQueue(_transparentRenderGroups);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clean();
|
clean();
|
||||||
|
|
|
@ -1549,9 +1549,9 @@ BillBoardTest::BillBoardTest()
|
||||||
_layerBillBorad->addChild(_camera);
|
_layerBillBorad->addChild(_camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewBillBoradWithCoords(Vec3(20,0,0));
|
addNewBillBoradWithCoords(Vec3(20,5,0));
|
||||||
addNewAniBillBoradWithCoords(Vec3(-20,0,0));
|
addNewAniBillBoradWithCoords(Vec3(-20,0,0));
|
||||||
_camera->setPosition3D(Vec3(0, 130, 130));
|
_camera->setPosition3D(Vec3(0, 0, 130));
|
||||||
_camera->lookAt(Vec3(0,0,0), Vec3(0,1,0));
|
_camera->lookAt(Vec3(0,0,0), Vec3(0,1,0));
|
||||||
|
|
||||||
for( int j =-20; j<=20 ;j++)
|
for( int j =-20; j<=20 ;j++)
|
||||||
|
@ -1566,7 +1566,7 @@ BillBoardTest::BillBoardTest()
|
||||||
//draw y
|
//draw y
|
||||||
//line->drawLine(Vec3(0, -50, 0),Vec3(0,0,0),Color4F(0,0.5,0,1));
|
//line->drawLine(Vec3(0, -50, 0),Vec3(0,0,0),Color4F(0,0.5,0,1));
|
||||||
//line->drawLine(Vec3(0, 0, 0),Vec3(0,50,0),Color4F(0,1,0,1));
|
//line->drawLine(Vec3(0, 0, 0),Vec3(0,50,0),Color4F(0,1,0,1));
|
||||||
_layerBillBorad->addChild(line,1);
|
_layerBillBorad->addChild(line);
|
||||||
|
|
||||||
TTFConfig ttfConfig("fonts/arial.ttf", 20);
|
TTFConfig ttfConfig("fonts/arial.ttf", 20);
|
||||||
auto label1 = Label::createWithTTF(ttfConfig,"rotate+");
|
auto label1 = Label::createWithTTF(ttfConfig,"rotate+");
|
||||||
|
@ -1601,26 +1601,36 @@ void BillBoardTest::addNewBillBoradWithCoords(Vec3 p)
|
||||||
_billborad->setScale(0.5f);
|
_billborad->setScale(0.5f);
|
||||||
_layerBillBorad->addChild(_billborad,10);
|
_layerBillBorad->addChild(_billborad,10);
|
||||||
_billborad->setPosition(Vec2( p.x,p.y ));
|
_billborad->setPosition(Vec2( p.x,p.y ));
|
||||||
|
_billborad->setBlendFunc(cocos2d::BlendFunc::ALPHA_PREMULTIPLIED);
|
||||||
|
_billborad->setOpacity(200);
|
||||||
|
|
||||||
auto billborad1 = BillBorad::create("Images/Icon.png");
|
auto billborad1 = BillBorad::create("Images/Icon.png");
|
||||||
billborad1->setScale(0.5f);
|
billborad1->setScale(0.5f);
|
||||||
_layerBillBorad->addChild(billborad1,10);
|
_layerBillBorad->addChild(billborad1,10);
|
||||||
billborad1->setPosition3D(Vec3(p.x,p.y,p.z - 130));
|
billborad1->setPosition3D(Vec3(p.x,p.y,p.z - 130));
|
||||||
|
billborad1->setBlendFunc(cocos2d::BlendFunc::ALPHA_PREMULTIPLIED);
|
||||||
|
billborad1->setOpacity(200);
|
||||||
|
|
||||||
auto billborad2 = BillBorad::create("Images/Icon.png");
|
auto billborad2 = BillBorad::create("Images/Icon.png");
|
||||||
billborad2->setScale(0.5f);
|
billborad2->setScale(0.5f);
|
||||||
_layerBillBorad->addChild(billborad2,10);
|
_layerBillBorad->addChild(billborad2,10);
|
||||||
billborad2->setPosition3D(Vec3(p.x,p.y,p.z + 50));
|
billborad2->setPosition3D(Vec3(p.x,p.y,p.z + 50));
|
||||||
|
billborad2->setBlendFunc(cocos2d::BlendFunc::ALPHA_PREMULTIPLIED);
|
||||||
|
billborad2->setOpacity(200);
|
||||||
|
|
||||||
auto billborad3 = BillBorad::create("Images/Icon.png");
|
auto billborad3 = BillBorad::create("Images/Icon.png");
|
||||||
billborad3->setScale(0.5f);
|
billborad3->setScale(0.5f);
|
||||||
_layerBillBorad->addChild(billborad3,10);
|
_layerBillBorad->addChild(billborad3,10);
|
||||||
billborad3->setPosition3D(Vec3(p.x,p.y,p.z + 90));
|
billborad3->setPosition3D(Vec3(p.x,p.y,p.z + 90));
|
||||||
|
billborad3->setBlendFunc(cocos2d::BlendFunc::ALPHA_PREMULTIPLIED);
|
||||||
|
billborad3->setOpacity(200);
|
||||||
|
|
||||||
auto billborad4 = BillBorad::create("Images/Icon.png");
|
auto billborad4 = BillBorad::create("Images/Icon.png");
|
||||||
billborad4->setScale(0.5f);
|
billborad4->setScale(0.5f);
|
||||||
_layerBillBorad->addChild(billborad4,10);
|
_layerBillBorad->addChild(billborad4,10);
|
||||||
billborad4->setPosition3D(Vec3(p.x,p.y,p.z - 60));
|
billborad4->setPosition3D(Vec3(p.x,p.y,p.z - 60));
|
||||||
|
billborad4->setBlendFunc(cocos2d::BlendFunc::ALPHA_PREMULTIPLIED);
|
||||||
|
billborad4->setOpacity(200);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue