PuzzleSDK
Camera3DTest.h
浏览该文件的文档.
1/****************************************************************************
2Copyright (c) 2013 cocos2d-x.org
3Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
4
5http://www.cocos2d-x.org
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in
15all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23THE SOFTWARE.
24****************************************************************************/
25
26#pragma once
27
28#include "../BaseTest.h"
29#include "../Sprite3DTest/DrawNode3D.h"
30
31#include "renderer/backend/ProgramState.h"
32#include "renderer/backend/Types.h"
33
34#include <string>
35
36namespace cocos2d {
37 class Sprite3D;
38 class Delay;
39}
40
42{
44 State_Idle = 0x01,
45 State_Move = 0x02,
51};
52enum class CameraType
53{
54 Free = 0,
55 FirstPerson = 1,
56 ThirdPerson = 2,
57};
58
60{
61 MoveCamera=0,
63};
64
65DEFINE_TEST_SUITE(Camera3DTests);
66
68{
69public:
70
71protected:
72 cocos2d::BillBoard* bill1;
73 cocos2d::BillBoard* bill2;
74 cocos2d::Label* l1;
75 cocos2d::Label* l2;
76};
77
79
80public:
83 virtual ~CameraRotationTest();
84
85 virtual void onEnter() override;
86 virtual void onExit() override;
87
88 virtual void update(float dt) override;
89
90 // overrides
91 virtual std::string title() const override;
92 virtual std::string subtitle() const override;
93
94protected:
95
96 cocos2d::Node* _camControlNode;
97 cocos2d::Node* _camNode;
98 cocos2d::EventListenerTouchOneByOne* _lis;
99};
100
102{
103public:
106 virtual ~Camera3DTestDemo();
107
108 virtual void onEnter() override;
109 virtual void onExit() override;
110 // overrides
111 virtual std::string title() const override;
112 void addNewSpriteWithCoords(cocos2d::Vec3 p,std::string fileName,bool playAnimation=false,float scale=1.0f,bool bindCamera=false);
113
114 void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event);
115 void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event);
116 void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event);
117
118 void scaleCameraCallback(cocos2d::Ref* sender,float value);
119 void rotateCameraCallback(cocos2d::Ref* sender,float value);
120 void SwitchViewCallback(cocos2d::Ref* sender,CameraType cameraType);
121 void updateCamera(float fDelta);
122 void move3D(float elapsedTime);
123 void updateState(float elapsedTime);
124 bool isState(unsigned int state,unsigned int bit) const;
125 void reachEndCallBack();
126
127 bool onTouchesCommon(cocos2d::Touch* touch, cocos2d::Event* event, bool* touchProperty);
128 bool onTouchesZoomOut(cocos2d::Touch* touch, cocos2d::Event* event);
129 void onTouchesZoomOutEnd(cocos2d::Touch* touch, cocos2d::Event* event);
130 bool onTouchesZoomIn(cocos2d::Touch* touch, cocos2d::Event* event);
131 void onTouchesZoomInEnd(cocos2d::Touch* touch, cocos2d::Event* event);
132
133 bool onTouchesRotateLeft(cocos2d::Touch* touch, cocos2d::Event* event);
134 void onTouchesRotateLeftEnd(cocos2d::Touch* touch, cocos2d::Event* event);
135 bool onTouchesRotateRight(cocos2d::Touch* touch, cocos2d::Event* event);
136 void onTouchesRotateRightEnd(cocos2d::Touch* touch, cocos2d::Event* event);
137protected:
138 std::string _title;
139 cocos2d::Layer* _layer3D;
140 cocos2d::Sprite3D* _sprite3D;
141 cocos2d::Vec3 _targetPos;
143 cocos2d::MenuItem* _incRot;
144 cocos2d::MenuItem* _decRot;
145 unsigned int _curState;
146 cocos2d::Camera* _camera;
147 cocos2d::MoveTo* _moveAction;
152 cocos2d::Label* _RotateRightlabel;
153 cocos2d::Label* _RotateLeftlabel;
154 cocos2d::Label* _ZoomInlabel;
155 cocos2d::Label* _ZoomOutlabel;
156};
157
159{
160public:
163 virtual ~CameraCullingDemo();
164
165 virtual void onEnter() override;
166 virtual void onExit() override;
167
168 virtual void update(float dt) override;
169
170 // overrides
171 virtual std::string title() const override;
172 void reachEndCallBack();
173 void switchViewCallback(cocos2d::Ref* sender);
174 void addSpriteCallback(cocos2d::Ref* sender);
175 void delSpriteCallback(cocos2d::Ref* sender);
176
177 void drawCameraFrustum();
178
179protected:
180 cocos2d::Label* _labelSprite3DCount;
181 cocos2d::Layer* _layer3D;
182 std::vector<cocos2d::Sprite3D*> _objects;
184 cocos2d::Camera* _cameraFirst;
185 cocos2d::Camera* _cameraThird;
186 cocos2d::MoveBy* _moveAction;
187 cocos2d::DrawNode3D* _drawAABB;
188 cocos2d::DrawNode3D* _drawFrustum;
189 int _row;
190};
191
193{
194public:
197 virtual ~CameraArcBallDemo();
198
199 virtual void onEnter() override;
200 virtual void onExit() override;
201
202 virtual void update(float dt) override;
203
204 // overrides
205 virtual std::string title() const override;
206
207 void switchOperateCallback(cocos2d::Ref* sender);
208 void switchTargetCallback(cocos2d::Ref* sender);
209 void onTouchsMoved(const std::vector<cocos2d::Touch*> &touchs, cocos2d::Event *event);
211 void calculateArcBall( cocos2d::Vec3 & axis, float & angle, float p1x, float p1y, float p2x, float p2y );//calculate rotation quaternion parameters
212 float projectToSphere( float r, float x, float y );//points on the screen project to arc ball
213
214protected:
215 cocos2d::Layer* _layer3D;
217 cocos2d::Camera* _camera;
218 cocos2d::DrawNode3D* _drawGrid;
219 cocos2d::Quaternion _rotationQuat; //rotation Quaternion
220 float _radius; //arc ball radius
222 OperateCamType _operate; //switch rotate or zoom
223 cocos2d::Vec3 _center; //camera look target
224 int _target; //switch camera look target
225 cocos2d::Sprite3D* _sprite3D1;
226 cocos2d::Sprite3D* _sprite3D2;
227};
228
230{
231public:
233 FogTestDemo();
234 virtual ~FogTestDemo();
235
236 virtual void onEnter() override;
237 virtual void onExit() override;
238
239 virtual void update(float dt) override;
240
241 // overrides
242 virtual std::string title() const override;
243
244 void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event);
245
246 void switchTypeCallback(cocos2d::Ref* sender,int type);
247
248protected:
250 cocos2d::Layer* _layer3D = nullptr;
251 cocos2d::Camera* _camera = nullptr;
252 cocos2d::Sprite3D* _sprite3D1 = nullptr;
253 cocos2d::Sprite3D* _sprite3D2 = nullptr;
254 cocos2d::backend::ProgramState* _programState1 = nullptr;
255 cocos2d::backend::ProgramState* _programState2 = nullptr;
256
257#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
258 cocos2d::EventListenerCustom* _backToForegroundListener;
259#endif
260};
261
262//class CameraFrameBufferTest : public CameraBaseTest
263//{
264//public:
265// CREATE_FUNC(CameraFrameBufferTest);
266// CameraFrameBufferTest();
267// virtual ~CameraFrameBufferTest();
268// // overrides
269// virtual std::string title() const override;
270//
271// virtual void onEnter() override;
272//};
273
275{
276public:
280
281 // overrides
282 virtual std::string title() const override;
283 virtual std::string subtitle() const override;
284
285 virtual void onEnter() override;
286};
287
DEFINE_TEST_SUITE(Camera3DTests)
State
Definition: Camera3DTest.h:42
@ State_None
Definition: Camera3DTest.h:43
@ State_Rotate
Definition: Camera3DTest.h:46
@ State_Attack
Definition: Camera3DTest.h:50
@ State_RemoteAttack
Definition: Camera3DTest.h:49
@ State_MeleeAttack
Definition: Camera3DTest.h:48
@ State_Idle
Definition: Camera3DTest.h:44
@ State_Move
Definition: Camera3DTest.h:45
@ State_Speak
Definition: Camera3DTest.h:47
OperateCamType
Definition: Camera3DTest.h:60
CameraType
Definition: Camera3DTest.h:53
virtual void onEnter() override
virtual std::string title() const override
virtual std::string subtitle() const override
CREATE_FUNC(BackgroundColorBrushTest)
void SwitchViewCallback(cocos2d::Ref *sender, CameraType cameraType)
bool onTouchesZoomIn(cocos2d::Touch *touch, cocos2d::Event *event)
cocos2d::Label * _ZoomOutlabel
Definition: Camera3DTest.h:155
bool onTouchesRotateLeft(cocos2d::Touch *touch, cocos2d::Event *event)
bool onTouchesZoomOut(cocos2d::Touch *touch, cocos2d::Event *event)
unsigned int _curState
Definition: Camera3DTest.h:145
void updateState(float elapsedTime)
cocos2d::MenuItem * _incRot
Definition: Camera3DTest.h:143
bool onTouchesCommon(cocos2d::Touch *touch, cocos2d::Event *event, bool *touchProperty)
bool isState(unsigned int state, unsigned int bit) const
CREATE_FUNC(Camera3DTestDemo)
virtual ~Camera3DTestDemo()
cocos2d::Label * _ZoomInlabel
Definition: Camera3DTest.h:154
cocos2d::Vec3 _targetPos
Definition: Camera3DTest.h:141
std::string _title
Definition: Camera3DTest.h:138
virtual void onEnter() override
cocos2d::Layer * _layer3D
Definition: Camera3DTest.h:139
cocos2d::MoveTo * _moveAction
Definition: Camera3DTest.h:147
void addNewSpriteWithCoords(cocos2d::Vec3 p, std::string fileName, bool playAnimation=false, float scale=1.0f, bool bindCamera=false)
cocos2d::Camera * _camera
Definition: Camera3DTest.h:146
void onTouchesBegan(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
cocos2d::Label * _RotateLeftlabel
Definition: Camera3DTest.h:153
void scaleCameraCallback(cocos2d::Ref *sender, float value)
cocos2d::Sprite3D * _sprite3D
Definition: Camera3DTest.h:140
void rotateCameraCallback(cocos2d::Ref *sender, float value)
virtual std::string title() const override
CameraType _cameraType
Definition: Camera3DTest.h:142
void updateCamera(float fDelta)
void onTouchesRotateRightEnd(cocos2d::Touch *touch, cocos2d::Event *event)
void onTouchesZoomOutEnd(cocos2d::Touch *touch, cocos2d::Event *event)
void move3D(float elapsedTime)
void onTouchesRotateLeftEnd(cocos2d::Touch *touch, cocos2d::Event *event)
bool onTouchesRotateRight(cocos2d::Touch *touch, cocos2d::Event *event)
void onTouchesZoomInEnd(cocos2d::Touch *touch, cocos2d::Event *event)
virtual void onExit() override
cocos2d::MenuItem * _decRot
Definition: Camera3DTest.h:144
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
cocos2d::Label * _RotateRightlabel
Definition: Camera3DTest.h:152
void onTouchsMoved(const std::vector< cocos2d::Touch * > &touchs, cocos2d::Event *event)
cocos2d::Quaternion _rotationQuat
Definition: Camera3DTest.h:219
float projectToSphere(float r, float x, float y)
virtual void onEnter() override
OperateCamType _operate
Definition: Camera3DTest.h:222
CREATE_FUNC(CameraArcBallDemo)
cocos2d::Camera * _camera
Definition: Camera3DTest.h:217
void switchTargetCallback(cocos2d::Ref *sender)
cocos2d::DrawNode3D * _drawGrid
Definition: Camera3DTest.h:218
virtual std::string title() const override
cocos2d::Vec3 _center
Definition: Camera3DTest.h:223
void switchOperateCallback(cocos2d::Ref *sender)
cocos2d::Layer * _layer3D
Definition: Camera3DTest.h:215
void calculateArcBall(cocos2d::Vec3 &axis, float &angle, float p1x, float p1y, float p2x, float p2y)
virtual void onExit() override
cocos2d::Sprite3D * _sprite3D2
Definition: Camera3DTest.h:226
virtual ~CameraArcBallDemo()
CameraType _cameraType
Definition: Camera3DTest.h:216
virtual void update(float dt) override
cocos2d::Sprite3D * _sprite3D1
Definition: Camera3DTest.h:225
cocos2d::BillBoard * bill1
Definition: Camera3DTest.h:72
cocos2d::Label * l2
Definition: Camera3DTest.h:75
cocos2d::Label * l1
Definition: Camera3DTest.h:74
cocos2d::BillBoard * bill2
Definition: Camera3DTest.h:73
cocos2d::DrawNode3D * _drawFrustum
Definition: Camera3DTest.h:188
CREATE_FUNC(CameraCullingDemo)
cocos2d::Layer * _layer3D
Definition: Camera3DTest.h:181
cocos2d::Camera * _cameraFirst
Definition: Camera3DTest.h:184
virtual ~CameraCullingDemo()
void addSpriteCallback(cocos2d::Ref *sender)
virtual void update(float dt) override
void switchViewCallback(cocos2d::Ref *sender)
virtual void onEnter() override
CameraType _cameraType
Definition: Camera3DTest.h:183
void delSpriteCallback(cocos2d::Ref *sender)
cocos2d::DrawNode3D * _drawAABB
Definition: Camera3DTest.h:187
cocos2d::Camera * _cameraThird
Definition: Camera3DTest.h:185
virtual void onExit() override
cocos2d::Label * _labelSprite3DCount
Definition: Camera3DTest.h:180
virtual std::string title() const override
std::vector< cocos2d::Sprite3D * > _objects
Definition: Camera3DTest.h:182
cocos2d::MoveBy * _moveAction
Definition: Camera3DTest.h:186
cocos2d::Node * _camControlNode
Definition: Camera3DTest.h:96
cocos2d::Node * _camNode
Definition: Camera3DTest.h:97
virtual ~CameraRotationTest()
CREATE_FUNC(CameraRotationTest)
cocos2d::EventListenerTouchOneByOne * _lis
Definition: Camera3DTest.h:98
virtual void update(float dt) override
virtual void onExit() override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
cocos2d::backend::ProgramState * _programState1
Definition: Camera3DTest.h:254
virtual ~FogTestDemo()
void switchTypeCallback(cocos2d::Ref *sender, int type)
cocos2d::Layer * _layer3D
Definition: Camera3DTest.h:250
virtual std::string title() const override
cocos2d::Camera * _camera
Definition: Camera3DTest.h:251
cocos2d::EventListenerCustom * _backToForegroundListener
Definition: Camera3DTest.h:258
cocos2d::Sprite3D * _sprite3D1
Definition: Camera3DTest.h:252
CREATE_FUNC(FogTestDemo)
cocos2d::Sprite3D * _sprite3D2
Definition: Camera3DTest.h:253
cocos2d::backend::ProgramState * _programState2
Definition: Camera3DTest.h:255
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual void onEnter() override
virtual void update(float dt) override
CameraType _cameraType
Definition: Camera3DTest.h:249
virtual void onExit() override