Hi i am using DirectX 10 and C++ to make a very simple first person shooter just a gun and targets, i have the gun and the target and the gun shoots bullets in the corrct direction etc.
however i cannot get the camera to be locked on the gun and looking at the crosshairs,
for the camera i have this
vecEye.x = g_f_GunX;
vecEye.y = g_f_GunY + 3;
vecEye.z = g_f_GunZ - 5.0;
vecAt.x = g_f_CrossX;
vecAt.y = g_f_CrossY;
vecAt.z = g_f_CrossZ;
g_Camera.SetViewParams( &vecEye, &vecAt );
for the purpose of this my crosshair is just an object that is infront of the gun and it moves with the gun, i have put the code for the camera in the ‘onFrameRender’ method
it is my assumption that this code should put the camera just behind my gun and when the gun (and crosshairs) are moved the camera should be looking at the crosshairs all the time in the center of the screen, however on running it the camera is not doing this at all and doesnt move with gun or crosshairs at all
any help would be much appriciated
That’s not going to work unless “eye” is located directly behind the gun barrel (gun will block the view) – if “eye” is even slightly above gun, you’ll end up looking at ground through the crosshair object, and view direction won’t match camera direction at all.
Several ways to deal with it:
Also in 3d shooters camera orientation is frequently stored as a yaw/pitch/roll combination of angles.