2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-07-10 09:47:41 +08:00
|
|
|
https://axis-project.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../BaseTest.h"
|
2022-07-05 14:48:46 +08:00
|
|
|
#include "../MeshRendererTest/DrawNode3D.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#include "renderer/backend/ProgramState.h"
|
|
|
|
#include "renderer/backend/Types.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2022-07-05 14:48:46 +08:00
|
|
|
class MeshRenderer;
|
2021-12-31 12:12:40 +08:00
|
|
|
class Delay;
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END // namespace axis
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
enum State
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
State_None = 0,
|
|
|
|
State_Idle = 0x01,
|
|
|
|
State_Move = 0x02,
|
|
|
|
State_Rotate = 0x04,
|
|
|
|
State_Speak = 0x08,
|
|
|
|
State_MeleeAttack = 0x10,
|
2019-11-23 20:27:39 +08:00
|
|
|
State_RemoteAttack = 0x20,
|
2021-12-31 12:12:40 +08:00
|
|
|
State_Attack = 0x40,
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
enum class CameraType
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
Free = 0,
|
2019-11-23 20:27:39 +08:00
|
|
|
FirstPerson = 1,
|
|
|
|
ThirdPerson = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class OperateCamType
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
MoveCamera = 0,
|
|
|
|
RotateCamera = 1,
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TEST_SUITE(Camera3DTests);
|
|
|
|
|
|
|
|
class CameraBaseTest : public TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
protected:
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::BillBoard* bill1;
|
|
|
|
axis::BillBoard* bill2;
|
|
|
|
axis::Label* l1;
|
|
|
|
axis::Label* l2;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
class CameraRotationTest : public CameraBaseTest
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(CameraRotationTest);
|
|
|
|
CameraRotationTest();
|
|
|
|
virtual ~CameraRotationTest();
|
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
|
|
|
|
|
|
|
virtual void update(float dt) override;
|
|
|
|
|
|
|
|
// overrides
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
|
|
|
|
protected:
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Node* _camControlNode;
|
|
|
|
axis::Node* _camNode;
|
|
|
|
axis::EventListenerTouchOneByOne* _lis;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class Camera3DTestDemo : public CameraBaseTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(Camera3DTestDemo);
|
|
|
|
Camera3DTestDemo();
|
|
|
|
virtual ~Camera3DTestDemo();
|
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
|
|
|
// overrides
|
|
|
|
virtual std::string title() const override;
|
2022-07-11 17:50:21 +08:00
|
|
|
void addNewSpriteWithCoords(axis::Vec3 p,
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string fileName,
|
|
|
|
bool playAnimation = false,
|
|
|
|
float scale = 1.0f,
|
|
|
|
bool bindCamera = false);
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void onTouchesBegan(const std::vector<axis::Touch*>& touches, axis::Event* event);
|
|
|
|
void onTouchesMoved(const std::vector<axis::Touch*>& touches, axis::Event* event);
|
|
|
|
void onTouchesEnded(const std::vector<axis::Touch*>& touches, axis::Event* event);
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void scaleCameraCallback(axis::Ref* sender, float value);
|
|
|
|
void rotateCameraCallback(axis::Ref* sender, float value);
|
|
|
|
void SwitchViewCallback(axis::Ref* sender, CameraType cameraType);
|
2019-11-23 20:27:39 +08:00
|
|
|
void updateCamera(float fDelta);
|
|
|
|
void move3D(float elapsedTime);
|
|
|
|
void updateState(float elapsedTime);
|
2021-12-31 12:12:40 +08:00
|
|
|
bool isState(unsigned int state, unsigned int bit) const;
|
2019-11-23 20:27:39 +08:00
|
|
|
void reachEndCallBack();
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
bool onTouchesCommon(axis::Touch* touch, axis::Event* event, bool* touchProperty);
|
|
|
|
bool onTouchesZoomOut(axis::Touch* touch, axis::Event* event);
|
|
|
|
void onTouchesZoomOutEnd(axis::Touch* touch, axis::Event* event);
|
|
|
|
bool onTouchesZoomIn(axis::Touch* touch, axis::Event* event);
|
|
|
|
void onTouchesZoomInEnd(axis::Touch* touch, axis::Event* event);
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
bool onTouchesRotateLeft(axis::Touch* touch, axis::Event* event);
|
|
|
|
void onTouchesRotateLeftEnd(axis::Touch* touch, axis::Event* event);
|
|
|
|
bool onTouchesRotateRight(axis::Touch* touch, axis::Event* event);
|
|
|
|
void onTouchesRotateRightEnd(axis::Touch* touch, axis::Event* event);
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string _title;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Layer* _layer3D;
|
|
|
|
axis::MeshRenderer* _mesh;
|
|
|
|
axis::Vec3 _targetPos;
|
2021-12-31 12:12:40 +08:00
|
|
|
CameraType _cameraType;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::MenuItem* _incRot;
|
|
|
|
axis::MenuItem* _decRot;
|
2021-12-31 12:12:40 +08:00
|
|
|
unsigned int _curState;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Camera* _camera;
|
|
|
|
axis::MoveTo* _moveAction;
|
2019-11-23 20:27:39 +08:00
|
|
|
bool _bZoomOut;
|
|
|
|
bool _bZoomIn;
|
|
|
|
bool _bRotateLeft;
|
|
|
|
bool _bRotateRight;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Label* _RotateRightlabel;
|
|
|
|
axis::Label* _RotateLeftlabel;
|
|
|
|
axis::Label* _ZoomInlabel;
|
|
|
|
axis::Label* _ZoomOutlabel;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CameraCullingDemo : public CameraBaseTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(CameraCullingDemo);
|
|
|
|
CameraCullingDemo();
|
|
|
|
virtual ~CameraCullingDemo();
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void update(float dt) override;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// overrides
|
|
|
|
virtual std::string title() const override;
|
|
|
|
void reachEndCallBack();
|
2022-07-11 17:50:21 +08:00
|
|
|
void switchViewCallback(axis::Ref* sender);
|
|
|
|
void addMeshCallback(axis::Ref* sender);
|
|
|
|
void delMeshCallback(axis::Ref* sender);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
void drawCameraFrustum();
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Label* _labelMeshCount;
|
|
|
|
axis::Layer* _layer3D;
|
|
|
|
std::vector<axis::MeshRenderer*> _objects;
|
2021-12-31 12:12:40 +08:00
|
|
|
CameraType _cameraType;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Camera* _cameraFirst;
|
|
|
|
axis::Camera* _cameraThird;
|
|
|
|
axis::MoveBy* _moveAction;
|
|
|
|
axis::DrawNode3D* _drawAABB;
|
|
|
|
axis::DrawNode3D* _drawFrustum;
|
2021-12-31 12:12:40 +08:00
|
|
|
int _row;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CameraArcBallDemo : public CameraBaseTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(CameraArcBallDemo);
|
|
|
|
CameraArcBallDemo();
|
|
|
|
virtual ~CameraArcBallDemo();
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void update(float dt) override;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// overrides
|
|
|
|
virtual std::string title() const override;
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void switchOperateCallback(axis::Ref* sender);
|
|
|
|
void switchTargetCallback(axis::Ref* sender);
|
|
|
|
void onTouchsMoved(const std::vector<axis::Touch*>& touchs, axis::Event* event);
|
2019-11-23 20:27:39 +08:00
|
|
|
void updateCameraTransform();
|
2022-07-11 17:50:21 +08:00
|
|
|
void calculateArcBall(axis::Vec3& axis,
|
2021-12-31 12:12:40 +08:00
|
|
|
float& angle,
|
|
|
|
float p1x,
|
|
|
|
float p1y,
|
|
|
|
float p2x,
|
|
|
|
float p2y); // calculate rotation quaternion parameters
|
|
|
|
float projectToSphere(float r, float x, float y); // points on the screen project to arc ball
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Layer* _layer3D;
|
2021-12-31 12:12:40 +08:00
|
|
|
CameraType _cameraType;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Camera* _camera;
|
|
|
|
axis::DrawNode3D* _drawGrid;
|
|
|
|
axis::Quaternion _rotationQuat; // rotation Quaternion
|
2021-12-31 12:12:40 +08:00
|
|
|
float _radius; // arc ball radius
|
|
|
|
float _distanceZ;
|
|
|
|
OperateCamType _operate; // switch rotate or zoom
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 _center; // camera look target
|
2021-12-31 12:12:40 +08:00
|
|
|
int _target; // switch camera look target
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::MeshRenderer* _mesh1;
|
|
|
|
axis::MeshRenderer* _mesh2;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class FogTestDemo : public CameraBaseTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(FogTestDemo);
|
|
|
|
FogTestDemo();
|
|
|
|
virtual ~FogTestDemo();
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void update(float dt) override;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// overrides
|
|
|
|
virtual std::string title() const override;
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void onTouchesMoved(const std::vector<axis::Touch*>& touches, axis::Event* event);
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void switchTypeCallback(axis::Ref* sender, int type);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
2021-12-31 12:12:40 +08:00
|
|
|
CameraType _cameraType = CameraType::Free;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Layer* _layer3D = nullptr;
|
|
|
|
axis::Camera* _camera = nullptr;
|
|
|
|
axis::MeshRenderer* _mesh1 = nullptr;
|
|
|
|
axis::MeshRenderer* _mesh2 = nullptr;
|
|
|
|
axis::backend::ProgramState* _programState1 = nullptr;
|
|
|
|
axis::backend::ProgramState* _programState2 = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-15 19:44:31 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::EventListenerCustom* _backToForegroundListener;
|
2019-11-23 20:27:39 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
// class CameraFrameBufferTest : public CameraBaseTest
|
2019-11-23 20:27:39 +08:00
|
|
|
//{
|
2021-12-31 12:12:40 +08:00
|
|
|
// public:
|
|
|
|
// CREATE_FUNC(CameraFrameBufferTest);
|
|
|
|
// CameraFrameBufferTest();
|
|
|
|
// virtual ~CameraFrameBufferTest();
|
|
|
|
// // overrides
|
|
|
|
// virtual std::string title() const override;
|
|
|
|
//
|
|
|
|
// virtual void onEnter() override;
|
|
|
|
// };
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
class BackgroundColorBrushTest : public CameraBaseTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(BackgroundColorBrushTest);
|
|
|
|
BackgroundColorBrushTest();
|
|
|
|
virtual ~BackgroundColorBrushTest();
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// overrides
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
};
|