I finished preliminary implementation of GPU based zombie movement. Right now it’s very simple, but I’m working on it. it’s coming together nicely. My next step is to finish the Imposter renderer. After that, I will on interaction between the world and the zombies. The game-play would suck if all the zombies just wandered around like … well.. zombie. I will blog about game-play ideas in an upcoming post.
Here is the ping pong source code to update the zombies (onUpdate function):
The Code
Notice that I’m using a naked pointer. I know it’s bad, but my idea is that this is the controller, and thus is not responsible for the state (the model). I think I should change it from pointer to reference to make that “borrowing” notion more clear. I think it should be a priority that I change my habit to use references more often.
And here are the two shaders:
positional update
directional update
…
Finished Imposter implementation:
The imposter renderer is not yet finished. All the imposter “views” are facing the camera; it does not correspond to the actual direction of the zombie. So to get the proper “view” of the imposter, we need to take into account the eye direction with respect to direction of the zombie.
Our imposters are stored in a single texture, and mapped according to two keys that is based on sphereical coordinate parameter of phi and theta, corresponding to the viewing direction. Thus, to properly calculate which imposter “view” texture to render we must map the current view direction into this singlular imposter storage texture. Therefore, the proper solution is to compute phi and theta from the current viewing vector.
We know that (let’s assume r = 1):
phi = arccos(z)
theta = atan2(y/x). (remembering to add 2pi for negative values).
But we know that actan2 is undefined when y = 0 and x = 0. So we need to carefully examine this case: When this happens, we are looking down at the object in question. But we can still derive theta, by looking at the camera’s orthonormal basis. Thus, when y=0 and x=0, we use the camera’s local axes. However, we need to transform the camera’s local axes into the object space. This can be done by noting the following:
For our purposes, we only require one degree of freedom, namely yaw, for the zombie. So the zombie’s directional vector will always be in the XY plane. So again, using atan2, we can compute it’s angle from the object’s direction in object space. So, we can then construct a rotation matrix, or quaternion, or whatever, which corresponds to the transformation of the object from object space into world space. Thus, the inverse of this transformation will transform the camera’s orthonormal basis in world space into object space. From here, we can then use it to compute theta by following the scheme noted above.