Hello guys,
I have a python tag that sits on a plane old camera object. The tag has some user data controls for position, rotation etc. along with the option to use a custom pivot object (e.g. c4d.BaseObject(c4d.Onull)
) to rotate the camera around.
If no custom pivot object is supllied I use the world origin i.e. a unit matrix c4d.Matrix()
as the pivot.
While this all works I noticed some odd behaviour when I nest the custom pivot object as a child object of the camera. Things start to get really weird then. I move the nested pivot object and the camera object starts flying all over the place.
I suspect that I either ran into some kind of logical limitation or that my math is not correct.
While I know that my question is probably way beyond support I still wonder if someone could be so kind and spare some time to help me out here.
Please find below the code I'm using along with the scene file.
Cheers,
Sebastian
from typing import Optional
import c4d
doc: c4d.documents.BaseDocument # The document evaluating this tag
op: c4d.BaseTag # The Python scripting tag
flags: int # c4d.EXECUTIONFLAGS
priority: int # c4d.EXECUTIONPRIORITY
tp: Optional[c4d.modules.thinkingparticles.TP_MasterSystem] # Particle system
thread: Optional[c4d.threading.BaseThread] # The thread executing this tag
def main() -> None:
# Called when the tag is executed. It can be called multiple time per frame. Similar to TagData.Execute.
# Write your code here
pivot = op[c4d.ID_USERDATA,1]
pivot_rotation_heading = op[c4d.ID_USERDATA,3]
pivot_rotation_pitch = op[c4d.ID_USERDATA,4]
pivot_rotation_banking = op[c4d.ID_USERDATA,5]
camera_position_x = op[c4d.ID_USERDATA,13]
camera_position_y = op[c4d.ID_USERDATA,17]
camera_position_z = op[c4d.ID_USERDATA,18]
camera_rotation_heading = op[c4d.ID_USERDATA,6]
camera_rotation_pitch = op[c4d.ID_USERDATA,7]
camera_rotation_banking = op[c4d.ID_USERDATA,8]
camera = op.GetObject()
if not camera or not camera.CheckType(c4d.Ocamera):
return
# Get the global matrix of the pivot.
# If there is no pivot object supplied use the unit matrix.
pivot_matrix = pivot.GetMg() if pivot is not None else c4d.Matrix()
# Construct a matrix to set our camera object to.
camera_matrix = (
pivot_matrix *
c4d.utils.MatrixRotY(pivot_rotation_heading) *
c4d.utils.MatrixRotX(pivot_rotation_pitch) *
c4d.utils.MatrixRotZ(pivot_rotation_banking) *
c4d.utils.MatrixMove(
c4d.Vector(camera_position_x, camera_position_y, camera_position_z)
) *
c4d.utils.MatrixRotY(camera_rotation_heading) *
c4d.utils.MatrixRotX(camera_rotation_pitch) *
c4d.utils.MatrixRotZ(camera_rotation_banking)
)
camera.SetMg(camera_matrix)