Game Development Community

Rotation Problem

by Nancy Lee · in Technical Issues · 08/18/2008 (6:09 am) · 1 replies

Hi, I am really having trouble with this SetTransform and GetTransform thing.The following is partial of my code, and it echos weriod huge numbers....yet i have no clue why...please help. Thanks a lot.

This code suppose to detect the bubble(ShapeName)'s position, and rotate the FishShooter(ShapeName) accordingly, the AngleCaculation() is based on 3d triangle calculation.

I don't quite understand how the setTransform and GetTransform work, like what kind of data they return, and how should I get the following code work!!!!

THanks.

function FishShooter::Rotation()
{
%fishShooter = $fishShooter;
%bubble = $bubble;
//%pi = 3.1415926
//FS = FishShooter, B = Bubble
%FSPosition = %fishShooter.getTransform();
%lxfs = getword(%FSPosition,0); // first, get the current transform values of the fishShooter
%lyfs = getword(%FSPosition,1);
%lzfs = getword(%FSPosition,2);
%rxfs = getword(%FSPosition,3);
%ryfs = getword(%FSPosition,4);
%rzfs = getword(%FSPosition,5);
%rdfs = getword(%FSPosition,6);

%BPosition = %bubble.getTransform();
%lxb = getword(%BPosition,0); // first, get the current transform values of bubble
%lyb = getword(%BPosition,1);
%lzb = getword(%BPosition,2);
%rxb = getword(%BPosition,3);
%ryb = getword(%BPosition,4);
%rzb = getword(%BPosition,5);
%rdb = getword(%BPosition,6);

%rxnew = AngleCalculation(%lzfs, %lyfs, %lzb, %lyb, %rxfs);
%rynew = AngleCalculation(%lxfs, %lzfs, %lxb, %lzb, %ryfs);
%rznew = AngleCalculation(%lxfs, %lyfs, %lxb, %lyb, %rzfs);
%rd = 1;

//%fishShooter.setTransform(%lxfs SPC %lyfs SPC %lzfs SPC %rd SPC 0 SPC 0 SPC %rxnew);
//%fishShooter.setTransform(%lxfs SPC %lyfs SPC %lzfs SPC 0 SPC %rd SPC 0 SPC %rynew);
%fishShooter.setTransform(%lxfs SPC %lyfs SPC %lzfs SPC %rxnew SPC %rynew SPC %rznew SPC %rd);

echo(%lxfs SPC %lyfs SPC %lzfs SPC %rxfs SPC %ryfs SPC %rzfs SPC %rdfs);
}

function AngleCalculation(%lx1, %ly1, %lx2, %ly2, %rz)
// I am assuming getTransform gives me radian value, but it doesn't seem all right
{
%rx = (mAtan((%ly2-%ly1),(%lx2-%lx1))); //get the radian value that it should be rotated
%rz = (%rz + %rx)*57.296; // 57.296 is the constant got from 180/pi
return %rz;
}

#1
08/19/2008 (7:51 pm)
It looks like anglecalculation is calculating an angle in degrees.
You are calculating 3 of them somehow and then setting them into the axis part of a setTransform.

The last 4 elements of the setTransform must be an axis-angle attitude representation. The angle part (the last element) should be in radians, if I remember correctly.

Wikipedia axis-angle article
I'd google it and also look for a better explanation than this link.

So you loaded three angles expressed in degrees into elements 3,4,5 instead of the expected unit length vector, and then rotated about that wierd axis by an angle of 1 radian. It is pretty confusing just what you are really trying to do (you didn't say.)

Start with understanding what the Torque "Transform" really is, then figure out which attitude you are trying to calculate, then work on calculating it.

If all you want to do is point a %fishShooter character at the %bubble, then there are probably several threads with examples where that is calculated. Calculating a transform to point at something is a common task.