1
\$\begingroup\$

At the moment, I basically have built out a large hash table of various angles and what direction they map to, if the user would press right, up, down, left. This is needed, in my case, as I have a collection of geometries that when the user presses right, they all go right, and when left, they all go left ...

However, when the scene containing these is rotated anything other than its original state, these controls need to be updated/reversed/etc. That is, if you're looking at the scene from behind, pressing left now has the objects all going right, etc.

I was trying to see if there is a simpler way of applying matrix transformations instead of hard coding a large hash table mapping various scene angles to keys.

\$\endgroup\$
1
\$\begingroup\$

I haven't thought about this for too long. But it seems fairly simple. I assume you know what the modelViewMatrix is. This 4x4 matrix transforms coordinates (points) from world space to camera space. There is a similar matrix called the normalMatrix that transforms vectors (usually normalvectors). It does the same as the modelViewMatrix, but skips all translating operations. This normalMatrix is a 3x3 matrix. Just invert that matrix and multiply it with a camera-space vector that represents the direction of the key being pressed. Once you get the vector back into world space, you might want to project it down onto the floor plane (dropping the y-component could possibly do).

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.