void GlWidget::paintGL()
{
    setMatrixes();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);

    QMatrix4x4 vMatrix;

    vMatrix.lookAt(camera[0], camera[1], camera[2]);

    for(int i=0; i<objects.size(); i++){
    if(i!=3 || canonFire==true){
    shaderProgram.bind();

    shaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * *objects[i]->getMMatrix());

    objects[i]->getTexture()->bind();

    DrawReferenceGrid();
    shaderProgram.setAttributeArray("vertex", objects[i]->getVertices()->constData());
    shaderProgram.enableAttributeArray("vertex");

    shaderProgram.setAttributeArray("textureCoordinate", objects[i]->getUVS()->constData());
    shaderProgram.enableAttributeArray("textureCoordinate");

    glDrawArrays(GL_TRIANGLES, 0, objects[i]->getVertices()->size());

    shaderProgram.disableAttributeArray("vertex");

    shaderProgram.disableAttributeArray("textureCoordinate");
    }
    }
    shaderProgram.release();
}
Exemple #2
0
void npBoneMesh::update(float timeStep,float _animeSlerp,int ani1,int ani2){

	int anime1 =ani1;
	int anime2 =ani2;
	float animeSlerp =_animeSlerp;
	//rootBone
	time+=timeStep;
	if (time> bones[1]->animations[1].totalTime)time =0;

	for (int i=0;i< bones.size();i++)
	{

		bones[i]->animeMatrix.makeIdentityMatrix();
		if (bones[i]->animations.size()>0)
		{
			
			ofQuaternion quat;
			ofQuaternion quat1;
			 quat1.set(1,0,0,0);
			if (bones[i]->animations[anime1].rotations.size() ==1)
			{
				quat1 = bones[i]->animations[anime1].rotations[0].quat;
			}
			else
			{
				for (int j=1; j<bones[i]->animations[anime1].rotations.size() ;j++)
				{
					if (bones[i]->animations[anime1].rotations[j].time >time)
					{
						
						
						float time1  = bones[i]->animations[anime1].rotations[j-1].time ;
						float timeTotal  = bones[i]->animations[anime1].rotations[j].time -time1 ;
						float timeCurrent = time-time1;
						float timeslerp = timeCurrent /timeTotal;
						
						quat1.slerp(timeslerp , bones[i]->animations[anime1].rotations[j-1].quat, bones[i]->animations[anime1].rotations[j].quat);
					
						break;
					}
				
				}
			
			}

			ofQuaternion quat2;
			 quat2.set(1,0,0,0);
			if (bones[i]->animations[anime2].rotations.size() ==1)
			{
				quat2 = bones[i]->animations[anime2].rotations[0].quat;
				
			}
			else
			{
				for (int j=1; j<bones[i]->animations[anime2].rotations.size() ;j++)
				{
					if (bones[i]->animations[anime2].rotations[j].time >time)
					{
						
						
						float time1  = bones[i]->animations[anime2].rotations[j-1].time ;
						float timeTotal  = bones[i]->animations[anime2].rotations[j].time -time1 ;
						float timeCurrent = time-time1;
						float timeslerp = timeCurrent /timeTotal;
						
						quat2.slerp(timeslerp , bones[i]->animations[anime2].rotations[j-1].quat, bones[i]->animations[anime2].rotations[j].quat);
					
						break;
					}
				
				}
			
			}


			quat.slerp(animeSlerp , quat1, quat2);
			if (i==4) quat.makeRotate(0,ofVec3f(0,1,0));
			bones[i]->animeMatrix.makeRotationMatrix(quat);

			
			
			
			ofVec3f translation(0,0,0);
			ofVec3f translation1(0,0,0);
			ofVec3f translation2(0,0,0);
			if (bones[i]->animations[0].translations.size()>0)
			{
				if (bones[i]->animations[anime1].translations.size() ==1)
				{
				translation1 = bones[i]->animations[anime1].translations[0].pos;
				}else
				{
					for (int j=1; j<bones[i]->animations[anime1].translations.size() ;j++)
					{
						if (bones[i]->animations[anime1].translations[j].time >time)
						{
						
						
							float time1  = bones[i]->animations[anime1].translations[j-1].time ;
							float timeTotal  = bones[i]->animations[anime1].translations[j].time -time1 ;
							float timeCurrent = time-time1;
							float timeslerp = timeCurrent /timeTotal;
						
					
						translation1 = bones[i]->animations[anime1].translations[j-1].pos *(1.0f -timeslerp) +bones[i]->animations[anime1].translations[j].pos *(timeslerp);

							break;
						}
				
					}
				}


				if (bones[i]->animations[anime2].translations.size() ==1)
				{
				translation2= bones[i]->animations[anime2].translations[0].pos;
				}else
				{
					for (int j=1; j<bones[i]->animations[anime2].translations.size() ;j++)
					{
						if (bones[i]->animations[anime2].translations[j].time >time)
						{
						
						
							float time1  = bones[i]->animations[anime2].translations[j-1].time ;
							float timeTotal  = bones[i]->animations[anime2].translations[j].time -time1 ;
							float timeCurrent = time-time1;
							float timeslerp = timeCurrent /timeTotal;
						
					
						translation2 = bones[i]->animations[anime2].translations[j-1].pos *(1.0f -timeslerp) +bones[i]->animations[anime2].translations[j].pos *(timeslerp);

							break;
						}
				
					}
				}

				translation= translation1 *(1.0f -animeSlerp) +translation2 *(animeSlerp);

				bones[i]->animeMatrix.postMultTranslate(translation);
				
			
			}
		

		}
	
	
	}

	for (int i=0;i< bones.size();i++)
	{
	
		bones[i]->finalMatrix=bones[i]->boneMatrix;
		const npBone* tempNode = bones[i];
		while( tempNode)
		{
				// check your matrix multiplication order here!!!
				bones[i]->finalMatrix =bones[i]->finalMatrix * tempNode->animeMatrix;
				
				tempNode = tempNode->parent;
		}
	//bones[i]->finalMatrix =bones[i]->animeMatrix;
	};

	setMatrixes();
}