Set EditorCamera "lookat" orientation
On 06/07/2016 at 15:47, xxxxxxxx wrote:
In python, How may I set the "lookat" position of a camera programmatically?
In particular, I am specifically interested in setting the orientation of the EditorCamera to look at position (0, 0, 0) (the center scene).
I imagine there is some matrix math that could be done but I'm not sure how to do it in C4D, and was hoping there was an easy way to update the EditorCamera matrix so that it maintains the poisition but changes the orientation to look at the center of the scene.
The only way I can see to do this without knowing the matrix math is to create a dummy camera at the EditorCamera position, create a dummy object at the center of the scene, add a Target tag to the dummy camera, set the target to the dummy object, copy the "Mg" to the EditorCamera, then delete the dummy object and dummy camera.
There must be a better way!
Any help would be much appreciated.
On 07/07/2016 at 07:41, xxxxxxxx wrote:
welcome to the Plugin Café forums
Actually I'm not aware of a better way.
Perhaps you can share some detail, why you need to do this with the editor camera instead of a dedicated camera. The editor camera has the disadvantage, that you can't add tags to it.
Instead of using the Target tag and a target object, you could of course either implement your own tag or use the Python tag on a camera to have it look at the origin at all times.
We have a Python example on how to achieve something similar: Py-LookAtCamera
On 07/07/2016 at 23:08, xxxxxxxx wrote:
Thanks Andreas; this is the script I ended up writing after looking at the code you linked:
import c4d from c4d import gui, utils, Vector def main() : bd = doc.GetRenderBaseDraw() ec = bd.GetEditorCamera() op = doc.GetActiveObject() if op is None: op = doc.SearchObject('Camera') if op is None: gui.MessageDialog('No object selected, and no object named "Camera"') return False doc.StartUndo() doc.AddUndo(c4d.UNDOTYPE_CHANGE_SMALL, ec) rp = op.GetRelPos() ec.SetRelPos(rp + Vector(0,1,0) + (rp.GetNormalized()*5)) ec.SetRelRot(utils.VectorToHPB(-rp)) c4d.EventAdd() doc.EndUndo() if __name__=='__main__': main()
I am using camera mapping, and the center of the scene for my projects will always be Vector(0,0,0). I desired to have a quick way to jump back to the the "Camera" position to preview changes and make minor adjustments without actually activating the camera (which distorts the view, and is immutable) or having to mouse over back to that position (tedious).
Thanks for your help, this is now solved as far as I am concerned, unless you have any other comments or tips on a better or different way of how I could have handled this.
On 07/07/2016 at 23:24, xxxxxxxx wrote:
I guess the only thing that's missing, that I haven't looked into, is taking into account the project units and scale... Have to modify the modifiers for projects in centimeters versus feet.