diff --git a/AUTHORS b/AUTHORS index 75b7360c1c..1b20f6df42 100644 --- a/AUTHORS +++ b/AUTHORS @@ -975,6 +975,9 @@ Developers: DavidPartouche Fixed the bug that video player not showing on iOS if it's not in FullScreen mode + + zaWasp + Added support for applicationDidEnterBackground / applicationWillEnterForeground on win32 Retired Core Developers: WenSheng Yang diff --git a/CHANGELOG b/CHANGELOG index 9e4b52c463..c7a4200e53 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,9 @@ cocos2d-x-3.3 ?? [NEW] Added submesh support, and support attaching a Sprite3D object to a bone [NEW] Added UIScale9Sprite - [NEW] Added Camera + [NEW] Added Camera, AABB, OBB and Ray [NEW] Added render primitive and render primitive command, support passing point, line and triangle data + [NEW] Added support for applicationDidEnterBackground / applicationWillEnterForeground on desktop [NEW] EventMouse: support getDelta, getDeltaX, getDeltaY functions [NEW] FileUtils: add isDirectoryExist(), createDirectory(), removeDirectory(), removeFile(), renameFile() getFileSize() @@ -14,8 +15,11 @@ cocos2d-x-3.3 ?? [NEW] RotateTo: added 3D rotation support [NEW] ScrollView: added `setMinScale()` and `setMaxScale()` [NEW] Sprite3D: added setCullFace() and setCullFaceEnabled() + [NEW] Sprite3D: added getBoundingBox() and getAABB() [NEW] SpriteFrameCache: load from plist file content data [NEW] utils: added gettime() + [NEW] ui::Button: support customize how much zoom scale is when pressing a button + [NEW] ui::PageView: added `customScrollThreshold`, could determine the swipe distance to trigger a PageView scroll event [NEW] ui::TextField: support utf8 [NEW] ui::TextField: support set color and placehold color [NEW] Text: added getter and setter for TextColor diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 138951d22f..00a135606f 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -690,6 +690,10 @@ 464AD6E6197EBB1400E502D8 /* pvr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 464AD6E3197EBB1400E502D8 /* pvr.cpp */; }; 464AD6E7197EBB1400E502D8 /* pvr.h in Headers */ = {isa = PBXBuildFile; fileRef = 464AD6E4197EBB1400E502D8 /* pvr.h */; }; 464AD6E8197EBB1400E502D8 /* pvr.h in Headers */ = {isa = PBXBuildFile; fileRef = 464AD6E4197EBB1400E502D8 /* pvr.h */; }; + 46633BC4199DDB2F00F6E838 /* CCModuleManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46633BC2199DDB2F00F6E838 /* CCModuleManager.cpp */; }; + 46633BC5199DDB2F00F6E838 /* CCModuleManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46633BC2199DDB2F00F6E838 /* CCModuleManager.cpp */; }; + 46633BC6199DDB2F00F6E838 /* CCModuleManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 46633BC3199DDB2F00F6E838 /* CCModuleManager.h */; }; + 46633BC7199DDB2F00F6E838 /* CCModuleManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 46633BC3199DDB2F00F6E838 /* CCModuleManager.h */; }; 46A160421807A5D4005B8026 /* Export.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A15FE11807A56F005B8026 /* Export.h */; }; 46A160431807A5D4005B8026 /* SimpleAudioEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A15FE21807A56F005B8026 /* SimpleAudioEngine.h */; }; 46A160441807A5D4005B8026 /* CDAudioManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A15FF41807A56F005B8026 /* CDAudioManager.h */; }; @@ -1871,6 +1875,18 @@ B3AF01A31842FBA400A98B85 /* b2MotorJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = B3AF019F1842FBA400A98B85 /* b2MotorJoint.h */; }; B3B12A5A17E7F44000026B4A /* libchipmunk Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A03F2CB81780BD04006731B9 /* libchipmunk Mac.a */; }; B3B12A5B17E7F45C00026B4A /* libchipmunk iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A07A4F3B178387670073F6A7 /* libchipmunk iOS.a */; }; + B610517B199CB1A600DC41CE /* CCAABB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6105175199CB1A600DC41CE /* CCAABB.cpp */; }; + B610517C199CB1A600DC41CE /* CCAABB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6105175199CB1A600DC41CE /* CCAABB.cpp */; }; + B610517D199CB1A600DC41CE /* CCAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = B6105176199CB1A600DC41CE /* CCAABB.h */; }; + B610517E199CB1A600DC41CE /* CCAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = B6105176199CB1A600DC41CE /* CCAABB.h */; }; + B610517F199CB1A600DC41CE /* CCOBB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6105177199CB1A600DC41CE /* CCOBB.cpp */; }; + B6105180199CB1A600DC41CE /* CCOBB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6105177199CB1A600DC41CE /* CCOBB.cpp */; }; + B6105181199CB1A600DC41CE /* CCOBB.h in Headers */ = {isa = PBXBuildFile; fileRef = B6105178199CB1A600DC41CE /* CCOBB.h */; }; + B6105182199CB1A600DC41CE /* CCOBB.h in Headers */ = {isa = PBXBuildFile; fileRef = B6105178199CB1A600DC41CE /* CCOBB.h */; }; + B6105183199CB1A600DC41CE /* CCRay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6105179199CB1A600DC41CE /* CCRay.cpp */; }; + B6105184199CB1A600DC41CE /* CCRay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6105179199CB1A600DC41CE /* CCRay.cpp */; }; + B6105185199CB1A600DC41CE /* CCRay.h in Headers */ = {isa = PBXBuildFile; fileRef = B610517A199CB1A600DC41CE /* CCRay.h */; }; + B6105186199CB1A600DC41CE /* CCRay.h in Headers */ = {isa = PBXBuildFile; fileRef = B610517A199CB1A600DC41CE /* CCRay.h */; }; B6AAF84119404E0D0069DE01 /* CCBundle3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6AAF83F19404E0D0069DE01 /* CCBundle3D.cpp */; }; B6AAF84219404E0D0069DE01 /* CCBundle3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6AAF83F19404E0D0069DE01 /* CCBundle3D.cpp */; }; B6AAF84319404E0D0069DE01 /* CCBundle3D.h in Headers */ = {isa = PBXBuildFile; fileRef = B6AAF84019404E0D0069DE01 /* CCBundle3D.h */; }; @@ -2505,6 +2521,8 @@ 3EA4786F195478E00068D9D1 /* CCBundleReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCBundleReader.h; sourceTree = ""; }; 464AD6E3197EBB1400E502D8 /* pvr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = pvr.cpp; path = ../base/pvr.cpp; sourceTree = ""; }; 464AD6E4197EBB1400E502D8 /* pvr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pvr.h; path = ../base/pvr.h; sourceTree = ""; }; + 46633BC2199DDB2F00F6E838 /* CCModuleManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCModuleManager.cpp; path = ../base/CCModuleManager.cpp; sourceTree = ""; }; + 46633BC3199DDB2F00F6E838 /* CCModuleManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCModuleManager.h; path = ../base/CCModuleManager.h; sourceTree = ""; }; 46A15FCC1807A544005B8026 /* AUTHORS */ = {isa = PBXFileReference; lastKnownFileType = text; name = AUTHORS; path = ../AUTHORS; sourceTree = ""; }; 46A15FCE1807A544005B8026 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; name = README.md; path = ../README.md; sourceTree = ""; }; 46A15FE11807A56F005B8026 /* Export.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Export.h; sourceTree = ""; }; @@ -3065,6 +3083,12 @@ B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorldInfo_chipmunk.h; sourceTree = ""; }; B3AF019E1842FBA400A98B85 /* b2MotorJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MotorJoint.cpp; sourceTree = ""; }; B3AF019F1842FBA400A98B85 /* b2MotorJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MotorJoint.h; sourceTree = ""; }; + B6105175199CB1A600DC41CE /* CCAABB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCAABB.cpp; sourceTree = ""; }; + B6105176199CB1A600DC41CE /* CCAABB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCAABB.h; sourceTree = ""; }; + B6105177199CB1A600DC41CE /* CCOBB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCOBB.cpp; sourceTree = ""; }; + B6105178199CB1A600DC41CE /* CCOBB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCOBB.h; sourceTree = ""; }; + B6105179199CB1A600DC41CE /* CCRay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCRay.cpp; sourceTree = ""; }; + B610517A199CB1A600DC41CE /* CCRay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCRay.h; sourceTree = ""; }; B6AAF83F19404E0D0069DE01 /* CCBundle3D.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCBundle3D.cpp; sourceTree = ""; }; B6AAF84019404E0D0069DE01 /* CCBundle3D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCBundle3D.h; sourceTree = ""; }; B6ACD895193D6693005E0B8A /* CCMeshSkin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCMeshSkin.cpp; sourceTree = ""; }; @@ -3411,6 +3435,8 @@ 1A570095180BC5B00088DEC7 /* base-nodes */ = { isa = PBXGroup; children = ( + 46633BC2199DDB2F00F6E838 /* CCModuleManager.cpp */, + 46633BC3199DDB2F00F6E838 /* CCModuleManager.h */, 15EFA20F198A2BB5000C57D3 /* CCProtectedNode.cpp */, 15EFA210198A2BB5000C57D3 /* CCProtectedNode.h */, 1A57009C180BC5D20088DEC7 /* CCNode.cpp */, @@ -5229,6 +5255,12 @@ B29594B81926D61F003EEF37 /* 3d */ = { isa = PBXGroup; children = ( + B6105175199CB1A600DC41CE /* CCAABB.cpp */, + B6105176199CB1A600DC41CE /* CCAABB.h */, + B6105177199CB1A600DC41CE /* CCOBB.cpp */, + B6105178199CB1A600DC41CE /* CCOBB.h */, + B6105179199CB1A600DC41CE /* CCRay.cpp */, + B610517A199CB1A600DC41CE /* CCRay.h */, 3EA2A83E1987A6810077B3D4 /* CCSkeleton3D.cpp */, 3EA2A83F1987A6810077B3D4 /* CCSkeleton3D.h */, 3E9E80E3198639EF00FA95D0 /* CCAttachNode.cpp */, @@ -5280,6 +5312,7 @@ 1ABA68B01888D700007D1BB4 /* CCFontCharMap.h in Headers */, 5034CA3F191D591100CE6051 /* ccShader_Position_uColor.vert in Headers */, 50ABBD461925AB0000A911A9 /* CCVertex.h in Headers */, + 46633BC6199DDB2F00F6E838 /* CCModuleManager.h in Headers */, 46A170E71807CECA005B8026 /* CCPhysicsBody.h in Headers */, 46A170EB1807CECA005B8026 /* CCPhysicsJoint.h in Headers */, 50ABBD3E1925AB0000A911A9 /* CCGeometry.h in Headers */, @@ -5333,6 +5366,7 @@ 1AC0269C1914068200FA920D /* ConvertUTF.h in Headers */, 50ABBED11925AB6F00A911A9 /* TGAlib.h in Headers */, 1A57019F180BCB590088DEC7 /* CCFont.h in Headers */, + B6105185199CB1A600DC41CE /* CCRay.h in Headers */, 1A5701A3180BCB590088DEC7 /* CCFontAtlas.h in Headers */, 1A01C68618F57BE800EFE3A6 /* CCArray.h in Headers */, 1A5701A7180BCB590088DEC7 /* CCFontAtlasCache.h in Headers */, @@ -5361,6 +5395,7 @@ 1A5701FD180BCBAD0088DEC7 /* CCMenuItem.h in Headers */, 1A570204180BCBD40088DEC7 /* CCClippingNode.h in Headers */, 1A01C6A618F58F7500EFE3A6 /* CCNotificationCenter.h in Headers */, + B6105181199CB1A600DC41CE /* CCOBB.h in Headers */, 1A57020A180BCBDF0088DEC7 /* CCMotionStreak.h in Headers */, 1A570212180BCBF40088DEC7 /* CCProgressTimer.h in Headers */, 1A570216180BCBF40088DEC7 /* CCRenderTexture.h in Headers */, @@ -5484,6 +5519,7 @@ 50ABBDB31925AB4100A911A9 /* ccShaders.h in Headers */, 50ABBDAB1925AB4100A911A9 /* CCRenderCommandPool.h in Headers */, 5034CA45191D591100CE6051 /* ccShader_Label_outline.frag in Headers */, + B610517D199CB1A600DC41CE /* CCAABB.h in Headers */, 50ABBEB11925AB6F00A911A9 /* CCUserDefault.h in Headers */, 50ABBEC71925AB6F00A911A9 /* etc1.h in Headers */, 50ABBEA91925AB6F00A911A9 /* CCTouch.h in Headers */, @@ -5664,6 +5700,7 @@ 50ABC0041926664800A911A9 /* CCLock.h in Headers */, 5034CA40191D591100CE6051 /* ccShader_Position_uColor.vert in Headers */, 50ABBEC21925AB6F00A911A9 /* CCValue.h in Headers */, + 46633BC7199DDB2F00F6E838 /* CCModuleManager.h in Headers */, 50ABBECA1925AB6F00A911A9 /* firePngData.h in Headers */, B257B4511989D5E800D9A687 /* CCPrimitive.h in Headers */, 50ABBE401925AB6F00A911A9 /* CCDataVisitor.h in Headers */, @@ -5749,6 +5786,7 @@ 50ABC00C1926664800A911A9 /* CCDevice.h in Headers */, 1A570205180BCBD40088DEC7 /* CCClippingNode.h in Headers */, 5034CA34191D591100CE6051 /* ccShader_PositionTexture_uColor.frag in Headers */, + B6105182199CB1A600DC41CE /* CCOBB.h in Headers */, 50ABBEA21925AB6F00A911A9 /* CCScheduler.h in Headers */, 1A57020B180BCBDF0088DEC7 /* CCMotionStreak.h in Headers */, 1A570213180BCBF40088DEC7 /* CCProgressTimer.h in Headers */, @@ -5846,6 +5884,7 @@ 50ABBE821925AB6F00A911A9 /* CCEventType.h in Headers */, 1AAF5852180E40B9000584C8 /* LocalStorage.h in Headers */, 50ABBD471925AB0000A911A9 /* CCVertex.h in Headers */, + B6105186199CB1A600DC41CE /* CCRay.h in Headers */, 1A9DCA2A180E6955007A3AD4 /* CCGLBufferedNode.h in Headers */, 1A01C69F18F57BE800EFE3A6 /* CCString.h in Headers */, 464AD6E8197EBB1400E502D8 /* pvr.h in Headers */, @@ -5861,6 +5900,7 @@ B276EF641988D1D500CD400F /* CCVertexIndexBuffer.h in Headers */, ED9C6A9718599AD8000A5232 /* CCNodeGrid.h in Headers */, 50ABC0201926664800A911A9 /* CCThread.h in Headers */, + B610517E199CB1A600DC41CE /* CCAABB.h in Headers */, 1A01C69318F57BE800EFE3A6 /* CCDouble.h in Headers */, 50ABBE221925AB6F00A911A9 /* atitc.h in Headers */, 3EA47873195478E00068D9D1 /* CCBundleReader.h in Headers */, @@ -6783,6 +6823,7 @@ 46A170ED1807CECA005B8026 /* CCPhysicsShape.cpp in Sources */, 50ABBE991925AB6F00A911A9 /* CCRef.cpp in Sources */, ED9C6A9418599AD8000A5232 /* CCNodeGrid.cpp in Sources */, + B610517F199CB1A600DC41CE /* CCOBB.cpp in Sources */, 46A170E61807CECA005B8026 /* CCPhysicsBody.cpp in Sources */, 50ABBDA71925AB4100A911A9 /* CCRenderCommand.cpp in Sources */, 50ABBD501925AB0000A911A9 /* Quaternion.cpp in Sources */, @@ -6821,6 +6862,7 @@ 50ABBE651925AB6F00A911A9 /* CCEventListenerCustom.cpp in Sources */, B37510781823AC9F00B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp in Sources */, 50ABBE391925AB6F00A911A9 /* CCData.cpp in Sources */, + 46633BC4199DDB2F00F6E838 /* CCModuleManager.cpp in Sources */, 1A57010E180BC8EE0088DEC7 /* CCDrawingPrimitives.cpp in Sources */, 50ABBED71925AB6F00A911A9 /* ZipUtils.cpp in Sources */, 1A01C68418F57BE800EFE3A6 /* CCArray.cpp in Sources */, @@ -6899,6 +6941,7 @@ 1A01C69C18F57BE800EFE3A6 /* CCString.cpp in Sources */, 50ABBD3C1925AB0000A911A9 /* CCGeometry.cpp in Sources */, 50ABC0011926664800A911A9 /* CCLock.cpp in Sources */, + B6105183199CB1A600DC41CE /* CCRay.cpp in Sources */, 50ABBD931925AB4100A911A9 /* CCGLProgramState.cpp in Sources */, 1A57034B180BD09B0088DEC7 /* tinyxml2.cpp in Sources */, 1A570354180BD0B00088DEC7 /* ioapi.cpp in Sources */, @@ -6909,6 +6952,7 @@ 50ABBE831925AB6F00A911A9 /* ccFPSImages.c in Sources */, 50ABBEA71925AB6F00A911A9 /* CCTouch.cpp in Sources */, 50ABBD8B1925AB4100A911A9 /* CCGLProgram.cpp in Sources */, + B610517B199CB1A600DC41CE /* CCAABB.cpp in Sources */, 464AD6E5197EBB1400E502D8 /* pvr.cpp in Sources */, 50ABBDA31925AB4100A911A9 /* CCQuadCommand.cpp in Sources */, B29594C61926D61F003EEF37 /* CCObjLoader.cpp in Sources */, @@ -7131,7 +7175,9 @@ 1A570072180BC5A10088DEC7 /* CCActionGrid.cpp in Sources */, 50ABBE621925AB6F00A911A9 /* CCEventListenerAcceleration.cpp in Sources */, 3E6176681960F89B00DE83F5 /* CCController-iOS.mm in Sources */, + B6105180199CB1A600DC41CE /* CCOBB.cpp in Sources */, B29594B51926D5EC003EEF37 /* CCMeshCommand.cpp in Sources */, + B6105184199CB1A600DC41CE /* CCRay.cpp in Sources */, 50ABBE7E1925AB6F00A911A9 /* CCEventTouch.cpp in Sources */, 50ABBE6E1925AB6F00A911A9 /* CCEventListenerKeyboard.cpp in Sources */, 50ABBE461925AB6F00A911A9 /* CCEvent.cpp in Sources */, @@ -7228,6 +7274,7 @@ 50ABBE8C1925AB6F00A911A9 /* CCNS.cpp in Sources */, 50ABBDAE1925AB4100A911A9 /* CCRenderer.cpp in Sources */, 50ABBDBA1925AB4100A911A9 /* CCTextureAtlas.cpp in Sources */, + 46633BC5199DDB2F00F6E838 /* CCModuleManager.cpp in Sources */, 1A5702FB180BCE750088DEC7 /* CCTMXXMLParser.cpp in Sources */, 1A570301180BCE890088DEC7 /* CCParallaxNode.cpp in Sources */, 1A57030D180BCF190088DEC7 /* CCComponent.cpp in Sources */, @@ -7284,6 +7331,7 @@ 50ABBE4A1925AB6F00A911A9 /* CCEventAcceleration.cpp in Sources */, 46C02E0818E91123004B7456 /* xxhash.c in Sources */, 50ABBED01925AB6F00A911A9 /* TGAlib.cpp in Sources */, + B610517C199CB1A600DC41CE /* CCAABB.cpp in Sources */, 1A01C68518F57BE800EFE3A6 /* CCArray.cpp in Sources */, 503DD8E31926736A00CD74DD /* CCDevice.mm in Sources */, 50ABBEB41925AB6F00A911A9 /* CCUserDefault.mm in Sources */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 0cc96da5ca..24d4e9d5be 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -962,6 +962,8 @@ 3EA0FB72191C844400B170C8 /* UIVideoPlayerTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA0FB70191C844400B170C8 /* UIVideoPlayerTest.cpp */; }; 59620E8F1921E5CF002021B6 /* Bug-Child.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59620E8D1921E5CF002021B6 /* Bug-Child.cpp */; }; 59620E901921E5CF002021B6 /* Bug-Child.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59620E8D1921E5CF002021B6 /* Bug-Child.cpp */; }; + 5EBEECB01995247000429821 /* DrawNode3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EBEECAE1995247000429821 /* DrawNode3D.cpp */; }; + 5EBEECB11995247000429821 /* DrawNode3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EBEECAE1995247000429821 /* DrawNode3D.cpp */; }; A05FCACA177C124500BE600E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64822165F391E007D4F18 /* Cocoa.framework */; }; A07A521E1783A1D20073F6A7 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C6482E165F399D007D4F18 /* libz.dylib */; }; A07A521F1783A1D20073F6A7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64832165F3AFD007D4F18 /* Foundation.framework */; }; @@ -3651,6 +3653,8 @@ 46A15F9C1807A4F8005B8026 /* cocos2d_libs.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = cocos2d_libs.xcodeproj; sourceTree = ""; }; 59620E8D1921E5CF002021B6 /* Bug-Child.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "Bug-Child.cpp"; sourceTree = ""; }; 59620E8E1921E5CF002021B6 /* Bug-Child.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bug-Child.h"; sourceTree = ""; }; + 5EBEECAE1995247000429821 /* DrawNode3D.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DrawNode3D.cpp; path = Sprite3DTest/DrawNode3D.cpp; sourceTree = ""; }; + 5EBEECAF1995247000429821 /* DrawNode3D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DrawNode3D.h; path = Sprite3DTest/DrawNode3D.h; sourceTree = ""; }; 70A7F72D191D3E4900F0F206 /* shaderTest.psh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = shaderTest.psh.h; sourceTree = ""; }; 70A7F730191D421B00F0F206 /* ShaderTest.vsh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShaderTest.vsh.h; sourceTree = ""; }; A035A71117822E9E00987F6C /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; }; @@ -7882,6 +7886,8 @@ 3E92EA7D1921A0C60094CD21 /* Sprite3DTest */ = { isa = PBXGroup; children = ( + 5EBEECAE1995247000429821 /* DrawNode3D.cpp */, + 5EBEECAF1995247000429821 /* DrawNode3D.h */, 3E92EA801921A1400094CD21 /* Sprite3DTest.cpp */, 3E92EA811921A1400094CD21 /* Sprite3DTest.h */, ); @@ -9138,6 +9144,7 @@ 29080DC3191B595E0066F8DF /* UIScene.cpp in Sources */, 29080D9B191B595E0066F8DF /* CustomParticleWidget.cpp in Sources */, 29080D8D191B595E0066F8DF /* CocosGUIScene.cpp in Sources */, + 5EBEECB01995247000429821 /* DrawNode3D.cpp in Sources */, 1AC35BED18CECF0C00F37B72 /* CCControlStepperTest.cpp in Sources */, 1AC35C3318CECF0C00F37B72 /* PerformanceScenarioTest.cpp in Sources */, 1AC35C5918CECF0C00F37B72 /* TextureAtlasEncryptionTest.cpp in Sources */, @@ -9232,6 +9239,7 @@ 29080DB4191B595E0066F8DF /* UILayoutTest_Editor.cpp in Sources */, 1AC35C4E18CECF0C00F37B72 /* SpineTest.cpp in Sources */, 1AC35C1E18CECF0C00F37B72 /* NewRendererTest.cpp in Sources */, + 5EBEECB11995247000429821 /* DrawNode3D.cpp in Sources */, 1AC35B6818CECF0C00F37B72 /* AnimationsTestLayer.cpp in Sources */, 29080D8E191B595E0066F8DF /* CocosGUIScene.cpp in Sources */, 1AC35BFA18CECF0C00F37B72 /* WebSocketTest.cpp in Sources */, diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 15d72f6541..b09a09d8c6 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -183,6 +183,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + @@ -191,7 +192,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + + @@ -224,6 +227,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + @@ -374,6 +378,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + @@ -384,7 +389,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + + @@ -422,6 +429,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index 54b98392f3..e66518514c 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -613,6 +613,15 @@ base + + 3d + + + 3d + + + 3d + renderer @@ -625,6 +634,9 @@ renderer + + base + 3d @@ -1261,6 +1273,15 @@ base + + 3d + + + 3d + + + 3d + renderer @@ -1273,6 +1294,9 @@ renderer + + base + 3d diff --git a/cocos/3d/CCAABB.cpp b/cocos/3d/CCAABB.cpp new file mode 100755 index 0000000000..4c159ae8b8 --- /dev/null +++ b/cocos/3d/CCAABB.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** + 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/CCAABB.h" + +NS_CC_BEGIN + +AABB::AABB() +{ + reset(); +} + +AABB::AABB(const Vec3& min, const Vec3& max) +{ + set(min, max); +} + +AABB::AABB(const AABB& box) +{ + set(box._min,box._max); +} + +Vec3 AABB::getCenter() +{ + Vec3 center; + center.x = 0.5f*(_min.x+_max.x); + center.y = 0.5f*(_min.y+_max.y); + center.z = 0.5f*(_min.z+_max.z); + + return center; +} + +void AABB::getCorners(Vec3 *dst) const +{ + assert(dst); + + // Near face, specified counter-clockwise looking towards the origin from the positive z-axis. + // Left-top-front. + dst[0].set(_min.x, _max.y, _max.z); + // Left-bottom-front. + dst[1].set(_min.x, _min.y, _max.z); + // Right-bottom-front. + dst[2].set(_max.x, _min.y, _max.z); + // Right-top-front. + dst[3].set(_max.x, _max.y, _max.z); + + // Far face, specified counter-clockwise looking towards the origin from the negative z-axis. + // Right-top-back. + dst[4].set(_max.x, _max.y, _min.z); + // Right-bottom-back. + dst[5].set(_max.x, _min.y, _min.z); + // Left-bottom-back. + dst[6].set(_min.x, _min.y, _min.z); + // Left-top-back. + dst[7].set(_min.x, _max.y, _min.z); +} + +bool AABB::intersects(const AABB& aabb) const +{ + return ((_min.x >= aabb._min.x && _min.x <= aabb._max.x) || (aabb._min.x >= _min.x && aabb._min.x <= _max.x)) && + ((_min.y >= aabb._min.y && _min.y <= aabb._max.y) || (aabb._min.y >= _min.y && aabb._min.y <= _max.y)) && + ((_min.z >= aabb._min.z && _min.z <= aabb._max.z) || (aabb._min.z >= _min.z && aabb._min.z <= _max.z)); +} + +bool AABB::containPoint(const Vec3& point) const +{ + if (point.x < _min.x) return false; + if (point.y < _min.y) return false; + if (point.z < _min.z) return false; + if (point.x > _max.x) return false; + if (point.y > _max.y) return false; + if (point.z > _max.z) return false; + return true; +} + +void AABB::merge(const AABB& box) +{ + // Calculate the new minimum point. + _min.x = std::min(_min.x, box._min.x); + _min.y = std::min(_min.y, box._min.y); + _min.z = std::min(_min.z, box._min.z); + + // Calculate the new maximum point. + _max.x = std::max(_max.x, box._max.x); + _max.y = std::max(_max.y, box._max.y); + _max.z = std::max(_max.z, box._max.z); +} + +void AABB::set(const Vec3& min, const Vec3& max) +{ + this->_min = min; + this->_max = max; +} + +void AABB::reset() +{ + _min.set(99999.0f, 99999.0f, 99999.0f); + _max.set(-99999.0f, -99999.0f, -99999.0f); +} + +void AABB::updateMinMax(const Vec3* point, ssize_t num) +{ + for (ssize_t i = 0; i < num; i++) + { + // Leftmost point. + if (point[i].x < _min.x) + _min.x = point[i].x; + + // Lowest point. + if (point[i].y < _min.y) + _min.y = point[i].y; + + // Farthest point. + if (point[i].z < _min.z) + _min.z = point[i].z; + + // Rightmost point. + if (point[i].x > _max.x) + _max.x = point[i].x; + + // Highest point. + if (point[i].y > _max.y) + _max.y = point[i].y; + + // Nearest point. + if (point[i].z > _max.z) + _max.z = point[i].z; + } +} + +void AABB::transform(const Mat4& mat) +{ + Vec3 corners[8]; + // Near face, specified counter-clockwise + // Left-top-front. + corners[0].set(_min.x, _max.y, _max.z); + // Left-bottom-front. + corners[1].set(_min.x, _min.y, _max.z); + // Right-bottom-front. + corners[2].set(_max.x, _min.y, _max.z); + // Right-top-front. + corners[3].set(_max.x, _max.y, _max.z); + + // Far face, specified clockwise + // Right-top-back. + corners[4].set(_max.x, _max.y, _min.z); + // Right-bottom-back. + corners[5].set(_max.x, _min.y, _min.z); + // Left-bottom-back. + corners[6].set(_min.x, _min.y, _min.z); + // Left-top-back. + corners[7].set(_min.x, _max.y, _min.z); + + // Transform the corners, recalculate the min and max points along the way. + for (int i = 0; i < 8; i++) + mat.transformPoint(&corners[i]); + + reset(); + + updateMinMax(corners, 8); +} + +NS_CC_END diff --git a/cocos/3d/CCAABB.h b/cocos/3d/CCAABB.h new file mode 100755 index 0000000000..8894aa0098 --- /dev/null +++ b/cocos/3d/CCAABB.h @@ -0,0 +1,114 @@ +/**************************************************************************** + 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 __CC_AABB_H__ +#define __CC_AABB_H__ + +#include "base/ccMacros.h" +#include "math/CCMath.h" + +NS_CC_BEGIN + +class CC_DLL AABB +{ + +public: + /** + * Constructor. + */ + AABB(); + + /** + * Constructor. + */ + AABB(const Vec3& min, const Vec3& max); + + /** + * Constructor. + */ + AABB(const AABB& box); + + /** + * Gets the center point of the bounding box. + */ + Vec3 getCenter(); + + /* Near face, specified counter-clockwise looking towards the origin from the positive z-axis. + * verts[0] : left top front + * verts[1] : left bottom front + * verts[2] : right bottom front + * verts[3] : right top front + * + * Far face, specified counter-clockwise looking towards the origin from the negative z-axis. + * verts[4] : right top back + * verts[5] : right bottom back + * verts[6] : left bottom back + * verts[7] : left top back + */ + void getCorners(Vec3 *dst) const; + + /** + * Tests whether this bounding box intersects the specified bounding object. + */ + bool intersects(const AABB& aabb) const; + + /** + * check whether the point is in. + */ + bool containPoint(const Vec3& point) const; + + /** + * Sets this bounding box to the smallest bounding box + * that contains both this bounding object and the specified bounding box. + */ + void merge(const AABB& box); + + /** + * Sets this bounding box to the specified values. + */ + void set(const Vec3& min, const Vec3& max); + + /** + * reset min and max value. + */ + void reset(); + + /** + * update the _min and _max from the given point. + */ + void updateMinMax(const Vec3* point, ssize_t num); + + /** + * Transforms the bounding box by the given transformation matrix. + */ + void transform(const Mat4& mat); + +public: + Vec3 _min; + Vec3 _max; +}; + +NS_CC_END + +#endif diff --git a/cocos/3d/CCBillBoard.cpp b/cocos/3d/CCBillBoard.cpp index 0bf2bbca24..d3e09b9394 100644 --- a/cocos/3d/CCBillBoard.cpp +++ b/cocos/3d/CCBillBoard.cpp @@ -52,17 +52,6 @@ BillBorad* BillBorad::createWithTexture(Texture2D *texture) return nullptr; } -BillBorad* BillBorad::createWithTexture(Texture2D *texture, const Rect& rect, bool rotated) -{ - BillBorad *billborad = new (std::nothrow) BillBorad(); - if (billborad && billborad->initWithTexture(texture, rect, rotated)) - { - billborad->autorelease(); - return billborad; - } - CC_SAFE_DELETE(billborad); - return nullptr; -} BillBorad* BillBorad::create(const std::string& filename) { @@ -88,31 +77,6 @@ BillBorad* BillBorad::create(const std::string& filename, const Rect& rect) return nullptr; } -BillBorad* BillBorad::createWithSpriteFrame(SpriteFrame *spriteFrame) -{ - BillBorad *billborad = new (std::nothrow) BillBorad(); - if (billborad && spriteFrame && billborad->initWithSpriteFrame(spriteFrame)) - { - billborad->autorelease(); - return billborad; - } - CC_SAFE_DELETE(billborad); - return nullptr; -} - -BillBorad* BillBorad::createWithSpriteFrameName(const std::string& spriteFrameName) -{ - SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName); - -#if COCOS2D_DEBUG > 0 - char msg[256] = {0}; - sprintf(msg, "Invalid spriteFrameName: %s", spriteFrameName.c_str()); - CCASSERT(frame != nullptr, msg); -#endif - - return createWithSpriteFrame(frame); -} - BillBorad* BillBorad::create() { BillBorad *billborad = new (std::nothrow) BillBorad(); @@ -150,4 +114,4 @@ void BillBorad::calculateBillBoradMatrix(Mat4 &dst) dst.m[14]=0; } -NS_CC_END \ No newline at end of file +NS_CC_END diff --git a/cocos/3d/CCBillBoard.h b/cocos/3d/CCBillBoard.h index 0c76142716..69a6099154 100644 --- a/cocos/3d/CCBillBoard.h +++ b/cocos/3d/CCBillBoard.h @@ -76,38 +76,6 @@ public: */ static BillBorad* createWithTexture(Texture2D *texture); - /** - * Creates a BillBorad with a texture and a rect. - * - * After creation, the offset will be (0,0). - * - * @param texture A pointer to an existing Texture2D object. - * You can use a Texture2D object for many sprites. - * @param rect Only the contents inside the rect of this texture will be applied for this sprite. - * @param rotated Whether or not the rect is rotated - * @return An autoreleased BillBorad object - */ - static BillBorad* createWithTexture(Texture2D *texture, const Rect& rect, bool rotated=false); - - /** - * Creates a BillBorad with an sprite frame. - * - * @param spriteFrame A sprite frame which involves a texture and a rect - * @return An autoreleased BillBorad object - */ - static BillBorad* createWithSpriteFrame(SpriteFrame *spriteFrame); - - /** - * Creates a BillBorad with an sprite frame name. - * - * A SpriteFrame will be fetched from the SpriteFrameCache by spriteFrameName param. - * If the SpriteFrame doesn't exist it will raise an exception. - * - * @param spriteFrameName A null terminated string which indicates the sprite frame name. - * @return An autoreleased BillBorad object - */ - static BillBorad* createWithSpriteFrameName(const std::string& spriteFrameName); - /** draw BillBorad object */ virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; @@ -130,4 +98,5 @@ private: NS_CC_END -#endif // __CCBILLBOARD_H__ \ No newline at end of file + +#endif // __CCBILLBOARD_H__ diff --git a/cocos/3d/CCMesh.cpp b/cocos/3d/CCMesh.cpp index 76438101b1..16007b1588 100644 --- a/cocos/3d/CCMesh.cpp +++ b/cocos/3d/CCMesh.cpp @@ -207,6 +207,9 @@ bool Mesh::init(const std::vector& positions, const std::vector& n buildSubMeshes(); buildBuffer(); + + calOriginAABB(positions, 3); + return true; } @@ -220,6 +223,10 @@ bool Mesh::init(const std::vector& vertices, int vertexSizeInFloat, const buildSubMeshes(); buildBuffer(); + + unsigned int perVertexSize = _renderdata.calVertexSizeBytes() / sizeof(float); + calOriginAABB(vertices, perVertexSize); + return true; } @@ -245,6 +252,16 @@ void Mesh::cleanAndFreeBuffers() } } +void Mesh::calOriginAABB(const std::vector& vertices, unsigned int stride) +{ + ssize_t vertexNum = vertices.size() / stride; + for(unsigned int i = 0; i < vertexNum; i++) + { + Vec3 point = Vec3(vertices[i * stride], vertices[i * stride + 1], vertices[i * stride + 2]); + _originAABB.updateMinMax(&point, 1); + } +} + void Mesh::buildBuffer() { cleanAndFreeBuffers(); @@ -273,6 +290,11 @@ void Mesh::restore() buildBuffer(); } +const AABB& Mesh::getOriginAABB() const +{ + return _originAABB; +} + /** * MeshCache */ diff --git a/cocos/3d/CCMesh.h b/cocos/3d/CCMesh.h index 2cea95b189..304a09f207 100644 --- a/cocos/3d/CCMesh.h +++ b/cocos/3d/CCMesh.h @@ -37,6 +37,9 @@ #include "math/CCMath.h" #include "renderer/CCGLProgram.h" +#include "CCAABB.h" + + NS_CC_BEGIN class EventListenerCustom; @@ -121,6 +124,9 @@ public: /**build vertex buffer from renderdata*/ void restore(); + /** get origin aabb that calculate from vertices*/ + const AABB& getOriginAABB() const; + /**to be deprecated, those functions have been moved to SubMesh*/ /** get primitive type*/ CC_DEPRECATED_ATTRIBUTE PrimitiveType getPrimitiveType() const { return _subMeshes.at(0)->getPrimitiveType(); } @@ -147,12 +153,21 @@ CC_CONSTRUCTOR_ACCESS: void buildBuffer(); /**free buffer*/ void cleanAndFreeBuffers(); + + /* + * calculate AABB by origin vertices + * @param the vertices list + * @param stride the stride between two vertex's position data. + */ + void calOriginAABB(const std::vector& vertices, unsigned int stride); protected: GLuint _vertexBuffer; Vector _subMeshes; RenderMeshData _renderdata; + + AABB _originAABB; }; /** diff --git a/cocos/3d/CCOBB.cpp b/cocos/3d/CCOBB.cpp new file mode 100755 index 0000000000..a9e3235c31 --- /dev/null +++ b/cocos/3d/CCOBB.cpp @@ -0,0 +1,452 @@ +/**************************************************************************** + 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/CCOBB.h" + +NS_CC_BEGIN + +#define ROTATE(a,i,j,k,l) g=a.m[i + 4 * j]; h=a.m[k + 4 * l]; a.m[i + 4 * j]=(float)(g-s*(h+g*tau)); a.m[k + 4 * l]=(float)(h+s*(g-h*tau)); + +static Mat4 _getConvarianceMatrix(const Vec3* vertPos, int vertCount) +{ + int i; + Mat4 Cov; + + double S1[3]; + double S2[3][3]; + + S1[0] = S1[1] = S1[2] = 0.0; + S2[0][0] = S2[1][0] = S2[2][0] = 0.0; + S2[0][1] = S2[1][1] = S2[2][1] = 0.0; + S2[0][2] = S2[1][2] = S2[2][2] = 0.0; + + // get center of mass + for(i=0; i3 && fabs(dmip) + g == fabs(dmip) && fabs(dmiq) + g == fabs(dmiq) ) + { + a.m[ip + 4 * iq] = 0.0; + } + else if (fabs(a.m[ip + 4 * iq]) > tresh) + { + h = dmiq - dmip; + if (fabs(h) + g == fabs(h)) + { + t=(a.m[ip + 4 * iq])/h; + } + else + { + theta = 0.5 * h / (a.m[ip + 4 * iq]); + t=1.0 / (fabs(theta) + sqrt(1.0 + theta * theta)); + if (theta < 0.0) t = -t; + } + c = 1.0 / sqrt(1+t*t); + s = t*c; + tau = s / (1.0+c); + h = t * a.m[ip + 4 * iq]; + _getElement(z, ip) -= (float)h; + _getElement(z, iq) += (float)h; + _getElement(d, ip) -= (float)h; + _getElement(d, iq) += (float)h; + a.m[ip + 4 * iq]=0.0; + for(j = 0; j < ip; j++) { ROTATE(a,j,ip,j,iq); } + for(j = ip + 1; j < iq; j++) { ROTATE(a,ip,j,j,iq); } + for(j = iq + 1; j < n; j++) { ROTATE(a,ip,j,iq,j); } + for(j = 0; j < n; j++) { ROTATE(v,j,ip,j,iq); } + nrot++; + } + } + } + + for(ip = 0; ip < n; ip++) + { + _getElement(b, ip) += _getElement(z, ip); + _getElement(d, ip) = _getElement(b, ip); + _getElement(z, ip) = 0.0f; + } + } + + v.transpose(); + *vout = v; + *dout = d; + return; +} + +static Mat4 _getOBBOrientation(const Vec3* vertPos, int num) +{ + Mat4 Cov; + + if (num <= 0) + return Mat4::IDENTITY; + + Cov = _getConvarianceMatrix(vertPos, num); + + // now get eigenvectors + Mat4 Evecs; + Vec3 Evals; + _getEigenVectors(&Evecs, &Evals, Cov); + + Evecs.transpose(); + + return Evecs; +} + +OBB::OBB() +{ + reset(); +} + +OBB::OBB(const AABB& aabb) +{ + reset(); + + _center = (aabb._min + aabb._max); + _center.scale(0.5f); + _xAxis = Vec3(1.0f, 0.0f, 0.0f); + _yAxis = Vec3(0.0f, 1.0f, 0.0f); + _zAxis = Vec3(0.0f, 0.0f, 1.0f); + + _extents = aabb._max - aabb._min; + _extents.scale(0.5f); +} + +OBB::OBB(const Vec3* verts, int num) +{ + if (!verts) return; + + reset(); + + Mat4 matTransform = _getOBBOrientation(verts, num); + + // For matTransform is orthogonal, so the inverse matrix is just rotate it; + matTransform.transpose(); + + Vec3 vecMax = matTransform * Vec3(verts[0].x, verts[0].y, verts[0].z); + + Vec3 vecMin = vecMax; + + for (int i = 1; i < num; i++) + { + Vec3 vect = matTransform * Vec3(verts[i].x, verts[i].y, verts[i].z); + + vecMax.x = vecMax.x > vect.x ? vecMax.x : vect.x; + vecMax.y = vecMax.y > vect.y ? vecMax.y : vect.y; + vecMax.z = vecMax.z > vect.z ? vecMax.z : vect.z; + + vecMin.x = vecMin.x < vect.x ? vecMin.x : vect.x; + vecMin.y = vecMin.y < vect.y ? vecMin.y : vect.y; + vecMin.z = vecMin.z < vect.z ? vecMin.z : vect.z; + } + + matTransform.transpose(); + + _xAxis = Vec3(matTransform.m[0], matTransform.m[1], matTransform.m[2]); + _yAxis = Vec3(matTransform.m[4], matTransform.m[5], matTransform.m[6]); + _zAxis = Vec3(matTransform.m[8], matTransform.m[9], matTransform.m[10]); + + _center = 0.5f * (vecMax + vecMin); + _center *= matTransform; + + _xAxis.normalize(); + _yAxis.normalize(); + _zAxis.normalize(); + + _extents = 0.5f * (vecMax - vecMin); +} + +bool OBB::containPoint(const Vec3& point) const +{ + Vec3 vd = point - _center; + + float d = vd.dot(_xAxis); + if (d > _extents.x || d < -_extents.x) + return false; + + d = vd.dot(_yAxis); + if (d > _extents.y || d < -_extents.y) + return false; + + d = vd.dot(_zAxis); + if (d > _extents.z || d < -_extents.z) + return false; + + return true; +} + +void OBB::set(const Vec3& center, const Vec3& xAxis, const Vec3& yAxis, const Vec3& zAxis, const Vec3& extents) +{ + _center = center; + _xAxis = xAxis; + _yAxis = yAxis; + _zAxis = zAxis; + _extents = extents; +} + +void OBB::reset() +{ + memset(this, 0, sizeof(OBB)); +} + +void OBB::getCorners(Vec3* verts) const +{ + Vec3 extX = _xAxis * _extents.x; + Vec3 extY = _yAxis * _extents.y; + Vec3 extZ = _zAxis * _extents.z; + + verts[0] = _center - extX + extY + extZ; // left top front + verts[1] = _center - extX - extY + extZ; // left bottom front + verts[2] = _center + extX - extY + extZ; // right bottom front + verts[3] = _center + extX + extY + extZ; // right top front + + verts[4] = _center + extX + extY - extZ; // right top back + verts[5] = _center + extX - extY - extZ; // right bottom back + verts[6] = _center - extX - extY - extZ; // left bottom back + verts[7] = _center - extX + extY - extZ; // left top back +} + +float OBB::projectPoint(const Vec3& point, const Vec3& axis)const +{ + float dot = axis.dot(point); + float ret = dot * point.length(); + return ret; +} + +void OBB::getInterval(const OBB& box, const Vec3& axis, float &min, float &max)const +{ + Vec3 corners[8]; + box.getCorners(corners); + float value; + min = max = projectPoint(axis, corners[0]); + for(int i = 1; i < 8; i++) + { + value = projectPoint(axis, corners[i]); + min = MIN(min, value); + max = MAX(max, value); + } +} + +Vec3 OBB::getEdgeDirection(int index)const +{ + Vec3 corners[8]; + getCorners(corners); + + Vec3 tmpLine; + switch(index) + { + case 0:// edge with x axis + tmpLine = corners[5] - corners[6]; + tmpLine.normalize(); + break; + case 1:// edge with y axis + tmpLine = corners[7] - corners[6]; + tmpLine.normalize(); + break; + case 2:// edge with z axis + tmpLine = corners[1] - corners[6]; + tmpLine.normalize(); + break; + default: + CCASSERT(0, "Invalid index!"); + break; + } + return tmpLine; +} + +Vec3 OBB::getFaceDirection(int index) const +{ + Vec3 corners[8]; + getCorners(corners); + + Vec3 faceDirection, v0, v1; + switch(index) + { + case 0:// front and back + v0 = corners[2] - corners[1]; + v1 = corners[0] - corners[1]; + Vec3::cross(v0, v1, &faceDirection); + faceDirection.normalize(); + break; + case 1:// left and right + v0 = corners[5] - corners[2]; + v1 = corners[3] - corners[2]; + Vec3::cross(v0, v1, &faceDirection); + faceDirection.normalize(); + break; + case 2:// top and bottom + v0 = corners[1] - corners[2]; + v1 = corners[5] - corners[2]; + Vec3::cross(v0, v1, &faceDirection); + faceDirection.normalize(); + break; + default: + CCASSERT(0, "Invalid index!"); + break; + } + return faceDirection; +} + +bool OBB::intersects(const OBB& box) const +{ + float min1, max1, min2, max2; + for (int i = 0; i < 3; i++) + { + getInterval(*this, getFaceDirection(i), min1, max1); + getInterval(box, getFaceDirection(i), min2, max2); + if (max1 < min2 || max2 < min1) return false; + } + + for (int i = 0; i < 3; i++) + { + getInterval(*this, box.getFaceDirection(i), min1, max1); + getInterval(box, box.getFaceDirection(i), min2, max2); + if (max1 < min2 || max2 < min1) return false; + } + + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + Vec3 axis; + Vec3::cross(getFaceDirection(i), box.getFaceDirection(j), &axis); + getInterval(*this, axis, min1, max1); + getInterval(box, axis, min2, max2); + if (max1 < min2 || max2 < min1) return false; + } + } + + return true; +} + + +void OBB::transform(const Mat4& mat) +{ + Vec4 newcenter = mat * Vec4(_center.x, _center.y, _center.z, 1.0f);// center; + _center.x = newcenter.x; + _center.y = newcenter.y; + _center.z = newcenter.z; + + _xAxis = mat * _xAxis; + _yAxis = mat * _yAxis; + _zAxis = mat * _zAxis; + + _xAxis.normalize(); + _yAxis.normalize(); + _zAxis.normalize(); + + Vec3 scale, trans; + Quaternion quat; + mat.decompose(&scale, &quat, &trans); + + _extents.x *= scale.x; + _extents.y *= scale.y; + _extents.z *= scale.z; +} + +NS_CC_END diff --git a/cocos/3d/CCOBB.h b/cocos/3d/CCOBB.h new file mode 100755 index 0000000000..0fd8c1eea1 --- /dev/null +++ b/cocos/3d/CCOBB.h @@ -0,0 +1,117 @@ +/**************************************************************************** + 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 __CC_OBB_H__ +#define __CC_OBB_H__ + +#include "CCAABB.h" + +NS_CC_BEGIN + +class CC_DLL OBB +{ +public: + OBB(); + + /* + * Construct obb from oriented bounding box + */ + OBB(const AABB& aabb); + + /* + * Construct obb from points + */ + OBB(const Vec3* verts, int num); + + /* + * Check point in + */ + bool containPoint(const Vec3& point) const; + + /* + * Specify obb values + */ + void set(const Vec3& center, const Vec3& _xAxis, const Vec3& _yAxis, const Vec3& _zAxis, const Vec3& _extents); + + /* + * Clear obb + */ + void reset(); + + /* face to the obb's -z direction + * verts[0] : left top front + * verts[1] : left bottom front + * verts[2] : right bottom front + * verts[3] : right top front + * + * face to the obb's z direction + * verts[4] : right top back + * verts[5] : right bottom back + * verts[6] : left bottom back + * verts[7] : left top back + */ + void getCorners(Vec3* verts) const; + + /* + * Check intersect with other + */ + bool intersects(const OBB& box) const; + + /** + * Transforms the obb by the given transformation matrix. + */ + void transform(const Mat4& mat); + +protected: + /* + * Project point to the target axis + */ + float projectPoint(const Vec3& point, const Vec3& axis) const; + + /* + * Calculate the min and max project value of through the box's corners + */ + void getInterval(const OBB& box, const Vec3& axis, float &min, float &max) const; + + /* + * Get the edege of x y z axis direction + */ + Vec3 getEdgeDirection(int index) const; + + /* + * Get the face of x y z axis direction + */ + Vec3 getFaceDirection(int index) const; + +public: + Vec3 _center; // obb center + Vec3 _xAxis; // x axis of obb, unit vector + Vec3 _yAxis; // y axis of obb, unit vecotr + Vec3 _zAxis; // z axis of obb, unit vector + Vec3 _extents; // obb length along each axis +}; + +NS_CC_END + +#endif diff --git a/cocos/3d/CCRay.cpp b/cocos/3d/CCRay.cpp new file mode 100755 index 0000000000..b8f6b1d56c --- /dev/null +++ b/cocos/3d/CCRay.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +Copyright (c) Chukong Technologies Inc. + +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 "CCRay.h" +#include "CCAABB.h" +#include "CCOBB.h" + +NS_CC_BEGIN + +Ray::Ray() +: _direction(0, 0, 1) +{ +} + +Ray::Ray(const Vec3& origin, const Vec3& direction) +{ + set(origin, direction); +} + +Ray::~Ray() +{ +} + +bool Ray::intersects(const AABB& aabb) const +{ + Vec3 ptOnPlane; + Vec3 min = aabb._min; + Vec3 max = aabb._max; + + const Vec3& origin = _origin; + const Vec3& dir = _direction; + + float t; + + if (dir.x != 0.f) + { + if (dir.x > 0) + t = (min.x - origin.x) / dir.x; + else + t = (max.x - origin.x) / dir.x; + + if (t > 0.f) + { + ptOnPlane = origin + t * dir; + + if (min.y < ptOnPlane.y && ptOnPlane.y < max.y && min.z < ptOnPlane.z && ptOnPlane.z < max.z) + { + return true; + } + } + } + + if (dir.y != 0.f) + { + if (dir.y > 0) + t = (min.y - origin.y) / dir.y; + else + t = (max.y - origin.y) / dir.y; + + if (t > 0.f) + { + ptOnPlane = origin + t * dir; + + if (min.z < ptOnPlane.z && ptOnPlane.z < max.z && min.x < ptOnPlane.x && ptOnPlane.x < max.x) + { + return true; + } + } + } + + if (dir.z != 0.f) + { + if (dir.z > 0) + t = (min.z - origin.z) / dir.z; + else + t = (max.z - origin.z) / dir.z; + + if (t > 0.f) + { + ptOnPlane = origin + t * dir; + + if (min.x < ptOnPlane.x && ptOnPlane.x < max.x && min.y < ptOnPlane.y && ptOnPlane.y < max.y) + { + return true; + } + } + } + + return false; +} + +bool Ray::intersects(const OBB& obb) const +{ + AABB aabb; + aabb._min = - obb._extents; + aabb._max = obb._extents; + + Ray ray; + ray._direction = _direction; + ray._origin = _origin; + + Mat4 mat = Mat4::IDENTITY; + mat.m[0] = obb._xAxis.x; + mat.m[1] = obb._xAxis.y; + mat.m[2] = obb._xAxis.z; + + mat.m[4] = obb._yAxis.x; + mat.m[5] = obb._yAxis.y; + mat.m[6] = obb._yAxis.z; + + mat.m[8] = obb._zAxis.x; + mat.m[9] = obb._zAxis.y; + mat.m[10] = obb._zAxis.z; + + mat.m[12] = obb._center.x; + mat.m[13] = obb._center.y; + mat.m[14] = obb._center.z; + + mat = mat.getInversed(); + + ray.transform(mat); + + return ray.intersects(aabb); +} + +void Ray::set(const Vec3& origin, const Vec3& direction) +{ + _origin = origin; + _direction = direction; +} + +void Ray::transform(const Mat4& matrix) +{ + matrix.transformPoint(&_origin); + matrix.transformVector(&_direction); + _direction.normalize(); +} + +NS_CC_END diff --git a/cocos/3d/CCRay.h b/cocos/3d/CCRay.h new file mode 100755 index 0000000000..0deab2a68a --- /dev/null +++ b/cocos/3d/CCRay.h @@ -0,0 +1,92 @@ +/**************************************************************************** + 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 __CC_RAY_H_ +#define __CC_RAY_H_ + +#include "base/ccMacros.h" +#include "math/CCMath.h" +#include "CCAABB.h" +#include "CCOBB.h" + +NS_CC_BEGIN + +class CC_DLL Ray +{ +public: + /** + * Constructor. + */ + Ray(); + + /** + * Constructor. + */ + Ray(const Ray& ray); + + /** + * Constructs a new ray initialized to the specified values. + * + * @param origin The ray's origin. + * @param direction The ray's direction. + */ + Ray(const Vec3& origin, const Vec3& direction); + + /** + * Destructor. + */ + ~Ray(); + + /** + * Check whether this ray intersects the specified bounding box. + */ + bool intersects(const AABB& aabb) const; + + /** + * Check whether this ray intersects the specified obb. + */ + bool intersects(const OBB& obb) const; + + /** + * Sets this ray to the specified values. + * + * @param origin The ray's origin. + * @param direction The ray's direction. + */ + void set(const Vec3& origin, const Vec3& direction); + + /** + * Transforms this ray by the given transformation matrix. + * + * @param matrix The transformation matrix to transform by. + */ + void transform(const Mat4& matrix); + + Vec3 _origin; // The ray origin position. + Vec3 _direction; // The ray direction vector. +}; + +NS_CC_END + +#endif diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index 796681837e..5e81c75532 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -399,6 +399,39 @@ const BlendFunc& Sprite3D::getBlendFunc() const return _blend; } +AABB Sprite3D::getAABB() const +{ + Mat4 nodeToWorldTransform(getNodeToWorldTransform()); + + // If nodeToWorldTransform matrix isn't changed, we don't need to transform aabb. + if (memcmp(_nodeToWorldTransform.m, nodeToWorldTransform.m, sizeof(Mat4)) == 0) + { + return _aabb; + } + else + { + Mat4 transform(nodeToWorldTransform); + _aabb = _mesh->getOriginAABB(); + + if (getSkin() && getSkin()->getRootBone()) + { + transform = nodeToWorldTransform * getSkin()->getRootBone()->getWorldMat(); + } + + _aabb.transform(transform); + _nodeToWorldTransform = nodeToWorldTransform; + } + + return _aabb; +} + +Rect Sprite3D::getBoundingBox() const +{ + AABB aabb = getAABB(); + Rect ret(aabb._min.x, aabb._min.y, (aabb._max.x - aabb._min.x), (aabb._max.y - aabb._min.y)); + return ret; +} + void Sprite3D::setCullFace(GLenum cullFace) { for (auto& it : _meshCommands) { diff --git a/cocos/3d/CCSprite3D.h b/cocos/3d/CCSprite3D.h index 9e79ba37ab..4a594d5483 100644 --- a/cocos/3d/CCSprite3D.h +++ b/cocos/3d/CCSprite3D.h @@ -33,6 +33,7 @@ #include "base/CCProtocols.h" #include "2d/CCNode.h" #include "renderer/CCMeshCommand.h" +#include "CCAABB.h" NS_CC_BEGIN @@ -80,6 +81,20 @@ public: virtual void setBlendFunc(const BlendFunc &blendFunc) override; virtual const BlendFunc &getBlendFunc() const override; + /* + * Get AABB + * If the sprite has animation, it can't be calculated accuratly, + * because bone can drive the vertices, we just use the origin vertices + * to calculate the AABB. + */ + AABB getAABB() const; + + /** + * Returns 2d bounding-box + * Note: the bouding-box is just get from the AABB which as Z=0, so that is not very accurate. + */ + virtual Rect getBoundingBox() const override; + // set which face is going to cull, GL_BACK, GL_FRONT, GL_FRONT_AND_BACK, default GL_BACK void setCullFace(GLenum cullFace); // set cull face enable or not @@ -124,6 +139,9 @@ protected: std::unordered_map _attachments; BlendFunc _blend; + + mutable AABB _aabb; // cache current aabb + mutable Mat4 _nodeToWorldTransform; // cache the matrix }; extern std::string CC_DLL s_attributeNames[];//attribute names array diff --git a/cocos/3d/CMakeLists.txt b/cocos/3d/CMakeLists.txt index ea4d614703..a5d625b094 100644 --- a/cocos/3d/CMakeLists.txt +++ b/cocos/3d/CMakeLists.txt @@ -1,4 +1,7 @@ set(COCOS_3D_SRC + 3d/CCAABB.cpp + 3d/CCOBB.cpp + 3d/CCRay.cpp 3d/CCSkeleton3D.cpp 3d/CCAttachNode.cpp 3d/CCSubMesh.cpp diff --git a/cocos/Android.mk b/cocos/Android.mk index 471ef20ff7..463fdd53c6 100644 --- a/cocos/Android.mk +++ b/cocos/Android.mk @@ -74,6 +74,9 @@ cocos2d.cpp \ 2d/CCTransitionPageTurn.cpp \ 2d/CCTransitionProgress.cpp \ 2d/CCTweenFunction.cpp \ +3d/CCRay.cpp\ +3d/CCAABB.cpp \ +3d/CCOBB.cpp \ 3d/CCAnimate3D.cpp \ 3d/CCAnimation3D.cpp \ 3d/CCAttachNode.cpp \ @@ -127,6 +130,7 @@ base/CCEventListenerTouch.cpp \ base/CCEventMouse.cpp \ base/CCEventTouch.cpp \ base/CCIMEDispatcher.cpp \ +base/CCModuleManager.cpp \ base/CCNS.cpp \ base/CCProfiling.cpp \ base/CCRef.cpp \ @@ -226,9 +230,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := cocos_freetype2_static LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_png_static -LOCAL_WHOLE_STATIC_LIBRARIES += cocos_jpeg_static -LOCAL_WHOLE_STATIC_LIBRARIES += cocos_tiff_static -LOCAL_WHOLE_STATIC_LIBRARIES += cocos_webp_static # define the macro to compile through support/zip_support/ioapi.c LOCAL_CFLAGS := -DUSE_FILE32API @@ -241,7 +242,4 @@ include $(BUILD_STATIC_LIBRARY) $(call import-module,freetype2/prebuilt/android) $(call import-module,chipmunk) $(call import-module,platform/android) -$(call import-module,jpeg/prebuilt/android) $(call import-module,png/prebuilt/android) -$(call import-module,tiff/prebuilt/android) -$(call import-module,webp/prebuilt/android) diff --git a/cocos/base/CCModuleManager.cpp b/cocos/base/CCModuleManager.cpp new file mode 100644 index 0000000000..d6a8d9b681 --- /dev/null +++ b/cocos/base/CCModuleManager.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** + Copyright (c) 2014 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. + ****************************************************************************/ + +#include "base/CCModuleManager.h" +#include +#include "base/CCConsole.h" + +using namespace std; + +//RegisterJPEG *temp = new RegisterJPEG(); + +NS_CC_BEGIN + +void ModuleManager::registerModule(const string &moduleName, void* module) +{ + auto &moduleMap = createMap(); + if (moduleMap.find(moduleName) != moduleMap.end()) + { + CCLOG("module: %s exists", moduleName.c_str()); + return; + } + + moduleMap[moduleName] = module; +} + +void ModuleManager::unRegisterModule(const string &moduleName) +{ + auto &moduleMap = createMap(); + moduleMap.erase(moduleName); +} + +void* ModuleManager::getModule(const string &moduleName) +{ + auto &moduleMap = createMap(); + auto result = moduleMap.find(moduleName); + if (result != moduleMap.end()) + { + return result->second; + } + else + return nullptr; +} + +unordered_map& ModuleManager::createMap() +{ + static unordered_map map; + return map; +} + +NS_CC_END diff --git a/cocos/base/CCModuleManager.h b/cocos/base/CCModuleManager.h new file mode 100644 index 0000000000..c6ec6f1268 --- /dev/null +++ b/cocos/base/CCModuleManager.h @@ -0,0 +1,50 @@ +/**************************************************************************** + Copyright (c) 2014 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 __BASE_CC_MODULE_MANAGER__ +#define __BASE_CC_MODULE_MANAGER__ + +#include +#include + +#include "base/CCPlatformMacros.h" + + +NS_CC_BEGIN + +class CC_DLL ModuleManager +{ +public: + static void registerModule(const std::string &moduleName, void* module); + static void unRegisterModule(const std::string &moduleName); + static void* getModule(const std::string &moduleName); + +private: + static std::unordered_map& createMap(); +}; + +NS_CC_END + +#endif + diff --git a/cocos/base/CMakeLists.txt b/cocos/base/CMakeLists.txt index 197e6bb7d4..a9b1f51ad9 100644 --- a/cocos/base/CMakeLists.txt +++ b/cocos/base/CMakeLists.txt @@ -22,6 +22,7 @@ set(COCOS_BASE_SRC base/CCEventMouse.cpp base/CCEventTouch.cpp base/CCIMEDispatcher.cpp + base/CCModuleManager.cpp base/CCNS.cpp base/CCProfiling.cpp base/CCRef.cpp diff --git a/cocos/cocos2d.h b/cocos/cocos2d.h index eb268cd324..3e19d4a5c5 100644 --- a/cocos/cocos2d.h +++ b/cocos/cocos2d.h @@ -262,6 +262,9 @@ THE SOFTWARE. #include "2d/CCComponentContainer.h" //3d +#include "3d/CCAABB.h" +#include "3d/CCOBB.h" +#include "3d/CCRay.h" #include "3d/CCSprite3D.h" #include "3d/CCMesh.h" #include "3d/CCMeshSkin.h" diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp index 08cd3e5f10..80ba8e672b 100644 --- a/cocos/platform/CCImage.cpp +++ b/cocos/platform/CCImage.cpp @@ -31,12 +31,6 @@ THE SOFTWARE. #include "base/CCData.h" - -#ifdef EMSCRIPTEN -#include -#include -#endif // EMSCRIPTEN - extern "C" { // To resolve link error when building 32bits with Xcode 6. @@ -57,22 +51,21 @@ extern "C" { return strerror(errnum); } + // int fputs(const char * __restrict, FILE * __restrict) __DARWIN_ALIAS(fputs); + int fputs$UNIX2003(const char *str, FILE *stream) + { + return fputs(str, stream); + } #endif #endif #include "png.h" -#include "tiffio.h" #include "base/etc1.h" -#include "jpeglib.h" } #include "base/s3tc.h" #include "base/atitc.h" #include "base/pvr.h" #include "base/TGAlib.h" -#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) -#include "decode.h" -#endif - #include "base/ccMacros.h" #include "CCCommon.h" #include "CCStdC.h" @@ -80,6 +73,7 @@ extern "C" #include "base/CCConfiguration.h" #include "base/ccUtils.h" #include "base/ZipUtils.h" +#include "base/CCModuleManager.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "android/CCFileUtilsAndroid.h" #endif @@ -96,7 +90,6 @@ NS_CC_BEGIN namespace { static const int PVR_TEXTURE_FLAG_TYPE_MASK = 0xff; - static bool _PVRHaveAlphaPremultiplied = false; // Values taken from PVRTexture.h from http://www.imgtec.com @@ -759,158 +752,28 @@ bool Image::isCompressed() return Texture2D::getPixelFormatInfoMap().at(_renderFormat).compressed; } -namespace -{ -/* - * ERROR HANDLING: - * - * The JPEG library's standard error handler (jerror.c) is divided into - * several "methods" which you can override individually. This lets you - * adjust the behavior without duplicating a lot of code, which you might - * have to update with each future release. - * - * We override the "error_exit" method so that control is returned to the - * library's caller when a fatal error occurs, rather than calling exit() - * as the standard error_exit method does. - * - * We use C's setjmp/longjmp facility to return control. This means that the - * routine which calls the JPEG library must first execute a setjmp() call to - * establish the return point. We want the replacement error_exit to do a - * longjmp(). But we need to make the setjmp buffer accessible to the - * error_exit routine. To do this, we make a private extension of the - * standard JPEG error handler object. (If we were using C++, we'd say we - * were making a subclass of the regular error handler.) - * - * Here's the extended error handler struct: - */ - struct MyErrorMgr - { - struct jpeg_error_mgr pub; /* "public" fields */ - jmp_buf setjmp_buffer; /* for return to caller */ - }; - - typedef struct MyErrorMgr * MyErrorPtr; - - /* - * Here's the routine that will replace the standard error_exit method: - */ - - METHODDEF(void) - myErrorExit(j_common_ptr cinfo) - { - /* cinfo->err really points to a MyErrorMgr struct, so coerce pointer */ - MyErrorPtr myerr = (MyErrorPtr) cinfo->err; - - /* Always display the message. */ - /* We could postpone this until after returning, if we chose. */ - /* internal message function cann't show error message in some platforms, so we rewrite it here. - * edit it if has version confilict. - */ - //(*cinfo->err->output_message) (cinfo); - char buffer[JMSG_LENGTH_MAX]; - (*cinfo->err->format_message) (cinfo, buffer); - CCLOG("jpeg error: %s", buffer); - - /* Return control to the setjmp point */ - longjmp(myerr->setjmp_buffer, 1); - } -} - bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) { - /* these are standard libjpeg structures for reading(decompression) */ - struct jpeg_decompress_struct cinfo; - /* We use our private extension JPEG error handler. - * Note that this struct must live as long as the main JPEG parameter - * struct, to avoid dangling-pointer problems. - */ - struct MyErrorMgr jerr; - /* libjpeg data structure for storing one row, that is, scanline of an image */ - JSAMPROW row_pointer[1] = {0}; - unsigned long location = 0; - unsigned int i = 0; - - bool bRet = false; - do + _hasPremultipliedAlpha = false; + + JPEGModule *jpegModule = static_cast(ModuleManager::getModule("jpeg")); + if (jpegModule) { - /* We set up the normal JPEG error routines, then override error_exit. */ - cinfo.err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = myErrorExit; - /* Establish the setjmp return context for MyErrorExit to use. */ - if (setjmp(jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. - * We need to clean up the JPEG object, close the input file, and return. - */ - jpeg_destroy_decompress(&cinfo); - break; - } - - /* setup decompression process and source, then read JPEG header */ - jpeg_create_decompress( &cinfo ); - -#ifndef CC_TARGET_QT5 - jpeg_mem_src( &cinfo, const_cast(data), dataLen ); -#endif /* CC_TARGET_QT5 */ - - /* reading the image header which contains image information */ -#if (JPEG_LIB_VERSION >= 90) - // libjpeg 0.9 adds stricter types. - jpeg_read_header( &cinfo, TRUE ); -#else - jpeg_read_header( &cinfo, true ); -#endif - - // we only support RGB or grayscale - if (cinfo.jpeg_color_space == JCS_GRAYSCALE) - { - _renderFormat = Texture2D::PixelFormat::I8; - }else - { - cinfo.out_color_space = JCS_RGB; - _renderFormat = Texture2D::PixelFormat::RGB888; - } - - /* Start decompression jpeg here */ - jpeg_start_decompress( &cinfo ); - - /* init image info */ - _width = cinfo.output_width; - _height = cinfo.output_height; - _hasPremultipliedAlpha = false; - row_pointer[0] = static_cast(malloc(cinfo.output_width*cinfo.output_components * sizeof(unsigned char))); - CC_BREAK_IF(! row_pointer[0]); - - _dataLen = cinfo.output_width*cinfo.output_height*cinfo.output_components; - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); - CC_BREAK_IF(! _data); - - /* now actually read the jpeg into the raw buffer */ - /* read one scan line at a time */ - while( cinfo.output_scanline < cinfo.output_height ) - { - jpeg_read_scanlines( &cinfo, row_pointer, 1 ); - for( i=0; iinitWithJPEGData(data, dataLen, dataFromJPEGInit); + _width = dataFromJPEGInit.width; + _height = dataFromJPEGInit.height; + _renderFormat = dataFromJPEGInit.renderFormat; + _dataLen = dataFromJPEGInit.dataLength; + _data = dataFromJPEGInit.data; + + return result; + } + else { - free(row_pointer[0]); - }; - return bRet; + CCLOG("jpeg module is not enabled"); + return false; + } } bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen) @@ -1062,175 +925,28 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen) return bRet; } -namespace -{ - static tmsize_t tiffReadProc(thandle_t fd, void* buf, tmsize_t size) - { - tImageSource* isource = (tImageSource*)fd; - uint8* ma; - uint64 mb; - unsigned long n; - unsigned long o; - tmsize_t p; - ma=(uint8*)buf; - mb=size; - p=0; - while (mb>0) - { - n=0x80000000UL; - if ((uint64)n>mb) - n=(unsigned long)mb; - - - if((int)(isource->offset + n) <= isource->size) - { - memcpy(ma, isource->data+isource->offset, n); - isource->offset += n; - o = n; - } - else - { - return 0; - } - - ma+=o; - mb-=o; - p+=o; - if (o!=n) - { - break; - } - } - return p; - } - - static tmsize_t tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) - { - CC_UNUSED_PARAM(fd); - CC_UNUSED_PARAM(buf); - CC_UNUSED_PARAM(size); - return 0; - } - - - static uint64 tiffSeekProc(thandle_t fd, uint64 off, int whence) - { - tImageSource* isource = (tImageSource*)fd; - uint64 ret = -1; - do - { - if (whence == SEEK_SET) - { - CC_BREAK_IF(off >= (uint64)isource->size); - ret = isource->offset = (uint32)off; - } - else if (whence == SEEK_CUR) - { - CC_BREAK_IF(isource->offset + off >= (uint64)isource->size); - ret = isource->offset += (uint32)off; - } - else if (whence == SEEK_END) - { - CC_BREAK_IF(off >= (uint64)isource->size); - ret = isource->offset = (uint32)(isource->size-1 - off); - } - else - { - CC_BREAK_IF(off >= (uint64)isource->size); - ret = isource->offset = (uint32)off; - } - } while (0); - - return ret; - } - - static uint64 tiffSizeProc(thandle_t fd) - { - tImageSource* pImageSrc = (tImageSource*)fd; - return pImageSrc->size; - } - - static int tiffCloseProc(thandle_t fd) - { - CC_UNUSED_PARAM(fd); - return 0; - } - - static int tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) - { - CC_UNUSED_PARAM(fd); - CC_UNUSED_PARAM(pbase); - CC_UNUSED_PARAM(psize); - return 0; - } - - static void tiffUnmapProc(thandle_t fd, void* base, toff_t size) - { - CC_UNUSED_PARAM(fd); - CC_UNUSED_PARAM(base); - CC_UNUSED_PARAM(size); - } -} - bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen) { - bool bRet = false; - do + _hasPremultipliedAlpha = true; + + TIFFModule *tiffModule = static_cast(ModuleManager::getModule("tiff")); + if (tiffModule) { - // set the read call back function - tImageSource imageSource; - imageSource.data = data; - imageSource.size = dataLen; - imageSource.offset = 0; - - TIFF* tif = TIFFClientOpen("file.tif", "r", (thandle_t)&imageSource, - tiffReadProc, tiffWriteProc, - tiffSeekProc, tiffCloseProc, tiffSizeProc, - tiffMapProc, - tiffUnmapProc); - - CC_BREAK_IF(nullptr == tif); - - uint32 w = 0, h = 0; - uint16 bitsPerSample = 0, samplePerPixel = 0, planarConfig = 0; - size_t npixels = 0; + DataFromModule dataFromTIFFInit; + bool result = tiffModule->initWithTIFFData(data, dataLen, dataFromTIFFInit); + _width = dataFromTIFFInit.width; + _height = dataFromTIFFInit.height; + _renderFormat = dataFromTIFFInit.renderFormat; + _dataLen = dataFromTIFFInit.dataLength; + _data = dataFromTIFFInit.data; - TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); - TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); - TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitsPerSample); - TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplePerPixel); - TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planarConfig); - - npixels = w * h; - - _renderFormat = Texture2D::PixelFormat::RGBA8888; - _width = w; - _height = h; - - _dataLen = npixels * sizeof (uint32); - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); - - uint32* raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32)); - if (raster != nullptr) - { - if (TIFFReadRGBAImageOriented(tif, w, h, raster, ORIENTATION_TOPLEFT, 0)) - { - /* the raster data is pre-multiplied by the alpha component - after invoking TIFFReadRGBAImageOriented*/ - _hasPremultipliedAlpha = true; - - memcpy(_data, raster, npixels*sizeof (uint32)); - } - - _TIFFfree(raster); - } - - - TIFFClose(tif); - - bRet = true; - } while (0); - return bRet; + return result; + } + else + { + CCLOG("tiff module is not enabled"); + return false; + } } namespace @@ -2011,42 +1727,29 @@ bool Image::initWithPVRData(const unsigned char * data, ssize_t dataLen) bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen) { - bool bRet = false; - #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) CCLOG("WEBP image format not supported on WinRT or WP8"); + return false; #else - do - { - WebPDecoderConfig config; - if (WebPInitDecoderConfig(&config) == 0) break; - if (WebPGetFeatures(static_cast(data), dataLen, &config.input) != VP8_STATUS_OK) break; - if (config.input.width == 0 || config.input.height == 0) break; + WEBPModule *webpModule = static_cast(ModuleManager::getModule("webp")); + if (webpModule) + { + DataFromModule dataFromWEBPInit; + bool result = webpModule->initWithWEBPData(data, dataLen, dataFromWEBPInit); + _width = dataFromWEBPInit.width; + _height = dataFromWEBPInit.height; + _renderFormat = dataFromWEBPInit.renderFormat; + _dataLen = dataFromWEBPInit.dataLength; + _data = dataFromWEBPInit.data; - config.output.colorspace = MODE_RGBA; - _renderFormat = Texture2D::PixelFormat::RGBA8888; - _width = config.input.width; - _height = config.input.height; - - _dataLen = _width * _height * 4; - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); - - config.output.u.RGBA.rgba = static_cast(_data); - config.output.u.RGBA.stride = _width * 4; - config.output.u.RGBA.size = _dataLen; - config.output.is_external_memory = 1; - - if (WebPDecode(static_cast(data), dataLen, &config) != VP8_STATUS_OK) - { - free(_data); - _data = nullptr; - break; - } - - bRet = true; - } while (0); + return result; + } + else + { + CCLOG("webp module is not enabled"); + return false; + } #endif - return bRet; } @@ -2265,82 +1968,16 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) } bool Image::saveImageToJPG(const std::string& filePath) { - bool bRet = false; - do + JPEGModule *jpegModule = static_cast(ModuleManager::getModule("jpeg")); + if (jpegModule) { - struct jpeg_compress_struct cinfo; - struct jpeg_error_mgr jerr; - FILE * outfile; /* target file */ - JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ - int row_stride; /* physical row width in image buffer */ - - cinfo.err = jpeg_std_error(&jerr); - /* Now we can initialize the JPEG compression object. */ - jpeg_create_compress(&cinfo); - - CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == nullptr); - - jpeg_stdio_dest(&cinfo, outfile); - - cinfo.image_width = _width; /* image width and height, in pixels */ - cinfo.image_height = _height; - cinfo.input_components = 3; /* # of color components per pixel */ - cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ - - jpeg_set_defaults(&cinfo); - jpeg_set_quality(&cinfo, 90, TRUE); - - jpeg_start_compress(&cinfo, TRUE); - - row_stride = _width * 3; /* JSAMPLEs per row in image_buffer */ - - if (hasAlpha()) - { - unsigned char *pTempData = static_cast(malloc(_width * _height * 3 * sizeof(unsigned char))); - if (nullptr == pTempData) - { - jpeg_finish_compress(&cinfo); - jpeg_destroy_compress(&cinfo); - fclose(outfile); - break; - } - - for (int i = 0; i < _height; ++i) - { - for (int j = 0; j < _width; ++j) - - { - pTempData[(i * _width + j) * 3] = _data[(i * _width + j) * 4]; - pTempData[(i * _width + j) * 3 + 1] = _data[(i * _width + j) * 4 + 1]; - pTempData[(i * _width + j) * 3 + 2] = _data[(i * _width + j) * 4 + 2]; - } - } - - while (cinfo.next_scanline < cinfo.image_height) { - row_pointer[0] = & pTempData[cinfo.next_scanline * row_stride]; - (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); - } - - if (pTempData != nullptr) - { - free(pTempData); - } - } - else - { - while (cinfo.next_scanline < cinfo.image_height) { - row_pointer[0] = & _data[cinfo.next_scanline * row_stride]; - (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); - } - } - - jpeg_finish_compress(&cinfo); - fclose(outfile); - jpeg_destroy_compress(&cinfo); - - bRet = true; - } while (0); - return bRet; + return jpegModule->saveImage(filePath, this); + } + else + { + CCLOG("jpeg module is not enabled"); + return false; + } } void Image::premultipliedAlpha() @@ -2357,7 +1994,6 @@ void Image::premultipliedAlpha() _hasPremultipliedAlpha = true; } - void Image::setPVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) { _PVRHaveAlphaPremultiplied = haveAlphaPremultiplied; diff --git a/cocos/platform/CCImage.h b/cocos/platform/CCImage.h index 483ea686ff..bb9e8d0014 100644 --- a/cocos/platform/CCImage.h +++ b/cocos/platform/CCImage.h @@ -26,6 +26,8 @@ THE SOFTWARE. #ifndef __CC_IMAGE_H__ #define __CC_IMAGE_H__ +#include +#include #include "base/CCRef.h" #include "renderer/CCTexture2D.h" @@ -167,6 +169,7 @@ protected: void premultipliedAlpha(); + protected: /** @brief Determine how many mipmaps can we have. @@ -212,6 +215,35 @@ protected: bool isATITC(const unsigned char *data, ssize_t dataLen); }; +/* Data returned from jpeg/tiff/webp module initialization + */ +typedef struct DataFromModule +{ + Texture2D::PixelFormat renderFormat; + int width; + int height; + ssize_t dataLength; + unsigned char* data; + bool hasPremultiAlpha; +} DataFromModule; + +struct JPEGModule +{ + std::function saveImage; + std::function initWithJPEGData; +}; + +struct TIFFModule +{ + std::function initWithTIFFData; +}; + +struct WEBPModule +{ + std::function initWithWEBPData; +}; + + // end of platform group /// @} diff --git a/cocos/platform/desktop/CCGLViewImpl.cpp b/cocos/platform/desktop/CCGLViewImpl.cpp index 534e52623a..4b7eef7f6b 100644 --- a/cocos/platform/desktop/CCGLViewImpl.cpp +++ b/cocos/platform/desktop/CCGLViewImpl.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. ****************************************************************************/ #include "CCGLViewImpl.h" +#include "CCApplication.h" #include "base/CCDirector.h" #include "base/CCTouch.h" #include "base/CCEventDispatcher.h" @@ -101,6 +102,14 @@ public: _view = view; } + static void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified) + { + if (_view) + { + _view->onGLFWWindowIconifyCallback(window, iconified); + } + } + private: static GLViewImpl* _view; }; @@ -352,6 +361,7 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram glfwSetWindowPosCallback(_mainWindow, GLFWEventHandler::onGLFWWindowPosCallback); glfwSetFramebufferSizeCallback(_mainWindow, GLFWEventHandler::onGLFWframebuffersize); glfwSetWindowSizeCallback(_mainWindow, GLFWEventHandler::onGLFWWindowSizeFunCallback); + glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback); setFrameSize(rect.size.width, rect.size.height); @@ -706,6 +716,18 @@ void GLViewImpl::onGLFWWindowSizeFunCallback(GLFWwindow *window, int width, int } } +void GLViewImpl::onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified) +{ + if (iconified == GL_TRUE) + { + Application::getInstance()->applicationDidEnterBackground(); + } + else + { + Application::getInstance()->applicationWillEnterForeground(); + } +} + #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) static bool glew_dynamic_binding() { diff --git a/cocos/platform/desktop/CCGLViewImpl.h b/cocos/platform/desktop/CCGLViewImpl.h index a9befbbd51..368e6d97a2 100644 --- a/cocos/platform/desktop/CCGLViewImpl.h +++ b/cocos/platform/desktop/CCGLViewImpl.h @@ -130,6 +130,7 @@ protected: void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y); void onGLFWframebuffersize(GLFWwindow* window, int w, int h); void onGLFWWindowSizeFunCallback(GLFWwindow *window, int width, int height); + void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified); bool _captured; bool _supportTouch; diff --git a/cocos/scripting/lua-bindings/auto/api/Button.lua b/cocos/scripting/lua-bindings/auto/api/Button.lua index 01e2a2990d..b0212c1988 100644 --- a/cocos/scripting/lua-bindings/auto/api/Button.lua +++ b/cocos/scripting/lua-bindings/auto/api/Button.lua @@ -19,6 +19,11 @@ -- @param self -- @param #bool bool +-------------------------------- +-- @function [parent=#Button] getZoomScale +-- @param self +-- @return float#float ret (return value: float) + -------------------------------- -- @function [parent=#Button] getCapInsetsDisabledRenderer -- @param self @@ -120,6 +125,11 @@ -- @param self -- @param #bool bool +-------------------------------- +-- @function [parent=#Button] setZoomScale +-- @param self +-- @param #float float + -------------------------------- -- @overload self, string, string, string, int -- @overload self diff --git a/cocos/scripting/lua-bindings/auto/api/PageView.lua b/cocos/scripting/lua-bindings/auto/api/PageView.lua index 2e660a0635..f68253b507 100644 --- a/cocos/scripting/lua-bindings/auto/api/PageView.lua +++ b/cocos/scripting/lua-bindings/auto/api/PageView.lua @@ -4,6 +4,11 @@ -- @extend Layout -- @parent_module ccui +-------------------------------- +-- @function [parent=#PageView] getCustomScrollThreshold +-- @param self +-- @return float#float ret (return value: float) + -------------------------------- -- @function [parent=#PageView] getCurPageIndex -- @param self @@ -16,6 +21,11 @@ -- @param #long long -- @param #bool bool +-------------------------------- +-- @function [parent=#PageView] isUsingCustomScrollThreshold +-- @param self +-- @return bool#bool ret (return value: bool) + -------------------------------- -- @function [parent=#PageView] getPage -- @param self @@ -32,6 +42,16 @@ -- @param self -- @param #function func +-------------------------------- +-- @function [parent=#PageView] setUsingCustomScrollThreshold +-- @param self +-- @param #bool bool + +-------------------------------- +-- @function [parent=#PageView] setCustomScrollThreshold +-- @param self +-- @param #float float + -------------------------------- -- @function [parent=#PageView] insertPage -- @param self diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp index c4c11ce464..6774030a18 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp @@ -5069,6 +5069,50 @@ int lua_cocos2dx_ui_Button_setScale9Enabled(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_Button_getZoomScale(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::Button* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.Button",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::Button*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_Button_getZoomScale'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + return 0; + double ret = cobj->getZoomScale(); + tolua_pushnumber(tolua_S,(lua_Number)ret); + return 1; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ccui.Button:getZoomScale",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Button_getZoomScale'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_Button_getCapInsetsDisabledRenderer(lua_State* tolua_S) { int argc = 0; @@ -6006,6 +6050,52 @@ int lua_cocos2dx_ui_Button_setPressedActionEnabled(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_Button_setZoomScale(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::Button* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.Button",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::Button*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_Button_setZoomScale'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + double arg0; + + ok &= luaval_to_number(tolua_S, 2,&arg0, "ccui.Button:setZoomScale"); + if(!ok) + return 0; + cobj->setZoomScale(arg0); + return 0; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ccui.Button:setZoomScale",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Button_setZoomScale'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_Button_create(lua_State* tolua_S) { int argc = 0; @@ -6189,6 +6279,7 @@ int lua_register_cocos2dx_ui_Button(lua_State* tolua_S) tolua_function(tolua_S,"getTitleText",lua_cocos2dx_ui_Button_getTitleText); tolua_function(tolua_S,"setTitleFontSize",lua_cocos2dx_ui_Button_setTitleFontSize); tolua_function(tolua_S,"setScale9Enabled",lua_cocos2dx_ui_Button_setScale9Enabled); + tolua_function(tolua_S,"getZoomScale",lua_cocos2dx_ui_Button_getZoomScale); tolua_function(tolua_S,"getCapInsetsDisabledRenderer",lua_cocos2dx_ui_Button_getCapInsetsDisabledRenderer); tolua_function(tolua_S,"setTitleColor",lua_cocos2dx_ui_Button_setTitleColor); tolua_function(tolua_S,"setCapInsetsDisabledRenderer",lua_cocos2dx_ui_Button_setCapInsetsDisabledRenderer); @@ -6208,6 +6299,7 @@ int lua_register_cocos2dx_ui_Button(lua_State* tolua_S) tolua_function(tolua_S,"getTitleFontName",lua_cocos2dx_ui_Button_getTitleFontName); tolua_function(tolua_S,"getTitleColor",lua_cocos2dx_ui_Button_getTitleColor); tolua_function(tolua_S,"setPressedActionEnabled",lua_cocos2dx_ui_Button_setPressedActionEnabled); + tolua_function(tolua_S,"setZoomScale",lua_cocos2dx_ui_Button_setZoomScale); tolua_function(tolua_S,"create", lua_cocos2dx_ui_Button_create); tolua_function(tolua_S,"createInstance", lua_cocos2dx_ui_Button_createInstance); tolua_endmodule(tolua_S); @@ -15318,6 +15410,50 @@ int lua_register_cocos2dx_ui_TextBMFont(lua_State* tolua_S) return 1; } +int lua_cocos2dx_ui_PageView_getCustomScrollThreshold(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::PageView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.PageView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::PageView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_PageView_getCustomScrollThreshold'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + return 0; + double ret = cobj->getCustomScrollThreshold(); + tolua_pushnumber(tolua_S,(lua_Number)ret); + return 1; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ccui.PageView:getCustomScrollThreshold",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_PageView_getCustomScrollThreshold'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_PageView_getCurPageIndex(lua_State* tolua_S) { int argc = 0; @@ -15414,6 +15550,50 @@ int lua_cocos2dx_ui_PageView_addWidgetToPage(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_PageView_isUsingCustomScrollThreshold(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::PageView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.PageView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::PageView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_PageView_isUsingCustomScrollThreshold'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + return 0; + bool ret = cobj->isUsingCustomScrollThreshold(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ccui.PageView:isUsingCustomScrollThreshold",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_PageView_isUsingCustomScrollThreshold'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_PageView_getPage(lua_State* tolua_S) { int argc = 0; @@ -15557,6 +15737,98 @@ int lua_cocos2dx_ui_PageView_addEventListener(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_PageView_setUsingCustomScrollThreshold(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::PageView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.PageView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::PageView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_PageView_setUsingCustomScrollThreshold'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + bool arg0; + + ok &= luaval_to_boolean(tolua_S, 2,&arg0, "ccui.PageView:setUsingCustomScrollThreshold"); + if(!ok) + return 0; + cobj->setUsingCustomScrollThreshold(arg0); + return 0; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ccui.PageView:setUsingCustomScrollThreshold",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_PageView_setUsingCustomScrollThreshold'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_ui_PageView_setCustomScrollThreshold(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::PageView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.PageView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::PageView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_PageView_setCustomScrollThreshold'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + double arg0; + + ok &= luaval_to_number(tolua_S, 2,&arg0, "ccui.PageView:setCustomScrollThreshold"); + if(!ok) + return 0; + cobj->setCustomScrollThreshold(arg0); + return 0; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ccui.PageView:setCustomScrollThreshold",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_PageView_setCustomScrollThreshold'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_PageView_insertPage(lua_State* tolua_S) { int argc = 0; @@ -15940,11 +16212,15 @@ int lua_register_cocos2dx_ui_PageView(lua_State* tolua_S) tolua_beginmodule(tolua_S,"PageView"); tolua_function(tolua_S,"new",lua_cocos2dx_ui_PageView_constructor); + tolua_function(tolua_S,"getCustomScrollThreshold",lua_cocos2dx_ui_PageView_getCustomScrollThreshold); tolua_function(tolua_S,"getCurPageIndex",lua_cocos2dx_ui_PageView_getCurPageIndex); tolua_function(tolua_S,"addWidgetToPage",lua_cocos2dx_ui_PageView_addWidgetToPage); + tolua_function(tolua_S,"isUsingCustomScrollThreshold",lua_cocos2dx_ui_PageView_isUsingCustomScrollThreshold); tolua_function(tolua_S,"getPage",lua_cocos2dx_ui_PageView_getPage); tolua_function(tolua_S,"removePage",lua_cocos2dx_ui_PageView_removePage); tolua_function(tolua_S,"addEventListener",lua_cocos2dx_ui_PageView_addEventListener); + tolua_function(tolua_S,"setUsingCustomScrollThreshold",lua_cocos2dx_ui_PageView_setUsingCustomScrollThreshold); + tolua_function(tolua_S,"setCustomScrollThreshold",lua_cocos2dx_ui_PageView_setCustomScrollThreshold); tolua_function(tolua_S,"insertPage",lua_cocos2dx_ui_PageView_insertPage); tolua_function(tolua_S,"scrollToPage",lua_cocos2dx_ui_PageView_scrollToPage); tolua_function(tolua_S,"removePageAtIndex",lua_cocos2dx_ui_PageView_removePageAtIndex); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp index e733905e27..fa92d1bdaa 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp @@ -398,6 +398,12 @@ int register_all_cocos2dx_ui(lua_State* tolua_S); + + + + + + diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index 25bc9dcd50..aebfd113d0 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -64,6 +64,7 @@ _normalTextureScaleXInSize(1.0f), _normalTextureScaleYInSize(1.0f), _pressedTextureScaleXInSize(1.0f), _pressedTextureScaleYInSize(1.0f), +_zoomScale(0.1f), _normalTextureLoaded(false), _pressedTextureLoaded(false), _disabledTextureLoaded(false), @@ -386,9 +387,9 @@ void Button::onPressStateChangedToPressed() { _buttonNormalRenderer->stopAllActions(); _buttonClickedRenderer->stopAllActions(); - Action *zoomAction = ScaleTo::create(0.05f, _pressedTextureScaleXInSize + 0.1f, _pressedTextureScaleYInSize + 0.1f); + Action *zoomAction = ScaleTo::create(0.05f, _pressedTextureScaleXInSize + _zoomScale, _pressedTextureScaleYInSize + _zoomScale); _buttonClickedRenderer->runAction(zoomAction); - _buttonNormalRenderer->setScale(_pressedTextureScaleXInSize + 0.1f, _pressedTextureScaleYInSize + 0.1f); + _buttonNormalRenderer->setScale(_pressedTextureScaleXInSize + _zoomScale, _pressedTextureScaleYInSize + _zoomScale); } } else @@ -403,7 +404,7 @@ void Button::onPressStateChangedToPressed() else { _buttonNormalRenderer->stopAllActions(); - _buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f); + _buttonNormalRenderer->setScale(_normalTextureScaleXInSize +_zoomScale, _normalTextureScaleYInSize + _zoomScale); } } } @@ -643,6 +644,16 @@ float Button::getTitleFontSize() const { return _fontSize; } + +void Button::setZoomScale(float scale) +{ + _zoomScale = scale; +} + +float Button::getZoomScale()const +{ + return _zoomScale; +} void Button::setTitleFontName(const std::string& fontName) { @@ -693,6 +704,7 @@ void Button::copySpecialProperties(Widget *widget) setTitleFontSize(button->getTitleFontSize()); setTitleColor(button->getTitleColor()); setPressedActionEnabled(button->_pressedActionEnabled); + setZoomScale(button->_zoomScale); } } diff --git a/cocos/ui/UIButton.h b/cocos/ui/UIButton.h index e44e148024..6d33e19770 100644 --- a/cocos/ui/UIButton.h +++ b/cocos/ui/UIButton.h @@ -188,6 +188,14 @@ public: float getTitleFontSize() const; void setTitleFontName(const std::string& fontName); const std::string& getTitleFontName() const; + /** When user pressed the button, the button will zoom to a scale. + * The final scale of the button equals (button original scale + _zoomScale) + */ + void setZoomScale(float scale); + /** + * @brief Return a zoom scale + */ + float getZoomScale()const; CC_CONSTRUCTOR_ACCESS: virtual bool init() override; @@ -222,7 +230,8 @@ protected: Scale9Sprite* _buttonClickedRenderer; Scale9Sprite* _buttonDisableRenderer; Label* _titleRenderer; - + + float _zoomScale; std::string _normalFileName; std::string _clickedFileName; std::string _disabledFileName; diff --git a/cocos/ui/UIPageView.cpp b/cocos/ui/UIPageView.cpp index c884be87e4..3931192a83 100644 --- a/cocos/ui/UIPageView.cpp +++ b/cocos/ui/UIPageView.cpp @@ -44,7 +44,9 @@ _autoScrollDirection(AutoScrollDirection::LEFT), _childFocusCancelOffset(5.0f), _pageViewEventListener(nullptr), _pageViewEventSelector(nullptr), -_eventCallback(nullptr) +_eventCallback(nullptr), +_customScrollThreshold(0.0), +_usingCustomScrollThreshold(false) { this->setTouchEnabled(true); } @@ -447,6 +449,28 @@ void PageView::handleMoveLogic(Touch *touch) } scrollPages(offset); } + +void PageView::setCustomScrollThreshold(float threshold) +{ + CCASSERT(threshold > 0, "Invalid threshold!"); + _customScrollThreshold = threshold; + this->setUsingCustomScrollThreshold(true); +} + +float PageView::getCustomScrollThreshold()const +{ + return _customScrollThreshold; +} + +void PageView::setUsingCustomScrollThreshold(bool flag) +{ + _usingCustomScrollThreshold = flag; +} + +bool PageView::isUsingCustomScrollThreshold()const +{ + return _usingCustomScrollThreshold; +} void PageView::handleReleaseLogic(Touch *touch) { @@ -461,7 +485,10 @@ void PageView::handleReleaseLogic(Touch *touch) ssize_t pageCount = this->getPageCount(); float curPageLocation = curPagePos.x; float pageWidth = getContentSize().width; - float boundary = pageWidth/2.0f; + if (!_usingCustomScrollThreshold) { + _customScrollThreshold = pageWidth / 2.0; + } + float boundary = _customScrollThreshold; if (curPageLocation <= -boundary) { if (_curPageIdx >= pageCount-1) @@ -590,6 +617,8 @@ void PageView::copySpecialProperties(Widget *widget) _eventCallback = pageView->_eventCallback; _pageViewEventListener = pageView->_pageViewEventListener; _pageViewEventSelector = pageView->_pageViewEventSelector; + _usingCustomScrollThreshold = pageView->_usingCustomScrollThreshold; + _customScrollThreshold = pageView->_customScrollThreshold; } } diff --git a/cocos/ui/UIPageView.h b/cocos/ui/UIPageView.h index 96d01c98df..65078870e9 100644 --- a/cocos/ui/UIPageView.h +++ b/cocos/ui/UIPageView.h @@ -168,6 +168,23 @@ public: virtual std::string getDescription() const override; virtual void onEnter() override; + /** + * @brief If you don't specify the value, the pageView will scroll when half pageview width reached + */ + void setCustomScrollThreshold(float threshold); + /** + *@brief Return user defined scroll page threshold + */ + float getCustomScrollThreshold()const; + /** + *@brief Set using user defined scroll page threshold or not + * If you set it to false, then the default scroll threshold is pageView.width / 2 + */ + void setUsingCustomScrollThreshold(bool flag); + /** + *@brief Query whether we are using user defined scroll page threshold or not + */ + bool isUsingCustomScrollThreshold()const; CC_CONSTRUCTOR_ACCESS: virtual bool init() override; @@ -219,7 +236,9 @@ protected: float _leftBoundary; float _rightBoundary; - + float _customScrollThreshold; + bool _usingCustomScrollThreshold; + float _childFocusCancelOffset; Ref* _pageViewEventListener; diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index 304082e7f1..1652b0fb8f 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -192,6 +192,8 @@ "cocos/2d/cocos2dx.props", "cocos/2d/libcocos2d.vcxproj", "cocos/2d/libcocos2d.vcxproj.filters", + "cocos/3d/CCAABB.cpp", + "cocos/3d/CCAABB.h", "cocos/3d/CCAnimate3D.cpp", "cocos/3d/CCAnimate3D.h", "cocos/3d/CCAnimation3D.cpp", @@ -209,8 +211,12 @@ "cocos/3d/CCMesh.h", "cocos/3d/CCMeshSkin.cpp", "cocos/3d/CCMeshSkin.h", + "cocos/3d/CCOBB.cpp", + "cocos/3d/CCOBB.h", "cocos/3d/CCObjLoader.cpp", "cocos/3d/CCObjLoader.h", + "cocos/3d/CCRay.cpp", + "cocos/3d/CCRay.h", "cocos/3d/CCSkeleton3D.cpp", "cocos/3d/CCSkeleton3D.h", "cocos/3d/CCSprite3D.cpp", @@ -339,6 +345,8 @@ "cocos/base/CCIMEDispatcher.cpp", "cocos/base/CCIMEDispatcher.h", "cocos/base/CCMap.h", + "cocos/base/CCModuleManager.cpp", + "cocos/base/CCModuleManager.h", "cocos/base/CCNS.cpp", "cocos/base/CCNS.h", "cocos/base/CCPlatformConfig.h", diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp index 94c78e7e56..065219dd92 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp @@ -72,11 +72,14 @@ const char* getRuntimeVersion() static string& replaceAll(string& str,const string& old_value,const string& new_value) { + int start = 0; while(true) { int pos=0; - if((pos=str.find(old_value,0))!=string::npos) + if((pos=str.find(old_value,start))!=string::npos) { str.replace(pos,old_value.length(),new_value); + start = pos + new_value.length(); + } else break; } return str; diff --git a/tests/cpp-tests/Android.mk b/tests/cpp-tests/Android.mk index 994ba9f81d..9b69186e42 100644 --- a/tests/cpp-tests/Android.mk +++ b/tests/cpp-tests/Android.mk @@ -168,6 +168,7 @@ Classes/ShaderTest/ShaderTest.cpp \ Classes/ShaderTest/ShaderTest2.cpp \ Classes/SpineTest/SpineTest.cpp \ Classes/SpriteTest/SpriteTest.cpp \ +Classes/Sprite3DTest/DrawNode3D.cpp \ Classes/Sprite3DTest/Sprite3DTest.cpp \ Classes/TextInputTest/TextInputTest.cpp \ Classes/Texture2dTest/Texture2dTest.cpp \ diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index 439db8020c..e457e435f2 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -162,6 +162,7 @@ set(SAMPLE_SRC Classes/ShaderTest/ShaderTest2.cpp Classes/SpriteTest/SpriteTest.cpp Classes/Sprite3DTest/Sprite3DTest.cpp + Classes/Sprite3DTest/DrawNode3D.cpp Classes/TextInputTest/TextInputTest.cpp Classes/Texture2dTest/Texture2dTest.cpp Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.cpp diff --git a/tests/cpp-tests/Classes/Sprite3DTest/DrawNode3D.cpp b/tests/cpp-tests/Classes/Sprite3DTest/DrawNode3D.cpp new file mode 100644 index 0000000000..acb88b95e9 --- /dev/null +++ b/tests/cpp-tests/Classes/Sprite3DTest/DrawNode3D.cpp @@ -0,0 +1,240 @@ +/**************************************************************************** + 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 "DrawNode3D.h" +#include "CCGL.h" +#include "base/CCEventType.h" +#include "base/CCConfiguration.h" +#include "renderer/CCCustomCommand.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCGLProgramState.h" +#include "base/CCDirector.h" +#include "base/CCEventListenerCustom.h" +#include "base/CCEventDispatcher.h" + +NS_CC_BEGIN + + +DrawNode3D::DrawNode3D() +: _vao(0) +, _vbo(0) +, _bufferCapacity(0) +, _bufferCount(0) +, _buffer(nullptr) +, _dirty(false) +{ + _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; +} + +DrawNode3D::~DrawNode3D() +{ + free(_buffer); + _buffer = nullptr; + + glDeleteBuffers(1, &_vbo); + _vbo = 0; + + if (Configuration::getInstance()->supportsShareableVAO()) + { + glDeleteVertexArrays(1, &_vao); + GL::bindVAO(0); + _vao = 0; + } +} + +DrawNode3D* DrawNode3D::create() +{ + DrawNode3D* ret = new DrawNode3D(); + if (ret && ret->init()) + { + ret->autorelease(); + } + else + { + CC_SAFE_DELETE(ret); + } + + return ret; +} + +void DrawNode3D::ensureCapacity(int count) +{ + CCASSERT(count>=0, "capacity must be >= 0"); + + if(_bufferCount + count > _bufferCapacity) + { + _bufferCapacity += MAX(_bufferCapacity, count); + _buffer = (V3F_C4B*)realloc(_buffer, _bufferCapacity*sizeof(V3F_C4B)); + } +} + +bool DrawNode3D::init() +{ + _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; + + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_COLOR)); + + ensureCapacity(512); + + if (Configuration::getInstance()->supportsShareableVAO()) + { + glGenVertexArrays(1, &_vao); + GL::bindVAO(_vao); + } + + glGenBuffers(1, &_vbo); + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B)* _bufferCapacity, _buffer, GL_STREAM_DRAW); + + glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, vertices)); + + glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, colors)); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + + if (Configuration::getInstance()->supportsShareableVAO()) + { + GL::bindVAO(0); + } + + CHECK_GL_ERROR_DEBUG(); + + _dirty = true; + +#if CC_ENABLE_CACHE_TEXTURE_DATA + // Need to listen the event only when not use batchnode, because it will use VBO + auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){ + /** listen the event that coming to foreground on Android */ + this->init(); + }); + + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); +#endif + + return true; +} + +void DrawNode3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) +{ + _customCommand.init(_globalZOrder); + _customCommand.func = CC_CALLBACK_0(DrawNode3D::onDraw, this, transform, flags); + renderer->addCommand(&_customCommand); +} + +void DrawNode3D::onDraw(const Mat4 &transform, uint32_t flags) +{ + auto glProgram = getGLProgram(); + glProgram->use(); + glProgram->setUniformsForBuiltins(transform); + glEnable(GL_DEPTH_TEST); + GL::blendFunc(_blendFunc.src, _blendFunc.dst); + + if (_dirty) + { + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B)*_bufferCapacity, _buffer, GL_STREAM_DRAW); + _dirty = false; + } + if (Configuration::getInstance()->supportsShareableVAO()) + { + GL::bindVAO(_vao); + } + else + { + GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + // vertex + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, vertices)); + + // color + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, colors)); + } + + glDrawArrays(GL_LINES, 0, _bufferCount); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCount); + glDisable(GL_DEPTH_TEST); + CHECK_GL_ERROR_DEBUG(); +} + +void DrawNode3D::drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color) +{ + unsigned int vertex_count = 2; + ensureCapacity(vertex_count); + + Color4B col = Color4B(color); + V3F_C4B a = {Vec3(from.x, from.y, from.z), col}; + V3F_C4B b = {Vec3(to.x, to.y, to.z), col, }; + + V3F_C4B *lines = (V3F_C4B *)(_buffer + _bufferCount); + lines[0] = a; + lines[1] = b; + + _bufferCount += vertex_count; + _dirty = true; + +} + +void DrawNode3D::drawCube(Vec3* vertices, const Color4F &color) +{ + // front face + drawLine(vertices[0], vertices[1], color); + drawLine(vertices[1], vertices[2], color); + drawLine(vertices[2], vertices[3], color); + drawLine(vertices[3], vertices[0], color); + + // back face + drawLine(vertices[4], vertices[5], color); + drawLine(vertices[5], vertices[6], color); + drawLine(vertices[6], vertices[7], color); + drawLine(vertices[7], vertices[4], color); + + // edge + drawLine(vertices[0], vertices[7], color); + drawLine(vertices[1], vertices[6], color); + drawLine(vertices[2], vertices[5], color); + drawLine(vertices[3], vertices[4], color); +} + +void DrawNode3D::clear() +{ + _bufferCount = 0; + _dirty = true; +} + +const BlendFunc& DrawNode3D::getBlendFunc() const +{ + return _blendFunc; +} + +void DrawNode3D::setBlendFunc(const BlendFunc &blendFunc) +{ + _blendFunc = blendFunc; +} + +NS_CC_END diff --git a/tests/cpp-tests/Classes/Sprite3DTest/DrawNode3D.h b/tests/cpp-tests/Classes/Sprite3DTest/DrawNode3D.h new file mode 100644 index 0000000000..240bb025ee --- /dev/null +++ b/tests/cpp-tests/Classes/Sprite3DTest/DrawNode3D.h @@ -0,0 +1,117 @@ +/**************************************************************************** + 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 __DRAW_NODE_3D_H__ +#define __DRAW_NODE_3D_H__ + +#include "2d/CCNode.h" +#include "base/ccTypes.h" +#include "renderer/CCCustomCommand.h" + +NS_CC_BEGIN + +/** + * Copy DrawNode for 3D geometry drawing. + */ +class DrawNode3D: public Node +{ +public: + /** creates and initialize a DrawNode3D node */ + static DrawNode3D* create(); + + /** + * Draw 3D Line + */ + void drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color); + + /** + * Draw 3D cube + * @param point to a vertex array who has 8 element. + * vertices[0]:Left-top-front, + * vertices[1]:Left-bottom-front, + * vertices[2]:Right-bottom-front, + * vertices[3]:Right-top-front, + * vertices[4]:Right-top-back, + * vertices[5]:Right-bottom-back, + * vertices[6]:Left-bottom-back, + * vertices[7]:Left-top-back. + * @param color + */ + void drawCube(Vec3* vertices, const Color4F &color); + + /** Clear the geometry in the node's buffer. */ + void clear(); + + /** + * @js NA + * @lua NA + */ + const BlendFunc& getBlendFunc() const; + + /** + * @code + * When this function bound into js or lua,the parameter will be changed + * In js: var setBlendFunc(var src, var dst) + * @endcode + * @lua NA + */ + void setBlendFunc(const BlendFunc &blendFunc); + + void onDraw(const Mat4 &transform, uint32_t flags); + + // Overrides + virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; + +CC_CONSTRUCTOR_ACCESS: + DrawNode3D(); + virtual ~DrawNode3D(); + virtual bool init(); + +protected: + struct V3F_C4B + { + Vec3 vertices; + Color4B colors; + }; + void ensureCapacity(int count); + + GLuint _vao; + GLuint _vbo; + + int _bufferCapacity; + GLsizei _bufferCount; + V3F_C4B* _buffer; + + BlendFunc _blendFunc; + CustomCommand _customCommand; + + bool _dirty; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(DrawNode3D); +}; + +NS_CC_END + +#endif // __DRAW_NODE_3D_H__ diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 7e6222eda5..157ca1ff02 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -28,111 +28,12 @@ #include "3d/CCAnimate3D.h" #include "3d/CCSubMesh.h" #include "3d/CCAttachNode.h" +#include "3d/CCRay.h" +#include "DrawNode3D.h" #include #include "../testResource.h" -////////////DrawNode3D///////////////////// - -class DrawNode3D: public Node -{ -public: - /** creates and initialize a node */ - static DrawNode3D* create(); - - /** - * Draw 3D Line - */ - void drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color); - - /** Clear the geometry in the node's buffer. */ - void clear() - { - _buffer.clear(); - } - - void onDraw(const Mat4 &transform, uint32_t flags); - - // Overrides - virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; - -CC_CONSTRUCTOR_ACCESS: - DrawNode3D() - { - - } - virtual ~DrawNode3D() - { - - } - virtual bool init(); - -protected: - struct V3F_C4B - { - Vec3 vertices; - Color4B colors; - }; - - std::vector _buffer; - - CustomCommand _customCommand; - -private: - CC_DISALLOW_COPY_AND_ASSIGN(DrawNode3D); -}; - -DrawNode3D* DrawNode3D::create() -{ - auto ret = new DrawNode3D(); - if (ret && ret->init()) - return ret; - CC_SAFE_DELETE(ret); - return nullptr; -} - -bool DrawNode3D::init() -{ - setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_COLOR)); - return true; -} - -void DrawNode3D::drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color) -{ - Color4B col = Color4B(color); - DrawNode3D::V3F_C4B vertex; - vertex.vertices = from; - vertex.colors = col; - _buffer.push_back(vertex); - vertex.vertices = to; - _buffer.push_back(vertex); -} - -void DrawNode3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) -{ - _customCommand.init(_globalZOrder); - _customCommand.func = CC_CALLBACK_0(DrawNode3D::onDraw, this, transform, flags); - renderer->addCommand(&_customCommand); -} - -void DrawNode3D::onDraw(const Mat4 &transform, uint32_t flags) -{ - auto glProgram = getGLProgram(); - glProgram->use(); - glProgram->setUniformsForBuiltins(transform); - glEnable(GL_DEPTH_TEST); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B), &(_buffer[0].vertices)); - - glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), &(_buffer[0].colors)); - glDrawArrays(GL_LINES, 0, _buffer.size()); - glDisable(GL_DEPTH_TEST); -} - -//////////////////////////////////////////////////////////////////////////////// - enum { IDC_NEXT = 100, @@ -157,6 +58,7 @@ static std::function createFunctions[] = #endif CL(Animate3DTest), CL(AttachmentTest), + CL(Sprite3DWithOBBPerfromanceTest), CL(Sprite3DMirrorTest), CL(BillBoardTest) }; @@ -1097,6 +999,261 @@ void AttachmentTest::onTouchesEnded(const std::vector& touches, Event* e _hasWeapon = !_hasWeapon; } +Sprite3DWithOBBPerfromanceTest::Sprite3DWithOBBPerfromanceTest() +{ + auto listener = EventListenerTouchAllAtOnce::create(); + listener->onTouchesBegan = CC_CALLBACK_2(Sprite3DWithOBBPerfromanceTest::onTouchesBegan, this); + listener->onTouchesEnded = CC_CALLBACK_2(Sprite3DWithOBBPerfromanceTest::onTouchesEnded, this); + listener->onTouchesMoved = CC_CALLBACK_2(Sprite3DWithOBBPerfromanceTest::onTouchesMoved, this); + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + auto s = Director::getInstance()->getWinSize(); + initDrawBox(); + + addNewSpriteWithCoords(Vec2(s.width/2, s.height/2)); + MenuItemFont::setFontName("fonts/arial.ttf"); + MenuItemFont::setFontSize(65); + auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(Sprite3DWithOBBPerfromanceTest::delOBBCallback, this)); + decrease->setColor(Color3B(0,200,20)); + auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(Sprite3DWithOBBPerfromanceTest::addOBBCallback, this)); + increase->setColor(Color3B(0,200,20)); + + auto menu = Menu::create(decrease, increase, nullptr); + menu->alignItemsHorizontally(); + menu->setPosition(Vec2(s.width/2, s.height-65)); + addChild(menu, 1); + + TTFConfig ttfCount("fonts/Marker Felt.ttf", 30); + _labelCubeCount = Label::createWithTTF(ttfCount,"0 cubes"); + _labelCubeCount->setColor(Color3B(0,200,20)); + _labelCubeCount->setPosition(Vec2(s.width/2, s.height-90)); + addChild(_labelCubeCount); + _hasCollider = false; + scheduleUpdate(); +} +std::string Sprite3DWithOBBPerfromanceTest::title() const +{ + return "OBB Collison Perfromance Test"; +} +std::string Sprite3DWithOBBPerfromanceTest::subtitle() const +{ + return ""; +} +void Sprite3DWithOBBPerfromanceTest::addNewOBBWithCoords(Vec2 p) +{ + Vec3 extents = Vec3(10, 10, 10); + AABB aabb(-extents, extents); + auto obb = OBB(aabb); + obb._center = Vec3(p.x,p.y,0); + _obb.push_back(obb); +} + +void Sprite3DWithOBBPerfromanceTest::onTouchesBegan(const std::vector& touches, Event* event) +{ + for (auto touch: touches) + { + auto location = touch->getLocationInView(); + + if(_obb.size() > 0) + { + _intersetList.clear(); + Ray ray; + calculateRayByLocationInView(&ray,location); + for(int i = 0; i < _obb.size(); i++) + { + if(ray.intersects(_obb[i])) + { + _intersetList.insert(i); + return; + } + } + } + } +} + +void Sprite3DWithOBBPerfromanceTest::onTouchesEnded(const std::vector& touches, Event* event) +{ + +} + +void Sprite3DWithOBBPerfromanceTest::onTouchesMoved(const std::vector& touches, Event* event) +{ + for (auto touch: touches) + { + auto location = touch->getLocation(); + + for(int i = 0; i < _obb.size(); i++) + { + if(_intersetList.find(i) != _intersetList.end()) + _obb[i]._center = Vec3(location.x,location.y,0); + } + } +} + +void Sprite3DWithOBBPerfromanceTest::update(float dt) +{ + char szText[16]; + sprintf(szText,"%lu cubes",_obb.size()); + _labelCubeCount->setString(szText); + + if (_drawDebug) + { + _drawDebug->clear(); + + Mat4 mat = _sprite->getNodeToWorldTransform(); + mat.getRightVector(&_obbt._xAxis); + _obbt._xAxis.normalize(); + + mat.getUpVector(&_obbt._yAxis); + _obbt._yAxis.normalize(); + + mat.getForwardVector(&_obbt._zAxis); + _obbt._zAxis.normalize(); + + _obbt._center = _sprite->getPosition3D(); + + Vec3 corners[8] = {}; + _obbt.getCorners(corners); + _drawDebug->drawCube(corners, Color4F(0,0,1,1)); + } + if(_obb.size() > 0) + { + _drawOBB->clear(); + for(int i =0; i < _obb.size(); i++) + { + Vec3 corners[8] = {}; + _obb[i].getCorners(corners); + _drawOBB->drawCube(corners, _obbt.intersects(_obb[i])?Color4F(1,0,0,1):Color4F(0,1,0,1)); + } + } +} + +void Sprite3DWithOBBPerfromanceTest::initDrawBox() +{ + _drawOBB = DrawNode3D::create(); + addChild(_drawOBB); +} + +void Sprite3DWithOBBPerfromanceTest::addNewSpriteWithCoords(Vec2 p) +{ + std::string fileName = "Sprite3DTest/tortoise.c3b"; + auto sprite = Sprite3D::create(fileName); + sprite->setScale(0.1f); + auto s = Director::getInstance()->getWinSize(); + sprite->setPosition(Vec2(s.width * 4.f / 5.f, s.height / 2.f)); + addChild(sprite); + _sprite = sprite; + auto animation = Animation3D::create(fileName); + if (animation) + { + auto animate = Animate3D::create(animation, 0.f, 1.933f); + sprite->runAction(RepeatForever::create(animate)); + } + + _moveAction = MoveTo::create(4.f, Vec2(s.width / 5.f, s.height / 2.f)); + _moveAction->retain(); + auto seq = Sequence::create(_moveAction, CallFunc::create(CC_CALLBACK_0(Sprite3DWithOBBPerfromanceTest::reachEndCallBack, this)), nullptr); + seq->setTag(100); + sprite->runAction(seq); + + AABB aabb = _sprite->getAABB(); + _obbt = OBB(aabb); + + _drawDebug = DrawNode3D::create(); + addChild(_drawDebug); +} + +void Sprite3DWithOBBPerfromanceTest::reachEndCallBack() +{ + _sprite->stopActionByTag(100); + auto inverse = (MoveTo*)_moveAction->reverse(); + inverse->retain(); + _moveAction->release(); + _moveAction = inverse; + auto rot = RotateBy::create(1.0f, Vec3(0.f, 180.f, 0.f)); + auto seq = Sequence::create(rot, _moveAction, CallFunc::create(CC_CALLBACK_0(Sprite3DWithOBBPerfromanceTest::reachEndCallBack, this)), nullptr); + seq->setTag(100); + _sprite->runAction(seq); +} + +void Sprite3DWithOBBPerfromanceTest::addOBBCallback(Ref* sender) +{ + addOBBWithCount(10); +} + +void Sprite3DWithOBBPerfromanceTest::addOBBWithCount(float value) +{ + for(int i = 0; i < value; i++) + { + Vec2 randompos = Vec2(CCRANDOM_0_1() * Director::getInstance()->getWinSize().width,CCRANDOM_0_1() * Director::getInstance()->getWinSize().height); + Vec3 extents = Vec3(10, 10, 10); + AABB aabb(-extents, extents); + auto obb = OBB(aabb); + obb._center = Vec3(randompos.x,randompos.y,0); + _obb.push_back(obb); + } +} + +void Sprite3DWithOBBPerfromanceTest::delOBBCallback(Ref* sender) +{ + delOBBWithCount(10); +} + +void Sprite3DWithOBBPerfromanceTest::delOBBWithCount(float value) +{ + if(_obb.size() >= 10) + { + _obb.erase(_obb.begin(),_obb.begin() + value); + _drawOBB->clear(); + } + else + return; +} +void Sprite3DWithOBBPerfromanceTest::unproject(const Mat4& viewProjection, const Size* viewport, Vec3* src, Vec3* dst) +{ + assert(dst); + + assert(viewport->width != 0.0f && viewport->height != 0.0f); + Vec4 screen(src->x / viewport->width, ((viewport->height - src->y)) / viewport->height, src->z, 1.0f); + + screen.x = screen.x * 2.0f - 1.0f; + screen.y = screen.y * 2.0f - 1.0f; + screen.z = screen.z * 2.0f - 1.0f; + + viewProjection.getInversed().transformVector(screen, &screen); + + if (screen.w != 0.0f) + { + screen.x /= screen.w; + screen.y /= screen.w; + screen.z /= screen.w; + } + + dst->set(screen.x, screen.y, screen.z); +} + +void Sprite3DWithOBBPerfromanceTest::calculateRayByLocationInView(Ray* ray, const Vec2& location) +{ + auto dir = Director::getInstance(); + auto view = dir->getWinSize(); + Mat4 mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + + Vec3 src = Vec3(location.x, location.y, -1); + Vec3 nearPoint; + unproject(mat, &view, &src, &nearPoint); + + src = Vec3(location.x, location.y, 1); + Vec3 farPoint; + unproject(mat, &view, &src, &farPoint); + + Vec3 direction; + Vec3::subtract(farPoint, nearPoint, &direction); + direction.normalize(); + + ray->_origin = nearPoint; + ray->_direction = direction; +} + Sprite3DMirrorTest::Sprite3DMirrorTest() : _sprite(nullptr) , _mirrorSprite(nullptr) @@ -1170,7 +1327,7 @@ BillBoardTest::BillBoardTest() auto layer3D=Layer::create(); addChild(layer3D,0); _layerBillBorad=layer3D; - DrawNode3D* line = DrawNode3D::create(); + DrawNode3D* line =DrawNode3D::create(); auto s = Director::getInstance()->getWinSize(); if (_camera == nullptr) { @@ -1178,6 +1335,7 @@ BillBoardTest::BillBoardTest() _camera->setCameraFlag(CameraFlag::USER1); _layerBillBorad->addChild(_camera); } + addNewBillBoradWithCoords(Vec3(20,0,0)); addNewAniBillBoradWithCoords(Vec3(-20,0,0)); _camera->setPosition3D(Vec3(0, 130, 130)); @@ -1383,4 +1541,4 @@ void BillBoardTest::rotateCameraCallback(Ref* sender,float value) Vec3 rotation3D= _camera->getRotation3D(); rotation3D.y+= value; _camera->setRotation3D(rotation3D); -} \ No newline at end of file +} diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index 29e73a3e82..d063d7caf4 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -34,7 +34,9 @@ namespace cocos2d { class Animate3D; class Sprite3D; class Delay; - class BillBorad; + class Ray; + class DrawNode3D; + class BillBorad; } class Sprite3DTestDemo : public BaseTest @@ -246,6 +248,40 @@ protected: cocos2d::Sprite3D* _sprite; }; +class Sprite3DWithOBBPerfromanceTest : public Sprite3DTestDemo +{ +public: + CREATE_FUNC(Sprite3DWithOBBPerfromanceTest); + Sprite3DWithOBBPerfromanceTest(); + virtual std::string title() const override; + virtual std::string subtitle() const override; + virtual void update(float dt) override; + void addNewOBBWithCoords(Vec2 p); + void addNewSpriteWithCoords(Vec2 p); + void onTouchesBegan(const std::vector& touches, Event* event); + void onTouchesEnded(const std::vector& touches, Event* event); + void onTouchesMoved(const std::vector& touches, Event* event); + void addOBBCallback(Ref* sender); + void delOBBCallback(Ref* sender); + void addOBBWithCount(float value); + void delOBBWithCount(float value); +protected: + cocos2d::Sprite3D* _sprite; + std::vector _obb; + DrawNode3D* _drawOBB; + Label* _labelCubeCount; + MoveTo* _moveAction; + OBB _obbt; + DrawNode3D* _drawDebug; + bool _hasCollider; + std::set _intersetList; + void initDrawBox(); + void reachEndCallBack(); + + void unproject(const Mat4& viewProjection, const Size* viewport, Vec3* src, Vec3* dst); + void calculateRayByLocationInView(Ray* ray, const Vec2& location); +}; + class Sprite3DMirrorTest : public Sprite3DTestDemo { public: @@ -262,6 +298,12 @@ protected: cocos2d::Sprite3D* _mirrorSprite; }; +class Sprite3DTestScene : public TestScene +{ +public: + virtual void runThisTest(); +}; + class BillBoardTest : public Sprite3DTestDemo { public: @@ -284,10 +326,4 @@ protected: }; -class Sprite3DTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index c9edfef871..6298b97f05 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -63,7 +63,7 @@ g_guisTests[] = UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); sceneManager->setCurrentUISceneId(kUIButtonTest); sceneManager->setMinUISceneId(kUIButtonTest); - sceneManager->setMaxUISceneId(kUIButtonTestSwitchScale9); + sceneManager->setMaxUISceneId(kUIButtonTestZoomScale); Scene* scene = sceneManager->currentUIScene(); Director::getInstance()->replaceScene(scene); } @@ -195,7 +195,7 @@ g_guisTests[] = UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); sceneManager->setCurrentUISceneId(kUIPageViewTest); sceneManager->setMinUISceneId(kUIPageViewTest); - sceneManager->setMaxUISceneId(kUIPageViewButtonTest); + sceneManager->setMaxUISceneId(kUIPageViewCustomScrollThreshold); Scene* scene = sceneManager->currentUIScene(); Director::getInstance()->replaceScene(scene); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index 68307eed18..9c1016f681 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -520,3 +520,71 @@ void UIButtonTestSwitchScale9::touchEvent(Ref *pSender, Widget::TouchEventType t break; } } + + +// UIButtonTestZoomScale +UIButtonTestZoomScale::UIButtonTestZoomScale() +: _displayValueLabel(nullptr) +{ + +} + +UIButtonTestZoomScale::~UIButtonTestZoomScale() +{ +} + +bool UIButtonTestZoomScale::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the button events will be displayed + _displayValueLabel = Text::create("Zoom Scale: 0.1", "fonts/Marker Felt.ttf",32); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20)); + _uiLayer->addChild(_displayValueLabel); + + // Add the alert + Text* alert = Text::create("Button","fonts/Marker Felt.ttf",30); + alert->setColor(Color3B(159, 168, 176)); + + alert->setPosition(Vec2(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f)); + + _uiLayer->addChild(alert); + + // Create the button + Button* button = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20)); + button->setPressedActionEnabled(true); + button->setName("button"); + _uiLayer->addChild(button); + button->setZoomScale(-0.5); + + Slider* slider = Slider::create(); + slider->loadBarTexture("cocosui/sliderTrack.png"); + slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); + slider->loadProgressBarTexture("cocosui/sliderProgress.png"); + slider->setPosition(Vec2(widgetSize.width / 2.0f , widgetSize.height / 2.0f - 20)); + slider->addEventListener(CC_CALLBACK_2(UIButtonTestZoomScale::sliderEvent, this)); + slider->setPercent(button->getZoomScale()*100); + _uiLayer->addChild(slider); + return true; + } + return false; +} + +void UIButtonTestZoomScale::sliderEvent(Ref *pSender, Slider::EventType type) +{ + if (type == Slider::EventType::ON_PERCENTAGE_CHANGED) + { + Slider* slider = dynamic_cast(pSender); + int percent = slider->getPercent(); + Button* btn = (Button*)_uiLayer->getChildByName("button"); + float zoomScale = percent * 0.01; + btn->setZoomScale(zoomScale); + _displayValueLabel->setString(String::createWithFormat("Zoom Scale: %f", zoomScale)->getCString()); + } +} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h index c9f7be36f7..668789066a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h @@ -105,4 +105,17 @@ protected: Text* _displayValueLabel; }; +class UIButtonTestZoomScale : public UIScene +{ +public: + UIButtonTestZoomScale(); + ~UIButtonTestZoomScale(); + bool init(); + void sliderEvent(Ref* pSender, Slider::EventType type); + +protected: + UI_SCENE_CREATE_FUNC(UIButtonTestZoomScale) + Text* _displayValueLabel; +}; + #endif /* defined(__TestCpp__UIButtonTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index 973d6ba1ef..8419708306 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -208,3 +208,103 @@ void UIPageViewButtonTest::pageViewEvent(Ref *pSender, PageView::EventType type) break; } } + + +// UIPageViewCustomScrollThreshold +UIPageViewCustomScrollThreshold::UIPageViewCustomScrollThreshold() +: _displayValueLabel(nullptr) +{ + +} + +UIPageViewCustomScrollThreshold::~UIPageViewCustomScrollThreshold() +{ +} + +bool UIPageViewCustomScrollThreshold::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the dragpanel events will be displayed + _displayValueLabel = Text::create("Scroll Threshold", "fonts/Marker Felt.ttf", 32); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + + _displayValueLabel->getContentSize().height * 1.5)); + _uiLayer->addChild(_displayValueLabel); + + // Add the black background + Text* alert = Text::create("PageView", "fonts/Marker Felt.ttf", 30); + alert->setColor(Color3B(159, 168, 176)); + alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); + _uiLayer->addChild(alert); + + Layout* root = static_cast(_uiLayer->getChildByTag(81)); + + Layout* background = dynamic_cast(root->getChildByName("background_Panel")); + + // Create the page view + PageView* pageView = PageView::create(); + pageView->setContentSize(Size(240.0f, 100.0f)); + Size backgroundSize = background->getContentSize(); + pageView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + + (backgroundSize.width - pageView->getContentSize().width) / 2.0f, + (widgetSize.height - backgroundSize.height) / 2.0f + + (backgroundSize.height - pageView->getContentSize().height) / 2.0f + 20)); + + int pageCount = 4; + for (int i = 0; i < pageCount; ++i) + { + Layout* layout = Layout::create(); + layout->setContentSize(Size(240.0f, 130.0f)); + + ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png"); + imageView->setScale9Enabled(true); + imageView->setContentSize(Size(240, 130)); + imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); + layout->addChild(imageView); + + Text* label = Text::create(StringUtils::format("page %d",(i+1)), "fonts/Marker Felt.ttf", 30); + label->setColor(Color3B(192, 192, 192)); + label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); + layout->addChild(label); + + pageView->insertPage(layout,i); + } + + _uiLayer->addChild(pageView); + pageView->setName("pageView"); + + Slider* slider = Slider::create(); + slider->loadBarTexture("cocosui/sliderTrack.png"); + slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); + slider->loadProgressBarTexture("cocosui/sliderProgress.png"); + slider->setPosition(Vec2(widgetSize.width / 2.0f , widgetSize.height / 2.0f - 40)); + slider->addEventListener(CC_CALLBACK_2(UIPageViewCustomScrollThreshold::sliderEvent, this)); + slider->setPercent(50); + _uiLayer->addChild(slider); + + + return true; + } + return false; +} + + +void UIPageViewCustomScrollThreshold::sliderEvent(Ref *pSender, Slider::EventType type) +{ + if (type == Slider::EventType::ON_PERCENTAGE_CHANGED) + { + Slider* slider = dynamic_cast(pSender); + int percent = slider->getPercent(); + PageView* pageView = (PageView*)_uiLayer->getChildByName("pageView"); + if (percent == 0) { + percent = 1; + } + pageView->setCustomScrollThreshold(percent * 0.01 * pageView->getContentSize().width); + + _displayValueLabel->setString(String::createWithFormat("Scroll Threshold: %f", pageView->getCustomScrollThreshold())->getCString()); + } +} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h index 114737a291..0892b3e936 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h @@ -55,4 +55,19 @@ protected: Text* _displayValueLabel; }; +class UIPageViewCustomScrollThreshold : public UIScene +{ +public: + UIPageViewCustomScrollThreshold(); + ~UIPageViewCustomScrollThreshold(); + bool init(); + + void sliderEvent(Ref* pSender, Slider::EventType type); + + void pageViewEvent(Ref* pSender, PageView::EventType type); +protected: + UI_SCENE_CREATE_FUNC(UIPageViewCustomScrollThreshold) + Text* _displayValueLabel; +}; + #endif /* defined(__TestCpp__UIPageViewTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index 939ae6586a..0d1bb60bd3 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -34,6 +34,7 @@ static const char* s_testArray[] = "UIButtonTest_Title", "UIButtonTest_RemoveSelf", "UIButtonTestSwitchScale9", + "UIButtonTestZoomScale", "UICheckBoxTest", "UISliderTest", "UISliderTest_Scale9", @@ -181,6 +182,8 @@ Scene *UISceneManager::currentUIScene() return UIButtonTestRemoveSelf::sceneWithTitle(s_testArray[_currentUISceneId]); case kUIButtonTestSwitchScale9: return UIButtonTestSwitchScale9::sceneWithTitle(s_testArray[_currentUISceneId]); + case kUIButtonTestZoomScale: + return UIButtonTestZoomScale::sceneWithTitle(s_testArray[_currentUISceneId]); case kUICheckBoxTest: return UICheckBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]); @@ -290,6 +293,8 @@ Scene *UISceneManager::currentUIScene() return UIPageViewTest::sceneWithTitle(s_testArray[_currentUISceneId]); case kUIPageViewButtonTest: return UIPageViewButtonTest::sceneWithTitle(s_testArray[_currentUISceneId]); + case kUIPageViewCustomScrollThreshold: + return UIPageViewCustomScrollThreshold::sceneWithTitle(s_testArray[_currentUISceneId]); case kUIListViewTest_Vertical: return UIListViewTest_Vertical::sceneWithTitle(s_testArray[_currentUISceneId]); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h index 4b9403172b..20c9471011 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -37,6 +37,7 @@ enum kUIButtonTest_Title, kUIButtonTest_RemoveSelf, kUIButtonTestSwitchScale9, + kUIButtonTestZoomScale, kUICheckBoxTest, kUISliderTest, kUISliderTest_Scale9, @@ -76,6 +77,7 @@ enum kUIScrollViewTest_ScrollToPercentBothDirection_Bounce, kUIPageViewTest, kUIPageViewButtonTest, + kUIPageViewCustomScrollThreshold, kUIListViewTest_Vertical, kUIListViewTest_Horizontal, kUIWidgetAddNodeTest, diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index 394aa71ab2..27cc2c0735 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -183,6 +183,7 @@ + @@ -370,6 +371,7 @@ + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters index eee082ff8a..e815660d53 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters @@ -864,6 +864,9 @@ Classes\Camera3DTest + + Classes\Sprite3DTest + @@ -1595,5 +1598,8 @@ Classes\Camera3DTest + + Classes\Sprite3DTest + \ No newline at end of file diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 82f02b5c14..146766e652 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/cocos2d.h %(cocosdir)s/cocos/2d/CCProtectedNode.h % # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console Mesh GLProgramCache GLProgramState SubMeshState AttachNode Camera +classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console Mesh GLProgramCache GLProgramState SubMeshState AttachNode Camera Ray AABB OBB # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -126,14 +126,17 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS TurnOffTiles::[shuffle], LabelTTF::[*], LabelBMFont::[*], - Mesh::[create], + Mesh::[create getOriginAABB], SubMeshState::[getSkin setSkin create], - Sprite3D::[getSkin getSubMeshState], + Sprite3D::[getSkin getSubMeshState getAABB], Animation3D::[getBoneCurveByName], Animation3DCache::[*], Sprite3DMaterialCache::[*], Bone3D::[*], - Scene::[getCameras] + Scene::[getCameras], + Ray::[*], + AABB::[*], + OBB::[*] rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame], ProgressTimer::[setReverseProgress=setReverseDirection],