From 0872cccd67291b8a721b9a667f32728ef7e357fa Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 24 Jun 2016 01:55:28 -0700 Subject: [PATCH] fix: collection of vr fixes (#15948) * fix: collection of vr fixes * Node::additionalTransform() and Node::setNodeToParentTransform() can be used at the same time * Node allocs _additionalTransform in runtime taking 60 bytes lees for 99% of the nodes * Node calculates the transform faster when an additionalTransform is being used * VR works when the camera is being moved manually with setNodeToParentTransform * VR has its own tests * VR can be disabled and works as expected * doc: documentation for the new fix * fix: restore submodule web * fix: compile and link on iOS * fix conflicts --- build/cocos2d_tests.xcodeproj/project.pbxproj | 18 ++ cocos/2d/CCNode.cpp | 58 ++-- cocos/2d/CCNode.h | 24 +- cocos/2d/CCScene.cpp | 1 + cocos/platform/CCGLView.cpp | 4 +- cocos/vr/CCVRGenericHeadTracker.cpp | 16 +- cocos/vr/CCVRGenericRenderer.cpp | 3 +- tests/cpp-tests/CMakeLists.txt | 2 + .../Classes/Camera3DTest/Camera3DTest.cpp | 1 - tests/cpp-tests/Classes/VRTest/VRTest.cpp | 81 ++++++ tests/cpp-tests/Classes/VRTest/VRTest.h | 52 ++++ tests/cpp-tests/Classes/controller.cpp | 1 + tests/cpp-tests/Classes/tests.h | 1 + .../proj.android-studio/app/jni/Android.mk | 1 + tests/cpp-tests/proj.android/jni/Android.mk | 1 + tests/cpp-tests/proj.win10/cpp-tests.vcxproj | 2 + .../proj.win10/cpp-tests.vcxproj.filters | 11 +- tests/cpp-tests/proj.win32/cpp-tests.vcxproj | 4 +- .../proj.win32/cpp-tests.vcxproj.filters | 264 ++++-------------- .../cpp-tests.Shared.vcxitems | 4 +- .../cpp-tests.Shared.vcxitems.filters | 11 +- 21 files changed, 306 insertions(+), 254 deletions(-) create mode 100644 tests/cpp-tests/Classes/VRTest/VRTest.cpp create mode 100644 tests/cpp-tests/Classes/VRTest/VRTest.h diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 0e983f906b..c63add8f48 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -793,6 +793,8 @@ 5046AB4B1AF2A8D80060550B /* MaterialSystemTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5046AB481AF2A8D80060550B /* MaterialSystemTest.cpp */; }; 5046AB5B1AF2C4180060550B /* Materials in Resources */ = {isa = PBXBuildFile; fileRef = 5046AB5A1AF2C4180060550B /* Materials */; }; 5046AB5C1AF2C4180060550B /* Materials in Resources */ = {isa = PBXBuildFile; fileRef = 5046AB5A1AF2C4180060550B /* Materials */; }; + 504C949C1D1C51BE00E4E9B3 /* VRTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 504C949A1D1C51BE00E4E9B3 /* VRTest.cpp */; }; + 504C949E1D1C51BE00E4E9B3 /* VRTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 504C949A1D1C51BE00E4E9B3 /* VRTest.cpp */; }; 507B41021C31BEA60067B53E /* components in Resources */ = {isa = PBXBuildFile; fileRef = 1AC35CB318CED84500F37B72 /* components */; }; 507B41031C31BEA60067B53E /* Icon-144.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AC35C7918CECF1400F37B72 /* Icon-144.png */; }; 507B41041C31BEA60067B53E /* Icon-50.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AC35C7D18CECF1400F37B72 /* Icon-50.png */; }; @@ -1178,6 +1180,7 @@ 507B44481C3370050067B53E /* project.json in Resources */ = {isa = PBXBuildFile; fileRef = 507B44461C3370050067B53E /* project.json */; }; 50921EAF1B746D5F00C085CC /* DownloaderTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 50921EAD1B746D5F00C085CC /* DownloaderTest.cpp */; }; 50921EB01B746D5F00C085CC /* DownloaderTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 50921EAD1B746D5F00C085CC /* DownloaderTest.cpp */; }; + 50D6E2511D1D1782000974D4 /* VRTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 504C949A1D1C51BE00E4E9B3 /* VRTest.cpp */; }; 50FC18521C3371C000DD15A3 /* AppDelegate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 50FC17C51C3371C000DD15A3 /* AppDelegate.cpp */; }; 50FC188C1C3371C000DD15A3 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 50FC18211C3371C000DD15A3 /* InfoPlist.strings */; }; 50FC188D1C3371C000DD15A3 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50FC18231C3371C000DD15A3 /* MainMenu.xib */; }; @@ -2426,6 +2429,8 @@ 5046AB481AF2A8D80060550B /* MaterialSystemTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MaterialSystemTest.cpp; sourceTree = ""; }; 5046AB491AF2A8D80060550B /* MaterialSystemTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MaterialSystemTest.h; sourceTree = ""; }; 5046AB5A1AF2C4180060550B /* Materials */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Materials; path = "../tests/cpp-tests/Resources/Materials"; sourceTree = ""; }; + 504C949A1D1C51BE00E4E9B3 /* VRTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VRTest.cpp; sourceTree = ""; }; + 504C949B1D1C51BE00E4E9B3 /* VRTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VRTest.h; sourceTree = ""; }; 507B420D1C31BEA60067B53E /* cpp-tests tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "cpp-tests tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 507B42B01C31E6070067B53E /* js-tests tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "js-tests tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 507B43B91C31FB670067B53E /* lua-tests tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "lua-tests tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -3360,6 +3365,7 @@ 1AC3592418CECF0A00F37B72 /* Classes */ = { isa = PBXGroup; children = ( + 504C94991D1C51BE00E4E9B3 /* VRTest */, 50921EAC1B746D5F00C085CC /* DownloaderTest */, B6DD2FF91B04972B00E47F5F /* NavMeshTest */, B6CAB54B1AF9AA4B00B9B856 /* Physics3DTest */, @@ -4969,6 +4975,15 @@ path = MaterialSystemTest; sourceTree = ""; }; + 504C94991D1C51BE00E4E9B3 /* VRTest */ = { + isa = PBXGroup; + children = ( + 504C949A1D1C51BE00E4E9B3 /* VRTest.cpp */, + 504C949B1D1C51BE00E4E9B3 /* VRTest.h */, + ); + path = VRTest; + sourceTree = ""; + }; 507B44491C3370140067B53E /* js-memory-gc-tests */ = { isa = PBXGroup; children = ( @@ -6839,6 +6854,7 @@ 29080DA3191B595E0066F8DF /* UIButtonTest.cpp in Sources */, 1AC35C5518CECF0C00F37B72 /* Texture2dTest.cpp in Sources */, 1AC35C0718CECF0C00F37B72 /* MouseTest.cpp in Sources */, + 504C949C1D1C51BE00E4E9B3 /* VRTest.cpp in Sources */, 1AC35C5D18CECF0C00F37B72 /* Ball.cpp in Sources */, 1AC35BF318CECF0C00F37B72 /* ExtensionsTest.cpp in Sources */, 1AC35B3518CECF0C00F37B72 /* TestEntries.cpp in Sources */, @@ -6973,6 +6989,7 @@ 507B41761C31BEA60067B53E /* testBasic.cpp in Sources */, 507B41791C31BEA60067B53E /* CocosBuilderTest.cpp in Sources */, 507B417B1C31BEA60067B53E /* QuestionContainerSprite.cpp in Sources */, + 504C949E1D1C51BE00E4E9B3 /* VRTest.cpp in Sources */, 507B417C1C31BEA60067B53E /* DrawPrimitivesTest.cpp in Sources */, 507B417D1C31BEA60067B53E /* UITextFieldTest.cpp in Sources */, 507B417E1C31BEA60067B53E /* MotionStreakTest.cpp in Sources */, @@ -7249,6 +7266,7 @@ 1AC35B2618CECF0C00F37B72 /* ActionsProgressTest.cpp in Sources */, 1AC35B6618CECF0C00F37B72 /* EffectsTest.cpp in Sources */, 1AC35B7218CECF0C00F37B72 /* TestHeaderLayer.cpp in Sources */, + 50D6E2511D1D1782000974D4 /* VRTest.cpp in Sources */, 1AC35B2218CECF0C00F37B72 /* ActionManagerTest.cpp in Sources */, 1AC35C3E18CECF0C00F37B72 /* PhysicsTest.cpp in Sources */, 29080DB2191B595E0066F8DF /* UILayoutTest.cpp in Sources */, diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 076deeaad1..6c0d4eed84 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -84,7 +84,8 @@ Node::Node() , _contentSizeDirty(true) , _transformDirty(true) , _inverseDirty(true) -, _useAdditionalTransform(false) +, _additionalTransform(nullptr) +, _additionalTransformDirty(false) , _transformUpdated(true) // children (lazy allocs) // lazy alloc @@ -133,7 +134,7 @@ Node::Node() ScriptEngineProtocol* engine = ScriptEngineManager::getInstance()->getScriptEngine(); _scriptType = engine != nullptr ? engine->getScriptType() : kScriptTypeNone; #endif - _transform = _inverse = _additionalTransform = Mat4::IDENTITY; + _transform = _inverse = Mat4::IDENTITY; } Node * Node::create() @@ -190,6 +191,8 @@ Node::~Node() CCASSERT(!_running, "Node still marked as running on node destruction! Was base class onExit() called in derived class onExit() implementations?"); CC_SAFE_RELEASE(_eventDispatcher); + + delete[] _additionalTransform; } bool Node::init() @@ -1757,15 +1760,25 @@ const Mat4& Node::getNodeToParentTransform() const _transform.m[13] += _transform.m[1] * -_anchorPointInPoints.x + _transform.m[5] * -_anchorPointInPoints.y; } } - - if (_useAdditionalTransform) - { - _transform = _transform * _additionalTransform; - } - - _transformDirty = false; } - + + if (_additionalTransform) + { + // This is needed to support both Node::setNodeToParentTransform() and Node::setAdditionalTransform() + // at the same time. The scenario is this: + // at some point setNodeToParentTransform() is called. + // and later setAdditionalTransform() is called every time. And since _transform + // is being overwritten everyframe, _additionalTransform[1] is used to have a copy + // of the last "_trasform without _additionalTransform" + if (_transformDirty) + _additionalTransform[1] = _transform; + + if (_transformUpdated) + _transform = _additionalTransform[1] * _additionalTransform[0]; + } + + _transformDirty = _additionalTransformDirty = false; + return _transform; } @@ -1774,6 +1787,10 @@ void Node::setNodeToParentTransform(const Mat4& transform) _transform = transform; _transformDirty = false; _transformUpdated = true; + + if (_additionalTransform) + // _additionalTransform[1] has a copy of lastest transform + _additionalTransform[1] = transform; } void Node::setAdditionalTransform(const AffineTransform& additionalTransform) @@ -1787,22 +1804,27 @@ void Node::setAdditionalTransform(Mat4* additionalTransform) { if (additionalTransform == nullptr) { - _useAdditionalTransform = false; - _additionalTransform = Mat4::IDENTITY; + delete[] _additionalTransform; + _additionalTransform = nullptr; } else { - _additionalTransform = *additionalTransform; - _useAdditionalTransform = true; + if (!_additionalTransform) { + _additionalTransform = new Mat4[2]; + + // _additionalTransform[1] is used as a backup for _transform + _additionalTransform[1] = _transform; + } + + _additionalTransform[0] = *additionalTransform; } - _transformUpdated = _transformDirty = _inverseDirty = true; + _transformUpdated = _additionalTransformDirty = _inverseDirty = true; } void Node::setAdditionalTransform(const Mat4& additionalTransform) { - _useAdditionalTransform = true; - _additionalTransform = additionalTransform; - _transformUpdated = _transformDirty = _inverseDirty = true; + Mat4* mat4= const_cast(&additionalTransform); + setAdditionalTransform(mat4); } AffineTransform Node::getParentToNodeAffineTransform() const diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 31dc80b559..9cb3aa3068 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1870,13 +1870,13 @@ protected: float _rotationZ_X; ///< rotation angle on Z-axis, component X float _rotationZ_Y; ///< rotation angle on Z-axis, component Y - Quaternion _rotationQuat; ///rotation using quaternion, if _rotationZ_X == _rotationZ_Y, _rotationQuat = RotationZ_X * RotationY * RotationX, else _rotationQuat = RotationY * RotationX + Quaternion _rotationQuat; ///rotation using quaternion, if _rotationZ_X == _rotationZ_Y, _rotationQuat = RotationZ_X * RotationY * RotationX, else _rotationQuat = RotationY * RotationX float _scaleX; ///< scaling factor on x-axis float _scaleY; ///< scaling factor on y-axis float _scaleZ; ///< scaling factor on z-axis - Vec2 _position; ///< position of the node + Vec2 _position; ///< position of the node float _positionZ; ///< OpenGL real Z position Vec2 _normalizedPosition; bool _usingNormalizedPosition; @@ -1885,21 +1885,21 @@ protected: float _skewX; ///< skew angle on x-axis float _skewY; ///< skew angle on y-axis - Vec2 _anchorPointInPoints; ///< anchor point in points - Vec2 _anchorPoint; ///< anchor point normalized (NOT in points) + Vec2 _anchorPointInPoints; ///< anchor point in points + Vec2 _anchorPoint; ///< anchor point normalized (NOT in points) Size _contentSize; ///< untransformed size of the node bool _contentSizeDirty; ///< whether or not the contentSize is dirty - Mat4 _modelViewTransform; ///< ModelView transform of the Node. + Mat4 _modelViewTransform; ///< ModelView transform of the Node. // "cache" variables are allowed to be mutable - mutable Mat4 _transform; ///< transform + mutable Mat4 _transform; ///< transform mutable bool _transformDirty; ///< transform dirty flag - mutable Mat4 _inverse; ///< inverse transform + mutable Mat4 _inverse; ///< inverse transform mutable bool _inverseDirty; ///< inverse transform dirty flag - mutable Mat4 _additionalTransform; ///< transform - bool _useAdditionalTransform; ///< The flag to check whether the additional transform is dirty + mutable Mat4* _additionalTransform; ///< two transforms needed by additional transforms + mutable bool _additionalTransformDirty; ///< transform dirty ? bool _transformUpdated; ///< Whether or not the Transform object was updated since the last frame int _localZOrder; ///< Local order (relative to its siblings) used to sort the node @@ -1908,10 +1908,10 @@ protected: Vector _children; ///< array of children nodes Node *_parent; ///< weak reference to parent node Director* _director; //cached director pointer to improve rendering performance - int _tag; ///< a tag. Can be any number you assigned just to identify this node + int _tag; ///< a tag. Can be any number you assigned just to identify this node - std::string _name; ///setAdditionalProjection(*eyeProjection * camera->getProjectionMatrix().getInversed()); + camera->setAdditionalTransform(eyeTransform.getInversed()); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix()); diff --git a/cocos/platform/CCGLView.cpp b/cocos/platform/CCGLView.cpp index 019b837c83..1ab18e18c0 100644 --- a/cocos/platform/CCGLView.cpp +++ b/cocos/platform/CCGLView.cpp @@ -493,8 +493,10 @@ void GLView::setVR(VRIRenderer* vrRenderer) { if (_vrImpl != vrRenderer) { - if (_vrImpl) + if (_vrImpl) { + _vrImpl->cleanup(); delete _vrImpl; + } if (vrRenderer) vrRenderer->setup(this); diff --git a/cocos/vr/CCVRGenericHeadTracker.cpp b/cocos/vr/CCVRGenericHeadTracker.cpp index 4e3fb59738..1228a7ecf6 100644 --- a/cocos/vr/CCVRGenericHeadTracker.cpp +++ b/cocos/vr/CCVRGenericHeadTracker.cpp @@ -228,13 +228,17 @@ Mat4 VRGenericHeadTracker::getLocalRotation() { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) CMMotionManager* motionMgr = (CMMotionManager*)_motionMgr; - CMDeviceMotion *motion = motionMgr.deviceMotion; + CMDeviceMotion* motion = motionMgr.deviceMotion; - CMRotationMatrix rotationMatrix = motion.attitude.rotationMatrix; - Mat4 inertialReferenceFrameToDevice0 = matrixFromRotationMatrix(rotationMatrix); // note the matrix inversion - Mat4 inertialReferenceFrameToDevice = inertialReferenceFrameToDevice0.getTransposed(); - Mat4 worldToDevice = inertialReferenceFrameToDevice * _worldToInertialReferenceFrame; - return _deviceToDisplay * worldToDevice; + if (motion) { + CMRotationMatrix rotationMatrix = motion.attitude.rotationMatrix; + Mat4 inertialReferenceFrameToDevice0 = matrixFromRotationMatrix(rotationMatrix); // note the matrix inversion + Mat4 inertialReferenceFrameToDevice = inertialReferenceFrameToDevice0.getTransposed(); + Mat4 worldToDevice = inertialReferenceFrameToDevice * _worldToInertialReferenceFrame; + return _deviceToDisplay * worldToDevice; + } + // bug! + return Mat4::IDENTITY; #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) static Vec3 prevAccel = Vec3(0,0,0); diff --git a/cocos/vr/CCVRGenericRenderer.cpp b/cocos/vr/CCVRGenericRenderer.cpp index a9659ce157..75e763a12a 100644 --- a/cocos/vr/CCVRGenericRenderer.cpp +++ b/cocos/vr/CCVRGenericRenderer.cpp @@ -87,7 +87,6 @@ void VRGenericRenderer::setup(GLView* glview) _fb->attachDepthStencilTarget(ds); _fb->setClearColor(Color4F(0,0,0,1)); - _distortion = new Distortion; _leftDistortionMesh = createDistortionMesh(VREye::EyeType::LEFT); _rightDistortionMesh = createDistortionMesh(VREye::EyeType::RIGHT); @@ -119,10 +118,12 @@ void VRGenericRenderer::render(Scene* scene, Renderer* renderer) rightTransform *= headRotation; _fb->applyFBO(); + auto defaultVP = Camera::getDefaultViewport(); Camera::setDefaultViewport(_leftEye.viewport); scene->render(renderer, leftTransform, nullptr); Camera::setDefaultViewport(_rightEye.viewport); scene->render(renderer, rightTransform, nullptr); + Camera::setDefaultViewport(defaultVP); _fb->restoreFBO(); auto texture = _fb->getRenderTarget()->getTexture(); diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index aa7ca602e0..5994767e04 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -162,6 +162,8 @@ set(TESTS_SRC Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp Classes/controller.cpp Classes/testBasic.cpp + Classes/VRTest/VRTest.cpp + Classes/VRTest/VRTest.h ${PLATFORM_SRC} ) diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index 2d882f4b30..299f704378 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -1162,7 +1162,6 @@ void CameraArcBallDemo::updateCameraTransform() Mat4::createTranslation(_center, ¢er); Mat4 result = center * rot * trans; _camera->setNodeToParentTransform(result); - } void CameraArcBallDemo::switchOperateCallback(Ref* sender) diff --git a/tests/cpp-tests/Classes/VRTest/VRTest.cpp b/tests/cpp-tests/Classes/VRTest/VRTest.cpp new file mode 100644 index 0000000000..f130641acc --- /dev/null +++ b/tests/cpp-tests/Classes/VRTest/VRTest.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** + Copyright (c) 2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "VRTest.h" + +USING_NS_CC; + +VRTests::VRTests() +{ + ADD_TEST_CASE(VRTest1); +}; + +//------------------------------------------------------------------ +// +// VRTest1 +// +//------------------------------------------------------------------ + +VRTest1::VRTest1() +{ + auto size = Director::getInstance()->getVisibleSize(); + + auto image = Sprite::create("Images/background.png"); + image->setPosition(size/2); + addChild(image); + + auto button = MenuItemFont::create("Enable / Disable VR", [](Ref* ref){ + + auto glview = Director::getInstance()->getOpenGLView(); + auto vrimpl = glview->getVR(); + if (vrimpl) + { + glview->setVR(nullptr); + } + else + { + auto genericvr = new VRGenericRenderer; + glview->setVR(genericvr); + } + }); + button->setFontSizeObj(16); + auto menu = Menu::create(button, nullptr); + addChild(menu); + + menu->setPosition(size / 6 ); +} + +std::string VRTest1::title() const +{ + return "Testing Generic VR"; +} + +std::string VRTest1::subtitle() const +{ + return "Enable / Disable it with the button"; +} + + + diff --git a/tests/cpp-tests/Classes/VRTest/VRTest.h b/tests/cpp-tests/Classes/VRTest/VRTest.h new file mode 100644 index 0000000000..818f789a40 --- /dev/null +++ b/tests/cpp-tests/Classes/VRTest/VRTest.h @@ -0,0 +1,52 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef _VR_TEST_H_ +#define _VR_TEST_H_ + +#include "cocos2d.h" +#include "../BaseTest.h" +#include + +DEFINE_TEST_SUITE(VRTests); + +class VRTestDemo : public TestCase +{ +protected: + std::string _title; + +public: +}; + +class VRTest1 : public VRTestDemo +{ +public: + CREATE_FUNC(VRTest1); + VRTest1(); + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + + +#endif diff --git a/tests/cpp-tests/Classes/controller.cpp b/tests/cpp-tests/Classes/controller.cpp index 8f2811d14b..266c718ec5 100644 --- a/tests/cpp-tests/Classes/controller.cpp +++ b/tests/cpp-tests/Classes/controller.cpp @@ -100,6 +100,7 @@ public: addTest("URL Open Test", []() { return new OpenURLTests(); }); addTest("UserDefault", []() { return new UserDefaultTests(); }); addTest("Vibrate", []() { return new VibrateTests(); }); + addTest("VR Test", []() { return new VRTests(); }); addTest("Zwoptex", []() { return new ZwoptexTests(); }); addTest("SpriteFrameCache", []() { return new SpriteFrameCacheTests(); }); } diff --git a/tests/cpp-tests/Classes/tests.h b/tests/cpp-tests/Classes/tests.h index d53084c7fd..29f9a87255 100644 --- a/tests/cpp-tests/Classes/tests.h +++ b/tests/cpp-tests/Classes/tests.h @@ -89,6 +89,7 @@ #include "UnitTest/UnitTest.h" #include "UserDefaultTest/UserDefaultTest.h" #include "VibrateTest/VibrateTest.h" +#include "VRTest/VRTest.h" #include "ZwoptexTest/ZwoptexTest.h" #include "SpriteFrameCacheTest/SpriteFrameCacheTest.h" diff --git a/tests/cpp-tests/proj.android-studio/app/jni/Android.mk b/tests/cpp-tests/proj.android-studio/app/jni/Android.mk index f7a55d15d9..2f885d393b 100644 --- a/tests/cpp-tests/proj.android-studio/app/jni/Android.mk +++ b/tests/cpp-tests/proj.android-studio/app/jni/Android.mk @@ -151,6 +151,7 @@ LOCAL_SRC_FILES := main.cpp \ ../../../Classes/UserDefaultTest/UserDefaultTest.cpp \ ../../../Classes/VisibleRect.cpp \ ../../../Classes/VibrateTest/VibrateTest.cpp \ +../../../Classes/VRTest/VRTest.cpp \ ../../../Classes/ZwoptexTest/ZwoptexTest.cpp \ ../../../Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp \ ../../../Classes/controller.cpp \ diff --git a/tests/cpp-tests/proj.android/jni/Android.mk b/tests/cpp-tests/proj.android/jni/Android.mk index 394b00550d..007bc92e97 100644 --- a/tests/cpp-tests/proj.android/jni/Android.mk +++ b/tests/cpp-tests/proj.android/jni/Android.mk @@ -151,6 +151,7 @@ LOCAL_SRC_FILES := main.cpp \ ../../Classes/UserDefaultTest/UserDefaultTest.cpp \ ../../Classes/VisibleRect.cpp \ ../../Classes/VibrateTest/VibrateTest.cpp \ +../../Classes/VRTest/VRTest.cpp \ ../../Classes/ZwoptexTest/ZwoptexTest.cpp \ ../../Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp \ ../../Classes/controller.cpp \ diff --git a/tests/cpp-tests/proj.win10/cpp-tests.vcxproj b/tests/cpp-tests/proj.win10/cpp-tests.vcxproj index f6bb648df9..80a6b004ba 100644 --- a/tests/cpp-tests/proj.win10/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win10/cpp-tests.vcxproj @@ -451,6 +451,7 @@ + @@ -624,6 +625,7 @@ + diff --git a/tests/cpp-tests/proj.win10/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win10/cpp-tests.vcxproj.filters index 3fd92e0d1d..20da53b1c5 100644 --- a/tests/cpp-tests/proj.win10/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win10/cpp-tests.vcxproj.filters @@ -350,6 +350,9 @@ {c6bd28ea-2696-4d05-90b2-2646ed934a49} + + {848aacea-a328-4797-9119-403b3c94d3d7} + @@ -790,6 +793,9 @@ Classes\UITest\CocoStudioGUITest\UITabContorlTest + + Classes\VRTests + @@ -1431,6 +1437,9 @@ + + Classes\VRTests + @@ -1474,4 +1483,4 @@ Assets - + \ No newline at end of file diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index a74675c692..d22fe9d61a 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -222,6 +222,7 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y + @@ -377,6 +378,7 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y + @@ -517,4 +519,4 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y - + \ No newline at end of file diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters index 309e430ec1..1d2b906e7c 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters @@ -241,54 +241,6 @@ {ee9a44a8-ec5e-4e71-bb62-1f684fe29125} - - {b339bf74-8da5-4910-a66b-5c29ea84969b} - - - {e560da84-2530-4642-9c7c-c57223e82b58} - - - {7255ed35-ec1a-4872-a633-a1ab0fd4d62c} - - - {d9a49c7a-219d-4d00-bb0d-5566e2a34cb1} - - - {d3b488b2-d666-448e-8727-e9193f19220d} - - - {4ccc551f-bc99-4609-97d9-948a0246b2f6} - - - {f70005e7-d796-4e6d-9970-837adc08cf05} - - - {e6f1c4c8-c222-4794-99e3-52f9c56a6aa0} - - - {0773584d-9c7f-4f00-995c-63031c963950} - - - {45c87afb-962e-47ab-83a1-6319d9899c87} - - - {361f6895-e9d1-4be7-a910-684d8d2a0d64} - - - {4762cfd1-9256-4988-97c7-6ae068689895} - - - {41d79a36-2286-402f-8dd7-d8a5af8f1363} - - - {ac3784ef-cbc6-4bff-8daf-21ffa9f124b6} - - - {492a20b0-e149-40f1-8bd5-98ec3f27aab2} - - - {5bde63be-bdba-4155-a3a9-72f06c169768} - {45e9becf-58e5-424e-903d-9bc7f9999d5b} @@ -337,8 +289,8 @@ {3442fab7-30f3-4bbc-8b7c-5821011d4935} - - {92f5bcdc-3671-4226-9340-66bf4b8f3305} + + {f88d1ce5-36f2-4dca-8ad6-b55a1becbfe8} @@ -438,9 +390,6 @@ Classes\ZwoptexTest - - Classes\SpriteFrameCacheTest - Classes\CurlTest @@ -645,72 +594,6 @@ Classes\UITest - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest\UITextTest - - - Classes\UITest\CocostudioGUISceneTest\UIButtonTest - - - Classes\UITest\CocostudioGUISceneTest\UICheckBoxTest - - - Classes\UITest\CocostudioGUISceneTest\UIFocusTest - - - Classes\UITest\CocostudioGUISceneTest\UIImageViewTest - - - Classes\UITest\CocostudioGUISceneTest\UILayoutTest - - - Classes\UITest\CocostudioGUISceneTest\UIListViewTest - - - Classes\UITest\CocostudioGUISceneTest\UILoadingBarTest - - - Classes\UITest\CocostudioGUISceneTest\UIPageViewTest - - - Classes\UITest\CocostudioGUISceneTest\UIRichTextTest - - - Classes\UITest\CocostudioGUISceneTest\UIScrollViewTest - - - Classes\UITest\CocostudioGUISceneTest\UISliderTest - - - Classes\UITest\CocostudioGUISceneTest\UITextAtlasTest - - - Classes\UITest\CocostudioGUISceneTest\UITextBMFontTest - - - Classes\UITest\CocostudioGUISceneTest\UITextFieldTest - - - Classes\UITest\CocostudioGUISceneTest\UIWidgetAddNodeTest - Classes\BugsTest @@ -720,18 +603,12 @@ Classes\TileMapTest - - Classes\UITest\CocostudioGUISceneTest - Classes\Camera3DTest Classes\Sprite3DTest - - Classes\UITest\CocostudioGUISceneTest - Classes\BillBoardTest @@ -750,9 +627,6 @@ Classes\Particle3DTest - - Classes\CocosStudio3DTest - Classes\AllocatorTest @@ -790,11 +664,31 @@ Classes\DownloaderTest - - Classes\UITest\CocostudioGUISceneTest\UITabContorlTest - - - Classes\UITest\CocostudioGUISceneTest\UILayoutTest + + + + + + + + + + + + + + + + + + + + + + + + + Classes\VRTests @@ -900,9 +794,6 @@ Classes\ZwoptexTest - - Classes\SpriteFrameCacheTest - Classes\CurlTest @@ -1296,72 +1187,6 @@ Classes\UITest - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest - - - Classes\UITest\CocostudioGUISceneTest\UITextTest - - - Classes\UITest\CocostudioGUISceneTest\UIButtonTest - - - Classes\UITest\CocostudioGUISceneTest\UICheckBoxTest - - - Classes\UITest\CocostudioGUISceneTest\UIFocusTest - - - Classes\UITest\CocostudioGUISceneTest\UIImageViewTest - - - Classes\UITest\CocostudioGUISceneTest\UILayoutTest - - - Classes\UITest\CocostudioGUISceneTest\UIListViewTest - - - Classes\UITest\CocostudioGUISceneTest\UILoadingBarTest - - - Classes\UITest\CocostudioGUISceneTest\UIPageViewTest - - - Classes\UITest\CocostudioGUISceneTest\UIRichTextTest - - - Classes\UITest\CocostudioGUISceneTest\UIScrollViewTest - - - Classes\UITest\CocostudioGUISceneTest\UISliderTest - - - Classes\UITest\CocostudioGUISceneTest\UITextAtlasTest - - - Classes\UITest\CocostudioGUISceneTest\UITextBMFontTest - - - Classes\UITest\CocostudioGUISceneTest\UITextFieldTest - - - Classes\UITest\CocostudioGUISceneTest\UIWidgetAddNodeTest - Classes\BugsTest @@ -1371,18 +1196,12 @@ Classes\TileMapTest - - Classes\UITest\CocostudioGUISceneTest - Classes\Camera3DTest Classes\Sprite3DTest - - Classes\UITest\CocostudioGUISceneTest - Classes\BillBoardTest @@ -1437,8 +1256,31 @@ Classes\DownloaderTest - - Classes\UITest\CocostudioGUISceneTest\UITabContorlTest + + + + + + + + + + + + + + + + + + + + + + + + + Classes\VRTests - + \ No newline at end of file diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems index 84b2ac26cd..68602e10d6 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems @@ -168,6 +168,7 @@ + @@ -390,6 +391,7 @@ + @@ -414,4 +416,4 @@ - + \ No newline at end of file diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters index 2c5a44b6de..e1ad327177 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters @@ -636,6 +636,9 @@ Classes\UITest\CocostudioGUISceneTest\UITabControlTest + + Classes\VRTests + @@ -1379,6 +1382,9 @@ {aa41698e-072b-4b8b-89e0-0065e2fbb7fd} + + {9f993b49-f2da-4359-a39d-c1015673f22a} + @@ -1430,5 +1436,8 @@ + + Classes\VRTests + - + \ No newline at end of file