add notes, deal with opengl shader in windows device, fix bug

This commit is contained in:
songmiao 2015-01-08 15:16:47 +08:00
parent dfa6137ce9
commit 71820e6db1
2 changed files with 20 additions and 38 deletions

View File

@ -974,7 +974,7 @@ CameraArcBallDemo::CameraArcBallDemo(void)
,_drawGrid(nullptr) ,_drawGrid(nullptr)
,_sprite3D1(nullptr) ,_sprite3D1(nullptr)
,_sprite3D2(nullptr) ,_sprite3D2(nullptr)
,_fRadius(1.0f) ,_radius(1.0f)
,_distanceZ(50.0f) ,_distanceZ(50.0f)
,_operate(OperateCamType::RotateCamera) ,_operate(OperateCamType::RotateCamera)
,_center(Vec3(0,0,0)) ,_center(Vec3(0,0,0))
@ -1100,7 +1100,7 @@ void CameraArcBallDemo::onTouchsMoved( const std::vector<Touch*> &touchs, Event
{ {
if (!touchs.empty()) if (!touchs.empty())
{ {
if(_operate == OperateCamType::RotateCamera) if(_operate == OperateCamType::RotateCamera) //arc ball rotate
{ {
Size visibleSize = Director::getInstance()->getVisibleSize(); Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 prelocation = touchs[0]->getPreviousLocationInView(); Vec2 prelocation = touchs[0]->getPreviousLocationInView();
@ -1112,13 +1112,13 @@ void CameraArcBallDemo::onTouchsMoved( const std::vector<Touch*> &touchs, Event
Vec3 axes; Vec3 axes;
float angle; float angle;
calculateArcBall(axes, angle, prelocation.x, prelocation.y, location.x, location.y); calculateArcBall(axes, angle, prelocation.x, prelocation.y, location.x, location.y); //calculate rotation quaternion parameters
Quaternion quat(axes, angle); Quaternion quat(axes, angle); //get rotation quaternion
_rotationQuat = quat * _rotationQuat; _rotationQuat = quat * _rotationQuat;
updateCameraTransform(); updateCameraTransform(); //update camera Transform
} }
else if(_operate == OperateCamType::MoveCamera) else if(_operate == OperateCamType::MoveCamera) //camera zoom
{ {
Point newPos = touchs[0]->getPreviousLocation() - touchs[0]->getLocation(); Point newPos = touchs[0]->getPreviousLocation() - touchs[0]->getLocation();
_distanceZ -= newPos.y*0.1f; _distanceZ -= newPos.y*0.1f;
@ -1137,13 +1137,13 @@ void CameraArcBallDemo::calculateArcBall( cocos2d::Vec3 & axis, float & angle, f
Vec3 sv = rotation_matrix * Vec3(1.0f,0.0f,0.0f); Vec3 sv = rotation_matrix * Vec3(1.0f,0.0f,0.0f);
Vec3 lv = rotation_matrix * Vec3(0.0f,0.0f,-1.0f); Vec3 lv = rotation_matrix * Vec3(0.0f,0.0f,-1.0f);
Vec3 p1 = sv * p1x + uv * p1y - lv * projectToSphere(_fRadius, p1x, p1y); Vec3 p1 = sv * p1x + uv * p1y - lv * projectToSphere(_radius, p1x, p1y);
Vec3 p2 = sv * p2x + uv * p2y - lv * projectToSphere(_fRadius, p2x, p2y); Vec3 p2 = sv * p2x + uv * p2y - lv * projectToSphere(_radius, p2x, p2y);
Vec3::cross(p2, p1, &axis); Vec3::cross(p2, p1, &axis);
axis.normalize(); axis.normalize();
float t = (p2 - p1).length() / (2.0 * _fRadius); float t = (p2 - p1).length() / (2.0 * _radius);
if (t > 1.0) t = 1.0; if (t > 1.0) t = 1.0;
if (t < -1.0) t = -1.0; if (t < -1.0) t = -1.0;
@ -1262,9 +1262,7 @@ void FogTestDemo::onEnter()
auto s = Director::getInstance()->getWinSize(); auto s = Director::getInstance()->getWinSize();
auto listener = EventListenerTouchAllAtOnce::create(); auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = CC_CALLBACK_2(FogTestDemo::onTouchesBegan, this);
listener->onTouchesMoved = CC_CALLBACK_2(FogTestDemo::onTouchesMoved, this); listener->onTouchesMoved = CC_CALLBACK_2(FogTestDemo::onTouchesMoved, this);
listener->onTouchesEnded = CC_CALLBACK_2(FogTestDemo::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
// swich fog type // swich fog type
@ -1401,15 +1399,6 @@ void FogTestDemo::update(float dt)
{ {
} }
void FogTestDemo::onTouchesBegan(const std::vector<Touch*>& touches, cocos2d::Event *event)
{
for ( auto &item: touches )
{
auto touch = item;
auto location = touch->getLocation();
}
}
void FogTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event) void FogTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event)
{ {
if(touches.size()==1) if(touches.size()==1)
@ -1435,15 +1424,6 @@ void FogTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Ev
} }
} }
void FogTestDemo::onTouchesEnded(const std::vector<Touch*>& touches, cocos2d::Event *event)
{
for ( auto &item: touches )
{
auto touch = item;
auto location = touch->getLocationInView();
}
}
void Camera3DTestScene::runThisTest() void Camera3DTestScene::runThisTest()
{ {
auto layer = nextSpriteTestAction(); auto layer = nextSpriteTestAction();

View File

@ -178,20 +178,20 @@ public:
void switchTargetCallback(Ref* sender); void switchTargetCallback(Ref* sender);
void onTouchsMoved(const std::vector<cocos2d::Touch*> &touchs, cocos2d::Event *event); void onTouchsMoved(const std::vector<cocos2d::Touch*> &touchs, cocos2d::Event *event);
void updateCameraTransform(); void updateCameraTransform();
void calculateArcBall( cocos2d::Vec3 & axis, float & angle, float p1x, float p1y, float p2x, float p2y ); void calculateArcBall( cocos2d::Vec3 & axis, float & angle, float p1x, float p1y, float p2x, float p2y );//calculate rotation quaternion parameters
float projectToSphere( float r, float x, float y ); float projectToSphere( float r, float x, float y );//points on the screen project to arc ball
protected: protected:
Layer* _layer3D; Layer* _layer3D;
CameraType _cameraType; CameraType _cameraType;
Camera* _camera; Camera* _camera;
DrawNode3D* _drawGrid; DrawNode3D* _drawGrid;
Quaternion _rotationQuat; Quaternion _rotationQuat; //rotation Quaternion
float _fRadius; float _radius; //arc ball radius
float _distanceZ; float _distanceZ;
OperateCamType _operate; OperateCamType _operate; //switch rotate or zoom
Vec3 _center; Vec3 _center; //camera look target
int _target; int _target; //switch camera look target
Sprite3D* _sprite3D1; Sprite3D* _sprite3D1;
Sprite3D* _sprite3D2; Sprite3D* _sprite3D2;
}; };
@ -215,9 +215,7 @@ public:
// overrides // overrides
virtual std::string title() const override; virtual std::string title() const override;
void onTouchesBegan(const std::vector<Touch*>& touches, cocos2d::Event *event);
void onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event); void onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event);
void onTouchesEnded(const std::vector<Touch*>& touches, cocos2d::Event *event);
void switchTypeCallback(Ref* sender,int type); void switchTypeCallback(Ref* sender,int type);
@ -229,6 +227,10 @@ protected:
Sprite3D* _sprite3D2; Sprite3D* _sprite3D2;
GLProgram* _shader; GLProgram* _shader;
GLProgramState* _state; GLProgramState* _state;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
EventListenerCustom* _backToForegroundListener;
#endif
}; };
class Camera3DTestScene : public TestScene class Camera3DTestScene : public TestScene