PDA

View Full Version : Driving a car with Xpresso


noseman
01-25-2005, 03:11 PM
Hello there!
I was messing up with xpresso today, in order to calculate the automatic rotation of car wheels, when the car moves in the X direction.
Simply enough, high school maths, just paid off and it works perfectly.
Then I had another idea, why not make a combination of xpresso, align to splines and nulls, in order to make the car move on the spline and steer the wheels automatically.
Even though the steering is not perfect, the visual effect was accomplished with one small glitch.
I don't know how to spin the wheels anymore, because I don't know how to measure the distance travelled by each wheel. I don't intend to get perfectly accurate, but I would like to know if there is a way (node) to calculate the length of a spline.

Thanks!

Srek
01-25-2005, 03:18 PM
Hi,
to ge the distance covered by a single wheel just use the previous poisition output (or a memory node) and calculate the difference between the current and former position. No some basic trigonometry and you are done. Keep in mind that you have to take care of the wheels turning direction by yourself.
Cheers
Srek

darf
01-25-2005, 03:20 PM
In the Object node there is Global Matrix and Previous Global Matrix. Subtract the offset component of the previous matrix from the current matrix and you have the velocity ( as a vector ). You can then evaluate the length of that vector and plug it into your algorithm.

darf

darf
01-25-2005, 03:22 PM
Assuming you have a hierarchy remember to use the global position ( that is why I proposed using the global matrix offset ). Right Srek?

darf

Hi,
to ge the distance covered by a single wheel just use the previous poisition output (or a memory node) and calculate the difference between the current and former position. No some basic trigonometry and you are done. Keep in mind that you have to take care of the wheels turning direction by yourself.
Cheers
Srek

noseman
01-25-2005, 03:25 PM
thanks Srek, but I had that in mind as a last solution.
I am wondering if there is a way to measure the distance of a spline between points or growth percentages automatically or with a special node... or something.
Thx again.

and thx darf

darf
01-25-2005, 03:35 PM
With the goal of using the length for tires it is a problem a making a right turn will make the left tire cover more area than the right. This would create a visual sliding effect of the tires as the car turned. Due to this you would definitely want to use a delta value ( the difference between previous frame and current frame ) evaluate the distance travelled. You could do it another way but I don't believe the result would be as realistic.
darf

thanks Srek, but I had that in mind as a last solution.
I am wondering if there is a way to measure the distance of a spline between points or growth percentages automatically or with a special node... or something.
Thx again.

and thx darf

noseman
01-25-2005, 03:38 PM
ok then mr know-it-all ;)

I have been through the manual, BUT I don't really get it.
Any tutorials on global matrix usage etc out there?
Thanx!

noseman
01-25-2005, 03:44 PM
ok ok ok ....
starting to get it now...
Position vector (V0) is the actual distance from 0.0.0?

darf
01-25-2005, 04:05 PM
ok ok ok ....
starting to get it now...
Position vector (V0) is the actual distance from 0.0.0?

If you use the matrix to vector adapter node the 'Offset' vector is what you want. I assume V0 is the offset vector in COFFEE? Not sure. Using the global matricies with the adpater node seemed to all work ( even if the object was deep in a hierarchy ).

That know-it-all is so wrong. Not sure how to change that. Should be, "I know some things" at best.

darf

TimC
01-25-2005, 04:18 PM
That know-it-all is so wrong. Not sure how to change that. Should be, "I know some things" at best.

darf

darf,

just click on User CP at the top and then click on edit profile. you can then change the text.

cheers
Tim

noseman
01-25-2005, 04:24 PM
OK pal I got that to work. Nice!
BUT... I want to use previous rotation (to add the rotation of the distance traveled) but it seems to give me a hard time.
What rotation does previous rotation refere to?

plus the fact that even though the animation is stopped, when I move my mouse, my wheels turn..

:banghead:

anyway I'll work on it a bit more and tomorrow I'll post the file.

Thx a lot!

