<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Object Target Expression in Python]]></title><description><![CDATA[<p dir="auto">H﻿i Friends,<br />
I try to build  the Object Target Expression in Python.<br />
So far I have this and it works but with a little issue.<br />
I have a flipping problem and I don't know how to build the up-vector in, so that it works perfectly.<br />
–</p>
<pre><code>import c4d
cam = op.GetObject()
target = op[c4d.ID_USERDATA,1]
    
def main():    
    cObj = cam.GetMg().off  
    tObj = target.GetMg().off
    upV =  c4d.Vector(0, 1, 0)

    m = c4d.Matrix()

    m.off = cObj   
    m.v1 = (tObj-cObj).Cross(cObj-upV).GetNormalized() 
    m.v3 = (tObj-cObj).GetNormalized() 
    m.v2 = (tObj-cObj).Cross(m.v1).GetNormalized()

    cam.SetMg(m)
</code></pre>
]]></description><link>http://developers.maxon.net/forum/topic/11152/object-target-expression-in-python</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 09:33:51 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/11152.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Nov 2018 17:12:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Object Target Expression in Python on Thu, 06 Dec 2018 16:05:53 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">unfortunately we can't help developing algorithms. So, what has been said here and in the <a href="https://developers.maxon.net/forum/topic/11170/quaternion-rotation" target="_blank" rel="noopener noreferrer nofollow ugc">Quaternion Rotation</a> thread, is probably all we can contribute from MAXON's side.</p>
<p dir="auto">Maybe somebody from our community is willing to step into this and help out?</p>
<p dir="auto">Cheers,<br />
Andreas</p>
]]></description><link>http://developers.maxon.net/forum/post/56610</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/56610</guid><dc:creator><![CDATA[a_block]]></dc:creator><pubDate>Thu, 06 Dec 2018 16:05:53 GMT</pubDate></item><item><title><![CDATA[Reply to Object Target Expression in Python on Thu, 06 Dec 2018 00:34:23 GMT]]></title><description><![CDATA[<p dir="auto">Does anyone have a suggestion how to work with Quaternions in my case to avoid the gimbal lock? I realy dont find any examples or approaches to this. Other APIs have different methods for this like SetFromToRotation, SetLookRotation, lookAt ....<br />
Maybe its possible to extend the Python Library with other classes? Don‘t have any idea and not very advanced in this.<br />
Thanks!</p>
]]></description><link>http://developers.maxon.net/forum/post/56604</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/56604</guid><dc:creator><![CDATA[Tudor]]></dc:creator><pubDate>Thu, 06 Dec 2018 00:34:23 GMT</pubDate></item><item><title><![CDATA[Reply to Object Target Expression in Python on Thu, 22 Nov 2018 11:13:59 GMT]]></title><description><![CDATA[<p dir="auto">Hi Tudor, with regard to using quaternions, I suggest to search around the web for it: there are hundreds of sites talking extensively about.<br />
I warmly suggest to have a look <a href="http://www.okanagan.ieee.ca/wp-content/uploads/2016/02/GimbalLockPresentationJan2016.pdf" target="_blank" rel="noopener noreferrer nofollow ugc">here</a> where Gimbal lock is presented and some notes are spent on how to avoid it.</p>
<p dir="auto">Best, Riccardo</p>
]]></description><link>http://developers.maxon.net/forum/post/56459</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/56459</guid><dc:creator><![CDATA[r_gigante]]></dc:creator><pubDate>Thu, 22 Nov 2018 11:13:59 GMT</pubDate></item><item><title><![CDATA[Reply to Object Target Expression in Python on Wed, 21 Nov 2018 18:36:08 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
thanks again.<br />
I really do not understand it yet but it works.<br />
There are some strange camera behaviors in the viewport but the system still stable.<br />
I have tried also the Quaternions-solution, but I don't know really now the syntax work.<br />
Do you have an idea?</p>
]]></description><link>http://developers.maxon.net/forum/post/56456</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/56456</guid><dc:creator><![CDATA[Tudor]]></dc:creator><pubDate>Wed, 21 Nov 2018 18:36:08 GMT</pubDate></item><item><title><![CDATA[Reply to Object Target Expression in Python on Mon, 11 Jul 2022 09:13:51 GMT]]></title><description><![CDATA[<p dir="auto">Hi Tudor, thanks for following up.</p>
<p dir="auto">The issue you notice takes place when the temporary up-vector is aligned with the forward-vector: under this scenario the rVec is ambiguous and the whole system results unstable. The solution to the issue is represented by <a href="https://developers.maxon.net/docs/py/2023_2/modules/c4d/Quaternion/index.html?highlight=quaternion" target="_blank" rel="noopener noreferrer nofollow ugc">Quaternions</a> or, alternatively you can try to mitigate the effect by putting in place some "work-around" like:</p>
<pre><code class="language-python">    ...
    uVec = fVec.Cross(rVec).GetNormalized()

    # try to mitigate Gimbal-lock
    if (fVec + tmpVec).z &lt; 0:
        uVec.x = -uVec.x

    if abs(rVec.x - 1.0) &lt; 0.001:
        rVec.x = -rVec.x

    # fill-up the transformation matrix
    ...
