]> icculus.org git repositories - btb/d2x.git/blob - 3d/matrix.c
divide negative window x-coordinates properly, fixing random crashes
[btb/d2x.git] / 3d / matrix.c
1 /* $Id: matrix.c,v 1.6 2005-08-02 06:14:48 chris 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.6 2005-08-02 06:14:48 chris 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         scale_matrix();
42 }
43
44 //set view from x,y,z, viewer matrix, and zoom.  Must call one of g3_set_view_*() 
45 void g3_set_view_matrix(vms_vector *view_pos,vms_matrix *view_matrix,fix zoom)
46 {
47         View_zoom = zoom;
48         View_position = *view_pos;
49
50         View_matrix = *view_matrix;
51
52         scale_matrix();
53 }
54
55 //performs aspect scaling on global view matrix
56 void scale_matrix(void)
57 {
58         Unscaled_matrix = View_matrix;          //so we can use unscaled if we want
59
60         Matrix_scale = Window_scale;
61
62         if (View_zoom <= f1_0)          //zoom in by scaling z
63
64                 Matrix_scale.z =  fixmul(Matrix_scale.z,View_zoom);
65
66         else {                  //zoom out by scaling x&y
67
68                 fix s = fixdiv(f1_0,View_zoom);
69
70                 Matrix_scale.x = fixmul(Matrix_scale.x,s);
71                 Matrix_scale.y = fixmul(Matrix_scale.y,s);
72         }
73
74         //now scale matrix elements
75
76         vm_vec_scale(&View_matrix.rvec,Matrix_scale.x);
77         vm_vec_scale(&View_matrix.uvec,Matrix_scale.y);
78         vm_vec_scale(&View_matrix.fvec,Matrix_scale.z);
79
80 }
81