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

Incorrect coordinate mapping in ScreenToGLCoords and GLToScreenCoords. #64

Closed
db47h opened this issue Feb 12, 2018 · 2 comments
Closed

Comments

@db47h
Copy link
Contributor

db47h commented Feb 12, 2018

Unless I'm mistaken, screen X coordinates are in the range [0, screenWidth-1], not [0, screenWidth] (the same applies to the Y coordinate), and GL's coordinate system maps [screenWidth-1,0] to [1.0,1.0] and [0,screenHeight-1] to [-1.0,-1.0].

So the code for ScreenToGLCoords should be:

func ScreenToGLCoords(x, y int, screenWidth, screenHeight int) (xOut, yOut float64) {
	xOut = 2.0*float64(x)/float64(screenWidth-1) - 1.0
	yOut = -2.0*float64(y)/float64(screenHeight-1) + 1.0

	return
}
@UserAB1236872
Copy link
Member

Hey, sorry, I've been working double-long hackathon-level days at work recently. If you submit a PR I'd be glad to accept it, but it will probably have to wait a few weeks otherwise.

@db47h
Copy link
Contributor Author

db47h commented Mar 9, 2018

No worries, PR incoming.

As I wrote a test for the fix, I found out that GLToScreenCoords inverts the sign of the returned y-coordinate. So that'll get fixed as well.

Reminder to self: trivial tests for trivial functions are not that useless 😉

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