mirror of https://github.com/axmolengine/axmol.git
commit
bb0b7a9b8a
|
@ -1799,6 +1799,10 @@
|
|||
B37510841823ACA100B3BA6A /* CCPhysicsShapeInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104D1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.h */; };
|
||||
B37510851823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B375104E1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp */; };
|
||||
B37510861823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */; };
|
||||
B60C5BD419AC68B10056FBDE /* CCBillBoard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B60C5BD219AC68B10056FBDE /* CCBillBoard.cpp */; };
|
||||
B60C5BD519AC68B10056FBDE /* CCBillBoard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B60C5BD219AC68B10056FBDE /* CCBillBoard.cpp */; };
|
||||
B60C5BD619AC68B10056FBDE /* CCBillBoard.h in Headers */ = {isa = PBXBuildFile; fileRef = B60C5BD319AC68B10056FBDE /* CCBillBoard.h */; };
|
||||
B60C5BD719AC68B10056FBDE /* CCBillBoard.h in Headers */ = {isa = PBXBuildFile; fileRef = B60C5BD319AC68B10056FBDE /* CCBillBoard.h */; };
|
||||
ED9C6A9418599AD8000A5232 /* CCNodeGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */; };
|
||||
ED9C6A9518599AD8000A5232 /* CCNodeGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */; };
|
||||
ED9C6A9618599AD8000A5232 /* CCNodeGrid.h in Headers */ = {isa = PBXBuildFile; fileRef = ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */; };
|
||||
|
@ -2782,6 +2786,8 @@
|
|||
B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorldInfo_chipmunk.h; sourceTree = "<group>"; };
|
||||
B3AF019E1842FBA400A98B85 /* b2MotorJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MotorJoint.cpp; sourceTree = "<group>"; };
|
||||
B3AF019F1842FBA400A98B85 /* b2MotorJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MotorJoint.h; sourceTree = "<group>"; };
|
||||
B60C5BD219AC68B10056FBDE /* CCBillBoard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCBillBoard.cpp; sourceTree = "<group>"; };
|
||||
B60C5BD319AC68B10056FBDE /* CCBillBoard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCBillBoard.h; sourceTree = "<group>"; };
|
||||
ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CCNodeGrid.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNodeGrid.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
@ -4727,6 +4733,8 @@
|
|||
B29594B81926D61F003EEF37 /* 3d */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B60C5BD219AC68B10056FBDE /* CCBillBoard.cpp */,
|
||||
B60C5BD319AC68B10056FBDE /* CCBillBoard.h */,
|
||||
15AE17E319AAD2F700C27E9E /* 3dExport.h */,
|
||||
15AE17E419AAD2F700C27E9E /* CCAABB.cpp */,
|
||||
15AE17E519AAD2F700C27E9E /* CCAABB.h */,
|
||||
|
@ -5094,6 +5102,7 @@
|
|||
15AE199119AAD37200C27E9E /* ImageViewReader.h in Headers */,
|
||||
15AE18FE19AAD35000C27E9E /* CCComAttribute.h in Headers */,
|
||||
50ABBD621925AB0000A911A9 /* Vec4.h in Headers */,
|
||||
B60C5BD619AC68B10056FBDE /* CCBillBoard.h in Headers */,
|
||||
15AE1BA419AADFDF00C27E9E /* UILayoutManager.h in Headers */,
|
||||
1A01C69418F57BE800EFE3A6 /* CCFloat.h in Headers */,
|
||||
1A57034D180BD09B0088DEC7 /* tinyxml2.h in Headers */,
|
||||
|
@ -5397,6 +5406,7 @@
|
|||
15AE181D19AAD2F700C27E9E /* CCBundle3D.h in Headers */,
|
||||
15AE192519AAD35100C27E9E /* CocoLoader.h in Headers */,
|
||||
15AE1BBB19AADFF000C27E9E /* HttpRequest.h in Headers */,
|
||||
B60C5BD719AC68B10056FBDE /* CCBillBoard.h in Headers */,
|
||||
B230ED7419B417AE00364AA8 /* CCTrianglesCommand.h in Headers */,
|
||||
15AE1A0019AAD3A700C27E9E /* AtlasAttachmentLoader.h in Headers */,
|
||||
50ED2BE119BEAF7900A0AB90 /* UIEditBoxImpl-win32.h in Headers */,
|
||||
|
@ -6013,6 +6023,7 @@
|
|||
1A570282180BCC900088DEC7 /* CCSpriteBatchNode.cpp in Sources */,
|
||||
1A570286180BCC900088DEC7 /* CCSpriteFrame.cpp in Sources */,
|
||||
B24AA989195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */,
|
||||
B60C5BD419AC68B10056FBDE /* CCBillBoard.cpp in Sources */,
|
||||
15AE199619AAD39600C27E9E /* ListViewReader.cpp in Sources */,
|
||||
50ABC0191926664800A911A9 /* CCSAXParser.cpp in Sources */,
|
||||
15AE189219AAD33D00C27E9E /* CCLayerGradientLoader.cpp in Sources */,
|
||||
|
@ -6420,6 +6431,7 @@
|
|||
50ABBDBE1925AB4100A911A9 /* CCTextureCache.cpp in Sources */,
|
||||
1A5701E3180BCB8C0088DEC7 /* CCScene.cpp in Sources */,
|
||||
50ABBD611925AB0000A911A9 /* Vec4.cpp in Sources */,
|
||||
B60C5BD519AC68B10056FBDE /* CCBillBoard.cpp in Sources */,
|
||||
15AE184519AAD2F700C27E9E /* CCSprite3DMaterial.cpp in Sources */,
|
||||
50ABBD9C1925AB4100A911A9 /* ccGLStateCache.cpp in Sources */,
|
||||
1A5701E7180BCB8C0088DEC7 /* CCTransition.cpp in Sources */,
|
||||
|
|
|
@ -933,6 +933,8 @@
|
|||
A07A52C31783B02C0073F6A7 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A07A52C11783B01F0073F6A7 /* AVFoundation.framework */; };
|
||||
B2507B6B192589AF00FA4972 /* Shaders3D in Resources */ = {isa = PBXBuildFile; fileRef = B2507B6A192589AF00FA4972 /* Shaders3D */; };
|
||||
B2507B6C192589AF00FA4972 /* Shaders3D in Resources */ = {isa = PBXBuildFile; fileRef = B2507B6A192589AF00FA4972 /* Shaders3D */; };
|
||||
B609E67319C18DAD003D0074 /* BillBoardTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B609E67119C18DAD003D0074 /* BillBoardTest.cpp */; };
|
||||
B609E67419C18DAD003D0074 /* BillBoardTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B609E67119C18DAD003D0074 /* BillBoardTest.cpp */; };
|
||||
C04F935A1941B05400E9FEAB /* TileMapTest2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C04F93581941B05400E9FEAB /* TileMapTest2.cpp */; };
|
||||
C04F935B1941B05400E9FEAB /* TileMapTest2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C04F93581941B05400E9FEAB /* TileMapTest2.cpp */; };
|
||||
C08689C118D370C90093E810 /* background.caf in Resources */ = {isa = PBXBuildFile; fileRef = C08689C018D370C90093E810 /* background.caf */; };
|
||||
|
@ -2953,6 +2955,8 @@
|
|||
A07A52BB1783AEB80073F6A7 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; };
|
||||
A07A52C11783B01F0073F6A7 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/AVFoundation.framework; sourceTree = DEVELOPER_DIR; };
|
||||
B2507B6A192589AF00FA4972 /* Shaders3D */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Shaders3D; path = "../tests/cpp-tests/Resources/Shaders3D"; sourceTree = "<group>"; };
|
||||
B609E67119C18DAD003D0074 /* BillBoardTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BillBoardTest.cpp; path = BillBoardTest/BillBoardTest.cpp; sourceTree = "<group>"; };
|
||||
B609E67219C18DAD003D0074 /* BillBoardTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BillBoardTest.h; path = BillBoardTest/BillBoardTest.h; sourceTree = "<group>"; };
|
||||
C04F93581941B05400E9FEAB /* TileMapTest2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TileMapTest2.cpp; sourceTree = "<group>"; };
|
||||
C04F93591941B05400E9FEAB /* TileMapTest2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TileMapTest2.h; sourceTree = "<group>"; };
|
||||
C08689C018D370C90093E810 /* background.caf */ = {isa = PBXFileReference; lastKnownFileType = file; name = background.caf; path = "../tests/cpp-tests/Resources/background.caf"; sourceTree = "<group>"; };
|
||||
|
@ -5427,6 +5431,7 @@
|
|||
1AC3592418CECF0A00F37B72 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B609E67019C18D90003D0074 /* BillBoardTest */,
|
||||
3E2BDACD19BEA3410055CDCD /* NewAudioEngineTest */,
|
||||
3E9E75CB199324A8005B7047 /* Camera3DTest */,
|
||||
1AC3592818CECF0A00F37B72 /* ActionManagerTest */,
|
||||
|
@ -7141,6 +7146,15 @@
|
|||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
B609E67019C18D90003D0074 /* BillBoardTest */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B609E67119C18DAD003D0074 /* BillBoardTest.cpp */,
|
||||
B609E67219C18DAD003D0074 /* BillBoardTest.h */,
|
||||
);
|
||||
name = BillBoardTest;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
|
@ -8033,6 +8047,7 @@
|
|||
1AC35B7D18CECF0C00F37B72 /* PlayerController.cpp in Sources */,
|
||||
29080D9F191B595E0066F8DF /* CustomReader.cpp in Sources */,
|
||||
1AC35BE718CECF0C00F37B72 /* CCControlScene.cpp in Sources */,
|
||||
B609E67319C18DAD003D0074 /* BillBoardTest.cpp in Sources */,
|
||||
292CF01419A1965E00E8E6A0 /* UIEditBoxTest.cpp in Sources */,
|
||||
29080DBF191B595E0066F8DF /* UIPageViewTest_Editor.cpp in Sources */,
|
||||
1AC35B5F18CECF0C00F37B72 /* DataVisitorTest.cpp in Sources */,
|
||||
|
@ -8217,6 +8232,7 @@
|
|||
292CF01519A1965E00E8E6A0 /* UIEditBoxTest.cpp in Sources */,
|
||||
1AC35B2818CECF0C00F37B72 /* ActionsTest.cpp in Sources */,
|
||||
1AC35C4A18CECF0C00F37B72 /* ShaderTest.cpp in Sources */,
|
||||
B609E67419C18DAD003D0074 /* BillBoardTest.cpp in Sources */,
|
||||
C04F935B1941B05400E9FEAB /* TileMapTest2.cpp in Sources */,
|
||||
1AC35B4418CECF0C00F37B72 /* Bug-624.cpp in Sources */,
|
||||
1AC35BF818CECF0C00F37B72 /* SocketIOTest.cpp in Sources */,
|
||||
|
|
|
@ -205,6 +205,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
|
|||
<ClCompile Include="..\3d\CCAnimate3D.cpp" />
|
||||
<ClCompile Include="..\3d\CCAnimation3D.cpp" />
|
||||
<ClCompile Include="..\3d\CCAttachNode.cpp" />
|
||||
<ClCompile Include="..\3d\CCBillBoard.cpp" />
|
||||
<ClCompile Include="..\3d\CCBundle3D.cpp" />
|
||||
<ClCompile Include="..\3d\CCBundleReader.cpp" />
|
||||
<ClCompile Include="..\3d\CCMesh.cpp" />
|
||||
|
@ -540,6 +541,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
|
|||
<ClInclude Include="..\3d\CCAnimation3D.h" />
|
||||
<ClInclude Include="..\3d\CCAnimationCurve.h" />
|
||||
<ClInclude Include="..\3d\CCAttachNode.h" />
|
||||
<ClInclude Include="..\3d\CCBillBoard.h" />
|
||||
<ClInclude Include="..\3d\CCBundle3D.h" />
|
||||
<ClInclude Include="..\3d\CCBundle3DData.h" />
|
||||
<ClInclude Include="..\3d\CCBundleReader.h" />
|
||||
|
|
|
@ -1105,6 +1105,9 @@
|
|||
<ClCompile Include="..\editor-support\cocosbuilder\CCSpriteLoader.cpp">
|
||||
<Filter>cocosbuilder\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\3d\CCBillBoard.cpp">
|
||||
<Filter>3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\ui\UIEditBox\UIEditBox.cpp">
|
||||
<Filter>ui\UIWidgets\EditBox</Filter>
|
||||
</ClCompile>
|
||||
|
@ -2224,6 +2227,9 @@
|
|||
<ClInclude Include="..\editor-support\cocosbuilder\CocosBuilder.h">
|
||||
<Filter>cocosbuilder\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\3d\CCBillBoard.h">
|
||||
<Filter>3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\ui\UIEditBox\UIEditBox.h">
|
||||
<Filter>ui\UIWidgets\EditBox</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -12,6 +12,7 @@ CCOBB.cpp \
|
|||
CCAnimate3D.cpp \
|
||||
CCAnimation3D.cpp \
|
||||
CCAttachNode.cpp \
|
||||
CCBillBoard.cpp \
|
||||
CCBundle3D.cpp \
|
||||
CCBundleReader.cpp \
|
||||
CCMesh.cpp \
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "3d/CCBillBoard.h"
|
||||
#include "2d/CCSpriteFrameCache.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "base/CCCamera.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCGLProgramCache.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
BillBoard::BillBoard()
|
||||
: _zDepthInView(0.0f)
|
||||
, _mode(Mode::VIEW_POINT_ORIENTED)
|
||||
, _modeDirty(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BillBoard::~BillBoard()
|
||||
{
|
||||
}
|
||||
|
||||
BillBoard* BillBoard::createWithTexture(Texture2D *texture, Mode mode)
|
||||
{
|
||||
BillBoard *billborad = new (std::nothrow) BillBoard();
|
||||
if (billborad && billborad->initWithTexture(texture))
|
||||
{
|
||||
billborad->_mode = mode;
|
||||
billborad->autorelease();
|
||||
return billborad;
|
||||
}
|
||||
CC_SAFE_DELETE(billborad);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
BillBoard* BillBoard::create(const std::string& filename, Mode mode)
|
||||
{
|
||||
BillBoard *billborad = new (std::nothrow) BillBoard();
|
||||
if (billborad && billborad->initWithFile(filename))
|
||||
{
|
||||
billborad->_mode = mode;
|
||||
billborad->autorelease();
|
||||
return billborad;
|
||||
}
|
||||
CC_SAFE_DELETE(billborad);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BillBoard* BillBoard::create(const std::string& filename, const Rect& rect, Mode mode)
|
||||
{
|
||||
BillBoard *billborad = new (std::nothrow) BillBoard();
|
||||
if (billborad && billborad->initWithFile(filename, rect))
|
||||
{
|
||||
billborad->_mode = mode;
|
||||
billborad->autorelease();
|
||||
return billborad;
|
||||
}
|
||||
CC_SAFE_DELETE(billborad);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BillBoard* BillBoard::create(Mode mode)
|
||||
{
|
||||
BillBoard *billborad = new (std::nothrow) BillBoard();
|
||||
if (billborad && billborad->init())
|
||||
{
|
||||
billborad->_mode = mode;
|
||||
billborad->autorelease();
|
||||
return billborad;
|
||||
}
|
||||
CC_SAFE_DELETE(billborad);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void BillBoard::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
auto camera = Camera::getVisitingCamera();
|
||||
|
||||
const Mat4& camWorldMat = camera->getNodeToWorldTransform();
|
||||
if (memcmp(_camWorldMat.m, camWorldMat.m, sizeof(float) * 16) != 0 || memcmp(_transform.m, transform.m, sizeof(float) * 16) != 0 || _modeDirty)
|
||||
{
|
||||
Vec3 camDir;
|
||||
switch (_mode)
|
||||
{
|
||||
case Mode::VIEW_POINT_ORIENTED:
|
||||
camDir = Vec3(transform.m[12] - camWorldMat.m[12], transform.m[13] - camWorldMat.m[13], transform.m[14] - camWorldMat.m[14]);
|
||||
break;
|
||||
case Mode::VIEW_PLANE_ORIENTED:
|
||||
camWorldMat.transformVector(Vec3(0.0f, 0.0f, -1.0f), &camDir);
|
||||
break;
|
||||
default:
|
||||
CCASSERT(false, "invalid billboard mode");
|
||||
break;
|
||||
}
|
||||
_modeDirty = false;
|
||||
|
||||
if (camDir.length() < MATH_TOLERANCE)
|
||||
{
|
||||
camDir.set(camWorldMat.m[8], camWorldMat.m[9], camWorldMat.m[10]);
|
||||
}
|
||||
camDir.normalize();
|
||||
|
||||
static Vec3 upAxis(0.0f, 1.0f, 0.0f);
|
||||
Vec3 x, y;
|
||||
camWorldMat.transformVector(upAxis, &y);
|
||||
Vec3::cross(camDir, y, &x);
|
||||
x.normalize();
|
||||
Vec3::cross(x, camDir, &y);
|
||||
float xlen = sqrtf(transform.m[0] * transform.m[0] + transform.m[1] * transform.m[1] + transform.m[2] * transform.m[2]);
|
||||
float ylen = sqrtf(transform.m[4] * transform.m[4] + transform.m[5] * transform.m[5] + transform.m[6] * transform.m[6]);
|
||||
float zlen = sqrtf(transform.m[8] * transform.m[8] + transform.m[9] * transform.m[9] + transform.m[10] * transform.m[10]);
|
||||
|
||||
_billboardTransform.m[0] = x.x * xlen; _billboardTransform.m[1] = x.y * xlen; _billboardTransform.m[2] = x.z * xlen;
|
||||
_billboardTransform.m[4] = y.x * ylen; _billboardTransform.m[5] = y.y * ylen; _billboardTransform.m[6] = y.z * ylen;
|
||||
_billboardTransform.m[8] = -camDir.x * zlen; _billboardTransform.m[9] = -camDir.y * zlen; _billboardTransform.m[10] = -camDir.z * zlen;
|
||||
_billboardTransform.m[12] = transform.m[12]; _billboardTransform.m[13] = transform.m[13]; _billboardTransform.m[14] = transform.m[14];
|
||||
|
||||
const Mat4 &viewMat = camWorldMat.getInversed();
|
||||
_zDepthInView = -(viewMat.m[2] * transform.m[12] + viewMat.m[6] * transform.m[13] + viewMat.m[10] * transform.m[14] + viewMat.m[14]);
|
||||
_transform = transform;
|
||||
_camWorldMat = camWorldMat;
|
||||
}
|
||||
|
||||
//FIXME: frustum culling here
|
||||
{
|
||||
_quadCommand.init(_zDepthInView, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, _billboardTransform);
|
||||
renderer->addCommandToTransparentQueue(&_quadCommand);
|
||||
}
|
||||
}
|
||||
|
||||
void BillBoard::setMode( Mode mode )
|
||||
{
|
||||
_mode = mode;
|
||||
_modeDirty = true;
|
||||
}
|
||||
|
||||
BillBoard::Mode BillBoard::getMode() const
|
||||
{
|
||||
return _mode;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,121 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCBILLBOARD_H__
|
||||
#define __CCBILLBOARD_H__
|
||||
|
||||
#include "2d/CCSprite.h"
|
||||
#include "3d/3dExport.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
/**
|
||||
* Inherit from Sprite, achieve BillBoard.
|
||||
*/
|
||||
class CC_3D_DLL BillBoard : public Sprite
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Mode
|
||||
{
|
||||
VIEW_POINT_ORIENTED, // orient to the camera
|
||||
VIEW_PLANE_ORIENTED // orient to the XOY plane of camera
|
||||
};
|
||||
/// @{
|
||||
/// @name Creators
|
||||
|
||||
/**
|
||||
* Creates an empty BillBoard without texture. You can call setTexture method subsequently.
|
||||
*
|
||||
* @return An autoreleased BillBoard object.
|
||||
*/
|
||||
static BillBoard* create(Mode mode = Mode::VIEW_POINT_ORIENTED);
|
||||
|
||||
/**
|
||||
* Creates a BillBoard with an image filename.
|
||||
*
|
||||
* After creation, the rect of BillBoard will be the size of the image,
|
||||
* and the offset will be (0,0).
|
||||
*
|
||||
* @param filename A path to image file, e.g., "scene1/monster.png"
|
||||
* @return An autoreleased BillBoard object.
|
||||
*/
|
||||
static BillBoard* create(const std::string& filename, Mode mode = Mode::VIEW_POINT_ORIENTED);
|
||||
|
||||
/**
|
||||
* Creates a BillBoard with an image filename and a rect.
|
||||
*
|
||||
* @param filename A path to image file, e.g., "scene1/monster.png"
|
||||
* @param rect A subrect of the image file
|
||||
* @return An autoreleased BillBoard object
|
||||
*/
|
||||
static BillBoard* create(const std::string& filename, const Rect& rect, Mode mode = Mode::VIEW_POINT_ORIENTED);
|
||||
|
||||
/**
|
||||
* Creates a BillBoard with a Texture2D object.
|
||||
*
|
||||
* After creation, the rect will be the size of the texture, and the offset will be (0,0).
|
||||
*
|
||||
* @param texture A pointer to a Texture2D object.
|
||||
* @return An autoreleased BillBoard object
|
||||
*/
|
||||
static BillBoard* createWithTexture(Texture2D *texture, Mode mode = Mode::VIEW_POINT_ORIENTED);
|
||||
|
||||
/** Set the billboard rotation mode. */
|
||||
void setMode(Mode mode);
|
||||
|
||||
/** Get the billboard rotation mode. */
|
||||
Mode getMode() const;
|
||||
|
||||
//override
|
||||
/** draw BillBoard object */
|
||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
||||
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
BillBoard();
|
||||
virtual ~BillBoard();
|
||||
|
||||
protected:
|
||||
|
||||
Mat4 _camWorldMat;
|
||||
Mat4 _transform;
|
||||
Mat4 _billboardTransform;
|
||||
|
||||
float _zDepthInView;
|
||||
|
||||
Mode _mode;
|
||||
bool _modeDirty;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(BillBoard);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
#endif // __CCBILLBOARD_H__
|
|
@ -192,6 +192,7 @@ set(COCOS2D_BASE_SRC
|
|||
3d/CCSkeleton3D.cpp
|
||||
3d/CCSprite3D.cpp
|
||||
3d/CCSprite3DMaterial.cpp
|
||||
3d/CCBillBoard.cpp
|
||||
|
||||
network/HttpClient.cpp
|
||||
network/SocketIO.cpp
|
||||
|
|
|
@ -284,6 +284,9 @@ void Director::drawScene()
|
|||
|
||||
if (_runningScene)
|
||||
{
|
||||
//clear draw stats
|
||||
_renderer->clearDrawStats();
|
||||
|
||||
Camera* defaultCamera = nullptr;
|
||||
const auto& cameras = _runningScene->_cameras;
|
||||
//draw with camera
|
||||
|
|
|
@ -280,6 +280,7 @@ THE SOFTWARE.
|
|||
#include "3d/CCAttachNode.h"
|
||||
#include "3d/CCMeshVertexIndexData.h"
|
||||
#include "3d/CCSkeleton3D.h"
|
||||
#include "3d/CCBillBoard.h"
|
||||
|
||||
// Deprecated include
|
||||
#include "deprecated/CCDictionary.h"
|
||||
|
|
|
@ -102,6 +102,32 @@ void RenderQueue::clear()
|
|||
_queuePosZ.clear();
|
||||
}
|
||||
|
||||
// helper
|
||||
static bool compareTransparentRenderCommand(RenderCommand* a, RenderCommand* b)
|
||||
{
|
||||
return a->getGlobalOrder() > b->getGlobalOrder();
|
||||
}
|
||||
|
||||
void TransparentRenderQueue::push_back(RenderCommand* command)
|
||||
{
|
||||
_queueCmd.push_back(command);
|
||||
}
|
||||
|
||||
void TransparentRenderQueue::sort()
|
||||
{
|
||||
std::sort(std::begin(_queueCmd), std::end(_queueCmd), compareTransparentRenderCommand);
|
||||
}
|
||||
|
||||
RenderCommand* TransparentRenderQueue::operator[](ssize_t index) const
|
||||
{
|
||||
return _queueCmd[index];
|
||||
}
|
||||
|
||||
void TransparentRenderQueue::clear()
|
||||
{
|
||||
_queueCmd.clear();
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
@ -245,6 +271,11 @@ void Renderer::addCommand(RenderCommand* command, int renderQueue)
|
|||
_renderGroups[renderQueue].push_back(command);
|
||||
}
|
||||
|
||||
void Renderer::addCommandToTransparentQueue(RenderCommand* command)
|
||||
{
|
||||
_transparentRenderGroups.push_back(command);
|
||||
}
|
||||
|
||||
void Renderer::pushGroup(int renderQueueID)
|
||||
{
|
||||
CCASSERT(!_isRendering, "Cannot change render queue while rendering");
|
||||
|
@ -337,6 +368,58 @@ void Renderer::visitRenderQueue(const RenderQueue& queue)
|
|||
}
|
||||
}
|
||||
|
||||
void Renderer::visitTransparentRenderQueue(const TransparentRenderQueue& queue)
|
||||
{
|
||||
// do not batch for transparent objects
|
||||
ssize_t size = queue.size();
|
||||
|
||||
_batchedCommands.clear();
|
||||
_filledVertex = 0;
|
||||
_filledIndex = 0;
|
||||
|
||||
for (ssize_t index = 0; index < size; ++index)
|
||||
{
|
||||
auto command = queue[index];
|
||||
auto commandType = command->getType();
|
||||
if(RenderCommand::Type::QUAD_COMMAND == commandType || RenderCommand::Type::TRIANGLES_COMMAND == commandType)
|
||||
{
|
||||
auto cmd = static_cast<TrianglesCommand*>(command);
|
||||
_batchedCommands.push_back(cmd);
|
||||
fillVerticesAndIndices(cmd);
|
||||
drawBatchedQuads();
|
||||
}
|
||||
else if(RenderCommand::Type::GROUP_COMMAND == commandType)
|
||||
{
|
||||
int renderQueueID = (static_cast<GroupCommand*>(command))->getRenderQueueID();
|
||||
visitRenderQueue(_renderGroups[renderQueueID]);
|
||||
}
|
||||
else if(RenderCommand::Type::CUSTOM_COMMAND == commandType)
|
||||
{
|
||||
auto cmd = static_cast<CustomCommand*>(command);
|
||||
cmd->execute();
|
||||
}
|
||||
else if(RenderCommand::Type::BATCH_COMMAND == commandType)
|
||||
{
|
||||
auto cmd = static_cast<BatchCommand*>(command);
|
||||
cmd->execute();
|
||||
}
|
||||
else if(RenderCommand::Type::PRIMITIVE_COMMAND == commandType)
|
||||
{
|
||||
auto cmd = static_cast<PrimitiveCommand*>(command);
|
||||
cmd->execute();
|
||||
}
|
||||
else if (RenderCommand::Type::MESH_COMMAND == commandType)
|
||||
{
|
||||
auto cmd = static_cast<MeshCommand*>(command);
|
||||
cmd->execute();
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOGERROR("Unknown commands in renderQueue");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::render()
|
||||
{
|
||||
//Uncomment this once everything is rendered by new renderer
|
||||
|
@ -347,9 +430,6 @@ void Renderer::render()
|
|||
|
||||
if (_glViewAssigned)
|
||||
{
|
||||
// cleanup
|
||||
_drawnBatches = _drawnVertices = 0;
|
||||
|
||||
//Process render commands
|
||||
//1. Sort render commands based on ID
|
||||
for (auto &renderqueue : _renderGroups)
|
||||
|
@ -358,6 +438,16 @@ void Renderer::render()
|
|||
}
|
||||
visitRenderQueue(_renderGroups[0]);
|
||||
flush();
|
||||
|
||||
//Process render commands
|
||||
//draw transparent objects here, do not batch for transparent objects
|
||||
if (0 < _transparentRenderGroups.size())
|
||||
{
|
||||
_transparentRenderGroups.sort();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
visitTransparentRenderQueue(_transparentRenderGroups);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
clean();
|
||||
_isRendering = false;
|
||||
|
@ -382,6 +472,8 @@ void Renderer::clean()
|
|||
_filledIndex = 0;
|
||||
_lastMaterialID = 0;
|
||||
_lastBatchedMeshCommand = nullptr;
|
||||
|
||||
_transparentRenderGroups.clear();
|
||||
}
|
||||
|
||||
void Renderer::fillVerticesAndIndices(const TrianglesCommand* cmd)
|
||||
|
|
|
@ -61,6 +61,22 @@ protected:
|
|||
std::vector<RenderCommand*> _queuePosZ;
|
||||
};
|
||||
|
||||
//render queue for transparency object, NOTE that the _globalOrder of RenderCommand is the distance to the camera when added to the transparent queue
|
||||
class TransparentRenderQueue {
|
||||
public:
|
||||
void push_back(RenderCommand* command);
|
||||
ssize_t size() const
|
||||
{
|
||||
return _queueCmd.size();
|
||||
}
|
||||
void sort();
|
||||
RenderCommand* operator[](ssize_t index) const;
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
std::vector<RenderCommand*> _queueCmd;
|
||||
};
|
||||
|
||||
struct RenderStackElement
|
||||
{
|
||||
int renderQueueID;
|
||||
|
@ -93,6 +109,9 @@ public:
|
|||
/** Adds a `RenderComamnd` into the renderer specifying a particular render queue ID */
|
||||
void addCommand(RenderCommand* command, int renderQueue);
|
||||
|
||||
/** add transprent command */
|
||||
void addCommandToTransparentQueue(RenderCommand* command);
|
||||
|
||||
/** Pushes a group into the render queue */
|
||||
void pushGroup(int renderQueueID);
|
||||
|
||||
|
@ -116,6 +135,8 @@ public:
|
|||
ssize_t getDrawnVertices() const { return _drawnVertices; }
|
||||
/* RenderCommands (except) QuadCommand should update this value */
|
||||
void addDrawnVertices(ssize_t number) { _drawnVertices += number; };
|
||||
/* clear draw stats */
|
||||
void clearDrawStats() { _drawnBatches = _drawnVertices = 0; }
|
||||
|
||||
inline GroupCommandManager* getGroupCommandManager() const { return _groupCommandManager; };
|
||||
|
||||
|
@ -141,11 +162,14 @@ protected:
|
|||
|
||||
void visitRenderQueue(const RenderQueue& queue);
|
||||
|
||||
void visitTransparentRenderQueue(const TransparentRenderQueue& queue);
|
||||
|
||||
void fillVerticesAndIndices(const TrianglesCommand* cmd);
|
||||
|
||||
std::stack<int> _commandGroupStack;
|
||||
|
||||
std::vector<RenderQueue> _renderGroups;
|
||||
TransparentRenderQueue _transparentRenderGroups; //transparency objects
|
||||
|
||||
uint32_t _lastMaterialID;
|
||||
|
||||
|
|
|
@ -203,6 +203,8 @@
|
|||
"cocos/3d/CCAnimationCurve.inl",
|
||||
"cocos/3d/CCAttachNode.cpp",
|
||||
"cocos/3d/CCAttachNode.h",
|
||||
"cocos/3d/CCBillBoard.cpp",
|
||||
"cocos/3d/CCBillBoard.h",
|
||||
"cocos/3d/CCBundle3D.cpp",
|
||||
"cocos/3d/CCBundle3D.h",
|
||||
"cocos/3d/CCBundle3DData.h",
|
||||
|
|
|
@ -16,6 +16,7 @@ Classes/ActionManagerTest/ActionManagerTest.cpp \
|
|||
Classes/ActionsEaseTest/ActionsEaseTest.cpp \
|
||||
Classes/ActionsProgressTest/ActionsProgressTest.cpp \
|
||||
Classes/ActionsTest/ActionsTest.cpp \
|
||||
Classes/BillBoardTest/BillBoardTest.cpp \
|
||||
Classes/Box2DTest/Box2dTest.cpp \
|
||||
Classes/Box2DTestBed/Box2dView.cpp \
|
||||
Classes/Box2DTestBed/GLES-Render.cpp \
|
||||
|
|
|
@ -21,6 +21,7 @@ set(TESTS_SRC
|
|||
Classes/ActionsEaseTest/ActionsEaseTest.cpp
|
||||
Classes/ActionsProgressTest/ActionsProgressTest.cpp
|
||||
Classes/ActionsTest/ActionsTest.cpp
|
||||
Classes/BillBoardTest/BillBoardTest.cpp
|
||||
Classes/Box2DTest/Box2dTest.cpp
|
||||
Classes/Box2DTestBed/Box2dView.cpp
|
||||
Classes/Box2DTestBed/GLES-Render.cpp
|
||||
|
|
|
@ -0,0 +1,255 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "BillBoardTest.h"
|
||||
#include "3d/CCBillBoard.h"
|
||||
#include "base/CCCamera.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "../testResource.h"
|
||||
|
||||
enum
|
||||
{
|
||||
IDC_NEXT = 100,
|
||||
IDC_BACK,
|
||||
IDC_RESTART
|
||||
};
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
|
||||
static std::function<Layer*()> createFunctions[] =
|
||||
{
|
||||
CL(BillBoardTest)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
static Layer* nextSpriteTestAction()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* backSpriteTestAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* restartSpriteTestAction()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
BillBoardTest::BillBoardTest()
|
||||
: _camera(nullptr)
|
||||
{
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesMoved = CC_CALLBACK_2(BillBoardTest::onTouchesMoved, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
auto layer3D=Layer::create();
|
||||
addChild(layer3D,0);
|
||||
_layerBillBorad=layer3D;
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
if (_camera == nullptr)
|
||||
{
|
||||
_camera=Camera::createPerspective(60, (GLfloat)s.width/s.height, 1, 500);
|
||||
_camera->setCameraFlag(CameraFlag::USER1);
|
||||
_layerBillBorad->addChild(_camera);
|
||||
}
|
||||
|
||||
std::string imgs[3] = {"Images/Icon.png", "Images/r2.png"};
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
{
|
||||
Layer *layer = Layer::create();
|
||||
auto billboard = BillBoard::create(imgs[(unsigned int)(CCRANDOM_0_1() * 1 + 0.5)]);
|
||||
billboard->setScale(0.5f);
|
||||
billboard->setPosition3D(Vec3(0.0f, 0.0f, CCRANDOM_MINUS1_1() * 150.0f));
|
||||
billboard->setBlendFunc(cocos2d::BlendFunc::ALPHA_NON_PREMULTIPLIED);
|
||||
billboard->setOpacity(CCRANDOM_0_1() * 128 + 128);
|
||||
_billboards.push_back(billboard);
|
||||
layer->addChild(billboard);
|
||||
_layerBillBorad->addChild(layer);
|
||||
layer->runAction( RepeatForever::create( RotateBy::create( CCRANDOM_0_1(), Vec3(0.0f, 45.0f, 0.0f) ) ) );
|
||||
}
|
||||
|
||||
addNewBillBoradWithCoords(Vec3(20,5,0));
|
||||
addNewBillBoradWithCoords(Vec3(60,5,0));
|
||||
addNewBillBoradWithCoords(Vec3(100,5,0));
|
||||
addNewBillBoradWithCoords(Vec3(140,5,0));
|
||||
addNewBillBoradWithCoords(Vec3(180,5,0));
|
||||
addNewAniBillBoradWithCoords(Vec3(-20,0,0));
|
||||
addNewAniBillBoradWithCoords(Vec3(-60,0,0));
|
||||
addNewAniBillBoradWithCoords(Vec3(-100,0,0));
|
||||
addNewAniBillBoradWithCoords(Vec3(-140,0,0));
|
||||
addNewAniBillBoradWithCoords(Vec3(-180,0,0));
|
||||
_camera->setPosition3D(Vec3(0, 130, 230));
|
||||
_camera->lookAt(Vec3(0,0,100), Vec3(0,1,0));
|
||||
|
||||
TTFConfig ttfConfig("fonts/arial.ttf", 16);
|
||||
auto label1 = Label::createWithTTF(ttfConfig,"rotate+");
|
||||
auto menuItem1 = MenuItemLabel::create(label1, CC_CALLBACK_1(BillBoardTest::rotateCameraCallback,this,10));
|
||||
auto label2 = Label::createWithTTF(ttfConfig,"rotate-");
|
||||
auto menuItem2 = MenuItemLabel::create(label2, CC_CALLBACK_1(BillBoardTest::rotateCameraCallback,this,-10));
|
||||
auto menu = Menu::create(menuItem1,menuItem2,NULL);
|
||||
menu->setPosition(Vec2::ZERO);
|
||||
menuItem1->setPosition( Vec2( s.width-80, VisibleRect::top().y-160) );
|
||||
menuItem2->setPosition( Vec2( s.width-80, VisibleRect::top().y-190) );
|
||||
addChild(menu, 0);
|
||||
_layerBillBorad->setCameraMask(2);
|
||||
|
||||
label1 = Label::createWithTTF(ttfConfig,"Point Oriented");
|
||||
menuItem1 = MenuItemLabel::create(label1,CC_CALLBACK_1(BillBoardTest::menuCallback_orientedPoint,this) );
|
||||
label2 = Label::createWithTTF(ttfConfig,"Plane Oriented");
|
||||
menuItem2 = MenuItemLabel::create(label2,CC_CALLBACK_1(BillBoardTest::menuCallback_orientedPlane,this) );
|
||||
menuItem1->setPosition( Vec2( s.width-80, VisibleRect::top().y-100) );
|
||||
menuItem2->setPosition( Vec2( s.width-80, VisibleRect::top().y-130) );
|
||||
|
||||
menu = Menu::create(menuItem1,menuItem2,NULL);
|
||||
menu->setPosition(Vec2(0,0));
|
||||
this->addChild(menu, 10);
|
||||
menuCallback_orientedPoint(nullptr);
|
||||
}
|
||||
|
||||
void BillBoardTest::menuCallback_orientedPoint(Ref* sender)
|
||||
{
|
||||
for (auto& billboard : _billboards) {
|
||||
billboard->setMode(BillBoard::Mode::VIEW_POINT_ORIENTED);
|
||||
}
|
||||
}
|
||||
|
||||
void BillBoardTest::menuCallback_orientedPlane(Ref* sender)
|
||||
{
|
||||
for (auto& billboard : _billboards) {
|
||||
billboard->setMode(BillBoard::Mode::VIEW_PLANE_ORIENTED);
|
||||
}
|
||||
}
|
||||
|
||||
BillBoardTest::~BillBoardTest()
|
||||
{
|
||||
if (_camera)
|
||||
{
|
||||
_camera = nullptr;
|
||||
}
|
||||
}
|
||||
std::string BillBoardTest::title() const
|
||||
{
|
||||
return "Testing BillBoard";
|
||||
}
|
||||
std::string BillBoardTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
void BillBoardTest::addNewBillBoradWithCoords(Vec3 p)
|
||||
{
|
||||
std::string imgs[3] = {"Images/Icon.png", "Images/r2.png"};
|
||||
for (unsigned int i = 0; i < 10; ++i)
|
||||
{
|
||||
auto billborad = BillBoard::create(imgs[(unsigned int)(CCRANDOM_0_1() * 1 + 0.5)]);
|
||||
billborad->setScale(0.5f);
|
||||
billborad->setPosition3D(Vec3(p.x, p.y, -150.0f + 30 * i));
|
||||
billborad->setBlendFunc(cocos2d::BlendFunc::ALPHA_NON_PREMULTIPLIED);
|
||||
billborad->setOpacity(CCRANDOM_0_1() * 128 + 128);
|
||||
_layerBillBorad->addChild(billborad);
|
||||
_billboards.push_back(billborad);
|
||||
}
|
||||
}
|
||||
void BillBoardTest::addNewAniBillBoradWithCoords(Vec3 p)
|
||||
{
|
||||
for (unsigned int i = 0; i < 10; ++i)
|
||||
{
|
||||
auto billboradAni = BillBoard::create("Images/grossini.png");
|
||||
billboradAni->setScale(0.5f);
|
||||
billboradAni->setPosition3D(Vec3(p.x, p.y, -150.0f + 30 * i));
|
||||
_layerBillBorad->addChild(billboradAni);
|
||||
|
||||
auto animation = Animation::create();
|
||||
for( int i=1;i<15;i++)
|
||||
{
|
||||
char szName1[100] = {0};
|
||||
sprintf(szName1, "Images/grossini_dance_%02d.png", i);
|
||||
animation->addSpriteFrameWithFile(szName1);
|
||||
}
|
||||
// should last 2.8 seconds. And there are 14 frames.
|
||||
animation->setDelayPerUnit(2.8f / 14.0f);
|
||||
animation->setRestoreOriginalFrame(true);
|
||||
|
||||
auto action = Animate::create(animation);
|
||||
billboradAni->runAction(RepeatForever::create(action));
|
||||
billboradAni->setBlendFunc(cocos2d::BlendFunc::ALPHA_NON_PREMULTIPLIED);
|
||||
billboradAni->setOpacity(CCRANDOM_0_1() * 128 + 128);
|
||||
_billboards.push_back(billboradAni);
|
||||
}
|
||||
}
|
||||
void BillBoardTest::update(float dt)
|
||||
{
|
||||
|
||||
}
|
||||
void BillBoardTest::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
||||
{
|
||||
if(touches.size()==1)
|
||||
{
|
||||
auto touch = touches[0];
|
||||
auto location = touch->getLocation();
|
||||
auto PreviousLocation = touch->getPreviousLocation();
|
||||
Point newPos = PreviousLocation - location;
|
||||
|
||||
Vec3 cameraDir;
|
||||
Vec3 cameraRightDir;
|
||||
_camera->getNodeToWorldTransform().getForwardVector(&cameraDir);
|
||||
cameraDir.normalize();
|
||||
cameraDir.y=0;
|
||||
_camera->getNodeToWorldTransform().getRightVector(&cameraRightDir);
|
||||
cameraRightDir.normalize();
|
||||
cameraRightDir.y=0;
|
||||
Vec3 cameraPos= _camera->getPosition3D();
|
||||
cameraPos+=cameraDir*newPos.y*0.5;
|
||||
cameraPos+=cameraRightDir*newPos.x*0.5;
|
||||
_camera->setPosition3D(cameraPos);
|
||||
}
|
||||
}
|
||||
void BillBoardTest::rotateCameraCallback(Ref* sender,float value)
|
||||
{
|
||||
Vec3 rotation3D= _camera->getRotation3D();
|
||||
rotation3D.y+= value;
|
||||
_camera->setRotation3D(rotation3D);
|
||||
}
|
||||
|
||||
void BillBoardTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextSpriteTestAction();
|
||||
addChild(layer);
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _BILLBOARD_TEST_H_
|
||||
#define _BILLBOARD_TEST_H_
|
||||
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
#include <string>
|
||||
|
||||
namespace cocos2d {
|
||||
class BillBoard;
|
||||
class Camera;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class BillBoardTest : public BaseTest
|
||||
{
|
||||
public:
|
||||
virtual ~BillBoardTest(void);
|
||||
CREATE_FUNC(BillBoardTest);
|
||||
BillBoardTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void update(float dt) override;
|
||||
void addNewBillBoradWithCoords(Vec3 p);
|
||||
void addNewAniBillBoradWithCoords(Vec3 p);
|
||||
void rotateCameraCallback(Ref* sender,float value);
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event* event);
|
||||
|
||||
void menuCallback_orientedPoint(Ref* sender);
|
||||
void menuCallback_orientedPlane(Ref* sender);
|
||||
|
||||
protected:
|
||||
Camera* _camera;
|
||||
Layer* _layerBillBorad;
|
||||
|
||||
std::vector<BillBoard*> _billboards;
|
||||
};
|
||||
|
||||
class BillBoardTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -63,6 +63,7 @@ Controller g_aTestNames[] = {
|
|||
{ "FileUtils", []() { return new FileUtilsTestScene(); } },
|
||||
{ "Fonts", []() { return new FontTestScene(); } },
|
||||
{ "Interval", [](){return new IntervalTestScene(); } },
|
||||
{ "Node: BillBoard Test", [](){ return new BillBoardTestScene(); }},
|
||||
{ "Node: Camera 3D Test", [](){ return new Camera3DTestScene(); }},
|
||||
{ "Node: Clipping", []() { return new ClippingNodeTestScene(); } },
|
||||
{ "Node: Draw", [](){return new DrawPrimitivesTestScene();} },
|
||||
|
|
|
@ -73,5 +73,6 @@
|
|||
|
||||
#include "Sprite3DTest/Sprite3DTest.h"
|
||||
#include "Camera3DTest/Camera3DTest.h"
|
||||
#include "BillBoardTest/BillBoardTest.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -137,6 +137,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\Classes\BaseTest.cpp" />
|
||||
<ClCompile Include="..\Classes\BillBoardTest\BillBoardTest.cpp" />
|
||||
<ClCompile Include="..\Classes\BugsTest\Bug-Child.cpp" />
|
||||
<ClCompile Include="..\Classes\Camera3DTest\Camera3DTest.cpp" />
|
||||
<ClCompile Include="..\Classes\ChipmunkTest\ChipmunkTest.cpp" />
|
||||
|
@ -316,6 +317,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\Classes\BaseTest.h" />
|
||||
<ClInclude Include="..\Classes\BillBoardTest\BillBoardTest.h" />
|
||||
<ClInclude Include="..\Classes\Box2DTestBed\Tests\ConvexHull.h" />
|
||||
<ClInclude Include="..\Classes\Box2DTestBed\Tests\ConveyorBelt.h" />
|
||||
<ClInclude Include="..\Classes\Box2DTestBed\Tests\Mobile.h" />
|
||||
|
|
|
@ -325,6 +325,9 @@
|
|||
<Filter Include="Classes\Camera3DTest">
|
||||
<UniqueIdentifier>{7f85be1c-98c5-4412-afc5-6f39ae1452a7}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Classes\BillBoardTest">
|
||||
<UniqueIdentifier>{54a30b92-ddfb-420e-908b-886c23c21cf1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
|
@ -858,6 +861,9 @@
|
|||
<ClCompile Include="..\Classes\UITest\CocoStudioGUITest\UIEditBoxTest.cpp">
|
||||
<Filter>Classes\UITest\CocostudioGUISceneTest</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\BillBoardTest\BillBoardTest.cpp">
|
||||
<Filter>Classes\BillBoardTest</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="main.h">
|
||||
|
@ -1589,5 +1595,8 @@
|
|||
<ClInclude Include="..\Classes\UITest\CocoStudioGUITest\UIEditBoxTest.h">
|
||||
<Filter>Classes\UITest\CocostudioGUISceneTest</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\BillBoardTest\BillBoardTest.h">
|
||||
<Filter>Classes\BillBoardTest</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -136,7 +136,8 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS
|
|||
Animation3DCache::[*],
|
||||
Sprite3DMaterialCache::[*],
|
||||
Sprite3DCache::[*],
|
||||
Bone3D::[*]
|
||||
Bone3D::[*],
|
||||
BillBoard::[*]
|
||||
|
||||
rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame],
|
||||
ProgressTimer::[setReverseProgress=setReverseDirection],
|
||||
|
|
|
@ -44,7 +44,8 @@ skip = Mesh::[create getAABB],
|
|||
Bone3D::[*],
|
||||
Ray::[*],
|
||||
AABB::[*],
|
||||
OBB::[*]
|
||||
OBB::[*],
|
||||
BillBoard::[create]
|
||||
|
||||
rename_functions =
|
||||
|
||||
|
|
Loading…
Reference in New Issue