go-gl / mathgl

A pure Go 3D math library.
BSD 3-Clause "New" or "Revised" License
554 stars 65 forks source link

Missing world<->screen transforms. #2

Closed toqueteos closed 10 years ago

toqueteos commented 11 years ago

Both GLU and GLM support this with project and unProject functions.

There's extensive docs on how both work: http://www.opengl.org/sdk/docs/man2/xhtml/gluProject.xml http://www.opengl.org/sdk/docs/man2/xhtml/gluUnProject.xml

Since these are common transformations I think they should be in on mathgl.

UserAB1236872 commented 11 years ago

I'll work on it. It looks like I'll need to do an inverse first (which really should be there already, I just never got around to it).

UserAB1236872 commented 11 years ago

I've committed Project/Unproject, but you should probably hold off on using them for anything important until I write some tests and verify they work.

toqueteos commented 11 years ago

:+1:

Awesome timing @Jragonmiris, when I found the repo I first thought it was abandoned but I've been using it for www.opengl-tutorial.org and it works perfect (I'm using the new glfw3 library).

It has more functionality and it follows the exact layout as GL's ADTs so it's easier to use with any GL library (go-gl/gl or chsc/gogl).

I'm trying to do some picking the "good way" if I get any useful code I'll try my best to send you a PR with tests.

dmitshur commented 10 years ago

Nice.

I ended up creating https://github.com/shurcooL/goglu/blob/master/glu21/glu.go temporarily until I found a better (native Go) solution. I'll try replacing it with your Project func in my code and see if it still works.

dmitshur commented 10 years ago

It seems to work in my testing at shurcooL/Conception-go@fc4345b426bdfd11f2dc180cf83a90e56473974e, thanks! I would imagine this issue can be closed now.

The performance seems to be slightly worse than the cgo version using glu, but only by a fraction of a millisecond. This timing included more type conversions for the mathgl version.

go version go1.2 darwin/amd64
glfw 3.0.4; ATI Technologies Inc. AMD Radeon HD 6770M OpenGL Engine 2.1 ATI-1.14.21
Loaded in 1346.934064 ms.
glu:          0.01208 milliseconds (all following times are in milliseconds)
new mathgl! : 0.016636 milliseconds (all following times are in milliseconds)
glu:          0.002081
new mathgl! : 0.002475
glu:          0.0005120000000000001
new mathgl! : 0.000895
glu:          0.00054
new mathgl! : 0.0009160000000000001
glu:          0.001528
new mathgl! : 0.002632
glu:          0.00165
new mathgl! : 0.002424
glu:          0.00073
new mathgl! : 0.001061
glu:          0.00048000000000000007
new mathgl! : 0.0008480000000000001
glu:          0.000849
new mathgl! : 0.001336
glu:          0.001853
new mathgl! : 0.0028390000000000004
...
glu:          0.0005070000000000001
new mathgl! : 0.000836
glu:          0.00044500000000000003
new mathgl! : 0.0008240000000000001
glu:          0.00084
new mathgl! : 0.001275
glu:          0.0018230000000000002
new mathgl! : 0.00235
glu:          0.00048800000000000004
new mathgl! : 0.000814
glu:          0.00047400000000000003
new mathgl! : 0.0008280000000000001
glu:          0.000978
new mathgl! : 0.001487
glu:          0.0017040000000000002
new mathgl! : 0.002136
glu:          0.00044800000000000005
new mathgl! : 0.0007740000000000001
glu:          0.0004830000000000001
new mathgl! : 0.0008550000000000001
glu:          0.0019430000000000003
new mathgl! : 0.0031820000000000004
glu:          0.001987
new mathgl! : 0.002875
glu:          0.0007040000000000001
new mathgl! : 0.0011400000000000002
glu:          0.0006180000000000001
new mathgl! : 0.001131
UserAB1236872 commented 10 years ago

Thanks! Do you think (if you have time) that you could do some work on converting your glu tests for this (using the go test framework) and submitting a pull request? I've been meaning to work on the package more, but I'm getting behind on tests.

dmitshur commented 10 years ago

I'm planning to delete https://github.com/shurcooL/goglu/blob/master/glu21/glu.go, but I'll see if I can make some tests without it.