1 /* $Id: instance.c,v 1.6 2005-08-02 06:14:48 chris Exp $ */
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.
30 #define MAX_INSTANCE_DEPTH 5
32 struct instance_context {
35 } instance_stack[MAX_INSTANCE_DEPTH];
37 int instance_depth = 0;
39 //instance at specified point with specified orientation
40 //if matrix==NULL, don't modify matrix. This will be like doing an offset
41 void g3_start_instance_matrix(vms_vector *pos,vms_matrix *orient)
44 vms_matrix tempm,tempm2;
46 Assert(instance_depth<MAX_INSTANCE_DEPTH);
48 instance_stack[instance_depth].m = View_matrix;
49 instance_stack[instance_depth].p = View_position;
52 //step 1: subtract object position from view position
54 vm_vec_sub(&tempv,&View_position,pos);
59 //step 2: rotate view vector through object matrix
61 vm_vec_rotate(&View_position,&tempv,orient);
63 //step 3: rotate object matrix through view_matrix (vm = ob * vm)
65 vm_copy_transpose_matrix(&tempm2,orient);
67 vm_matrix_x_matrix(&tempm,&tempm2,&View_matrix);
73 //instance at specified point with specified orientation
74 //if angles==NULL, don't modify matrix. This will be like doing an offset
75 void g3_start_instance_angles(vms_vector *pos,vms_angvec *angles)
80 g3_start_instance_matrix(pos,NULL);
84 vm_angles_2_matrix(&tm,angles);
86 g3_start_instance_matrix(pos,&tm);
91 //pops the old context
92 void g3_done_instance()
96 Assert(instance_depth >= 0);
98 View_position = instance_stack[instance_depth].p;
99 View_matrix = instance_stack[instance_depth].m;