Script to turning a wheel question

Smart people ~ Great Scripts
Post Reply
User avatar
DesignDevil
Master Chief Petty Officer
Posts: 500
Joined: 22 May 2009, 08:52
Type the number ten into the box: 0
Location: Neuruppin, Germany, Earth.
Contact:

Script to turning a wheel question

Post by DesignDevil »

Hello again,

i have a question about the needed functions to turning a wheel. In python it was very easy to do that. I have calculated the amount of rotation and then i "added" this rotation angle onto my object for the specific axis:

Code: Select all

me.Rotate("x", angle)
In my "real" plugin (SDK) there is no me.Rotate function. I used for this the following lines of code:

Code: Select all

'get the object rotation of the previous frame
tsxGNodeGetAxesOrientation( pObj, @axis )
					
'set the time back to actual for this object
tsxAnimSetActiveTimeObject( pObj, actFrame )
					
'calculate the distance from this position to the last one
b = tsxDistanceToPoint3f( prevPos, actualPos )

'calculate the diameter of the object
tsxGNodeGetSize( pObj, @size ) 
r = size.y / 2
					
'calculate the amount of rotation
a = tsxDeg2Rad( ( b / ( r * PI ) ) * 180 )
					
'set the new rotation 
tsxGNodeRotate( pObj, @actualPos, @axis, a, actFrame ) 
The problem is, the calculation rotates my wheel around is Y axis - so far so good, but i also get a tilt around the X Axis of 6.07 degrees and i don't understand why (see attached images). Can anybody help me out?
I still use TrueSpace 6.6
Link: My Youtube Channel
Link: www.DesignDevil.de - Plugins, Tutorials and more about TrueSpace 6.6

v3rd3
Lieutenant Commander
Posts: 1135
Joined: 21 May 2009, 20:04

Re: Script to turning a wheel question

Post by v3rd3 »

Interesting issue .... DD I am not the guy to give you "the answer" but I am willing to guess.... :D

Do you have any gravity or other physics working on the wheel? If so, that could be it.

Where is the wheel's axis? If the axis if off centre then your rotations might be off because of that as well.

You might want to think through the issue of gimbel lock as well.

Just a thought for a possible fix would be to set the other rotation values for each frame you create.

HTH

User avatar
DesignDevil
Master Chief Petty Officer
Posts: 500
Joined: 22 May 2009, 08:52
Type the number ten into the box: 0
Location: Neuruppin, Germany, Earth.
Contact:

Re: Script to turning a wheel question

Post by DesignDevil »

Thanks....

There is no physic applied and the axis is in the center of the cylinder.
You might want to think through the issue of gimbel lock as well.
what's that?
I still use TrueSpace 6.6
Link: My Youtube Channel
Link: www.DesignDevil.de - Plugins, Tutorials and more about TrueSpace 6.6

v3rd3
Lieutenant Commander
Posts: 1135
Joined: 21 May 2009, 20:04

Re: Script to turning a wheel question

Post by v3rd3 »

The best explanation I have ever seen is here....

http://www.guerrillacg.org/home/3d-rigg ... -explained

User avatar
DesignDevil
Master Chief Petty Officer
Posts: 500
Joined: 22 May 2009, 08:52
Type the number ten into the box: 0
Location: Neuruppin, Germany, Earth.
Contact:

Re: Script to turning a wheel question

Post by DesignDevil »

Ok, i understand - thanks.

I found out that the "Gimbel lock" is not the reason for this curious thingy.

I tried a few things and found out that i get the problem on frame 1. To explain this better i tell you what my function does.

Normaly i record two "Move" positions of my object, in this case my cylinder. One key at frame 0 and one, maybe at frame 50. - the cylinder moves.

My function goes now on the actual frame and get's the axes position and rotation. Then it does the same thing for the previous frame. With this Values i calculate the rotation. The function works from frame 1 on because there is no previous frame before frame 0.

If i now on Frame 1 the function should get the position and rotation of frame 0 - and here comes the problem - i get wrong values.

If i allow my function to start the calculation at frame 2 then everything works fine.

In my eyes is there a problem to get correct values from the frame 0. Don't ask my why but with this system it works.
I still use TrueSpace 6.6
Link: My Youtube Channel
Link: www.DesignDevil.de - Plugins, Tutorials and more about TrueSpace 6.6

v3rd3
Lieutenant Commander
Posts: 1135
Joined: 21 May 2009, 20:04

Re: Script to turning a wheel question

Post by v3rd3 »

If that is the case then you need to intialize the previous position values for frames 0 and 1 and create conditional statements for those frames.

User avatar
DesignDevil
Master Chief Petty Officer
Posts: 500
Joined: 22 May 2009, 08:52
Type the number ten into the box: 0
Location: Neuruppin, Germany, Earth.
Contact:

Re: Script to turning a wheel question

Post by DesignDevil »

Thx a lot for your help. :bananacool2:

...now - yeppiee - my first PlugIn written in FreeBasic for TS 6.6. works. I'm so proud.
I still use TrueSpace 6.6
Link: My Youtube Channel
Link: www.DesignDevil.de - Plugins, Tutorials and more about TrueSpace 6.6

froo
Captain
Posts: 2554
Joined: 22 May 2009, 12:13

Re: Script to turning a wheel question

Post by froo »

Congratulations DesignDevil! :bananacheers:

User avatar
DesignDevil
Master Chief Petty Officer
Posts: 500
Joined: 22 May 2009, 08:52
Type the number ten into the box: 0
Location: Neuruppin, Germany, Earth.
Contact:

Re: Script to turning a wheel question

Post by DesignDevil »

Thanks.

I'm now working on a tutorial about that what i have done. Beginning with installation of FreeBasic until creating the PlugIn. So that anybody who is interested can follow my steps and come with my onto the "be a '(free)basic' PlugIn Developer for trueSpace" journey.

That means - if you can write computer programs but C++ is the bracket hell for you (like me) and you would ever create plugins with TS - follow this link ...

http://united3dartists.com/forum/vi ... f=12&t=452
I still use TrueSpace 6.6
Link: My Youtube Channel
Link: www.DesignDevil.de - Plugins, Tutorials and more about TrueSpace 6.6

User avatar
First Light
Senior Chief Petty Officer
Posts: 169
Joined: 22 May 2009, 11:17
Type the number ten into the box: 0
Location: Michigan, U.S.
Contact:

Re: Script to turning a wheel question

Post by First Light »

Excellent, DesignDevil! I'll look forward to your tutorial. :bananacheers:

Post Reply