NAME
Games::3D::Model - load/render 3D models
SYNOPSIS
use Games::3D::Model;
my $model = Games::3D::Model->new(
file => 'ogre.md2', type => 'MD2' );
$model->render_frame(0);
EXPORTS
Exports nothing on default.
DESCRIPTION
This package let's you load and render (via OpenGL) 3D models based on various file formats (these are realized as subclasses).
METHODS
- new()
-
my $model = Games::3D::Model->new( $args );
Load a model into memory and return an object reference.
$args
is a hash ref containing the following keys:file filename of model type 'MD2' etc
- render_frame()
-
$model->render_frame($frame_num);
Render one frame from the model.
- frames()
-
$model->frames();
Return the number of frames in the model.
- time_warp()
-
print $model->time_warp(); $model->time_warp(1);
Set/get the model's local time_warp factor. This factor is used to adjust the animation speed of the model on top of the speed of the overall timeflow. So you can make some models run faster and others slower, depending on whatever information you want.
The default is 1. The factor should be > 0.01 and < 100, although values between 0.1 and 10 work best.
- render()
-
$model->render($current_time); # at current time $model->render($current_time,$time_warp); # faster/slower
Renders the a morphed frame of the model, between the current frame and the next frame bases on the current time. This will loop frame in the current state, see state() on how to change to the next state.
The optional parameter time_warp will be multiplied with the model's default time_warp, so you can make different instances of one model (e.g. each guard in your game) render in a different speed. This avoids the "syncronus" look of groupds of the same type of models. Values would, f.i. be between 0.9 and 1.10 to make the different guards slower or faster.
- color()
-
$rgb = $model->color(); # [$r,$g, $b ] $model->color(1,0.1,0.8); # set RGB $model->color(undef); # random color (default)
Sets the color, that will be set to render the model. The random color setting means each triangle will get a random RGB color.
- alpha()
-
$a = $model->alpha(); # $a $model->color(0.8); # set A $model->alpha(undef); # set's it to 1.0 (seems an OpenGL # specific set because # glColor($r,$g,$b) also sets $a == 1
Sets the alpha value. Only usefull when using blending (e.g. transparency).
- current_frame()
-
$frame = $model->current_frame();
Returns the index number of the current frame.
- last_frame()
-
$frame = $model->last_frame();
Returns the index number of the last rendered frame.
KNOWN BUGS
Currently the model is loaded as soon as the object is constructed. In some cases however it might be better to do a delayed loading of models, like when the player never sees a certain model because it is in a far-away spot of the level for a long time. This can be fixed in each subclass.
AUTHORS
(c) 2003 Tels <http://bloodgate.com/>
SEE ALSO
Games::3D, SDL:App::FPS, and SDL::OpenGL.