darf
01-25-2005, 04:27 PM
As far as I can tell it relates to the local transformation. If it is in a hierarchy you may have to extract the rotation from the object that actually turns. My assumption here is that the tire ( or tire plus wheel ) is attached to a parent object that rotates ( maybe? ). If that is the case that is the obejct that you should be working with. This is all pure speculation on my part as I am not sure how the scene is set up.

darf

OK pal I got that to work. Nice!
BUT... I want to use previous rotation (to add the rotation of the distance traveled) but it seems to give me a hard time.
What rotation does previous rotation refere to?

thx

darf
01-25-2005, 04:29 PM
It would be hard to believe that I looked right at it and missed it right? :argh:

Thanks Tim!
darf

darf,
just click on User CP at the top and then click on edit profile. you can then change the text.
cheers
Tim

noseman
01-25-2005, 04:42 PM
just for the sake of history, it's a lot simpler than that (up to now).
I just have a cogwheel (to visually check proper rotation). I assume that y=0 is the floor and that the center of the cogwheel is the radius (Y distance from floor).
So I calculate the degrees that the wheel has to turn as:
(2*pi*relative distance travelled)/360
then I add that to the previous Global Rotation B and that's that.

The problem is that it doesn't work (yet). I'm probably messing up the "previous this previous that..."
oh well
:hmm:

I think I found a tut on maxon's site..

thx again!

P.S. when I complete my "Virtual car driving expression set", that will include:
a. Throttle
b. Brakes
c. Steering wheel
d. suspentions (when accelerating and braking)
e. banking on turns
f. honking etc...
I will give it to you as a present! :)

Srek
01-25-2005, 04:50 PM
Sounds ok to me. The Previous values are previous local values. When adding up the rotation you should keep in mind that due to precision problems you might get unwanted rotations after a while. Maybe try to cut the rotation down to 2xPI (modulo).
As for movement during stopped animation, this happens since Xpresso is evaluated for each screen refresh too. You can stop this by using a memory and a time node to determine if the animation time has changed and enable or disable functions depending on this.
Hope this helps
Srek

noseman
01-26-2005, 10:52 AM
Ok I have totally lost it....
here is the file, I just don't know what's going wrong.
It seems that after the incremental rotation calculation, the wheel doesn't inherit the new rotation value. Instead of increasing the rotation value, it just sets it to the new increment for the last frame's distance travelled.... doh! :cry:

the file... (http://noseman.org/testrenders/wheeltest001.c4d)

Srek
01-26-2005, 11:17 AM
Hi,
the tangential option in the align to spline expression will override your pitch setting.
You can find an optimised scene here: http://www.bonkers.de/download/wheeltest001.c4d
I reduced the calculations to the neccesary part and used a Null to avoid the alignment/rotation override problem.
Cheers
Srek

base80
01-26-2005, 11:42 AM
I am working on a car solution
You can download the file here; here (http://www.base80.com/oldsite/xpressoDL.html)
(second from the top)

Oh and by the way; The Position of the wheel divided by its Radius(r) = Rotation of the wheel... so Pos/r=Rot

I don't advise to use the spline for measuring distance. It doesn't really work as it should. And be careful with using a previous position as it tends to become unstable a very low speed.

noseman
01-26-2005, 11:46 AM
ahhhh!
so that's why we learned about radians in school... for C4D :applause:

You are the best Srek!

Is this what you do for a living? Giving answers to ignorants like me.
Thanks a million! I owe you big time!
:bowdown:

Thanks too Base80, I just saw your post! I'm dlding now.
thank you thank you thank you thank you thank you alll!

noseman
01-26-2005, 11:54 AM
Hey base80
I went to your site and I saw the "tapping feet" cubes (on the left), at that time I was listening to rory Gallagher's "moonchild" and it seemed to me that they where tapping in sync with the music.
I kinda thought it was a expresso-safari plugin that "taps-feet-while-itunes-plays-music"....

I am definitely losing it :banghead:

CGTalk Moderation
01-26-2006, 12:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.