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

About the function of face() #136

Open
plallallla opened this issue Nov 17, 2023 · 1 comment
Open

About the function of face() #136

plallallla opened this issue Nov 17, 2023 · 1 comment

Comments

@plallallla
Copy link

i make some adjust to overcome the missing function face() in lesson 1.
here is my code,I encapsulated x and y using the Point structure in the simplest way,so it may looks a lttle different from lesson 1.

struct Point
{
	int x = 0;
	int y = 0;
};

Model mFace("../_Input/african_head/african_head.obj");

int width = 800;
int height = 800;
TGAImage imageobj(width, height, TGAImage::RGB);
for (int i = 0; i < mFace.nfaces(); i++)
{
	for (int j = 0; j < 3; j++)
	{
		vec3 v1 = mFace.vert(i, j);
		vec3 v2 = mFace.vert(i, (j + 1) % 3);;
		Point pt1{ (v1.x + 1.0f) * width / 2.0f,(v1.y + 1.0f) * height / 2.0f };
		Point pt2{ (v2.x + 1.0f) * width / 2.0f,(v2.y + 1.0f) * height / 2.0f };// view transport

		line(pt1, pt2, imageobj, white);
	}
}
imageobj.write_tga_file("../_Output/lesson1_obj.tga");

according to the class Model,the Model class has an overloaded function 'vert' that allows you to access a specified vertex or visit a specified node in a specified face.

vec3 Model::vert(const int i) const {
    return verts[i];
}
vec3 Model::vert(const int iface, const int nthvert) const {
    return verts[facet_vrt[iface*3+nthvert]];
}
@plallallla
Copy link
Author

here is my output
image

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

1 participant