Object orientation on spline
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/03/2004 at 16:29, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 8.206
Platform:
Language(s) : C++ ;---------
Hi,
Im making a plugin that is similiar to the Arrange tool in Cinema4D. My problem is that I can't work out how to orientate the objects properly against the spline.
I'm using the following code to rotate the objectsvTempRot = spline->GetSplineTangent(rPosition,j); m.v3 = Abs(vTempRot); m.v1 = -(vTempRot % m.v2); m.v2 = (vTempRot % m.v1);
This works for about 98% of the time, on some occasions on more complicated splines, the rotation of the objects is wrong (one of the axis will be in the opposite direction).
I have a feeling that I have the code wrong as my 3d math is not that good. Infact most of the code above was trial and error
Can someone shed some light on what I have done wrong?
Thanks -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/03/2004 at 15:23, xxxxxxxx wrote:
Well, C++ is an "Object oriented" language, so this cannot be too hard...
First of all, the Abs() on your first line is a no-op. I suppose you meant to write "m.v3 = !vTempRot".
The rest of your code is fine, using the standard "z = x % y" relation combined with circular permutation ("x = y % z" and "y = z % x") and antisymmetry ("a % b = - b % a"). You can write it a bit simpler as:m.v3 = vTempRot; // Z = Z m.v1 = m.v2 % m.v3; // X = Y % Z m.v2 = m.v3 % m.v1; // Y = Z % X
The immediate problem is where "m.v2" comes from. If you haven't assigned anything to it, then the orientation will depend on the previous orientation of the object that m belongs to. A common choice is to assign Vector(0,1,0) to it, i.e. decide that it should initially point upwards. That will work for all splines without upside-down loops.
Generally you can permute the expressions above as much as you want, but you'll still always have to add in one vector more. There's just not enough information in the single vTempRot vector to completely decide the whole rotation. So first you'll have to decide what you want from your algorithm.