bsabiston

10-27-2017, 02:56 PM

I'm setting up a program where I would like to be able to use two different styles of camera rotation. I want to be able to rotate the camera in the style of a first-person shooter, where you are in a position and you swing the camera around to look everywhere. But then I would like to be able to switch to "arcball" style, where moving the mouse actually swings you around the focal point of the camera. Is it possible to switch between these two seamlessly?

From a naive perspective, it seems like the difference between these two modes is basically just the order in which you multiply the translate and rotate matrices. If I use translate*rotate, I get an arcball effect. If I use rotate*translate, it behaves like an FPS.

var translate = float4x4()

translate.translate(camPosition.x, y: camPosition.y, z: camPosition.z)

var rotate = float4x4()

rotate.rotateAroundX(camRotation.x, y: camRotation.y, z: camRotation.z)

if arcball {

viewMatrix = translate * rotate

}

else {

viewMatrix = rotate * translate

}

But I can't just seamlessly switch back and forth between these two. The 'arcball' style essentially always points at the origin, whereas the 'FPS' style aims out from the camera position in which ever direction it's pointing. How could I calculate things so that I could flip back and forth between these? It seems like it would basically involve moving the arcball 'origin' point to where the FPS camera is pointing. And *IS* there a specific point at which a ViewMatrix aims? I'm a little confused about that. I know you can make a ViewMatrix by specifying an Eye position and a LookAt position, but is that basically just used to establish a direction? Or is there an actual focal position encoded into a View Matrix? If not, it seems like I could still maybe do what I want just by specifying a constant focal distance from the eye, with which to calculate the arcball origin.

Hopefully this question makes sense and someone can provide some guidance!! I flunked linear algebra in college :(

Thanks

From a naive perspective, it seems like the difference between these two modes is basically just the order in which you multiply the translate and rotate matrices. If I use translate*rotate, I get an arcball effect. If I use rotate*translate, it behaves like an FPS.

var translate = float4x4()

translate.translate(camPosition.x, y: camPosition.y, z: camPosition.z)

var rotate = float4x4()

rotate.rotateAroundX(camRotation.x, y: camRotation.y, z: camRotation.z)

if arcball {

viewMatrix = translate * rotate

}

else {

viewMatrix = rotate * translate

}

But I can't just seamlessly switch back and forth between these two. The 'arcball' style essentially always points at the origin, whereas the 'FPS' style aims out from the camera position in which ever direction it's pointing. How could I calculate things so that I could flip back and forth between these? It seems like it would basically involve moving the arcball 'origin' point to where the FPS camera is pointing. And *IS* there a specific point at which a ViewMatrix aims? I'm a little confused about that. I know you can make a ViewMatrix by specifying an Eye position and a LookAt position, but is that basically just used to establish a direction? Or is there an actual focal position encoded into a View Matrix? If not, it seems like I could still maybe do what I want just by specifying a constant focal distance from the eye, with which to calculate the arcball origin.

Hopefully this question makes sense and someone can provide some guidance!! I flunked linear algebra in college :(

Thanks