Switching Cam Position Based on Distance to Targeted Object

Discussions about animating in SOFTIMAGE©
Frank1000
Posts: 339
Joined: 16 Oct 2011, 14:13
Skype: the2he

Switching Cam Position Based on Distance to Targeted Object

Post by Frank1000 » 12 Nov 2011, 03:16

Hi,
I’ve setup a simple object translation animation, where I want the cam to follow a moving object ... but, the cam can only switch to certain allowed cam positions (bright cubes), simulating a set of affixed cameras.

So the cam needs to switch from one possible cam position to the next, depending on the distance to the animated object ... which ever cam position is closer to the moving object.

I probably need to do this with expressions or a script and need help please on how to get this task started.
Any hint / help very appreciated.

Thx,
Frank

Image

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 17:43

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Chris_TC » 12 Nov 2011, 12:41

Somebody else will have to explain the scripting way of doing this because I don't know.
Here's how it's done in ICE. I've added the three position nulls into a group. Then I've put this ICE tree onto the camera:
Image

The great thing about this setup is that it's very easy to make changes. For example, add a new position null into the group, and everything updates.

Frank1000
Posts: 339
Joined: 16 Oct 2011, 14:13
Skype: the2he

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Frank1000 » 12 Nov 2011, 17:53

Hi Chris, tx for reply. I've never used ICE before and although I have taken the last hours to watch tutorials and demos I have no idea which button to start with to get your result ... would it be possible to make a mini screen-movie from putting it together and youtube it ? That'd be mega.

Frank

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 17:43

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Chris_TC » 12 Nov 2011, 19:02

I may make a video version of this next week. But it's really easy to do, I hope this helps:

1) Put all your position nulls or objects into a group
2) Select your camera (the camera object itself, not the camera root null!)
3) Open an ICE tree window in one of your viewports (or Alt+9 for a floating ICE tree)
4) In the ICE tree window, choose Create->ICE Tree (this puts an ICE tree operator onto your camera)
5a) EITHER find all the nodes from my previous screenshot and connect them like I did
5b) OR download the compound I attached, drag the .xsicompound file into your ICE tree window and connect it to one of the ports on the ICE Tree node, like so:
Image

The Get Group and Get Cone nodes are Get Data nodes. You can simply drag your group and your object of interest from an explorer into the ICE tree to get those. Or add a Get Data node, double click it and add the names manually.
You do not have the required permissions to view the files attached to this post.

Frank1000
Posts: 339
Joined: 16 Oct 2011, 14:13
Skype: the2he

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Frank1000 » 12 Nov 2011, 19:27

ok cool ... I was able to put most of it together by my own, only the Get .kine.global.pos I couldn't find where they come from ...

Image

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 17:43

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Chris_TC » 12 Nov 2011, 19:44

These are all Get Data nodes. Double click them and type the attribute name.
The Set Data node also needs to be double clicked and the attribute name entered (self.kine.global)

Frank1000
Posts: 339
Joined: 16 Oct 2011, 14:13
Skype: the2he

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Frank1000 » 12 Nov 2011, 23:14

ok tx, worked out fine, one last one is that my Set Data node does not have self.kine.global and I couldn't find out how to rename or add one. Also, what do I need to understand if I want to know what I have to do if I want the camera to take the orientation of the current null it is positioned by ? Do I need programming knowledge ? The array of functions set together in this solution don't make me understand it yet ... for example what is self.kine or Matrix ? How did you get to understand ICE ? Do you have a recommendation for beginners tutorials ? The tutorials I saw so far were not so great yet ...

Image

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 17:43

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Chris_TC » 12 Nov 2011, 23:49

You have to double click the Set Data node and type the attribute name like you did for the Get Data nodes.
In my test scene I had the camera interest position-constrained to the cone to always keep it centered. If you want camera angles based on the rotation of your nulls, you'll have to change the tree slightly, like so:

Image

A matrix in this case is a combination of scale, rotation and translation. Using SRT to Matrix and Matrix to SRT nodes, you can "split" the matrix up into these individual components. When setting data, you can only set the entire matrix. When getting data, you can also get the subcomponents directly (e.g. "kine.global.pos" for the position).
You don't have to memorize all attributes, even though you will quickly remember the most common ones. The Get Data and Set Data nodes have Explorer buttons, which you can use to look into an object's hierarchy and see all of its various attributes.

