示例#1
0
void internal_best_effort_load( objLoader &objLoader, MeshData_t &meshData )
{
	for (int i=0; i<objLoader.faceCount; i++){
		obj_face *facePtr = objLoader.faceList[i];

		if ( facePtr->vertex_count==3 ) {

			for (int coord=0; coord<3; coord++){
				meshData.vertices.push_back( getVertex(objLoader, facePtr->vertex_index[coord]) );
				if (facePtr->normal_index[coord] != -1 ) meshData.normals.push_back( getNormal(objLoader, facePtr->normal_index[coord]) );
				if (facePtr->texture_index[coord] != -1 ) meshData.texcoords.push_back( getTexCoord(objLoader, facePtr->texture_index[coord]) );
			}

		} else if (facePtr->vertex_count==4 ) {

			for (int coord=0; coord<3; coord++){
				meshData.vertices.push_back( getVertex(objLoader, facePtr->vertex_index[coord]) );
				if (facePtr->normal_index[coord] != -1 ) meshData.normals.push_back( getNormal(objLoader, facePtr->normal_index[coord]) );
				if (facePtr->texture_index[coord] != -1 ) meshData.texcoords.push_back( getTexCoord(objLoader, facePtr->texture_index[coord]) );
			}

			int triangle_two[] = {0,2,3};
			for (int coord=0; coord<3; coord++){
				int idx2 = triangle_two[coord];
				meshData.vertices.push_back( getVertex(objLoader, facePtr->vertex_index[idx2]) );
				if (facePtr->normal_index[idx2] != -1 ) meshData.normals.push_back( getNormal(objLoader, facePtr->normal_index[idx2]) );
				if (facePtr->texture_index[idx2] != -1 ) meshData.texcoords.push_back( getTexCoord(objLoader, facePtr->texture_index[idx2]) );
			}

		}
	}
	// do NOT create indices
}
示例#2
0
vec3f SceneObject::getWorldNormal(unsigned fi, const vec3f& position, bool flat) const 
{
	vec3f original_normal = SimpleShape::getWorldNormal(fi, position, flat);
	if(bumpTex.size() <= 1 || fi >= faceVertexTexCoordIndexList.size())
		return original_normal;

	printf("use not original normal\n");

	vec3f vps[3], vts[3], vns[3];
	for(unsigned i=0; i<3; i++)
	{
		vps[i] = getWorldVertexPosition(faceVertexIndexList[fi][i]);
		if(faceVertexTexCoordIndexList[fi][i] >= vertexTexCoordList.size())
			return original_normal;
		vts[i] = vertexTexCoordList[faceVertexTexCoordIndexList[fi][i]];
	}
	vec3f uv_grad = bumpTex.getGrad(getTexCoord(fi, position));
	vec3f b1 = vps[1] - vps[0];
	vec3f b2 = vps[2] - vps[0];
	vec3f duv1 = vts[1] - vts[0];
	vec3f duv2 = vts[2] - vts[0];
	float k2 = (uv_grad.x*duv1.y - uv_grad.y*duv1.x) / (duv1.y*duv2.x - duv1.x*duv2.y);
	float k1 = (uv_grad.y - k2*duv2.y) / duv1.y;
	b1.normalize();
	b2.normalize();
	vec3f dl = k1*b1+k2*b2;
	vec3f dh = original_normal*uv_grad.z;
	if(dh.length()*1000 < dl.length())
		return original_normal;
	float angle = atan2(dh.length(), dl.length());
	vec3f axis = dl.cross(dh);
	axis.normalize();
	return vec3f(rotMat(axis, angle) * vec4f(original_normal, 0));
}
示例#3
0
文件: Astar.cpp 项目: OrangeKnife/NBE
		void AstarMap::changeNodeTexInVBO(AstarMapNode& nd, int tp)//keep the nd info ,just change the coordnates in vbo
		{
			uint idx = (width * nd.z + nd.x) * 4;
			vec2f tc = getTexCoord(tp);
			static_cast<PT_Vertex*>(renderObj->vbo)[idx].texcoord = tc;
			static_cast<PT_Vertex*>(renderObj->vbo)[idx + 1].texcoord = tc + vec2f(1, 0);
			static_cast<PT_Vertex*>(renderObj->vbo)[idx + 2].texcoord = tc + vec2f(1, 1 / TEXCOUNT);
			static_cast<PT_Vertex*>(renderObj->vbo)[idx + 3].texcoord = tc + vec2f(0, 1 / TEXCOUNT);
		}
