float fOrient = GetFacing( GetFirstPC() -90.0 );
float fX = cos( fOrient/2 );
float fY = sin( fOrient/2);
####
# The below section should do the math right.
my $pi = 3.14159265358979;
#my $pi = 4*atan2(1,1);
sub deg_to_rad { ($_[0]/180) * $pi;}
sub rad_to_deg { ($_[0]/$pi) * 180; }
sub calc_quatcam
{
my $camx = shift;
my $camy = shift;
print "\nRad X:Y\t $camx : $camy\n";
# my $qx = rad_to_deg(acos($camx));
# my $qy = rad_to_deg(asin($camy));
my $qx = rad_to_deg($camx);
my $qy = rad_to_deg($camy);
print "\nRadian X:Y\t $qx : $qy\n";
print "Total: " . ($qx + $qy) . "\n";
$qx = ($qx * 2);# + 90.0;
$qy = ($qy * 2);# + 90.0;
my @calc_cam = ($qx, $qy);
# print "\nQuat X:Y\t $qx : $qy\n";
return @calc_cam;
}
# Read in from the Hash. The function that reads from
# the file returns an anon Array, so I have to access
# as a scalar, then turn it into an Array.
my $can_ori = $gff_files{Cameras}{$num}{Orientation};
@cam_ori = @$can_ori;
my $cam_ori1 = @cam_ori[0]; # X-orientation
my $cam_ori2 = @cam_ori[1]; # Always 0
my $cam_ori3 = @cam_ori[2]; # Always 0
my $cam_ori4 = @cam_ori[3]; # Y-orientation
# Debugging print-out
print "Orientation:\n\t$cam_ori1\n\t$cam_ori2\n\t$cam_ori3\n\t$cam_ori4\n\n";
# The orientation values are stored as radians, so
# calc_quatcam returns the degree equivalent, or should...
my @cam_quats = calc_quatcam($cam_ori1, $cam_ori4);
my $qx = @cam_quats[0];
my $qy = @cam_quats[1];
####
my $ori_deglab = $ori_framey->Label(-text=>"Facing (in Degrees):")->pack(-side=>left);
my $ori_deg = $ori_framey->Spinbox(-from=>0.0, -to=>360.0, -increment=>0.5, -width=>12, -command=>sub {
my $deg = shift;
my $degg = $deg;
my $fl = $degg/2;
my $flo = deg_to_rad($fl); print "Order:\n\t$deg\n\t$fl\n\t$flo\n";
$quatx = cos($fl); $quaty = sin($fl);
my @cal = calc_quatcam($quatx, $quaty);
print "The deg is: $deg\n";
$ori_xlab->configure(-text=>"X Quaternion Value: $quatx");
$ori_ylab->configure(-text=>"Y Quaternion Value: $quaty");})->pack(-side=>right);
$ori_deg->set($qy);
$ori_xlab = $ori_framey1->Label(-text=>"X Quaternion Value: $quatx", -font=>[-family=>'fixed', -size=>10], -width=>30)->pack(-expand=>1, -fill=>x);
$ori_ylab = $ori_framey2->Label(-text=>"Y Quaternion Value: $quaty", -font=>[-family=>'fixed', -size=>10], -width=>30)->pack(-expand=>1, -fill=>x);