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

Bug on face drawing code in lesson 1 #60

Closed
tristancalderbank opened this issue Dec 21, 2020 · 2 comments
Closed

Bug on face drawing code in lesson 1 #60

tristancalderbank opened this issue Dec 21, 2020 · 2 comments

Comments

@tristancalderbank
Copy link

tristancalderbank commented Dec 21, 2020

Please correct if this is wrong here but I think there's a bug in the lesson one code when we draw the obj mesh.

Specifically here:

int x0 = (v0.x+1.)*width/2.;

If a vertex has a x/y value equal to 1.0 or -1.0, then x or y becomes equal to width/height.

The problem is the data variable in TGAImage has a max width/height of (width - 1)/(height - 1) because its zero indexed.

What is hiding this bug is the fact that we just exit TGAImage::set if the x/y is out of bounds:

if (!data || x<0 || y<0 || x>=width || y>=height) {

I think we're effectively cutting off the top/right edge of the image in the current lesson 1 code.

I think the solution here would be to do something like this?

int x0 = (v0.x+1.)*(width - 1)/2.;
int y0 = (v0.y+1.)*(height - 1)/2.;
int x1 = (v1.x+1.)*(width - 1)/2.;
int y1 = (v1.y+1.)*(height - 1)/2.;

Happened to notice this because I implemented a difference image drawing class (for BMP instead of TGA), and I didn't have the bounds check in the set method.

As an easier way to confirm this, just comment out the bounds check code in TGAImage::set and you will get an out of bounds exception.

@ssloy
Copy link
Owner

ssloy commented Dec 21, 2020

Well, i would not call it a bug, it depends really what you want to do (and what part of the pixel corresponds to a given coordinage)...

@ssloy ssloy closed this as completed Dec 21, 2020
@tristancalderbank
Copy link
Author

tristancalderbank commented Dec 21, 2020

Ok I think I see what you mean.

I think we're saying that for example 1.0 as an x value in obj coordinates corresponds to the right side of the right-most pixel in image coordinates which seems logical to not draw.

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