示例#4
0
文件: Astar.cpp 项目: OrangeKnife/NBE
		void AstarMap::changeNodeTexInVBO(AstarMapNode& nd)
		{
			uint idx = (width * nd.z + nd.x) * 4;
			vec2f tc = getTexCoord(nd.nodeType);
			static_cast<PT_Vertex*>(renderObj->vbo)[idx].texcoord = tc;
			static_cast<PT_Vertex*>(renderObj->vbo)[idx + 1].texcoord = tc + vec2f(1, 0);
			static_cast<PT_Vertex*>(renderObj->vbo)[idx + 2].texcoord = tc + vec2f(1, 1 / TEXCOUNT);
			static_cast<PT_Vertex*>(renderObj->vbo)[idx + 3].texcoord = tc + vec2f(0, 1 / TEXCOUNT);
		}
示例#5
0
    void WarpGrid::reset()
    {
        points_.clear();
        points_.reserve(vertical() * horizontal());

        for (size_t y = 0; y < vertical(); ++y)
            for (size_t x = 0; x < horizontal();
                 ++x) points_.emplace_back((getTexCoord(x, y) - QVector2D(0.5,
                                                                          0.5)).toPointF());
        hasChanged_ = true;
    }
示例#6
0
    bool WarpGrid::isReset() const
    {
        for (size_t y = 0; y < vertical(); ++y)
            for (size_t x = 0; x < horizontal(); ++x)
            {
                if (QVector2D(getPoint(x,
                                       y)->pos()) !=
                    (getTexCoord(x, y) - QVector2D(0.5, 0.5))) return false;
            }

        return true;
    }
示例#7
0
// function: internal_efficient_load
// description: uses mesh indices. Loads normals, only if there is one normal pr vertex in objLoader
void internal_efficient_load( objLoader &objLoader, MeshData_t &meshData )
{
	for (int i=0; i<objLoader.vertexCount; i++)
	{
		meshData.vertices.push_back( getVertex(objLoader, i) );
	}

	if ( objLoader.normalCount == objLoader.vertexCount )
	{
		for (int i=0; i<objLoader.normalCount; i++)
		{
			meshData.normals.push_back( getNormal(objLoader, i) );
		}
	}

	if ( objLoader.textureCount == objLoader.vertexCount )
	{
		for (int i=0; i<objLoader.normalCount; i++)
		{
			meshData.texcoords.push_back( getTexCoord(objLoader, i) );
		}
	}

	for (int i=0; i<objLoader.faceCount; i++){
		obj_face *facePtr = objLoader.faceList[i];

		if ( facePtr->vertex_count==3 ) {
			meshData.indices.push_back( (unsigned int)facePtr->vertex_index[0] );
			meshData.indices.push_back( (unsigned int)facePtr->vertex_index[1] );
			meshData.indices.push_back( (unsigned int)facePtr->vertex_index[2] );
		} else if (facePtr->vertex_count==4 ) {
			unsigned int v0 = (unsigned int)facePtr->vertex_index[0];
			unsigned int v1 = (unsigned int)facePtr->vertex_index[1];
			unsigned int v2 = (unsigned int)facePtr->vertex_index[2];
			unsigned int v3 = (unsigned int)facePtr->vertex_index[3];
			meshData.indices.push_back(v0);
			meshData.indices.push_back(v1);
			meshData.indices.push_back(v2);

			meshData.indices.push_back(v0);
			meshData.indices.push_back(v2);
			meshData.indices.push_back(v3);
		}
	}
}
void ContentWindowRenderer::renderContent(const bool showZoomContext)
{
    const QRectF winCoord = window_->getCoordinates();
    const QRectF texCoord = getTexCoord();

    // transform to a normalize coordinate system so the content
    // can be rendered at (x,y,w,h) = (0,0,1,1)
    glPushMatrix();

    glTranslatef(winCoord.x(), winCoord.y(), 0.f);
    glScalef(winCoord.width(), winCoord.height(), 1.f);

    FactoryObjectPtr object = factories_->getFactoryObject(window_->getContent());
    object->render(texCoord);

    if(showZoomContext && window_->getZoom() > 1.)
        renderContextView(object, texCoord);

    glPopMatrix();
}