I'm having some trouble using the lib3d 'setCameraTarget' routine... it's not acting anything like I'd expect. As I don't see 'setCameraTarget' used in any of the example code that comes with lib3d, I may be expecting it to do things it wasn't designed to do (?) - though it is a public interface.
What I'm trying to accomplish is to wander the camera around in the scene - translation (setCameraOrigin) acts like I'd expect. I'm trying to also use the 'setCameraTarget' rotate the camera around the Y axis ('camera turn left or right'). I've tried various flavors/combination of first translating the camera to world origin, applying a 'look at', translating it back again, etc. etc. and things are just acting strange.
To keep this question/example simple, as a test case I leave the camera origin fixed at 0,1.5,0 - so I'm basically trying to rotate a slightly elevated camera while sitting at the scene origin. Initial camera parms are:
local cameraX = 0
local cameraY = 1.5
local cameraZ = 0
local cameraAngle = 90 -- init: looking from world origin, up the Z axis
I create a simple wire cube (four faces, wireframe, 2 units length for each edge) centered at 0,0,10 and place it in the scene. This gives us a view like this:
All good so far.
So now, I'm trying to just spin the camera around the Y axis at the center of the scene, I'd expect that cube to go left or right (eventually going past the edge / behind the camera eye) depending on the direction of the spin.
I put together a little trig in a function to compute a simple 'look at' point - the x,z coordinates on the edge of a unit circle lying flat, with it's normal pointing up the Y axis:
local function applyPlayerAngleToCamera()
-- assumption for this test is that camera _position_ remains at 0,cameraY=1.5,0
-- we're just spinning the camera around the Y axis
local lookX = math.cos(math.rad(cameraAngle))
local lookZ = math.sin(math.rad(cameraAngle))
scene:setCameraTarget(lookX, cameraY, lookZ)
end
But when I bump 'cameraAngle' (one degree per update cycle using left/right buttons), I don't see the cube moving off the left or right edge as I'd expect - instead the cube remains centered in the camera view while spinning around its y-axis:
This is acting like the camera 'look at' is locked on the aggregate center of the nodes of the scene, and somehow results in panning the camera around that (and even if it was doing that I don't see how unit circle coords could result in something that looks like the camera is being swung around some arbitrary point in the scene on a string 10 units long).
I think I'm really missing something. Is 'setCameraTarget' supposed to be used by a client application? Am I just using it wrong? Is my math just wrong (quite possible)? Or am I completely off base and I should leave the camera where it is at the origin and instead move the scene nodes around (translation and rotation matrix magic using node:addTransform) to get the desired effect (edit: and if that's the case, why are 'setCameraOrigin' and 'setCameraTarget' even there)?
Edit edit: I guess what I'd really like is, in addition to 'setCameraOrigin(x,y,z)' a 'setCameraRotation(xDegrees, yDegrees, zDegrees)' and bypass the 'setCameraTarget' function altogether. I know that's not in there now, but I'm effectively trying to write one on my own and it definitely isn't working .
Any advice/help appreciated!