Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Your way #26

Closed
osozero opened this issue Dec 23, 2018 · 1 comment
Closed

Your way #26

osozero opened this issue Dec 23, 2018 · 1 comment

Comments

@osozero
Copy link

osozero commented Dec 23, 2018

Vec3f barycentric(Vec3f A, Vec3f B, Vec3f C, Vec3f P) {

I do not understand your barycentric method's way. When i implement lesson 2 with my own barycentric method (finding cross products of edges and check point is inside with dot product, x and y are in screen coordinates format, but z is world coordinate) the final image is not same as yours. this is my method, if you can give me the point it would be glad.

Vec3f barycentric(Vec3f A, Vec3f B, Vec3f C, Vec3f P)
{
	float u;
	float v;
	float w;

	Vec3f AB(B - A);
	Vec3f AP(P - A);

	Vec3f BC(C - B);
	Vec3f BP(P - B);

	Vec3f CA(A - C);
	Vec3f CP(P - C);

	//for plane normal calculation
	Vec3f AC(C - A);

	Vec3f normal = cross(AB, AC);

	float denom = normal.dot(normal);

	Vec3f crossABAP = cross(AB, AP);

	if (normal.dot(crossABAP) < 0)
	{
		return Vec3f(-1, -1, -1);
	}

	Vec3f crossBCBP = cross(BC, BP);

	if ((u = normal.dot(crossBCBP)) < 0)
	{
		return Vec3f(-1, -1, -1);
	}

	Vec3f crossCACP = cross(CA, CP);

	if ((v = normal.dot(crossCACP) < 0))
	{
		return Vec3f(-1, -1, -1);
	}

	u /= denom;
	v /= denom;
	w = 1 - u - v;

	return Vec3f(w, u, v);
}
@ssloy
Copy link
Owner

ssloy commented Dec 25, 2018

Check this link:
https://github.com/ssloy/tinyrenderer/wiki/Lesson-2:-Triangle-rasterization-and-back-face-culling

Start reading from here:

Okay, let us start: first of all we need to know what the barycentric coordinates are. Given a 2D

@ssloy ssloy closed this as completed Dec 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants