I could really use some help here, if anyone has time.
I'm trying to move my camera around, and make it look at a certain position by using the mouse. (like you use in a first-person-shooter game)
So I have the movement all done; I can use keys to move forward/back/left/right, and it works depending on the direction the camera is facing.
My problem is positioning the "look to" coordinates. Essentially, I want to move the "Look To" position to be on the surface of 'an invisible sphere' surrounding the Camera - Giving me total use of moving the mouse and changing where I look (like FPS).
I can find out easily which direction the mouse is going, and I have two variables which change depending on the direction (Rotation X and Rotation Y). So, mouse moves left, Rotation X = Rotation X - 1, if mouse moves right, it's +1. That's fine, and I can read these variables and see that it works. I have 'locked' them both into being >=0 and <=360.
So here's the tricky part. I've written this code (with help on wikipedia's article on spherical coordinates) :
dxCAMERAto.X = (RADIUS * Sin(ROTATION_Y * gRAD) * Cos(TEMP_ROTATION_X * gRAD))
dxCAMERAto.Y = (RADIUS * Sin(ROTATION_Y * gRAD) * Sin(TEMP_ROTATION_X * gRAD))
dxCAMERAto.z = (RADIUS * Cos(ROTATION_Y * gRAD))
dxCAMERAto.X = dxCAMERAfrom.X + dxCAMERAto.X
dxCAMERAto.Y = dxCAMERAfrom.Y + dxCAMERAto.Y
dxCAMERAto.z = dxCAMERAfrom.z + dxCAMERAto.z
'(gRAD = PI / 180)
The 'First bit' takes two angles, Rotation X and Rotation Y, and a Radius, then translates that to X/Y/Z (cartesian coordinates)
The 'Second bit' then adds this position to the Camera's position.
When I test this with a random object (a cube), and I have it placed in the center of the world, I can see the cube move around on this 'invisible sphere' when I move the mouse. It looks almost perfect, like it's working correctly.
When I then try to apply this *exact same* code to the Camera's 'To' position, it fails dramatically.
Logic tells me that this should work. It doesn't work. It's driving me crazy.
Has anyone here ever tried to do anything like this and succeeded? Any assistance would be really helpful.
Thanks for your time,