Author Topic: Vector problems  (Read 2185 times)

Vectors are used for everything!
But I ran into a problem.
How do I rotate it?

Let's say we have object blah with transform = 0 0 1 0 0 0 0

Now, object cube is supposed to stay relative to this transform, with an offset of 0 5 1 0 0 0 0 to blah's initial position/roatation.

Right now we can easily add the position together
BUT

Now imagine blah has the transform = 0 0 1 0.5 -0.1 1 45
I can't figure out how to place object cube relative to that transform

Can someone help me solve this?

What do you mean "relative"? Do you want both objects to be facing the same direction, or towards the same point, or what?

What do you mean "relative"? Do you want both objects to be facing the same direction, or towards the same point, or what?
Like you parent cube to blah
So when you move/rotate blah then cube moves/rotates relative to blah, keeping the same distance from it and stuff

Like you parent cube to blah
So when you move/rotate blah then cube moves/rotates relative to blah, keeping the same distance from it and stuff
Uhh, excuse me if I'm misunderstanding you here, but just copy the exact rotation numbers from the parent object...

Uhh, excuse me if I'm misunderstanding you here, but just copy the exact rotation numbers from the parent object...
The rotation of the object is not the problem.
The problem is the rotated position offset

cube is parented to blah.

blah has been moved and rotated.
cube has moved and rotated relatively.


That's what I mean.
« Last Edit: December 01, 2012, 02:30:53 PM by Blocki »

That would require some sort of artificial linkage and a schedule loop, if you wanted it in the game with actual objects it would be choppy.

That would require some sort of artificial linkage and a schedule loop, if you wanted it in the game with actual objects it would be choppy.
But how would I calculate the position of cube after moving blah?

I'm still a bit confused are you asking about how you would move an object along with rotating it to face the center to a specific position on an orbit trajectory by specifying what angle/or what position it should be in and then calculate the other?
« Last Edit: December 01, 2012, 03:34:17 PM by dotdotoctagon »

I'm still a bit confused are you asking about how you would move an object to a specific position on an orbit trajectory by specifying what angle/or what position it should be in and then calculate the other?
Yes

blah has been moved and rotated.
cube has moved and rotated relatively.


That's what I mean.
I see now. You should try to be more clear in future OPs
Here is the code I would use, if you converted the axis angles to euler angles with that coding resource

This code only assumes a two dimensional mirror, I can add functionality for three dimensions if you'd like
Code: [Select]
$posOffset = "0 5 0"

function getChildTransform(%parent)
{
    %pTrans = %parent.getTransform();
    %pPos = getWords(%pTrans,0,2);
    %pRot = axisToEuler(getWords(%pTrans,3,6));
    %offsetLen = vectorLen($posOffset);
    %offsetTheta = mAtan(getWord($posOffset,1),getWord($posOffset,0));

    %xComp = %offsetLen * mCos(%pRot + %offsetTheta);
    %yComp = %offsetLen * mSin(%pRot + %offsetTheta);

    return vectorAdd(%xComp SPC %yCom @ " 0",%pPos) SPC %pRot;
}
I've never used the axis to euler converter before, you may have to adjust by a factor of 90 degrees to get it perfect but this code will get you in the ballpark

This code only assumes a two dimensional mirror, I can add functionality for three dimensions if you'd like
Yes pls

Ok I'll try that out right when I get back on my comp :D

Yes pls

Ok I'll try that out right when I get back on my comp :D
On RTB i have released a Tron Light Bike that does this exactly, check it out

On RTB i have released a Tron Light Bike that does this exactly, check it out
What
which part of the code


OK wikipedia tells me to put a bunch of numbers in a table and then apply black magic to calculate something without operators
wat
http://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions