Page 1 of 3

Switching Cam Position Based on Distance to Targeted Object

Posted: 12 Nov 2011, 03:16
by Frank1000
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

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 12 Nov 2011, 12:41
by Chris_TC
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.

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 12 Nov 2011, 17:53
by Frank1000
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

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 12 Nov 2011, 19:02
by Chris_TC
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.

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 12 Nov 2011, 19:27
by Frank1000
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

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 12 Nov 2011, 19:44
by Chris_TC
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)

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 12 Nov 2011, 23:14
by Frank1000
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

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 12 Nov 2011, 23:49
by Chris_TC
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

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 13 Nov 2011, 00:49
by Frank1000
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

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 13 Nov 2011, 00:54
by Frank1000
just tried it out with cam-root and it worked ... yea

tx for the tutorial links

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 13 Nov 2011, 01:10
by Frank1000
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

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 13 Nov 2011, 01:30
by Chris_TC
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.

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 13 Nov 2011, 19:13
by Frank1000
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

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 13 Nov 2011, 20:12
by Chris_TC
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.

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 13 Nov 2011, 23:39
by Frank1000
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

Re: Switching Cam Position Based on Distance to Targeted Object

Posted: 14 Nov 2011, 01:27
by Chris_TC
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.