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