Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Need help with scaling limbs

Author
Message
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 23rd Sep 2008 12:18
I've been working on a revised version of Lightning Limbs and I'm trying to add in the "Scale Limb" command. Unfortunately, there's trouble with making my 3d axis pointer line up correctly.

If the axis pointer (a 3d object) is glued to the selected limb then the pointer gets stretched when the limb gets scaled. I can't just apply a scale factor of "1/Scale" because when a limb is scaled, all child limbs in the hierarchy get scaled but still register as being at 100%.

I tried loading the main object twice, colouring it black and setting black to be transparent, and glued the pointer to that. Unfortunately, I can't get the 3d axis pointer to be positioned at the exact point in space as the limb.

Limb Offset returns the position relative to the parent limb (the parent is located at 0,0,0). Limb Position returns the exact position in 3d space.

Some of you may say there's a really easy way:

But I can't get the object rotated right - I want it to line up with the limb when it's rotated 0,0,0. I could just call "Limb Direction", but Limb Direction Z returns 0 under all circumstances.

Help??

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Sep 2008 22:55 Edited at: 23rd Sep 2008 23:51
[edit]

I had to tweak my approach a bit from what I originally wrote but the idea still stands... You'll have to manage the angles yourself by storing them in an array or some other means that you manage. Don't glue the axis object to the limb but instead position it at the absolute 3d limb position.

You could use your quat functions to effectively manage the angles of the limbs and axis object, but you can also manage them using the free flight rotation controls. When it comes to limbs and rotations relative to the main object, the regular rotate commands give back results that are hard to manage without additional math. In this particular case, turn,pitch and roll come in real handy.

The idea is this: set and store the angles you want to rotate the limb. Then rotate the limb. Rotate the axis object to the orientation of the main object. Now rotate the axis object to the orientation of the limb based on the angles you store. Finally, position the axis object at the absoulte 3d limb position.

The following example doesn't use an array, but it updates the x y and z angles constantly. The cone represents the axis object and ultimately is oriented relative to the limb (the red limb in this case):


Enjoy your day.
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 26th Sep 2008 18:52
Hi Latch, sorry I've been a few days getting back to you, I haven't had much time for coding.

Your solution works but only for the first limb in the series. To rotate the axes pointer object to match the final limb, I have to apply the Pitch/Roll/Yaw commands based on every limb in the chain.

This may well prove to be possible, if I manage to read in the limb hierarchy, but it won't be possible if the source .x file is a binary file. I think I may have to port all this over to GDK after all...

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Sep 2008 02:40 Edited at: 27th Sep 2008 02:43
Quote: "I think I may have to port all this over to GDK after all..."


Unless you want to, but I don't think it's necessary.

If you are playing the entire animation and you want there to be an axis object on each limb at the time of playing, then I can see it being a bit tricky - unless you use your quat to euler to get the correct angles of the limbs. Then no problem!

But, I assume the axis object is for identifying which limb you are rotating (to set up the animation) and supply a visual aid of that rotation and limb selection. If you have a hand on an arm, and you rotate the arm, if the limbs are linked, the hand will be at a new position. This is the cue that identifies the hierarchy. If you do a check through the limbs and match their old position to any new positions after the rotation of a single limb is made, you'll end up with the child limbs to rotate to match the parent limb. And remember, hopefully you've created an array to store each keyframe rotation of a limb, so if you rotate a parent, once you find the limbs whose position(s) have changed, you apply the parent rotation + whatever angles the child was rotated previously (stored for the axis object), and apply that rotation to the axis object.

This example expands a bit on the last one. It's a little clumsy, but it shows the idea. The crosses represent the axis pointers. A little work would streamline the code:




Enjoy your day.
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 29th Sep 2008 22:21
Quote: "If you do a check through the limbs and match their old position to any new positions after the rotation of a single limb is made, you'll end up with the child limbs to rotate to match the parent limb. "


That one comment set off skyrockets in my mind! I went away and created a function that stores all limb positions, rotates the limb, and then checks which limbs have moved. Those that have moved are descended (in some way) from the current limb. Repeat for every limb in the list, and you'll build up a limb hierarchy!

Each limb can only have one parent, so when you look up the parent of (say) limb 5 you get the value stored in the array at LimbHierarchy(5), and that's the limb number of it's parent. The parent for limb 1 is defined here as -1 because in LL that signifies no parent (and if I defined it as 0, you'd start accessing the root data).

This algorithm does run a little slow, but it only needs performing once so I think I get away with it!




To rotate the axis pointer correctly, I use a bit of code based on your first example - Pitch/Roll/Yaw the axes object based on the object orientation, and then apply Pitch/Roll/Yaw commands based on everylimb in the chain back to limb one. To make the axes line up correctly, they have to be matching the parent limbs orientation, so I skip the Pitch/Roll/Yaw commands at the selected limb, and only use higher limbs in the hierarchy. Thanks for all your help!!



"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Sep 2008 00:27
Good job! I had forgotten about this idea when we had gone off on a tangent with quaternions. I was originally using it similarly to your axis object - then got side-tracked with the no results problem using LIMB DIRECTION Z(). I hadn't, at the time, decided to store my own limb angles and started looking for other solutions. So, when you mentioned gluing the object to a limb and the scaling problem, it reminded me of some of the problems I had had when trying the same thing and I remebered my object to limb positioning idea. Messing around with the quaternions and eulers has made all of this stuff so much clearer. All in all, helping you has helped me big time!

Enjoy your day.

Login to post a reply

Server time is: 2025-06-07 08:04:40
Your offset time is: 2025-06-07 08:04:40