Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - dotdotcircle

Pages: [1]
1
Modification Help / Rotation Help
« on: October 27, 2012, 02:50:48 PM »
I need help with a small cable mod that I'm making for ship rigging etc. The wand model seems like a good auxiliary model, so I am using it. I am also using a simple output event right now because it's easy to test with, but eventually there will be sender/receiver bricks or some other system. Anyway, I need help with rotating the correctly sized and positioned cable StaticShape to connect the %this.position and %targetPos.

Code: [Select]
datablock StaticShapeData(CableData) {
shapeFile = "base/data/shapes/wand.dts";
};

function fxDtsBrick::createCable(%this, %string, %client) {
%targetBrick = ("_" @ %string).getID();

if(isObject(%targetBrick) && %targetBrick.getClassName() $= "fxDTSBrick") {
%targetPos = %targetBrick.position;

if((%cableLen = VectorDist(%this.position, %targetPos)) > 1) {
%cableShape = new StaticShape() { datablock = CableData; };

if(isObject(%cableShape)) {
for(%i = 0; %i < 3; %i++)
%mid = %mid SPC ((getWord(%this.position, %i) + getWord(%targetPos, %i)) / 2);

%currentNormal = VectorNormalize(%cableShape.position);          // BLATANTLY loving WRONG
%targetNormal  = VectorNormalize(%targetPos);                         // BLATANTLY loving WRONG

%angle = mAcos(VectorDot(%currentNormal, %targetNormal));    // BLATANTLY loving WRONG
%axis  = VectorCross(%currentNormal, %targetNormal);              // BLATANTLY loving WRONG

%cableShape.setScale("1 1 " @ (%cableLen * 0.55));
%cableShape.setTransform(%mid SPC %axis SPC %angle);

MissionCleanup.add(%cableShape);
}
}
}
}

registerOutputEvent(fxDTSBrick, "createCable", "string 20 250", 1);

My initial idea (represented by the picture below) favored the axial rotation system (as opposed to Euler rotation angles) and was to create a vector B from the src and receiver and then create a perpendicular vector A of which to rotate around. I quickly realized that there could be an infinite number of perpendicular vectors which renders this solution moot.


I haven't done this kind of math in quite a while and am rusty... any help? Am I being stupid?

Pages: [1]