LDCad ldc.camera.setThirdPerson API


ldc.camera.setThirdPerson API
#1
(Probably for Roland but if someone else has worked this out, please chip in).

Context:
I'm trying to write a (Lua) animation script which will rotate the 3rd person view camera around the Y axis starting at the current view, rather than the start point used in the sample script. From the sample scripts, I can see the purpose of the first two arguments (helped by the description in LD4Studio documentation) but I'm struggling to understand the purpose next 3 angle (?) related arguments. The sample script in the function OnCameraFrame ...

Code:
function onCameraFrame()

  --Rotate a 3rd person camera around the center of the model.
  local ani=ldc.animation.getCurrent()
  local angle=ani:getFrameTime()/ani:getLength()*360

  local cam=ldc.camera()
  cam:setThirdPerson(camPos, camDist, angle+45, 25, 0)
  cam:apply(0)
end
 
... is applying an appropriate angle change to the third parameter. From playing around a bit, it seems that parameters three, four and five are related to a x, y, z coordinate. But even though the code applies the angle delta to the X value (I think), the camera appears to rotate around the Y axis. And that confuses me as I would have though that to rotate the camera around the Y axis would have required the angle delta to be applied to the y coordinate.

I'd appreciate it if someone could clear up my misunderstanding.

Regards,

David
Reply
RE: ldc.camera.setThirdPerson API
#2
[quote pid="42618" dateline="1630401603"]
I'd appreciate it if someone could clear up my misunderstanding.
[/quote]

The parameters are:

yaw, moves the camera around the look at point like the hands on a clock.
tilt, indirectly controls the 'height' of the camera stand.
roll, rotates the camera around its looking direction. e.g. 180 degrees is like holding your camera up side down while taking a picture.

LD4DStuido didn't have the roll option, but it felt more complete to always offer yaw,tilt and roll parameters for all the camera variants.

In practice you'll usually have a static tilt and a roll of zero.
Reply
RE: ldc.camera.setThirdPerson API
#3
(2021-08-31, 17:54)Roland Melkert Wrote: [quote pid="42618" dateline="1630401603"]
The parameters are:

yaw, moves the camera around the look at point like the hands on a clock.
tilt, indirectly controls the 'height' of the camera stand.
roll, rotates the camera around its looking direction. e.g. 180 degrees is like holding your camera up side down while taking a picture.

LD4DStuido didn't have the roll option, but it felt more complete to always offer yaw,tilt and roll parameters for all the camera variants.

In practice you'll usually have a static tilt and a roll of zero.

[/quote]

Thank you Roland, that helped a lot. I can now demonstrate a comparison between the standard camera view rotation (from the samples scripts) and a customised rotation, which allows a user to select the degrees to rotate, the duration of the rotation while using the current view as the animation start point.



If anyone wants this rotation script, it is listed here:

Code:
function animation_parameter_prompt_gf()
    -- Establish the animation's parameters.
  local rotation_ln = ldc.dialog.runInput("Rotate through how many degrees?")
  local duration_ln = ldc.dialog.runInput('Duration of the animation?')
  if (rotation_ln ~= "") then
    rotation_gn = tonumber(rotation_ln)
  end
  if (duration_ln ~= "") then
    duration_gn = tonumber(duration_ln)
    local ani_lo = ldc.animation('Configured Y-Axis Rotation')
      -- Set the animation length.
    ani_lo:setLength(duration_gn)
  end
    -- Update the macro hint.
  local macro_lo=ldc.macro('Rotation Parameters')
  macro_lo:setHint
  (
    'Set values for parameter driven rotation (' ..
        tostring(rotation_gn) .. ' degrees for ' .. tostring(duration_gn) ..
        ' seconds).'
  )
end  -- animation_paramter_prompt_gf


function register()
    -- Establish animation parameter defaults should the parameter macro not
    -- be called.
  rotation_gn = 360
  duration_gn = 10
    -- Macro which will prompt for the animation rotation parameters.
  local macro_lo=ldc.macro('Rotation Parameters')
  macro_lo:setHint
  (
    'Set values for parameter driven rotation (' ..
        tostring(rotation_gn) .. ' degrees for ' .. tostring(duration_gn) ..
        ' seconds).'
  )
  macro_lo:setEvent('run', 'animation_parameter_prompt_gf')
    -- Rotation driven by parameters.
  local ani_lo=ldc.animation('Configured Y-Axis Rotation')
  ani_lo:setLength(duration_gn)
  ani_lo:setEvent('start', 'onRotateStart')
  ani_lo:setEvent('frame', 'onRotateFrame')
end  -- register


function onRotateFrame()
    -- Rotate a 3rd person camera around the point the camera is looking at.
  local ani_lo = ldc.animation.getCurrent()
  local angle_ln = yaw_start_angle_gn + (ani_lo:getFrameTime() /
      ani_lo:getLength() * rotation_gn)
  local cam_lo = ldc.camera()
  cam_lo:setThirdPerson
  (
    camera_look_at_go,
    camera_distance_from_gn,
    angle_ln,
    pitch_angle_gn,
    0
  )
  cam_lo:apply(0)
end  -- onFrame


function onRotateStart()
    -- Want to use the current camera view as the animation start point
    -- and rotate around the Y axis.
  local cam_lo = ldc.view():getCamera()
  cam_lo:setMode(3)
    -- The camera's "looking at" point and distance from it are required when
    -- setting the camera position for each rotation step.
  camera_look_at_go = cam_lo:getLookAt()
  camera_distance_from_gn = cam_lo:getDistance()
    -- Need the camera current yaw and tile as the animation rotation start points.
  yaw_start_angle_gn = cam_lo:getYaw()
  pitch_angle_gn = cam_lo:getTilt()
end  -- onStart


register()


Regards,

David
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 2 Guest(s)