PuzzleSDK
Camera3DTestDemo类 参考

#include <Camera3DTest.h>

+ 类 Camera3DTestDemo 继承关系图:
+ Camera3DTestDemo 的协作图:

Public 成员函数

 CREATE_FUNC (Camera3DTestDemo)
 
 Camera3DTestDemo ()
 
virtual ~Camera3DTestDemo ()
 
virtual void onEnter () override
 
virtual void onExit () override
 
virtual std::string title () const override
 
void addNewSpriteWithCoords (cocos2d::Vec3 p, std::string fileName, bool playAnimation=false, float scale=1.0f, bool bindCamera=false)
 
void onTouchesBegan (const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
 
void onTouchesMoved (const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
 
void onTouchesEnded (const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
 
void scaleCameraCallback (cocos2d::Ref *sender, float value)
 
void rotateCameraCallback (cocos2d::Ref *sender, float value)
 
void SwitchViewCallback (cocos2d::Ref *sender, CameraType cameraType)
 
void updateCamera (float fDelta)
 
void move3D (float elapsedTime)
 
void updateState (float elapsedTime)
 
bool isState (unsigned int state, unsigned int bit) const
 
void reachEndCallBack ()
 
bool onTouchesCommon (cocos2d::Touch *touch, cocos2d::Event *event, bool *touchProperty)
 
bool onTouchesZoomOut (cocos2d::Touch *touch, cocos2d::Event *event)
 
void onTouchesZoomOutEnd (cocos2d::Touch *touch, cocos2d::Event *event)
 
bool onTouchesZoomIn (cocos2d::Touch *touch, cocos2d::Event *event)
 
void onTouchesZoomInEnd (cocos2d::Touch *touch, cocos2d::Event *event)
 
bool onTouchesRotateLeft (cocos2d::Touch *touch, cocos2d::Event *event)
 
void onTouchesRotateLeftEnd (cocos2d::Touch *touch, cocos2d::Event *event)
 
bool onTouchesRotateRight (cocos2d::Touch *touch, cocos2d::Event *event)
 
void onTouchesRotateRightEnd (cocos2d::Touch *touch, cocos2d::Event *event)
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual std::string subtitle () const
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 

Protected 属性

std::string _title
 
cocos2d::Layer * _layer3D
 
cocos2d::Sprite3D * _sprite3D
 
cocos2d::Vec3 _targetPos
 
CameraType _cameraType
 
cocos2d::MenuItem * _incRot
 
cocos2d::MenuItem * _decRot
 
unsigned int _curState
 
cocos2d::Camera * _camera
 
cocos2d::MoveTo * _moveAction
 
bool _bZoomOut
 
bool _bZoomIn
 
bool _bRotateLeft
 
bool _bRotateRight
 
cocos2d::Label * _RotateRightlabel
 
cocos2d::Label * _RotateLeftlabel
 
cocos2d::Label * _ZoomInlabel
 
cocos2d::Label * _ZoomOutlabel
 
- Protected 属性 继承自 CameraBaseTest
cocos2d::BillBoard * bill1
 
cocos2d::BillBoard * bill2
 
cocos2d::Label * l1
 
cocos2d::Label * l2
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 

详细描述

在文件 Camera3DTest.h101 行定义.

构造及析构函数说明

◆ Camera3DTestDemo()

Camera3DTestDemo::Camera3DTestDemo ( )

在文件 Camera3DTest.cpp187 行定义.

189, _incRot(nullptr)
190, _decRot(nullptr)
191, _camera(nullptr)
192, _bZoomOut(false)
193, _bZoomIn(false)
194, _bRotateLeft(false)
195, _bRotateRight(false)
196{
197}
cocos2d::MenuItem * _incRot
Definition: Camera3DTest.h:143
cocos2d::Camera * _camera
Definition: Camera3DTest.h:146
CameraType _cameraType
Definition: Camera3DTest.h:142
cocos2d::MenuItem * _decRot
Definition: Camera3DTest.h:144

引用了 Free.

◆ ~Camera3DTestDemo()

Camera3DTestDemo::~Camera3DTestDemo ( )
virtual

在文件 Camera3DTest.cpp198 行定义.

199{
200}

成员函数说明

◆ addNewSpriteWithCoords()

void Camera3DTestDemo::addNewSpriteWithCoords ( cocos2d::Vec3  p,
std::string  fileName,
bool  playAnimation = false,
float  scale = 1.0f,
bool  bindCamera = false 
)

在文件 Camera3DTest.cpp390 行定义.

391{
392 auto sprite = Sprite3D::create(fileName);
393 _layer3D->addChild(sprite);
394 float globalZOrder=sprite->getGlobalZOrder();
395 sprite->setPosition3D( Vec3( p.x, p.y,p.z) );
396 sprite->setGlobalZOrder(globalZOrder);
397 if(playAnimation)
398 {
399 auto animation = Animation3D::create(fileName,"Take 001");
400 if (animation)
401 {
402 auto animate = Animate3D::create(animation);
403 sprite->runAction(RepeatForever::create(animate));
404 }
405 }
406 if(bindCamera)
407 {
408 _sprite3D=sprite;
409 }
410 sprite->setScale(scale);
411}
cocos2d::Layer * _layer3D
Definition: Camera3DTest.h:139
cocos2d::Sprite3D * _sprite3D
Definition: Camera3DTest.h:140

引用了 _layer3D , 以及 _sprite3D.

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ CREATE_FUNC()

Camera3DTestDemo::CREATE_FUNC ( Camera3DTestDemo  )

◆ isState()

bool Camera3DTestDemo::isState ( unsigned int  state,
unsigned int  bit 
) const

在文件 Camera3DTest.cpp668 行定义.

669{
670 return (state & bit) == bit;
671}

被这些函数引用 updateCamera().

+ 这是这个函数的调用关系图:

◆ move3D()

void Camera3DTestDemo::move3D ( float  elapsedTime)

在文件 Camera3DTest.cpp444 行定义.

445{
446 if(_sprite3D)
447 {
448 Vec3 curPos= _sprite3D->getPosition3D();
449 Vec3 newFaceDir = _targetPos - curPos;
450 newFaceDir.y = 0.0f;
451 newFaceDir.normalize();
452 Vec3 offset = newFaceDir * 25.0f * elapsedTime;
453 curPos+=offset;
454 _sprite3D->setPosition3D(curPos);
456 {
457 Vec3 cameraPos= _camera->getPosition3D();
458 cameraPos.x+=offset.x;
459 cameraPos.z+=offset.z;
460 _camera->setPosition3D(cameraPos);
461 }
462 }
463}
cocos2d::Vec3 _targetPos
Definition: Camera3DTest.h:141

引用了 _camera, _cameraType, _sprite3D, _targetPos , 以及 ThirdPerson.

被这些函数引用 updateCamera().

+ 这是这个函数的调用关系图:

◆ onEnter()

void Camera3DTestDemo::onEnter ( )
overridevirtual

重载 TestCase .

在文件 Camera3DTest.cpp268 行定义.

269{
271 _sprite3D=nullptr;
272 auto s = Director::getInstance()->getWinSize();
273 auto listener = EventListenerTouchAllAtOnce::create();
274 listener->onTouchesBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesBegan, this);
275 listener->onTouchesMoved = CC_CALLBACK_2(Camera3DTestDemo::onTouchesMoved, this);
276 listener->onTouchesEnded = CC_CALLBACK_2(Camera3DTestDemo::onTouchesEnded, this);
277 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
278 auto layer3D=Layer::create();
279 addChild(layer3D,0);
280 _layer3D=layer3D;
282 addNewSpriteWithCoords( Vec3(0,0,0),"Sprite3DTest/girl.c3b",true,0.2f,true);
283 TTFConfig ttfConfig("fonts/arial.ttf", 20);
284
285 auto containerForLabel1 = Node::create();
286 _ZoomOutlabel = Label::createWithTTF(ttfConfig,"zoom out");
287 _ZoomOutlabel->setPosition(s.width-50, VisibleRect::top().y-20);
288 containerForLabel1->addChild(_ZoomOutlabel);
289 addChild(containerForLabel1, 10);
290
291 auto listener1 = EventListenerTouchOneByOne::create();
292 listener1->setSwallowTouches(true);
293
294 listener1->onTouchBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesZoomOut, this);
295 listener1->onTouchEnded = CC_CALLBACK_2(Camera3DTestDemo::onTouchesZoomOutEnd, this);
296
297 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, _ZoomOutlabel);
298
299 auto containerForLabel2 = Node::create();
300 _ZoomInlabel = Label::createWithTTF(ttfConfig,"zoom in");
301 _ZoomInlabel->setPosition(s.width-50, VisibleRect::top().y-70);
302 containerForLabel2->addChild(_ZoomInlabel);
303 addChild(containerForLabel2, 10);
304
305 auto listener2 = EventListenerTouchOneByOne::create();
306 listener2->setSwallowTouches(true);
307
308 listener2->onTouchBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesZoomIn, this);
309 listener2->onTouchEnded = CC_CALLBACK_2(Camera3DTestDemo::onTouchesZoomInEnd, this);
310
311 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener2, _ZoomInlabel);
312
313 auto containerForLabel3 = Node::create();
314 _RotateLeftlabel = Label::createWithTTF(ttfConfig,"rotate left");
315 _RotateLeftlabel->setPosition(s.width-50, VisibleRect::top().y-120);
316 containerForLabel3->addChild(_RotateLeftlabel);
317 addChild(containerForLabel3, 10);
318
319 auto listener3 = EventListenerTouchOneByOne::create();
320 listener3->setSwallowTouches(true);
321
322 listener3->onTouchBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesRotateLeft, this);
323 listener3->onTouchEnded = CC_CALLBACK_2(Camera3DTestDemo::onTouchesRotateLeftEnd, this);
324
325 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener3, _RotateLeftlabel);
326
327 auto containerForLabel4 = Node::create();
328 _RotateRightlabel = Label::createWithTTF(ttfConfig,"rotate right");
329 _RotateRightlabel->setPosition(s.width-50, VisibleRect::top().y-170);
330 containerForLabel4->addChild(_RotateRightlabel);
331 addChild(containerForLabel4, 10);
332
333 auto listener4 = EventListenerTouchOneByOne::create();
334 listener4->setSwallowTouches(true);
335
336 listener4->onTouchBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesRotateRight, this);
337 listener4->onTouchEnded = CC_CALLBACK_2(Camera3DTestDemo::onTouchesRotateRightEnd, this);
338
339 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener4, _RotateRightlabel);
340
341 auto label1 = Label::createWithTTF(ttfConfig,"free ");
342 auto menuItem1 = MenuItemLabel::create(label1, CC_CALLBACK_1(Camera3DTestDemo::SwitchViewCallback,this,CameraType::Free));
343 auto label2 = Label::createWithTTF(ttfConfig,"third person");
344 auto menuItem2 = MenuItemLabel::create(label2, CC_CALLBACK_1(Camera3DTestDemo::SwitchViewCallback,this,CameraType::ThirdPerson));
345 auto label3 = Label::createWithTTF(ttfConfig,"first person");
346 auto menuItem3 = MenuItemLabel::create(label3, CC_CALLBACK_1(Camera3DTestDemo::SwitchViewCallback,this,CameraType::FirstPerson));
347 auto menu = Menu::create(menuItem1, menuItem2, menuItem3, nullptr);
348
349 menu->setPosition(Vec2::ZERO);
350
351 menuItem1->setPosition(VisibleRect::left().x+100, VisibleRect::top().y-50);
352 menuItem2->setPosition(VisibleRect::left().x+100, VisibleRect::top().y -100);
353 menuItem3->setPosition(VisibleRect::left().x+100, VisibleRect::top().y -150);
354 addChild(menu, 0);
355 schedule(CC_SCHEDULE_SELECTOR(Camera3DTestDemo::updateCamera), 0.0f);
356 if (_camera == nullptr)
357 {
358 _camera=Camera::createPerspective(60, (float)s.width/s.height, 1, 1000);
359 _camera->setCameraFlag(CameraFlag::USER1);
360 _layer3D->addChild(_camera);
361 }
364 //draw x
365 for( int j =-20; j<=20 ;j++)
366 {
367 line->drawLine(Vec3(-100.0f, 0.0f, 5.0f*j),Vec3(100.0f,0.0f,5.0f*j),Color4F(1,0,0,1));
368 }
369 //draw z
370 for( int j =-20; j<=20 ;j++)
371 {
372 line->drawLine(Vec3(5.0f*j, 0.0f, -100.0f),Vec3(5.0f*j,0.0f,100.0f),Color4F(0,0,1,1));
373 }
374 //draw y
375 line->drawLine(Vec3(0.0f, -50.0f, 0.0f),Vec3(0,0,0),Color4F(0,0.5,0,1));
376 line->drawLine(Vec3(0, 0, 0),Vec3(0,50.0f,0),Color4F(0,1,0,1));
377 _layer3D->addChild(line);
378
379 _layer3D->setCameraMask(2);
380}
@ State_None
Definition: Camera3DTest.h:43
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
cocos2d::Label * _ZoomInlabel
Definition: Camera3DTest.h:154
void addNewSpriteWithCoords(cocos2d::Vec3 p, std::string fileName, bool playAnimation=false, float scale=1.0f, bool bindCamera=false)
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 updateCamera(float fDelta)
void onTouchesRotateRightEnd(cocos2d::Touch *touch, cocos2d::Event *event)
void onTouchesZoomOutEnd(cocos2d::Touch *touch, cocos2d::Event *event)
void onTouchesRotateLeftEnd(cocos2d::Touch *touch, cocos2d::Event *event)
bool onTouchesRotateRight(cocos2d::Touch *touch, cocos2d::Event *event)
void onTouchesZoomInEnd(cocos2d::Touch *touch, cocos2d::Event *event)
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
cocos2d::Label * _RotateRightlabel
Definition: Camera3DTest.h:152
static cocos2d::DrawNode3D * create()
Definition: DrawNode3D.cpp:42
void drawLine(const cocos2d::Vec3 &from, const cocos2d::Vec3 &to, const Color4F &color)
Definition: DrawNode3D.cpp:157
virtual void onEnter() override
Definition: BaseTest.cpp:430
static cocos2d::Vec2 top()
Definition: VisibleRect.cpp:57
static cocos2d::Vec2 left()
Definition: VisibleRect.cpp:45

