void ObjToMesh::perVertexFace(Mesh::PerVertex* perVertex[3], const ObjLoader::Face3v &f, const ObjLoader::ObjFileInfo &objFile) {
	Vertex v_a, v_b, v_c;
	Normal vn_a, vn_b, vn_c;
	TexVertex vt_a, vt_b, vt_c;

	// PER VERTEX
	v_a = objFile.v.vertices[f.v[0] - 1];
	v_b = objFile.v.vertices[f.v[1] - 1];
	v_c = objFile.v.vertices[f.v[2] - 1];

	if (f.vn[0] != -1) {
		vn_a = objFile.vn.normals[f.vn[0] - 1];
		vn_b = objFile.vn.normals[f.vn[1] - 1];
		vn_c = objFile.vn.normals[f.vn[2] - 1];
	} else {
		vn_a = vn_b = vn_c = Normal({0, 0, 0});
	}

	if (f.vt[0] != -1) {
		vt_a = objFile.vt.texVertices[f.vt[0] - 1];
		vt_b = objFile.vt.texVertices[f.vt[1] - 1];
		vt_c = objFile.vt.texVertices[f.vt[2] - 1];
	} else {
		vt_a = vt_b = vt_c = TexVertex({-1, -1});
	}

	perVertex[0] = new Mesh::PerVertex({ v_a, vn_a, vt_a });
	perVertex[1] = new Mesh::PerVertex({ v_b, vn_b, vt_b });
	perVertex[2] = new Mesh::PerVertex({ v_c, vn_c, vt_c });
}
Пример #2
0
// renders a finite rectangle
static void finite_xy_plane( const eCoord &pos,const eCoord &dir,REAL h, eRectangle rect )
{
    // expand plane to camera position to avoid embarrasing reflection bug
    if ( sr_floorMirror )
        rect.Include( pos );

    // fetch rectangle coordinates
    REAL lx = rect.GetLow().x;
    REAL ly = rect.GetLow().y;
    REAL hx = rect.GetHigh().x;
    REAL hy = rect.GetHigh().y;

    // draw rectangle as triangle fan (good for avoiding artefacts near pos)
    BeginTriangleFan();
    TexVertex( pos.x-dir.x, pos.y-dir.y, h );
    TexVertex(lx, ly, h);
    TexVertex(lx, hy, h);
    TexVertex(hx, hy, h);
    TexVertex(hx, ly, h);
    TexVertex(lx, ly, h);
    RenderEnd();
}
Пример #3
0
void Widget::drawSoftBorderQuad(Renderer *renderer, const SamplerStateID linearClamp, const BlendStateID blendSrcAlpha, const DepthStateID depthState, const float x0, const float y0, const float x1, const float y1, const float borderWidth, const float colScale, const float transScale){
	if (corner == TEXTURE_NONE){
		ubyte pixels[32][32][4];

		for (int y = 0; y < 32; y++){
			for (int x = 0; x < 32; x++){
				int r = 255 - int(powf(sqrtf(float(x * x + y * y)) * (255.0f / 31.0f), 1.0f));
				if (r < 0) r = 0;
				pixels[y][x][0] = r;
				pixels[y][x][1] = r;
				pixels[y][x][2] = r;
				pixels[y][x][3] = r;
			}
		}

		Image img;
		img.loadFromMemory(pixels, FORMAT_RGBA8, 32, 32, 1, 1, false);
		corner = renderer->addTexture(img, false, linearClamp);
	}

	float x0bw = x0 + borderWidth;
	float y0bw = y0 + borderWidth;
	float x1bw = x1 - borderWidth;
	float y1bw = y1 - borderWidth;

	TexVertex border[] = {
		TexVertex(vec2(x0,   y0bw), vec2(1, 0)),
		TexVertex(vec2(x0,   y0  ), vec2(1, 1)),
		TexVertex(vec2(x0bw, y0bw), vec2(0, 0)),
		TexVertex(vec2(x0bw, y0  ), vec2(0, 1)),
		TexVertex(vec2(x1bw, y0bw), vec2(0, 0)),
		TexVertex(vec2(x1bw, y0  ), vec2(0, 1)),

		TexVertex(vec2(x1bw, y0  ), vec2(0, 1)),
		TexVertex(vec2(x1,   y0  ), vec2(1, 1)),
		TexVertex(vec2(x1bw, y0bw), vec2(0, 0)),
		TexVertex(vec2(x1,   y0bw), vec2(1, 0)),
		TexVertex(vec2(x1bw, y1bw), vec2(0, 0)),
		TexVertex(vec2(x1,   y1bw), vec2(1, 0)),

		TexVertex(vec2(x1,   y1bw), vec2(1, 0)),
		TexVertex(vec2(x1,   y1  ), vec2(1, 1)),
		TexVertex(vec2(x1bw, y1bw), vec2(0, 0)),
		TexVertex(vec2(x1bw, y1  ), vec2(0, 1)),
		TexVertex(vec2(x0bw, y1bw), vec2(0, 0)),
		TexVertex(vec2(x0bw, y1  ), vec2(0, 1)),

		TexVertex(vec2(x0bw, y1  ), vec2(0, 1)),
		TexVertex(vec2(x0,   y1  ), vec2(1, 1)),
		TexVertex(vec2(x0bw, y1bw), vec2(0, 0)),
		TexVertex(vec2(x0,   y1bw), vec2(1, 0)),
		TexVertex(vec2(x0bw, y0bw), vec2(0, 0)),
		TexVertex(vec2(x0,   y0bw), vec2(1, 0)),
	};
	vec4 col = color * vec4(colScale, colScale, colScale, transScale);

	renderer->drawTextured(PRIM_TRIANGLE_STRIP, border, elementsOf(border), corner, linearClamp, blendSrcAlpha, depthState, &col);

	// Center
	vec2 center[] = { vec2(x0bw, y0bw), vec2(x1bw, y0bw), vec2(x0bw, y1bw), vec2(x1bw, y1bw) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, center, 4, blendSrcAlpha, depthState, &col);
}