Good vertex buffers gone bad

I encountered a particularly interesting bug, I thought I’d post it here. It’s actually fairly easy to reproduce. As you can see from the screenshot, my scene is all screwed up. I’m attempting to draw a triangle grid. I know it’s being generated correctly because it was displaying earlier, but as you can see, it’s interesting because I’m drawing in wireframe. The real reason is because I have a memcpy() going on that is copying a vertex from 1 array to another (for various reasons). When I did this, I was copying only 3 vertices ( and forgetting about the 4th color), and overwriting the 4th element (the color) with the next vertex component (x value).  Note the vertex positions are capped along the x,y, & z. This is because I am giving (what I thought), each vertex a red color. This red color stomps all over the vertex positions in the array. The reason it caps the x,y,z is because the red has a max value of 255.

Besides that, I finally got my camera operational. I’ve done cameras in the past, but I had a bit of trouble with this one because I was hazy on my transforms.. After brushing up, I was trying different things such as using Quaternions, giving the camera a model world matrix and just inverting that for the view transform. Calculating the view transform myself by using only cross products or by using the Grahm Schmidt rule. For the mean time, I opted not to go with Quaternions even though I wanted to because I don’t have my quaternion library fully operational yet. So I decided to use spherical coordinates.

This worked better than expected, but there are a few corner cases. Looking straight up or straight down results in a division by zero so the screen goes blank. Also, you can flip the camera completely around so the controls are backwards. For example, if you were to look up, and then keep rotating your head so that you’re head is upside down and you were looking behind you (don’t try this at home, or anywhere else for that matter, you might scare people). This was really irritating for me, but clamping the latitude value between 0 and pi for the camera orientation solved all 3 cases.

Where delta is some small value.

Leave a Reply

You must be logged in to post a comment.