oakes / play-clj

A Clojure game library
The Unlicense
940 stars 72 forks source link

Best way to update the direction vector of a camera #68

Closed kamn closed 9 years ago

kamn commented 9 years ago

Hi @oakes, As previously meantioned I am working on a First Person Controller example. I am mostly done but there is one part that I wanted some input form you on. In order to look around correctly I need to modify the direction vector of the camera. The direction! calls the lookAt function which does not seem to work for me. Currently in my project I just directly modify the camera vector and have a custom function camera-update! in the play-clj fork. I was wondering if there was some other way to update the camera and if it might be better to have a direction-vector! function added.

Thanks!

oakes commented 9 years ago

How about we add a new arity to direction!? We could allow passing a single argument, which is interpreted as a vector-3.

kamn commented 9 years ago

That could work to but I can forsee someone posting a bug about how there is a different in functionality between the arities.

oakes commented 9 years ago

Does the lookAt function that takes a vector not work for you?

kamn commented 9 years ago

I was having some issues with it. It seemed to be causing a jittering and would constatly look near the center 0, 0, 0. I assume it is because of the extra calculations it performs. Once I got around it looking worked fine. I can make a simple test case if you want to try it out yourself.

oakes commented 9 years ago

I'm not sure why I chose to use lookAt there. I think we could just change it to modify the direction vector directly.

kamn commented 9 years ago

That works! I was worried it might change some functionality of existing projects but code search is down so I can't check. We could also change the current direction! to lookAt! since I think that might be valuable. I can do that tomorrow if you like.

oakes commented 9 years ago

Ah, I just tried it on my 3d examples and it does seem to break them, so I'd rather avoid that. Have you tried calling (.normalizeUp (:camera screen)) before calling direction!? The docs seem to indicate you may need to.

oakes commented 9 years ago

I added a new arity to direction!, but in a different way. It takes an optional fourth arg, a boolean value that I called look-at? for lack of a better term. If you set it to false, it will just set the direction vector as you were looking for. Hopefully that works for you. I pushed 0.4.5-SNAPSHOT so you can try it.

kamn commented 9 years ago

Thanks for responding so quickly. I have used the new arity direction! and it works! I have not pushed it because now that everything is working I am trying to figure out how to reorganize and clean up the code.