引用了 _camera, _curState, _layer3D, _RotateLeftlabel, _RotateRightlabel, _sprite3D, _ZoomInlabel, _ZoomOutlabel, addNewSpriteWithCoords(), DrawNode3D::create(), DrawNode3D::drawLine(), FirstPerson, Free, VisibleRect::left(), TestCase::onEnter(), onTouchesBegan(), onTouchesEnded(), onTouchesMoved(), onTouchesRotateLeft(), onTouchesRotateLeftEnd(), onTouchesRotateRight(), onTouchesRotateRightEnd(), onTouchesZoomIn(), onTouchesZoomInEnd(), onTouchesZoomOut(), onTouchesZoomOutEnd(), State_None, SwitchViewCallback(), ThirdPerson, VisibleRect::top() , 以及 updateCamera().

+ 函数调用图:

◆ onExit()

void Camera3DTestDemo::onExit ( )
overridevirtual

在文件 Camera3DTest.cpp381 行定义.

382{
383 CameraBaseTest::onExit();
384 if (_camera)
385 {
386 _camera = nullptr;
387 }
388}

引用了 _camera.

◆ onTouchesBegan()

void Camera3DTestDemo::onTouchesBegan ( const std::vector< cocos2d::Touch * > &  touches,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp412 行定义.

413{
414}

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ onTouchesCommon()

bool Camera3DTestDemo::onTouchesCommon ( cocos2d::Touch *  touch,
cocos2d::Event *  event,
bool *  touchProperty 
)

在文件 Camera3DTest.cpp653 行定义.

654{
655 auto target = static_cast<Label*>(event->getCurrentTarget());
656
657 Vec2 locationInNode = target->convertToNodeSpace(touch->getLocation());
658 Size s = target->getContentSize();
659 Rect rect = Rect(0, 0, s.width, s.height);
660
661 if (rect.containsPoint(locationInNode))
662 {
663 *touchProperty = true;
664 return true;
665 }
666 return false;
667}

被这些函数引用 onTouchesRotateLeft(), onTouchesRotateRight(), onTouchesZoomIn() , 以及 onTouchesZoomOut().

+ 这是这个函数的调用关系图:

◆ onTouchesEnded()

void Camera3DTestDemo::onTouchesEnded ( const std::vector< cocos2d::Touch * > &  touches,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp494 行定义.

495{
496 for ( auto &item: touches )
497 {
498 auto touch = item;
499 auto location = touch->getLocationInView();
500 if(_camera)
501 {
502 if(_sprite3D && _cameraType==CameraType::ThirdPerson && _bZoomOut == false && _bZoomIn == false && _bRotateLeft == false && _bRotateRight == false)
503 {
504 Vec3 nearP(location.x, location.y, -1.0f), farP(location.x, location.y, 1.0f);
505
506 auto size = Director::getInstance()->getWinSize();
507 nearP = _camera->unproject(nearP);
508 farP = _camera->unproject(farP);
509 Vec3 dir(farP - nearP);
510 float dist=0.0f;
511 float ndd = Vec3::dot(Vec3(0,1,0),dir);
512 if(ndd == 0)
513 dist=0.0f;
514 float ndo = Vec3::dot(Vec3(0,1,0),nearP);
515 dist= (0 - ndo) / ndd;
516 Vec3 p = nearP + dist * dir;
517
518 if( p.x > 100)
519 p.x = 100;
520 if( p.x < -100)
521 p.x = -100;
522 if( p.z > 100)
523 p.z = 100;
524 if( p.z < -100)
525 p.z = -100;
526
527 _targetPos=p;
528 }
529 }
530 }
531}

引用了 _bRotateLeft, _bRotateRight, _bZoomIn, _bZoomOut, _camera, _cameraType, _sprite3D, _targetPos , 以及 ThirdPerson.

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ onTouchesMoved()

void Camera3DTestDemo::onTouchesMoved ( const std::vector< cocos2d::Touch * > &  touches,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp415 行定义.

416{
417 if(touches.size()==1)
418 {
419 auto touch = touches[0];
420 auto location = touch->getLocation();
421 Point newPos = touch->getPreviousLocation()-location;
423 {
424 Vec3 cameraDir;
425 Vec3 cameraRightDir;
426 _camera->getNodeToWorldTransform().getForwardVector(&cameraDir);
427 cameraDir.normalize();
428 cameraDir.y=0;
429 _camera->getNodeToWorldTransform().getRightVector(&cameraRightDir);
430 cameraRightDir.normalize();
431 cameraRightDir.y=0;
432 Vec3 cameraPos= _camera->getPosition3D();
433 cameraPos+=cameraDir*newPos.y*0.1f;
434 cameraPos+=cameraRightDir*newPos.x*0.1f;
435 _camera->setPosition3D(cameraPos);
437 {
438 _sprite3D->setPosition3D(Vec3(_camera->getPositionX(),0,_camera->getPositionZ()));
439 _targetPos=_sprite3D->getPosition3D();
440 }
441 }
442 }
443}

引用了 _camera, _cameraType, _sprite3D, _targetPos, FirstPerson , 以及 Free.

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ onTouchesRotateLeft()

bool Camera3DTestDemo::onTouchesRotateLeft ( cocos2d::Touch *  touch,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp688 行定义.

689{
690 return Camera3DTestDemo::onTouchesCommon(touch, event, &_bRotateLeft);
691}
bool onTouchesCommon(cocos2d::Touch *touch, cocos2d::Event *event, bool *touchProperty)

引用了 _bRotateLeft , 以及 onTouchesCommon().

被这些函数引用 onEnter().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onTouchesRotateLeftEnd()

void Camera3DTestDemo::onTouchesRotateLeftEnd ( cocos2d::Touch *  touch,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp692 行定义.

693{
694 _bRotateLeft = false;
695}

引用了 _bRotateLeft.

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ onTouchesRotateRight()

bool Camera3DTestDemo::onTouchesRotateRight ( cocos2d::Touch *  touch,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp696 行定义.

697{
699}

引用了 _bRotateRight , 以及 onTouchesCommon().

被这些函数引用 onEnter().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onTouchesRotateRightEnd()

void Camera3DTestDemo::onTouchesRotateRightEnd ( cocos2d::Touch *  touch,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp700 行定义.

701{
702 _bRotateRight = false;
703}

引用了 _bRotateRight.

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ onTouchesZoomIn()

bool Camera3DTestDemo::onTouchesZoomIn ( cocos2d::Touch *  touch,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp680 行定义.

681{
682 return Camera3DTestDemo::onTouchesCommon(touch, event, &_bZoomIn);
683}

引用了 _bZoomIn , 以及 onTouchesCommon().

被这些函数引用 onEnter().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onTouchesZoomInEnd()

void Camera3DTestDemo::onTouchesZoomInEnd ( cocos2d::Touch *  touch,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp684 行定义.

685{
686 _bZoomIn = false;
687}

引用了 _bZoomIn.

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ onTouchesZoomOut()

bool Camera3DTestDemo::onTouchesZoomOut ( cocos2d::Touch *  touch,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp672 行定义.

673{
674 return Camera3DTestDemo::onTouchesCommon(touch, event, &_bZoomOut);
675}

引用了 _bZoomOut , 以及 onTouchesCommon().

被这些函数引用 onEnter().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onTouchesZoomOutEnd()

void Camera3DTestDemo::onTouchesZoomOutEnd ( cocos2d::Touch *  touch,
cocos2d::Event *  event 
)

在文件 Camera3DTest.cpp676 行定义.

677{
678 _bZoomOut = false;
679}

引用了 _bZoomOut.

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ reachEndCallBack()

void Camera3DTestDemo::reachEndCallBack ( )

在文件 Camera3DTest.cpp201 行定义.

202{
203}

◆ rotateCameraCallback()

void Camera3DTestDemo::rotateCameraCallback ( cocos2d::Ref *  sender,
float  value 
)

在文件 Camera3DTest.cpp218 行定义.

219{
221 {
222 Vec3 rotation3D= _camera->getRotation3D();
223 rotation3D.y+= value;
224 _camera->setRotation3D(rotation3D);
225 }
226}

引用了 _camera, _cameraType, FirstPerson , 以及 Free.

◆ scaleCameraCallback()

void Camera3DTestDemo::scaleCameraCallback ( cocos2d::Ref *  sender,
float  value 
)

在文件 Camera3DTest.cpp209 行定义.

210{
212 {
213 Vec3 cameraPos= _camera->getPosition3D();
214 cameraPos+= cameraPos.getNormalized()*value;
215 _camera->setPosition3D(cameraPos);
216 }
217}

引用了 _camera, _cameraType , 以及 FirstPerson.

◆ SwitchViewCallback()

void Camera3DTestDemo::SwitchViewCallback ( cocos2d::Ref *  sender,
CameraType  cameraType 
)

在文件 Camera3DTest.cpp227 行定义.

228{
229 if(_cameraType==cameraType)
230 {
231 return ;
232 }
233 _cameraType = cameraType;
235 {
236 _camera->setPosition3D(Vec3(0, 130, 130) + _sprite3D->getPosition3D());
237 _camera->lookAt(_sprite3D->getPosition3D());
238
239 _RotateRightlabel->setColor(Color3B::WHITE);
240 _RotateLeftlabel->setColor(Color3B::WHITE);
241 _ZoomInlabel->setColor(Color3B::WHITE);
242 _ZoomOutlabel->setColor(Color3B::WHITE);
243 }
245 {
246 Vec3 newFaceDir;
247 _sprite3D->getWorldToNodeTransform().getForwardVector(&newFaceDir);
248 newFaceDir.normalize();
249 _camera->setPosition3D(Vec3(0,35,0) + _sprite3D->getPosition3D());
250 _camera->lookAt(_sprite3D->getPosition3D() + newFaceDir*50);
251
252 _RotateRightlabel->setColor(Color3B::WHITE);
253 _RotateLeftlabel->setColor(Color3B::WHITE);
254 _ZoomInlabel->setColor(Color3B::GRAY);
255 _ZoomOutlabel->setColor(Color3B::GRAY);
256 }
258 {
259 _camera->setPosition3D(Vec3(0, 130, 130) + _sprite3D->getPosition3D());
260 _camera->lookAt(_sprite3D->getPosition3D());
261
262 _RotateRightlabel->setColor(Color3B::GRAY);
263 _RotateLeftlabel->setColor(Color3B::GRAY);
264 _ZoomInlabel->setColor(Color3B::WHITE);
265 _ZoomOutlabel->setColor(Color3B::WHITE);
266 }
267}

引用了 _camera, _cameraType, _RotateLeftlabel, _RotateRightlabel, _sprite3D, _ZoomInlabel, _ZoomOutlabel, FirstPerson, Free , 以及 ThirdPerson.

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ title()

std::string Camera3DTestDemo::title ( ) const
overridevirtual

重载 TestCase .

在文件 Camera3DTest.cpp204 行定义.

205{
206 return "Testing Camera";
207}

◆ updateCamera()

void Camera3DTestDemo::updateCamera ( float  fDelta)

在文件 Camera3DTest.cpp535 行定义.

536{
537 if(_sprite3D)
538 {
540 {
541 updateState(fDelta);
543 {
544 move3D(fDelta);
546 {
547 Vec3 curPos = _sprite3D->getPosition3D();
548
549 Vec3 newFaceDir = _targetPos - curPos;
550 newFaceDir.y = 0;
551 newFaceDir.normalize();
552 Vec3 up;
553 _sprite3D->getNodeToWorldTransform().getUpVector(&up);
554 up.normalize();
555 Vec3 right;
556 Vec3::cross(-newFaceDir,up,&right);
557 right.normalize();
558 Vec3 pos = Vec3(0,0,0);
559 Mat4 mat;
560 mat.m[0] = right.x;
561 mat.m[1] = right.y;
562 mat.m[2] = right.z;
563 mat.m[3] = 0.0f;
564
565 mat.m[4] = up.x;
566 mat.m[5] = up.y;
567 mat.m[6] = up.z;
568 mat.m[7] = 0.0f;
569
570 mat.m[8] = newFaceDir.x;
571 mat.m[9] = newFaceDir.y;
572 mat.m[10] = newFaceDir.z;
573 mat.m[11] = 0.0f;
574
575 mat.m[12] = pos.x;
576 mat.m[13] = pos.y;
577 mat.m[14] = pos.z;
578 mat.m[15] = 1.0f;
579 _sprite3D->setAdditionalTransform(&mat);
580 }
581 }
582 }
583 if(_bZoomOut == true)
584 {
585 if(_camera)
586 {
588 {
589 Vec3 lookDir = _camera->getPosition3D() - _sprite3D->getPosition3D();
590 Vec3 cameraPos = _camera->getPosition3D();
591 if(lookDir.length() <= 300)
592 {
593 cameraPos += lookDir.getNormalized();
594 _camera->setPosition3D(cameraPos);
595 }
596 }
597 else if(_cameraType == CameraType::Free)
598 {
599 Vec3 cameraPos = _camera->getPosition3D();
600 if(cameraPos.length() <= 300)
601 {
602 cameraPos += cameraPos.getNormalized();
603 _camera->setPosition3D(cameraPos);
604 }
605 }
606 }
607 }
608 if(_bZoomIn == true)
609 {
610 if(_camera)
611 {
613 {
614 Vec3 lookDir = _camera->getPosition3D() - _sprite3D->getPosition3D();
615 Vec3 cameraPos = _camera->getPosition3D();
616 if(lookDir.length() >= 50)
617 {
618 cameraPos -= lookDir.getNormalized();
619 _camera->setPosition3D(cameraPos);
620 }
621 }
622 else if(_cameraType == CameraType::Free)
623 {
624 Vec3 cameraPos = _camera->getPosition3D();
625 if(cameraPos.length() >= 50)
626 {
627 cameraPos -= cameraPos.getNormalized();
628 _camera->setPosition3D(cameraPos);
629 }
630 }
631 }
632 }
633 if(_bRotateLeft == true)
634 {
636 {
637 Vec3 rotation3D= _camera->getRotation3D();
638 rotation3D.y+= 1;
639 _camera->setRotation3D(rotation3D);
640 }
641 }
642 if(_bRotateRight == true)
643 {
645 {
646 Vec3 rotation3D= _camera->getRotation3D();
647 rotation3D.y-= 1;
648 _camera->setRotation3D(rotation3D);
649 }
650 }
651 }
652}
@ State_Rotate
Definition: Camera3DTest.h:46
@ State_Move
Definition: Camera3DTest.h:45
void updateState(float elapsedTime)
bool isState(unsigned int state, unsigned int bit) const
void move3D(float elapsedTime)

引用了 _bRotateLeft, _bRotateRight, _bZoomIn, _bZoomOut, _camera, _cameraType, _curState, _sprite3D, _targetPos, FirstPerson, Free, isState(), move3D(), State_Move, State_Rotate, ThirdPerson , 以及 updateState().

被这些函数引用 onEnter().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ updateState()

void Camera3DTestDemo::updateState ( float  elapsedTime)

在文件 Camera3DTest.cpp464 行定义.

465{
466 if(_sprite3D)
467 {
468 Vec3 curPos= _sprite3D->getPosition3D();
469 Vec3 curFaceDir;
470 _sprite3D->getNodeToWorldTransform().getForwardVector(&curFaceDir);
471 curFaceDir=-curFaceDir;
472 curFaceDir.normalize();
473 Vec3 newFaceDir = _targetPos - curPos;
474 newFaceDir.y = 0.0f;
475 newFaceDir.normalize();
476 float cosAngle = std::fabs(Vec3::dot(curFaceDir,newFaceDir) - 1.0f);
477 float dist = curPos.distanceSquared(_targetPos);
478 if(dist<=4.0f)
479 {
480 if(cosAngle<=0.01f)
482 else
484 }
485 else
486 {
487 if(cosAngle>0.01f)
489 else
491 }
492 }
493}
@ State_Idle
Definition: Camera3DTest.h:44

引用了 _curState, _sprite3D, _targetPos, State_Idle, State_Move , 以及 State_Rotate.

被这些函数引用 updateCamera().

+ 这是这个函数的调用关系图:

类成员变量说明

◆ _bRotateLeft

bool Camera3DTestDemo::_bRotateLeft
protected

在文件 Camera3DTest.h150 行定义.

被这些函数引用 onTouchesEnded(), onTouchesRotateLeft(), onTouchesRotateLeftEnd() , 以及 updateCamera().

◆ _bRotateRight

bool Camera3DTestDemo::_bRotateRight
protected

在文件 Camera3DTest.h151 行定义.

被这些函数引用 onTouchesEnded(), onTouchesRotateRight(), onTouchesRotateRightEnd() , 以及 updateCamera().

◆ _bZoomIn

bool Camera3DTestDemo::_bZoomIn
protected

在文件 Camera3DTest.h149 行定义.

被这些函数引用 onTouchesEnded(), onTouchesZoomIn(), onTouchesZoomInEnd() , 以及 updateCamera().

◆ _bZoomOut

bool Camera3DTestDemo::_bZoomOut
protected

在文件 Camera3DTest.h148 行定义.

被这些函数引用 onTouchesEnded(), onTouchesZoomOut(), onTouchesZoomOutEnd() , 以及 updateCamera().

◆ _camera

cocos2d::Camera* Camera3DTestDemo::_camera
protected

◆ _cameraType

CameraType Camera3DTestDemo::_cameraType
protected

◆ _curState

unsigned int Camera3DTestDemo::_curState
protected

在文件 Camera3DTest.h145 行定义.

被这些函数引用 onEnter(), updateCamera() , 以及 updateState().

◆ _decRot

cocos2d::MenuItem* Camera3DTestDemo::_decRot
protected

在文件 Camera3DTest.h144 行定义.

◆ _incRot

cocos2d::MenuItem* Camera3DTestDemo::_incRot
protected

在文件 Camera3DTest.h143 行定义.

◆ _layer3D

cocos2d::Layer* Camera3DTestDemo::_layer3D
protected

在文件 Camera3DTest.h139 行定义.

被这些函数引用 addNewSpriteWithCoords() , 以及 onEnter().

◆ _moveAction

cocos2d::MoveTo* Camera3DTestDemo::_moveAction
protected

在文件 Camera3DTest.h147 行定义.

◆ _RotateLeftlabel

cocos2d::Label* Camera3DTestDemo::_RotateLeftlabel
protected

在文件 Camera3DTest.h153 行定义.

被这些函数引用 onEnter() , 以及 SwitchViewCallback().

◆ _RotateRightlabel

cocos2d::Label* Camera3DTestDemo::_RotateRightlabel
protected

在文件 Camera3DTest.h152 行定义.

被这些函数引用 onEnter() , 以及 SwitchViewCallback().

◆ _sprite3D

cocos2d::Sprite3D* Camera3DTestDemo::_sprite3D
protected

◆ _targetPos

cocos2d::Vec3 Camera3DTestDemo::_targetPos
protected

在文件 Camera3DTest.h141 行定义.

被这些函数引用 move3D(), onTouchesEnded(), onTouchesMoved(), updateCamera() , 以及 updateState().

◆ _title

std::string Camera3DTestDemo::_title
protected

在文件 Camera3DTest.h138 行定义.

◆ _ZoomInlabel

cocos2d::Label* Camera3DTestDemo::_ZoomInlabel
protected

在文件 Camera3DTest.h154 行定义.

被这些函数引用 onEnter() , 以及 SwitchViewCallback().

◆ _ZoomOutlabel

cocos2d::Label* Camera3DTestDemo::_ZoomOutlabel
protected

在文件 Camera3DTest.h155 行定义.

被这些函数引用 onEnter() , 以及 SwitchViewCallback().


该类的文档由以下文件生成: