Game Development Community

Simple tree animation

by arteria3d · in Torque Game Engine · 11/23/2004 (3:54 pm) · 10 replies

Hi

Rather than using animation to move a trees branches - in previous programs i have used, i.e. db pro etc - i simply use a cosine routine to gently sway the tree object on its x pos. Can this be done via scripting in torque??? so an endless loop would simply transform the x pos using cos?

Steve

About the author

Owner of uk based Ltd company ArteriaMediaLtd. with a trading name of Arteria3d Website;arteria3d.com


#1
11/23/2004 (4:04 pm)
Just make your animation, and use the playThread command.
#2
11/23/2004 (4:06 pm)
Can u explain a little further. I have only been with torque three weeks now. I would apreaciate it - as my trees look odd not moving against a foilage rep background.

Thanks

Steve
#3
11/23/2004 (7:13 pm)
Stevie,

You create your animation using milkshape or whatever 3d modeling program you use.

When you export your model, give the animation a name like sway.

Then use playThread as indicated to run sway. There are examples on using playThread, just may have to search for them.


Another way, would be to add bones to your tree, and create a custom class that reads the bones and applys wind direction sways. (It's something I'm planning on creating myself soon.)
#4
11/23/2004 (7:47 pm)
Or you can just use a script.

But the other suggestions are probably more efficient.

A script would require a schedule called very often to get a smooth effect.

Assuming you have a tree object named $tree...
Then something like this would work:


schedule(2000,0,swayTree); // calls swayTree 2 seconds after loading

function swayTree()
{
%temp = $tree.getTransform();

%lx = getword(%temp,0);
%ly = getword(%temp,1);
%lz = getword(%temp,2);
%rx = getword(%temp,3);
%ry = getword(%temp,4);
%rz = getword(%temp,5);
%angle = getword(%temp,6);

................ something to add/subtract from %angle


$tree.setTransform(%lx SPC %ly SPC %lz SPC %rx SPC %ry SPC %rz SPC %angle);

schedule(100,0,swayTree); // calls swayTree 10 times per second after loading

}

Not very elegant, is it?
#5
11/24/2004 (3:23 am)
Buts thats what i was after - simple sway routine rather than a complex milkshake/3ds animation - especially with the ammount of trees i have - proper animation would pos kill my fps

Cheers All
#6
11/24/2004 (3:40 am)
Stevie

Unfortunetly there is no easy way of making a tree sway if it does not have any animation or if the DTS has not been setup with bones.

The easiest way still is to add animation via milkshape or what not, export it and then call the proper animation routines.

I understand what your saying about a simple sway routine, but there is no such beast.
#7
11/24/2004 (3:42 am)
Hi Simon - not even if i within a loop, move the x transform using cos???? and the then repositioning it??

Steve
#8
11/24/2004 (4:35 am)
No one has asked... how many trees are we talking? If there's more than just a few, script will be extremely inefficient at updating tree positions.

- Brett
#9
11/24/2004 (4:38 am)
Maybe 50
dotted over the lansscape in between all the stagnant ones. Why would scirpt be in-efficient. Hey this could be a good time to learn my first C program!!!!

Steve
#10
11/24/2004 (5:24 am)
Steve

I suppose you could try appling a rotation transform using cos around the up vector. But then the whole tree would move, it would be like swaying a pole, stiff and unlife like.

Quote:
Why would scirpt be in-efficient

It takes more c++ operations do run script than to run C++ it'self.

For instance

[b]CS Script[/b]

%i = %i + 1;

 
[b]C++ Code[/b]

i = i + 1;

If I remember, the CS script will take about 8 C++ functions( each with numberous operations) to perform that line, where C++ will take 2 operations;

Edit: Code spacing