</code></pre>
<p dir="auto">Best, Riccardo</p>
<p dir="auto">edit: <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a></p>
<p dir="auto">The approach shown here can be problematic. You instead should choose an up-vector which is not parallel or anti-parallel to the input vector. See <a href="https://developers.maxon.net/forum/topic/14117/gimbal-lock-safe-target-expression/2" target="_blank" rel="noopener noreferrer nofollow ugc">Gimbal Lock Safe Target Expression</a> for an example.</p>
]]></description><link>http://developers.maxon.net/forum/post/56448</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/56448</guid><dc:creator><![CDATA[r_gigante]]></dc:creator><pubDate>Mon, 11 Jul 2022 09:13:51 GMT</pubDate></item><item><title><![CDATA[Reply to Object Target Expression in Python on Tue, 20 Nov 2018 13:19:07 GMT]]></title><description><![CDATA[<p dir="auto">Hi Riccardo,<br />
thank you for your help.<br />
After I put  <strong>GetNormalized()</strong> in your line <strong>rVec</strong> and <strong>uVec</strong> it works.<br />
But now I get a flipping problem if the cam-Obj is direct over (or under) the target-Obj.<br />
The same happened by the Target-Tag. The Target-Tag has a option to stabilize the system with an up-Vector.<br />
Could I calculate this up-Vector to my matrix to stabilize it too? Or maybe there is a other approach?<br />
Thanks<br />
Tudor</p>
]]></description><link>http://developers.maxon.net/forum/post/56425</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/56425</guid><dc:creator><![CDATA[Tudor]]></dc:creator><pubDate>Tue, 20 Nov 2018 13:19:07 GMT</pubDate></item><item><title><![CDATA[Reply to Object Target Expression in Python on Tue, 20 Nov 2018 11:08:18 GMT]]></title><description><![CDATA[<p dir="auto">Hi Tudor,</p>
<p dir="auto">looking at your code I think there's a wrong assumption about the up-vector and how consequently it is used in the definition of the transformation matrix.</p>
<p dir="auto">The correct approach should look like:</p>
<pre><code class="language-python">import c4d

cam = op.GetObject()    
target = cam[c4d.ID_USERDATA, 1]

def main():    
    # get "from" and "to vectors
    fromVec = cam.GetMg().off
    toVec = target.GetMg().off
    
    # use a temporary Up-vector
    tmpVec = c4d.Vector(0, 1, 0)
    # calculate the forward-vector
    fVec = (toVec - fromVec).GetNormalized()
    # calculate the right-vector
    rVec = tmpVec.Cross(fVec)
    # recalculate the proper up-vector
    uVec = fVec.Cross(rVec)
    
    # fill-up the transformation matrix
    m = c4d.Matrix()
    m.off = fromVec
    m.v1 = rVec
    m.v2 = uVec
    m.v3 = fVec
    
    # set the camera transformation
    cam.SetMg(m)
</code></pre>
<p dir="auto">Last but not least, please set tags accordingly to your topic and use the <a href="https://developers.maxon.net/forum/topic/11004/q-a-new-functionality" target="_blank" rel="noopener noreferrer nofollow ugc">Q&amp;A functionality</a>.</p>
<p dir="auto">Best, Riccardo</p>
]]></description><link>http://developers.maxon.net/forum/post/56423</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/56423</guid><dc:creator><![CDATA[r_gigante]]></dc:creator><pubDate>Tue, 20 Nov 2018 11:08:18 GMT</pubDate></item></channel></rss>