From 6d09b50699ec03f08a44725d3ca44794c08917dd Mon Sep 17 00:00:00 2001 From: yangxiao Date: Tue, 10 Jun 2014 19:53:06 +0800 Subject: [PATCH] animation bug --- cocos/3d/CCAnimate3D.cpp | 1 + cocos/3d/CCAnimationCurve.inl | 2 +- cocos/3d/CCBundle3D.cpp | 26 ++++++++++--------- cocos/renderer/CCGLProgram.cpp | 6 +++++ .../Classes/Sprite3DTest/Sprite3DTest.cpp | 4 ++- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/cocos/3d/CCAnimate3D.cpp b/cocos/3d/CCAnimate3D.cpp index 4bf6aafe4e..2ce927c222 100644 --- a/cocos/3d/CCAnimate3D.cpp +++ b/cocos/3d/CCAnimate3D.cpp @@ -116,6 +116,7 @@ void Animate3D::update(float t) if (curve->rotCurve) { curve->rotCurve->evaluate(t, dst, QuatSlerp); + CCLOG("%f,%f,%f,%f", dst[0], dst[1], dst[2], dst[3]); bone->setAnimationValueRotation(dst); } if (curve->scaleCurve) diff --git a/cocos/3d/CCAnimationCurve.inl b/cocos/3d/CCAnimationCurve.inl index 45fc513fcb..bdcd6284be 100644 --- a/cocos/3d/CCAnimationCurve.inl +++ b/cocos/3d/CCAnimationCurve.inl @@ -21,7 +21,7 @@ void AnimationCurve::evaluate(float time, float* dst, EvaluateTyp float scale = (_keytime[index + 1] - _keytime[index]); float t = (time - _keytime[index]) / scale; - float* fromValue = &_value[index * _componentSizeByte]; + float* fromValue = &_value[index * componentSize]; float* toValue = fromValue + componentSize; switch (type) { diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index 4b1e45e9ff..6446fcea7e 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -85,17 +85,19 @@ bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata) meshdata->resetData(); meshdata->vertexSizeInFloat = 13 * 4; meshdata->vertex = new float[meshdata->vertexSizeInFloat]; - float vert[] = {0.f,50.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,1.f,0.f,0.f,0.f, - 0.f,0.f,50.f,1.f,1.f,0.f,0.f,0.f,0.f,1.f,0.f,0.f,0.f, - 50.f,0.f,0.f,1.f,1.f,0.f,0.f,0.f,0.f,1.f,0.f,0.f,0.f, - -50.f,0.f,0.f,1.f,1.f,0.f,0.f,0.f,0.f,1.f,0.f,0.f,0.f}; + float vert[] = {0.f,50.f,0.f, 0.f,0.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f, + 0.f,0.f,50.f, 1.f,1.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f, + 50.f,0.f,0.f, 1.f,1.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f, + -50.f,0.f,0.f, 1.f,1.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f}; //float vert[] = {0.f,50.f,0.f, 0.f,0.f,50.f, 50.f,0.f,0.f, -50.f,0.f,0.f}; memcpy(meshdata->vertex, vert, meshdata->vertexSizeInFloat * sizeof(float)); - meshdata->numIndex = 4 * 3; - //meshdata->numIndex = 3; + //meshdata->numIndex = 4 * 3; + meshdata->numIndex = 3; meshdata->indices = new unsigned short[meshdata->numIndex]; - unsigned short index[] = {0,1,2, 0,3,1, 0,2,3, 3,2,1}; + //unsigned short index[] = {0,1,2, 0,3,1, 0,2,3, 3,2,1}; + unsigned short index[] = {0,3,2}; + //unsigned short index[] = {0,1,2}; memcpy(meshdata->indices, index, meshdata->numIndex * sizeof(unsigned short)); meshdata->attribCount = 4; @@ -167,16 +169,16 @@ bool Bundle3D::loadAnimationData(const std::string& id, Animation3DData* animati //curve->translateCurve = Animation3D::Curve::AnimationCurveVec3::create(keytime, pos, 2); //curve->translateCurve->retain(); - float keytime1[] = {0.f, 0.25f, 0.5f, 1.f}; + float keytime1[] = {0.f, 0.333f, 0.667f, 1.f}; float rot[4 * 4]; Quaternion quat; - Quaternion::createFromAxisAngle(Vec3(0.f, 1.f, 0.f), 0, &quat); + Quaternion::createFromAxisAngle(Vec3(1.f, 0.f, 0.f), 0, &quat); rot[0] = quat.x, rot[1] = quat.y, rot[2] = quat.z, rot[3] = quat.w; - Quaternion::createFromAxisAngle(Vec3(0.f, 1.f, 0.f), MATH_DEG_TO_RAD(90), &quat); + Quaternion::createFromAxisAngle(Vec3(1.f, 0.f, 0.f), MATH_DEG_TO_RAD(0), &quat); rot[4] = quat.x, rot[5] = quat.y, rot[6] = quat.z, rot[7] = quat.w; - Quaternion::createFromAxisAngle(Vec3(0.f, 1.f, 0.f), MATH_DEG_TO_RAD(180), &quat); + Quaternion::createFromAxisAngle(Vec3(1.f, 0.f, 0.f), MATH_DEG_TO_RAD(0), &quat); rot[8] = quat.x, rot[9] = quat.y, rot[10] = quat.z, rot[11] = quat.w; - Quaternion::createFromAxisAngle(Vec3(0.f, 1.f, 0.f), MATH_DEG_TO_RAD(270), &quat); + Quaternion::createFromAxisAngle(Vec3(1.f, 0.f, 0.f), MATH_DEG_TO_RAD(0), &quat); rot[12] = quat.x, rot[13] = quat.y, rot[14] = quat.z, rot[15] = quat.w; curve->rotCurve = Animation3D::Curve::AnimationCurveQuat::create(keytime1, rot, 4); curve->rotCurve->retain(); diff --git a/cocos/renderer/CCGLProgram.cpp b/cocos/renderer/CCGLProgram.cpp index 0abf4a2d27..da2f4cf503 100644 --- a/cocos/renderer/CCGLProgram.cpp +++ b/cocos/renderer/CCGLProgram.cpp @@ -353,6 +353,12 @@ void GLProgram::parseUniforms() } uniform.name = std::string(uniformName); uniform.location = glGetUniformLocation(_program, uniformName); + GLenum __gl_error_code = glGetError(); + if (__gl_error_code != GL_NO_ERROR) + { + CCLOG("error: 0x%x", (int)__gl_error_code); + } + assert(__gl_error_code == GL_NO_ERROR); _userUniforms[uniform.name] = uniform; } diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 0fdd777f1f..8c4fc33bc2 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -534,8 +534,10 @@ void Sprite3DWithSkinTest::addNewSpriteWithCoords(Vec2 p) sprite->setPosition( Vec2( p.x, p.y) ); auto animation = Animation3D::getOrCreate("Sprite3DTest/XXX.c3t"); + auto animate = Animate3D::create(animation); - sprite->runAction(animate); + + sprite->runAction(RepeatForever::create(animate)); } void Sprite3DWithSkinTest::onTouchesEnded(const std::vector& touches, Event* event)