ok firstly, I am using REALbasic so my code will be a bit different.
I am trying to make it so that the user can click and drag on the window and rotate the angle of the camera around a certain point. I asked how to do this, and was told to use gluLookAt() to position the camera.
With some calculations, it worked like a charm. Except for one thing: the Y position.
my code is as follows:
Sub MouseDrag(X as Integer, Y as Integer)
dim cX, cY, cZ as single
beta = (X-oX)/57.2957795
gamma = (Y-oY)/57.2957795
alpha = (90/57.2957795) - beta
cX = cos(beta)* (10)
cY = cos(gamma)*(10)
cZ = cos(alpha)*(10)
oX and oY (o standing for “original”) are set in the MouseDown() event, so X-oX and Y-oY are the amounts by which the mouse moved on the screen. I’m using this as the amount in degrees by which to rotate the camera.
anyhoo, I used some of the formulas here: http://nehe.gamedev.net/data/articles/article.asp?article=08
basically, I multiply the cosines of the 3 angles by 10, which is the distance from the “center” vertex in gluLookAt() and that will get me the eyeX, eyeY, eyeZ values to use in the function.
now, if you click and drag long enough horizontally, you end up rotating the thing all the way around, and numerous times. BUT if you drag vertically, it will rotate to a certain amount, and then start to rotate back in the other direction. Needless to say, that will be very annoying for anyone who tries to use my program.