Exemplo n.º 1
0
GLC_Mesh& GLC_Mesh::transformVertice(const GLC_Matrix4x4& matrix)
{
	if (matrix.type() != GLC_Matrix4x4::Identity)
	{
		delete m_pBoundingBox;
		m_pBoundingBox= NULL;
		copyVboToClientSide();
		const int stride= 3;
		GLfloatVector* pVectPos= m_MeshData.positionVectorHandle();
		const GLC_Matrix4x4 rotationMatrix= matrix.rotationMatrix();
		GLfloatVector* pVectNormal= m_MeshData.normalVectorHandle();
		const int verticeCount= pVectPos->size() / stride;
		for (int i= 0; i < verticeCount; ++i)
		{
			GLC_Vector3d newPos(pVectPos->at(stride * i), pVectPos->at(stride * i + 1), pVectPos->at(stride * i + 2));
			newPos= matrix * newPos;
			pVectPos->operator[](stride * i)= static_cast<GLfloat>(newPos.x());
			pVectPos->operator[](stride * i + 1)= static_cast<GLfloat>(newPos.y());
			pVectPos->operator[](stride * i + 2)= static_cast<GLfloat>(newPos.z());

			GLC_Vector3d newNormal(pVectNormal->at(stride * i), pVectNormal->at(stride * i + 1), pVectNormal->at(stride * i + 2));
			newNormal= rotationMatrix * newNormal;
			pVectNormal->operator[](stride * i)= static_cast<GLfloat>(newNormal.x());
			pVectNormal->operator[](stride * i + 1)= static_cast<GLfloat>(newNormal.y());
			pVectNormal->operator[](stride * i + 2)= static_cast<GLfloat>(newNormal.z());
		}
		releaseVboClientSide(true);
	}

	return *this;
}
Exemplo n.º 2
0
int main(int argc, char *argv[]){
    FILE *arch;
    char line[100], *word[6];
    int count, x, y;
    //license
    license();
    
    if (argc < 3) { printf("I need the modelname too\n"); exit(1); }
    
    if (argc == 5) {
        printf("I did it\n");
        adjust = atof(argv[4]);
    }
    
    strcpy(modelname,argv[3]);
    
    //access obj file
    arch=fopen(argv[1],"r");
    if(arch==NULL){
        printf("Error: file not found or file unavailable\n\n");
        exit(1);
    }
    else{
        while(!feof(arch)){
            //read line
            fgets(line,100,arch);
            //parse tokens
            for(count=0; count<6; count++){
                word[count]=    count==0 ?    strtok(line," ") :    strtok(NULL," ");
                if(word[count]==NULL){
                    word[count-1]=strtok(word[count-1],"\n");
                    break;
                }
            }
            //process data
            if(word[0]!=NULL){
                if(strcmp(word[0],"v")==0){
                    newVertex(word);
                }
                else if(strcmp(word[0],"vt")==0){
                    newTexture(word);
                }
                else if(strcmp(word[0],"vn")==0){
                    newNormal(word);
                }
                else if(strcmp(word[0],"f")==0){
                    makeFace(word);
                }
                else{
                    //skip
                }
            }
        }
        fclose(arch);
        //save to file
        arch=fopen(argv[2],"w");
        if(arch==NULL){
            printf("Error: File creation unsuccessful\n\n");
        }
        else{
            fprintf(arch,"//Generated through PatchObj v.1.0 by Patricio Figueroa\n\n");
            dataDump(arch);
            fclose(arch);
        }
    }
    printf("Success!\n\n");
    return 0;
}