Virtual Steel
to tx
ty tz
pf1 pf2
pr1 pr2
pf1b pf2b
pr1b pr2b
h1 h2
h1 h3
j z 0, 0,0
l 0 0, 0,0
r 1 1,-1,0
l 2 0,-1,0
r 3 -1,-1,0
l 4 1, 0,0
r 5 0, 0,1
l 6 -1, 0,0
r 7 1, 1,0
l 8 0, 1,0
r 9 -1, 1,0
#!perl
use tc;
sub init
{ $root = tc::Treeroot();
$camera = $root->getframe_name('camera');
$c1 = $camera->getframe_name('camera');
$c1->camera(0);
# just get the weapon for demo
$weapon = $root->getframe_name('weapons')->getframe_name('halbred');
$right = $camera->getframe_name('right');
$right->{proto} = $weapon;
$positions = $weapon->getvar_name('positions')->{data};
@positions = split /\n/, $positions;
#print $positions;
$head = $root->getpoint_name('head');
$tail = $root->getpoint_name('tail');
$weaptail = $root->getpoint_name('weaptail');
$speed = 0.01;
#$safehead = 1;
#$safetail = 1;
$head = $root->getpoint_name('head');
$tail = $root->getpoint_name('tail');
$weaptail = $root->getpoint_name('weaptail');
}
sub veclen
{ my $vec = shift;
my @vec = @$vec;
my $e, $tot;
while ($e = shift @vec)
{ $tot += $e*$e; }
sqrt ($tot);
}
&init();
sub main
{ # repeat initialization for bad perl
if ($reinit)
{ &init();
}
# interpret target position of weapon
foreach $position (@positions)
{ @command = split /\s+/, $position;
if ($button = tc::tcss_in("button", $command[1]))
{ @position = split /,\s*/, $command[2];
if ($command[0] eq 'r')
{ #@head = @position;
$head->{at}->{x} = $position[0];
$head->{at}->{y} = $position[1];
$head->{at}->{z} = $position[2];
}
elsif ($command[0] eq 'l')
{ #@tail = @position;
$tail->{at}->{x} = $position[0];
$tail->{at}->{y} = $position[1];
$tail->{at}->{z} = $position[2];
}
#print "button = $button\n";
}
}
# move weapon towards target position
# the head
$del = $head->distance($right->{x});
$del1 = $speed*$tc::tcdifftime;
#if ($del >= ($del1))
if ($del > 0.1)
{ if ($del1 > $del) { $del = $del1 = 1; }
{ $right->{x}->interpolate($right->{x}, $head, $del1/$del); }
}
if ($safehead)
{ $right->{x}->interpolate($head, $head, 0);
}
# and the tail
$weaptail->interpolate($right->{x}, $right->{at}, 2);
$del = $tail->distance($weaptail); #&veclen (\@del);
$del1 = $speed*$tc::tcdifftime;
#if ($del >= ($del1))
if ($del > 0.1)
{ if ($del1 > $del) { $del = $del1 = 1; }
{ $weaptail->interpolate($weaptail, $tail, $del1/$del) ; }
}
$right->{at}->interpolate($right->{x}, $weaptail, 0.5);
if ($safetail)
{ $right->{at}->interpolate($tail, $right->{x}, 0.5);
}
$right->renormalize();
# and move about the field
$camera->navi_key(" =-jk ", tc::tcss_in("button", ""), 5, 1);
if (tc::tcss_in("button", "q")) { tc::tcss_close_program(); }
if (tc::tcss_in("button", "c"))
{ $right->{at}->{at}->{x} = $right->{at}->{at}->{y} = $right->{at}->{at}->{z} = 0; }
$right->renormalize();
}
main