]> icculus.org git repositories - btb/d2x.git/blob - 3d/matrix.c
use the orientation parameter of g3_draw_bitmap
[btb/d2x.git] / 3d / matrix.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13 /*
14  * 
15  * Matrix setup & manipulation routines
16  * 
17  */
18  
19 #ifdef HAVE_CONFIG_H
20 #include <conf.h>
21 #endif
22
23 #include "3d.h"
24 #include "globvars.h"
25
26 void scale_matrix(void);
27
28 //set view from x,y,z & p,b,h, zoom.  Must call one of g3_set_view_*() 
29 void g3_set_view_angles(vms_vector *view_pos,vms_angvec *view_orient,fix zoom)
30 {
31         View_zoom = zoom;
32         View_position = *view_pos;
33
34         vm_angles_2_matrix(&View_matrix,view_orient);
35
36         scale_matrix();
37 }
38
39 //set view from x,y,z, viewer matrix, and zoom.  Must call one of g3_set_view_*() 
40 void g3_set_view_matrix(vms_vector *view_pos,vms_matrix *view_matrix,fix zoom)
41 {
42         View_zoom = zoom;
43         View_position = *view_pos;
44
45         View_matrix = *view_matrix;
46
47         scale_matrix();
48 }
49
50 //performs aspect scaling on global view matrix
51 void scale_matrix(void)
52 {
53         Unscaled_matrix = View_matrix;          //so we can use unscaled if we want
54
55         Matrix_scale = Window_scale;
56
57         if (View_zoom <= f1_0)          //zoom in by scaling z
58
59                 Matrix_scale.z =  fixmul(Matrix_scale.z,View_zoom);
60
61         else {                  //zoom out by scaling x&y
62
63                 fix s = fixdiv(f1_0,View_zoom);
64
65                 Matrix_scale.x = fixmul(Matrix_scale.x,s);
66                 Matrix_scale.y = fixmul(Matrix_scale.y,s);
67         }
68
69         //now scale matrix elements
70
71         vm_vec_scale(&View_matrix.rvec,Matrix_scale.x);
72         vm_vec_scale(&View_matrix.uvec,Matrix_scale.y);
73         vm_vec_scale(&View_matrix.fvec,Matrix_scale.z);
74
75 }
76