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