]> icculus.org git repositories - btb/d2x.git/blob - 3d/instance.c
remove rcs tags
[btb/d2x.git] / 3d / instance.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  * Instancing routines
16  * 
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include <conf.h>
21 #endif
22
23 #include <stdlib.h>
24 #include "error.h"
25
26 #include "3d.h"
27 #include "globvars.h"
28
29 #define MAX_INSTANCE_DEPTH      5
30
31 struct instance_context {
32         vms_matrix m;
33         vms_vector p;
34 } instance_stack[MAX_INSTANCE_DEPTH];
35
36 int instance_depth = 0;
37
38 //instance at specified point with specified orientation
39 //if matrix==NULL, don't modify matrix.  This will be like doing an offset   
40 void g3_start_instance_matrix(vms_vector *pos,vms_matrix *orient)
41 {
42         vms_vector tempv;
43         vms_matrix tempm,tempm2;
44
45         Assert(instance_depth<MAX_INSTANCE_DEPTH);
46
47         instance_stack[instance_depth].m = View_matrix;
48         instance_stack[instance_depth].p = View_position;
49         instance_depth++;
50
51         //step 1: subtract object position from view position
52
53         vm_vec_sub(&tempv,&View_position,pos);
54
55
56         if (orient) {
57
58                 //step 2: rotate view vector through object matrix
59
60                 vm_vec_rotate(&View_position,&tempv,orient);
61
62                 //step 3: rotate object matrix through view_matrix (vm = ob * vm)
63
64                 vm_copy_transpose_matrix(&tempm2,orient);
65
66                 vm_matrix_x_matrix(&tempm,&tempm2,&View_matrix);
67                 View_matrix = tempm;
68         }
69 }
70
71
72 //instance at specified point with specified orientation
73 //if angles==NULL, don't modify matrix.  This will be like doing an offset
74 void g3_start_instance_angles(vms_vector *pos,vms_angvec *angles)
75 {
76         vms_matrix tm;
77
78         if (angles==NULL) {
79                 g3_start_instance_matrix(pos,NULL);
80                 return;
81         }
82
83         vm_angles_2_matrix(&tm,angles);
84
85         g3_start_instance_matrix(pos,&tm);
86
87 }
88
89
90 //pops the old context
91 void g3_done_instance()
92 {
93         instance_depth--;
94
95         Assert(instance_depth >= 0);
96
97         View_position = instance_stack[instance_depth].p;
98         View_matrix = instance_stack[instance_depth].m;
99 }
100
101