当前位置: 首页>>代码示例>>C++>>正文


C++ Quad::calcNormal方法代码示例

本文整理汇总了C++中Quad::calcNormal方法的典型用法代码示例。如果您正苦于以下问题:C++ Quad::calcNormal方法的具体用法?C++ Quad::calcNormal怎么用?C++ Quad::calcNormal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Quad的用法示例。


在下文中一共展示了Quad::calcNormal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buildAOBJ

void SharkMesh::buildAOBJ(FILE* readFile) {
	vector<Vector3f> localVerts = vector<Vector3f>();   //in order to use OBJs as keys, need to remember their order.
	while(!feof(readFile)) {
		//tokenize the line identifier. It's only one character and 
		//it should be on the first on the line
		char identifier = fgetc(readFile);
		if(ferror(readFile)){ 
		   printf("888888888Error reading FILE\n"); 
		   exit(-1);
		}

		//load in the vertices
		//v x y z nx ny nz boneName/weight boneName/weight ...
		if(identifier == 'v') {
			char cur = fgetc(readFile);  //space
			if(ferror(readFile)) { 
			   printf("0Error reading FILE\n"); 
			   exit(-1);
			}
			while(cur != '\n') { // per line
				SharkVertex* sv = new SharkVertex();

				//location of vertex    
				Vector3f vert;
				vert.x = atof(nextToken(' ', readFile).c_str());
				vert.y = atof(nextToken(' ', readFile).c_str());
				vert.z = atof(nextToken(' ', readFile).c_str());
				sv->sLocal(vert);

				Vector3f nor; //normal
				nor.x = atof(nextToken(' ', readFile).c_str());
				nor.y = atof(nextToken(' ', readFile).c_str());
				nor.z = atof(nextToken(' ', readFile).c_str());
				sv->sNormal(nor*-1.0);  //TODO magic.  fix blender normals. shouldn't need to reverse them.

				sv->sTransformed(Vector3f(0,0,0));
				//bone / weight repeats
				fseek(readFile, -1, SEEK_CUR);
				cur = fgetc(readFile);
				while(cur != '\n') {
					string boneName = nextToken('/', readFile);
					float weight = atof(nextToken(' ', readFile).c_str());
					sv->sBonePair(boneName, weight);
					fseek(readFile, -1, SEEK_CUR);
					cur = fgetc(readFile);
				}
				localVerts.push_back(vert);
				insertVec(pair<Vector3f, SharkVertex*>(vert, sv));
			}
		}
		//faces
		//f ... vertices in mesh .....
		else if(identifier == 'f') {
			char cur = fgetc(readFile); //space
			if(ferror(readFile)){ printf("4Error reading FILE\n"); exit(-1);}
			Quad *curQuad = new Quad();
			curQuad->sNormal(Vector3f(0,0,0));

			//caution. Vertices listed in mesh may not be consistant with other quads 
			int vertex1 = atoi(nextToken(' ', readFile).c_str());
			int vertex2 = atoi(nextToken(' ', readFile).c_str());
			int vertex3 = atoi(nextToken(' ', readFile).c_str());
			int vertex4 = atoi(nextToken(' ', readFile).c_str());

			curQuad->sVert(0, gVertex(localVerts[vertex1-1]));
			curQuad->sVert(1, gVertex(localVerts[vertex2-1]));
			curQuad->sVert(2, gVertex(localVerts[vertex3-1]));
			curQuad->sVert(3, gVertex(localVerts[vertex4-1]));
			curQuad->calcNormal();

			pushFace(curQuad);	
			//neighboring quads are to be found later, after parsing is done.

			fseek(readFile, -1, SEEK_CUR);
			cur = fgetc(readFile);
			while(cur != '\n') {
				cur = fgetc(readFile);
				if(ferror(readFile)) { 
				   printf("5Error reading FILE\n"); 
				   exit(-1);
				}
			}
		}		
		else if(identifier == 'b') {
			return;
		}
	}
}
开发者ID:mejanly,项目名称:Sharkify,代码行数:88,代码来源:SharkMesh.cpp


注:本文中的Quad::calcNormal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。