Regarding tutorials, it may be a good idea to start here and watch all of his ICE videos:
http://vimeo.com/19028797

These five videos explain kinematics:
http://vimeo.com/28030812

And I've posted a list of video links here yesterday (bottom of the page):
http://www.xsibase.com/forum/index.php? ... 64;start=0

Frank1000
Posts: 339
Joined: 16 Oct 2011, 14:13
Skype: the2he

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Frank1000 » 13 Nov 2011, 00:49

did implement it but cam still pointing to interest and not oriented by null orientation ... do I need to apply the positioning to the cam-root rather than to the cam itself ... so interest is dependent to cam ?

Image

Frank1000
Posts: 339
Joined: 16 Oct 2011, 14:13
Skype: the2he

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Frank1000 » 13 Nov 2011, 00:54

just tried it out with cam-root and it worked ... yea

tx for the tutorial links

Frank1000
Posts: 339
Joined: 16 Oct 2011, 14:13
Skype: the2he

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Frank1000 » 13 Nov 2011, 01:10

if I want to move ahead or behind the cone, how is this to be achieved ? I basically want to set the distance to keep to the cone ... distinguishing between ahead of the cone and running after the cone.

Image

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 17:43

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Chris_TC » 13 Nov 2011, 01:30

Frank1000 wrote:did implement it but cam still pointing to interest and not oriented by null orientation ... do I need to apply the positioning to the cam-root rather than to the cam itself ... so interest is dependent to cam ?
If you don't want to use the camera interest, you'd typically delete it. The camera's rotation is constrained by the interest, so setting its rotation has no effect as long as that constraint exists.
Frank1000 wrote:if I want to move ahead or behind the cone, how is this to be achieved ? I basically want to set the distance to keep to the cone ... distinguishing between ahead of the cone and running after the cone.
Instead of getting the Array Minimum, you would have to find the value that's closest to what you want. Let's say the distance values are 10, 20 and 30. You want the camera to be at a distance of 27. You would then have to find the value 30, because that's closest to your desired value of 27.
Instead of directly hooking the Distance Between Node into the Array Minimum, you would first SUBTRACT a scalar value (e.g. 27), then do an ABSOLUTE VALUE, then hook that into the Array Minimum.

Frank1000
Posts: 339
Joined: 16 Oct 2011, 14:13
Skype: the2he

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Frank1000 » 13 Nov 2011, 19:13

ok, interest del works nice. now to the minimum array, I opened it but don't know how and where to subtract the scalar value :

Image

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 17:43

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Chris_TC » 13 Nov 2011, 20:12

You don't have to open the node. You can put the subtract outside, between the Distance Between and the Array Minimum.

Think about the data we're looking at (and simply right click any of the pipes to visualize that data in the viewport):
The Distance Between outputs an array of distance values. One distance for every position null. So let's say these are the values that flow out of the Distance Between: 10.3 | 18.9 | 13.4 | 7.7
You now want to find a camera position that has a distance of about 11. So you subtract 11 from the data we looked at above. You will get: -0.7 | 7.9 | 2.4 | -3.3
Now you do an Absolute value, so you get: 0.7 | 7.9 | 2.4 | 3.3
The result of that plugs into the Array Minimum, which will figure out that 0.7 is the smallest value, and that it is found at index 0. The rest of the tree behaves as always.

Frank1000
Posts: 339
Joined: 16 Oct 2011, 14:13
Skype: the2he

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Frank1000 » 13 Nov 2011, 23:39

thx, did "subtract" and "absolute value" which works fine now, only thing is that the cam still jumps back and forth in front or behind the targeted cone, depending on which distance is closer at that time ... how is this solved that I can determine whether I want to be in front or behind the target ?

Image
Image

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 17:43

Re: Switching Cam Position Based on Distance to Targeted Object

Post by Chris_TC » 14 Nov 2011, 01:27

What exactly are you trying to do? It looks like you're working with a second curve and many different nulls now.
There is no way to define what's "in front" or "behind". For each cone-null pair you have two positions in 3d space which let you determine a distance vector.

If you want the camera to be positioned on the exterior curve, it would make more sense to directly sample the curve at various positions instead of using nulls. This way you could determine what's in front and what's behind, because from any given point on the curve you can only move in two possible directions.