NAME

Game::3D::Vector - a vector in 3D space

SYNOPSIS

use Game::3D::Vector;

my $vec = Game::3D::Vector->new( x => 1, y => 9, z => -1 );
$vec->scale(5);
$vec->normalize();
print $vec->length();
$vec->flip(5);		# same as scale(-1)

EXPORTS

Exports nothing on default.

DESCRIPTION

This package provides a base class for vectors in 3D space, including the ability to manipulate (rotate, translate, scale, normalize) them.

METHODS

new()
my $vector = Game::3D::Vector->new( $arguments );

Creates a new vector. The arguments are the x,y and z components like:

my $vector = Game::3D::Vector->new( x => 9, y => -8.1, z => -2);
id()

Return the vectors's unique id.

x()
print $vector->x();
$vector->x(123);

Set and return or just return the vector's X component.

y()
print $vector->y();
$vector->y(123);

Set and return or just return the vector's Y component.

z()
print $vector->z();
$vector->z(123);

Set and return or just return the vector's Z component.

pos()
print join (" ", $vector->pos());
$vector->pos(123,456,-1);		# set X,Y and Z
$vector->pos(undef,undef,1);		# set only Z

Set and return or just return the vector's components.

length()
$vector->length();

Returns the vectors length.

normalize()
$vector->normalize();

Normalizes the length of the vector to 1.0.

scale()
$vector->scale($factor);

Scales the vector by this factor.

flip()
$vector->flip();

Makes the vector point backward, e.g. is equivalent to $vector-scale(-1);>.

translate()
$vector->translate($x,$y,$z);

Translates the vector in X, Y and Z direction. Undef values are the same as 0, e.g. leave that axis alone:

$vector->translate(1,undef,2);

is the same as:

$vecotr->translate(1,0,2);
rotate()
$vector->rotate($xr,$yr,$zr);

Rotates the vector around the X, Y and Z axis (in that order). The arguments are expected to be passed in radians.

AUTHORS

(c) 2003, Tels <http://bloodgate.com/>

SEE ALSO

Game::3D::Point, SDL:App::FPS, SDL::App and SDL.