| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  | * $Id: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. The Blender | 
					
						
							|  |  |  |  * Foundation also sells licenses for use in proprietary software under | 
					
						
							|  |  |  |  * the Blender License.  See http://www.blender.org/BL/ for information
 | 
					
						
							|  |  |  |  * about this. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2005 Blender Foundation | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is: all of this file. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): none yet. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <math.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							|  |  |  | #include <config.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef WIN32
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #include <io.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_armature_types.h"
 | 
					
						
							|  |  |  | #include "DNA_curve_types.h"
 | 
					
						
							|  |  |  | #include "DNA_lattice_types.h"
 | 
					
						
							|  |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							|  |  |  | #include "DNA_meta_types.h"
 | 
					
						
							|  |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | #include "DNA_screen_types.h"
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							|  |  |  | #include "DNA_space_types.h"
 | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | #include "DNA_userdef_types.h"
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | #include "DNA_view3d_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | #include "BKE_armature.h"
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | #include "BKE_global.h"
 | 
					
						
							|  |  |  | #include "BKE_lattice.h"
 | 
					
						
							|  |  |  | #include "BKE_object.h"
 | 
					
						
							|  |  |  | #include "BKE_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_arithb.h"
 | 
					
						
							|  |  |  | #include "BLI_editVert.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BIF_editarmature.h"
 | 
					
						
							|  |  |  | #include "BIF_gl.h"
 | 
					
						
							|  |  |  | #include "BIF_mywindow.h"
 | 
					
						
							|  |  |  | #include "BIF_resources.h"
 | 
					
						
							|  |  |  | #include "BIF_screen.h"
 | 
					
						
							|  |  |  | #include "BIF_space.h"
 | 
					
						
							|  |  |  | #include "BIF_transform.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BSE_edit.h"
 | 
					
						
							|  |  |  | #include "BSE_view.h"
 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | #include "BDR_drawobject.h"
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "blendef.h"
 | 
					
						
							|  |  |  | #include "transform.h"
 | 
					
						
							| 
									
										
										
										
											2005-03-20 02:00:16 +00:00
										 |  |  | #include "transform_generics.h"
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | /* return codes for select, and drawing flags */ | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define MAN_TRANS_X		1
 | 
					
						
							|  |  |  | #define MAN_TRANS_Y		2
 | 
					
						
							|  |  |  | #define MAN_TRANS_Z		4
 | 
					
						
							|  |  |  | #define MAN_TRANS_C		7
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MAN_ROT_X		8
 | 
					
						
							|  |  |  | #define MAN_ROT_Y		16
 | 
					
						
							|  |  |  | #define MAN_ROT_Z		32
 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | #define MAN_ROT_V		64
 | 
					
						
							|  |  |  | #define MAN_ROT_T		128
 | 
					
						
							|  |  |  | #define MAN_ROT_C		248
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MAN_SCALE_X		256
 | 
					
						
							|  |  |  | #define MAN_SCALE_Y		512
 | 
					
						
							|  |  |  | #define MAN_SCALE_Z		1024
 | 
					
						
							|  |  |  | #define MAN_SCALE_C		1792
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | /* color codes */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MAN_RGB		0
 | 
					
						
							|  |  |  | #define MAN_GREY	1
 | 
					
						
							|  |  |  | #define MAN_MOVECOL	2
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* GLOBAL VARIABLE THAT SHOULD MOVED TO SCREEN MEMBER OR SOMETHING  */ | 
					
						
							|  |  |  | extern TransInfo Trans; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-27 19:54:18 +00:00
										 |  |  | static int is_mat4_flipped(float mat[][4]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float vec[3]; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	Crossf(vec, mat[0], mat[1]); | 
					
						
							|  |  |  | 	if( Inpf(vec, mat[2]) < 0.0 ) return 1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | }	 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | /* transform widget center calc helper for below */ | 
					
						
							|  |  |  | static void calc_tw_center(float *co) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float *twcent= G.scene->twcent; | 
					
						
							|  |  |  | 	float *min= G.scene->twmin; | 
					
						
							|  |  |  | 	float *max= G.scene->twmax; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	DO_MINMAX(co, min, max); | 
					
						
							|  |  |  | 	VecAddf(twcent, twcent, co); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | /* callback */ | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | static void stats_pose(ListBase *lb, float *normal, float *plane) | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Bone *bone; | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 	float vec[3], mat[4][4]; | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	for(bone= lb->first; bone; bone= bone->next) { | 
					
						
							|  |  |  | 		if (bone->flag & BONE_SELECTED) { | 
					
						
							|  |  |  | 			/* We don't let IK children get "grabbed" */ | 
					
						
							|  |  |  | 			/* ALERT! abusive global Trans here */ | 
					
						
							|  |  |  | 			if ( (Trans.mode!=TFM_TRANSLATION) || (bone->flag & BONE_IK_TOPARENT)==0 ) { | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				get_bone_root_pos (bone, vec, 1); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				calc_tw_center(vec); | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 				where_is_bone(G.obpose, bone); | 
					
						
							|  |  |  | 				get_objectspace_bone_matrix(bone, mat, 1, 1);	// points in negative Y o_O
 | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 				VecAddf(normal, normal, mat[2]); | 
					
						
							|  |  |  | 				VecAddf(plane, plane, mat[1]); | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | 				return;	// see above function
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 		stats_pose(&bone->childbase, normal, plane); | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* centroid, boundbox, of selection */ | 
					
						
							|  |  |  | /* returns total items selected */ | 
					
						
							|  |  |  | static int calc_manipulator(ScrArea *sa) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	extern ListBase editNurb; | 
					
						
							|  |  |  | 	View3D *v3d= sa->spacedata.first; | 
					
						
							|  |  |  | 	Base *base; | 
					
						
							|  |  |  | 	Object *ob=NULL; | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 	float normal[3]={0.0, 0.0, 0.0}; | 
					
						
							|  |  |  | 	float plane[3]={0.0, 0.0, 0.0}; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	int a, totsel=0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* transform widget matrix */ | 
					
						
							|  |  |  | 	Mat4One(v3d->twmat); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* transform widget centroid/center */ | 
					
						
							|  |  |  | 	G.scene->twcent[0]= G.scene->twcent[1]= G.scene->twcent[2]= 0.0f; | 
					
						
							|  |  |  | 	INIT_MINMAX(G.scene->twmin, G.scene->twmax); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(G.obedit) { | 
					
						
							|  |  |  | 		ob= G.obedit; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if(G.obedit->type==OB_MESH) { | 
					
						
							|  |  |  | 			EditMesh *em = G.editMesh; | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			EditVert *eve; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			for(eve= em->verts.first; eve; eve= eve->next) { | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 				if(eve->f & SELECT) { | 
					
						
							|  |  |  | 					totsel++; | 
					
						
							|  |  |  | 					calc_tw_center(eve->co); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			if(v3d->twmode == V3D_MANIP_NORMAL) { | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 				EditFace *efa; | 
					
						
							|  |  |  | 				float vec[3]; | 
					
						
							|  |  |  | 				for(efa= em->faces.first; efa; efa= efa->next) { | 
					
						
							|  |  |  | 					if(efa->f & SELECT) { | 
					
						
							|  |  |  | 						VecAddf(normal, normal, efa->n); | 
					
						
							|  |  |  | 						VecSubf(vec, efa->v2->co, efa->v1->co); | 
					
						
							|  |  |  | 						VecAddf(plane, plane, vec); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if (G.obedit->type==OB_ARMATURE){ | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			EditBone *ebo; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 			for (ebo=G.edbo.first;ebo;ebo=ebo->next){ | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				//	If this is an IK child and it's parent is being moved, don't count as selected
 | 
					
						
							|  |  |  | 				if ((ebo->flag & BONE_IK_TOPARENT)&& (ebo->flag & BONE_ROOTSEL) && ebo->parent && (ebo->parent->flag & BONE_TIPSEL)); | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					if (ebo->flag & BONE_TIPSEL) { | 
					
						
							|  |  |  | 						calc_tw_center(ebo->tail); | 
					
						
							|  |  |  | 						totsel++; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					if (ebo->flag & BONE_ROOTSEL) { | 
					
						
							|  |  |  | 						calc_tw_center(ebo->head); | 
					
						
							|  |  |  | 						totsel++; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if ELEM3(G.obedit->type, OB_CURVE, OB_SURF, OB_FONT) { | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			Nurb *nu; | 
					
						
							|  |  |  | 			BezTriple *bezt; | 
					
						
							|  |  |  | 			BPoint *bp; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 			nu= editNurb.first; | 
					
						
							|  |  |  | 			while(nu) { | 
					
						
							|  |  |  | 				if((nu->type & 7)==CU_BEZIER) { | 
					
						
							|  |  |  | 					bezt= nu->bezt; | 
					
						
							|  |  |  | 					a= nu->pntsu; | 
					
						
							|  |  |  | 					while(a--) { | 
					
						
							|  |  |  | 						if(bezt->f1) { | 
					
						
							|  |  |  | 							calc_tw_center(bezt->vec[0]); | 
					
						
							|  |  |  | 							totsel++; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						if(bezt->f2) { | 
					
						
							|  |  |  | 							calc_tw_center(bezt->vec[1]); | 
					
						
							|  |  |  | 							totsel++; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						if(bezt->f3) { | 
					
						
							|  |  |  | 							calc_tw_center(bezt->vec[2]); | 
					
						
							|  |  |  | 							totsel++; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						bezt++; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					bp= nu->bp; | 
					
						
							|  |  |  | 					a= nu->pntsu*nu->pntsv; | 
					
						
							|  |  |  | 					while(a--) { | 
					
						
							|  |  |  | 						if(bp->f1 & 1) { | 
					
						
							|  |  |  | 							calc_tw_center(bp->vec); | 
					
						
							|  |  |  | 							totsel++; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						bp++; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				nu= nu->next; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(G.obedit->type==OB_MBALL) { | 
					
						
							|  |  |  | 			/* editmball.c */ | 
					
						
							|  |  |  | 			extern ListBase editelems;  /* go away ! */ | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			MetaElem *ml; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 			ml= editelems.first; | 
					
						
							|  |  |  | 			while(ml) { | 
					
						
							|  |  |  | 				if(ml->flag & SELECT) { | 
					
						
							|  |  |  | 					calc_tw_center(&ml->x); | 
					
						
							|  |  |  | 					totsel++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				ml= ml->next; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(G.obedit->type==OB_LATTICE) { | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			BPoint *bp; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 			bp= editLatt->def; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw; | 
					
						
							|  |  |  | 			while(a--) { | 
					
						
							|  |  |  | 				if(bp->f1 & 1) { | 
					
						
							|  |  |  | 					calc_tw_center(bp->vec); | 
					
						
							|  |  |  | 					totsel++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				bp++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* selection center */ | 
					
						
							|  |  |  | 		if(totsel) { | 
					
						
							|  |  |  | 			VecMulf(G.scene->twcent, 1.0f/(float)totsel);	// centroid!
 | 
					
						
							|  |  |  | 			Mat4MulVecfl(G.obedit->obmat, G.scene->twcent); | 
					
						
							|  |  |  | 			Mat4MulVecfl(G.obedit->obmat, G.scene->twmin); | 
					
						
							|  |  |  | 			Mat4MulVecfl(G.obedit->obmat, G.scene->twmax); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(G.obpose) { | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | 		bArmature *arm= G.obpose->data; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 		ob= G.obpose; | 
					
						
							|  |  |  | 		Trans.mode= TFM_ROTATION;	// mislead counting bones... bah
 | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | 		/* count total */ | 
					
						
							|  |  |  | 		count_bone_select(&arm->bonebase, &totsel); | 
					
						
							|  |  |  | 		if(totsel) { | 
					
						
							|  |  |  | 			/* recursive get stats */ | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			stats_pose(&arm->bonebase, normal, plane); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			//VecMulf(normal, -1.0);
 | 
					
						
							|  |  |  | 			VecMulf(plane, -1.0); | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			VecMulf(G.scene->twcent, 1.0f/(float)totsel);	// centroid!
 | 
					
						
							|  |  |  | 			Mat4MulVecfl(G.obpose->obmat, G.scene->twcent); | 
					
						
							|  |  |  | 			Mat4MulVecfl(G.obpose->obmat, G.scene->twmin); | 
					
						
							|  |  |  | 			Mat4MulVecfl(G.obpose->obmat, G.scene->twmax); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if(G.f & (G_FACESELECT + G_VERTEXPAINT + G_TEXTUREPAINT +G_WEIGHTPAINT)) { | 
					
						
							|  |  |  | 		; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 		/* we need the one selected object, if its not active */ | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		ob= OBACT; | 
					
						
							|  |  |  | 		if(ob && !(ob->flag & SELECT)) ob= NULL; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		base= (G.scene->base.first); | 
					
						
							|  |  |  | 		while(base) { | 
					
						
							|  |  |  | 			if(v3d->lay & base->lay) { | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				if(base->flag & SELECT) { | 
					
						
							|  |  |  | 					if(ob==NULL) ob= base->object; | 
					
						
							|  |  |  | 					calc_tw_center(base->object->obmat[3]); | 
					
						
							|  |  |  | 					totsel++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			base= base->next; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* selection center */ | 
					
						
							|  |  |  | 		if(totsel) { | 
					
						
							|  |  |  | 			VecMulf(G.scene->twcent, 1.0f/(float)totsel);	// centroid!
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* global, local or normal orientation? */ | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 	if(ob && totsel) { | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		switch(v3d->twmode) { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		case V3D_MANIP_GLOBAL: | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		case V3D_MANIP_NORMAL: | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			if(G.obedit || G.obpose) { | 
					
						
							|  |  |  | 				if(normal[0]!=0.0 || normal[1]!=0.0 || normal[2]!=0.0) { | 
					
						
							|  |  |  | 					float mat[3][3]; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					Normalise(normal); | 
					
						
							|  |  |  | 					Normalise(plane); | 
					
						
							|  |  |  | 					VECCOPY(mat[2], normal); | 
					
						
							|  |  |  | 					Crossf(mat[0], normal, plane); | 
					
						
							|  |  |  | 					Crossf(mat[1], mat[2], mat[0]); | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					Mat4MulMat43(v3d->twmat, ob->obmat, mat); | 
					
						
							|  |  |  | 					Mat4Ortho(v3d->twmat); | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* no break we define 'normal' as 'local' in Object mode */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		case V3D_MANIP_LOCAL: | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			if(totsel==1 || v3d->around==V3D_LOCAL || G.obedit || G.obpose) { | 
					
						
							|  |  |  | 				Mat4CpyMat4(v3d->twmat, ob->obmat); | 
					
						
							|  |  |  | 				Mat4Ortho(v3d->twmat); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		}		 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	    | 
					
						
							|  |  |  | 	return totsel; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | /* ******************** DRAWING STUFFIES *********** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* radring = radius of donut rings
 | 
					
						
							|  |  |  |    radhole = radius hole | 
					
						
							|  |  |  |    start = starting segment (based on nrings) | 
					
						
							|  |  |  |    end   = end segment | 
					
						
							|  |  |  |    nsides = amount of points in ring | 
					
						
							|  |  |  |    nrigns = amount of rings | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static void partial_donut(float radring, float radhole, int start, int end, int nsides, int nrings) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float theta, phi, theta1; | 
					
						
							|  |  |  | 	float cos_theta, sin_theta; | 
					
						
							|  |  |  | 	float cos_theta1, sin_theta1; | 
					
						
							|  |  |  | 	float ring_delta, side_delta; | 
					
						
							|  |  |  | 	int i, j; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	ring_delta= 2.0*M_PI/(float)nrings; | 
					
						
							|  |  |  | 	side_delta= 2.0*M_PI/(float)nsides; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	theta= M_PI+0.5*ring_delta; | 
					
						
							|  |  |  | 	cos_theta= cos(theta); | 
					
						
							|  |  |  | 	sin_theta= sin(theta); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	for(i= nrings - 1; i >= 0; i--) { | 
					
						
							|  |  |  | 		theta1= theta + ring_delta; | 
					
						
							|  |  |  | 		cos_theta1= cos(theta1); | 
					
						
							|  |  |  | 		sin_theta1= sin(theta1); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if(i==start) {	// cap
 | 
					
						
							|  |  |  | 			glBegin(GL_POLYGON); | 
					
						
							|  |  |  | 			glNormal3f(-sin_theta1, -cos_theta1, 0.0); | 
					
						
							|  |  |  | 			phi= 0.0; | 
					
						
							|  |  |  | 			for(j= nsides; j >= 0; j--) { | 
					
						
							|  |  |  | 				float cos_phi, sin_phi, dist; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				phi += side_delta; | 
					
						
							|  |  |  | 				cos_phi= cos(phi); | 
					
						
							|  |  |  | 				sin_phi= sin(phi); | 
					
						
							|  |  |  | 				dist= radhole + radring * cos_phi; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				glVertex3f(cos_theta1 * dist, -sin_theta1 * dist,  radring * sin_phi); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			glEnd(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(i>=start && i<=end) { | 
					
						
							|  |  |  | 			glBegin(GL_QUAD_STRIP); | 
					
						
							|  |  |  | 			phi= 0.0; | 
					
						
							|  |  |  | 			for(j= nsides; j >= 0; j--) { | 
					
						
							|  |  |  | 				float cos_phi, sin_phi, dist; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				phi += side_delta; | 
					
						
							|  |  |  | 				cos_phi= cos(phi); | 
					
						
							|  |  |  | 				sin_phi= sin(phi); | 
					
						
							|  |  |  | 				dist= radhole + radring * cos_phi; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				glNormal3f(cos_theta1 * cos_phi, -sin_theta1 * cos_phi, sin_phi); | 
					
						
							|  |  |  | 				glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi); | 
					
						
							|  |  |  | 				glNormal3f(cos_theta * cos_phi, -sin_theta * cos_phi, sin_phi); | 
					
						
							|  |  |  | 				glVertex3f(cos_theta * dist, -sin_theta * dist,  radring * sin_phi); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			glEnd(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if(i==end) {	// cap
 | 
					
						
							|  |  |  | 			glBegin(GL_POLYGON); | 
					
						
							|  |  |  | 			glNormal3f(sin_theta, cos_theta, 0.0); | 
					
						
							|  |  |  | 			phi= 0.0; | 
					
						
							|  |  |  | 			for(j= nsides; j >= 0; j--) { | 
					
						
							|  |  |  | 				float cos_phi, sin_phi, dist; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				phi -= side_delta; | 
					
						
							|  |  |  | 				cos_phi= cos(phi); | 
					
						
							|  |  |  | 				sin_phi= sin(phi); | 
					
						
							|  |  |  | 				dist= radhole + radring * cos_phi; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				glVertex3f(cos_theta * dist, -sin_theta * dist,  radring * sin_phi); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			glEnd(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		theta= theta1; | 
					
						
							|  |  |  | 		cos_theta= cos_theta1; | 
					
						
							|  |  |  | 		sin_theta= sin_theta1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | /* three colors can be set;
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  |    grey for ghosting | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  |    moving: in transform theme color | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  |    else the red/green/blue | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | static void manipulator_setcolor(char axis, int colcode) | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float vec[4]; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	vec[3]= 0.7; // alpha set on 0.5, can be glEnabled or not
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	if(colcode==MAN_GREY) { | 
					
						
							|  |  |  | 		if(axis > 'Z') glColor4ub(0, 0, 0, 70); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		else { | 
					
						
							|  |  |  | 			vec[0]= vec[1]= vec[2]= 1.0; vec[3]= 0.3; | 
					
						
							|  |  |  | 			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, vec); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	else if(colcode==MAN_MOVECOL) { | 
					
						
							|  |  |  | 		if(axis > 'Z') BIF_ThemeColor(TH_TRANSFORM); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		else { | 
					
						
							|  |  |  | 			BIF_GetThemeColor3fv(TH_TRANSFORM, vec); | 
					
						
							|  |  |  | 			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, vec); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		switch(axis) { | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		case 'x': | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 			glColor3ub(255, 0, 100); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 'y': | 
					
						
							|  |  |  | 			glColor3ub(100, 255, 100); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'z': | 
					
						
							|  |  |  | 			glColor3ub(50, 50, 225); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'X': | 
					
						
							|  |  |  | 			vec[2]= vec[1]= 0.0; vec[0]= 1.0; | 
					
						
							|  |  |  | 			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, vec); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'Y': | 
					
						
							|  |  |  | 			vec[0]= vec[2]= 0.0; vec[1]= 1.0; | 
					
						
							|  |  |  | 			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, vec); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'Z': | 
					
						
							|  |  |  | 			vec[0]= vec[1]= 0.0; vec[2]= 1.0; | 
					
						
							|  |  |  | 			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, vec); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		case 'C': | 
					
						
							|  |  |  | 			BIF_GetThemeColor3fv(TH_TRANSFORM, vec); | 
					
						
							|  |  |  | 			if(G.vd->twmode == V3D_MANIP_LOCAL) {vec[0]+= 0.25; vec[1]+=0.25; vec[2]+=0.25;} | 
					
						
							|  |  |  | 			else if(G.vd->twmode == V3D_MANIP_NORMAL) {vec[0]-= 0.2; vec[1]-=0.2; vec[2]-=0.2;} | 
					
						
							|  |  |  | 			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, vec); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | /* viewmatrix should have been set OK, also no shademode! */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | static void draw_manipulator_axes(int colcode, int flagx, int flagy, int flagz) | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* axes */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(flagx) { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('x', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		glBegin(GL_LINES); | 
					
						
							|  |  |  | 		glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 		glVertex3f(1.0, 0.0, 0.0); | 
					
						
							|  |  |  | 		glEnd(); | 
					
						
							|  |  |  | 	}		 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(flagy) { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('y', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		glBegin(GL_LINES); | 
					
						
							|  |  |  | 		glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 		glVertex3f(0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 		glEnd(); | 
					
						
							|  |  |  | 	}		 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(flagz) { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('z', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		glBegin(GL_LINES); | 
					
						
							|  |  |  | 		glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 		glVertex3f(0.0, 0.0, 1.0); | 
					
						
							|  |  |  | 		glEnd(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* only called while G.moving */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | static void draw_manipulator_rotate_ghost(float mat[][4], int drawflags) | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	GLUquadricObj *qobj= gluNewQuadric();  | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	float size, phi, vec[3], matt[4][4], cross[3]; | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	glDisable(GL_DEPTH_TEST); | 
					
						
							|  |  |  | 	gluQuadricDrawStyle(qobj, GLU_FILL);  | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glColor4ub(0,0,0,64); | 
					
						
							|  |  |  | 	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); | 
					
						
							|  |  |  | 	glEnable(GL_BLEND); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 	/* we need both [4][4] transforms, Trans.mat seems to be premul, not post for mat[][4] */ | 
					
						
							|  |  |  | 	Mat4CpyMat4(matt, mat); // to copy the parts outside of [3][3]
 | 
					
						
							|  |  |  | 	Mat4MulMat34(matt, Trans.mat, mat); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Screen aligned view rot circle */ | 
					
						
							|  |  |  | 	if(drawflags & MAN_ROT_V) { | 
					
						
							|  |  |  | 		float startphi; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* prepare for screen aligned draw */ | 
					
						
							|  |  |  | 		VECCOPY(vec, mat[0]); | 
					
						
							|  |  |  | 		size= Normalise(vec); | 
					
						
							|  |  |  | 		glPushMatrix(); | 
					
						
							|  |  |  | 		glTranslatef(mat[3][0], mat[3][1], mat[3][2]); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* sets view screen aligned */ | 
					
						
							|  |  |  | 		glRotatef( -360.0*saacos(G.vd->viewquat[0])/M_PI, G.vd->viewquat[1], G.vd->viewquat[2], G.vd->viewquat[3]); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		vec[0]= Trans.imval[0] - Trans.center2d[0]; | 
					
						
							|  |  |  | 		vec[1]= Trans.imval[1] - Trans.center2d[1]; | 
					
						
							|  |  |  | 		vec[2]= 0.0; | 
					
						
							|  |  |  | 		Normalise(vec); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		startphi= saacos( vec[1] ); | 
					
						
							|  |  |  | 		if(vec[0]<0.0) startphi= -startphi; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		phi= fmod(-180.0*Trans.val/M_PI, 360.0); | 
					
						
							|  |  |  | 		if(phi > 180.0) phi-= 360.0; | 
					
						
							|  |  |  | 		else if(phi<-180.0) phi+= 360.0; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		gluPartialDisk(qobj, 0.0, size, 32, 1, 180.0*startphi/M_PI, phi); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		glPopMatrix(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	mymultmatrix(mat);	// aligns with original widget
 | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* Z disk */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_ROT_Z) { | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		VECCOPY(vec, mat[0]);	// use x axis to detect rotation
 | 
					
						
							|  |  |  | 		Normalise(vec); | 
					
						
							|  |  |  | 		Normalise(matt[0]); | 
					
						
							|  |  |  | 		phi= saacos( Inpf(vec, matt[0]) ); | 
					
						
							|  |  |  | 		if(phi!=0.0) { | 
					
						
							|  |  |  | 			Crossf(cross, vec, matt[0]);	// results in z vector
 | 
					
						
							|  |  |  | 			if(Inpf(cross, mat[2]) > 0.0) phi= -phi; | 
					
						
							|  |  |  | 			gluPartialDisk(qobj, 0.0, 1.0, 32, 1, 90.0, 180.0*phi/M_PI); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* X disk */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_ROT_X) { | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		VECCOPY(vec, mat[1]);	// use y axis to detect rotation
 | 
					
						
							|  |  |  | 		Normalise(vec); | 
					
						
							|  |  |  | 		Normalise(matt[1]); | 
					
						
							|  |  |  | 		phi= saacos( Inpf(vec, matt[1]) ); | 
					
						
							|  |  |  | 		if(phi!=0.0) { | 
					
						
							|  |  |  | 			Crossf(cross, vec, matt[1]);	// results in x vector
 | 
					
						
							|  |  |  | 			if(Inpf(cross, mat[0]) > 0.0) phi= -phi; | 
					
						
							|  |  |  | 			glRotatef(90.0, 0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 			gluPartialDisk(qobj, 0.0, 1.0, 32, 1, 0.0, 180.0*phi/M_PI); | 
					
						
							|  |  |  | 			glRotatef(-90.0, 0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}	 | 
					
						
							|  |  |  | 	/* Y circle */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_ROT_Y) { | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		VECCOPY(vec, mat[2]);	// use z axis to detect rotation
 | 
					
						
							|  |  |  | 		Normalise(vec); | 
					
						
							|  |  |  | 		Normalise(matt[2]); | 
					
						
							|  |  |  | 		phi= saacos( Inpf(vec, matt[2]) ); | 
					
						
							|  |  |  | 		if(phi!=0.0) { | 
					
						
							|  |  |  | 			Crossf(cross, vec, matt[2]);	// results in y vector
 | 
					
						
							|  |  |  | 			if(Inpf(cross, mat[1]) > 0.0) phi= -phi; | 
					
						
							|  |  |  | 			glRotatef(-90.0, 1.0, 0.0, 0.0); | 
					
						
							|  |  |  | 			gluPartialDisk(qobj, 0.0, 1.0, 32, 1, 180.0, 180.0*phi/M_PI); | 
					
						
							|  |  |  | 			glRotatef(90.0, 1.0, 0.0, 0.0); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	glDisable(GL_BLEND); | 
					
						
							|  |  |  | 	myloadmatrix(G.vd->viewmat); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | static void draw_manipulator_rotate(float mat[][4], int moving, int drawflags, int combo) | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 	GLUquadricObj *qobj= gluNewQuadric();  | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	double plane[4]; | 
					
						
							|  |  |  | 	float size, vec[3], unitmat[4][4]; | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 	float cywid= 0.33f*0.01f*(float)U.tw_handlesize;	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	float cusize= cywid*0.65; | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 	int arcs= (G.rt==2); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	int colcode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(moving) colcode= MAN_MOVECOL; | 
					
						
							|  |  |  | 	else colcode= MAN_RGB; | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	if(G.rt==3) cusize= cywid*0.3; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* when called while moving in mixed mode, do not draw when... */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if((drawflags & MAN_ROT_C)==0) return; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	/* Init stuff */ | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	glDisable(GL_DEPTH_TEST); | 
					
						
							|  |  |  | 	Mat4One(unitmat); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	gluQuadricDrawStyle(qobj, GLU_FILL);  | 
					
						
							|  |  |  | 	gluQuadricNormals(qobj, GLU_SMOOTH); | 
					
						
							|  |  |  | 	glEnable(GL_CULL_FACE);		// backface removal
 | 
					
						
							|  |  |  | 	glShadeModel(GL_SMOOTH); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 22:03:14 +00:00
										 |  |  | 	/* prepare for screen aligned draw */ | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	VECCOPY(vec, mat[0]); | 
					
						
							|  |  |  | 	size= Normalise(vec); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	glPushMatrix(); | 
					
						
							|  |  |  | 	glTranslatef(mat[3][0], mat[3][1], mat[3][2]); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	if(arcs) { | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		/* clipplane makes nice handles, calc here because of multmatrix but with translate! */ | 
					
						
							|  |  |  | 		VECCOPY(plane, G.vd->viewinv[2]); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 		plane[3]= -0.1; // clip more
 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		glClipPlane(GL_CLIP_PLANE0, plane); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-19 22:03:14 +00:00
										 |  |  | 	/* sets view screen aligned */ | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	glRotatef( -360.0*saacos(G.vd->viewquat[0])/M_PI, G.vd->viewquat[1], G.vd->viewquat[2], G.vd->viewquat[3]); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 22:03:14 +00:00
										 |  |  | 	/* Screen aligned help circle */ | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	if(arcs) { | 
					
						
							|  |  |  | 		if((G.f & G_PICKSEL)==0) { | 
					
						
							|  |  |  | 			BIF_ThemeColorShade(TH_BACK, -30); | 
					
						
							|  |  |  | 			drawcircball(unitmat[3], size, unitmat); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	/* Screen aligned view rot circle */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_ROT_V) { | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_ROT_V); | 
					
						
							|  |  |  | 		BIF_ThemeColor(TH_TRANSFORM); | 
					
						
							|  |  |  | 		drawcircball(unitmat[3], 1.2*size, unitmat); | 
					
						
							| 
									
										
										
										
											2005-03-19 22:03:14 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(moving) {	 | 
					
						
							| 
									
										
										
										
											2005-03-19 22:03:14 +00:00
										 |  |  | 			float vec[3]; | 
					
						
							|  |  |  | 			vec[0]= Trans.imval[0] - Trans.center2d[0]; | 
					
						
							|  |  |  | 			vec[1]= Trans.imval[1] - Trans.center2d[1]; | 
					
						
							|  |  |  | 			vec[2]= 0.0; | 
					
						
							|  |  |  | 			Normalise(vec); | 
					
						
							|  |  |  | 			VecMulf(vec, 1.2*size); | 
					
						
							|  |  |  | 			glBegin(GL_LINES); | 
					
						
							|  |  |  | 			glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 			glVertex3fv(vec); | 
					
						
							|  |  |  | 			glEnd(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	glPopMatrix(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* apply the transform delta */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(moving) { | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		float matt[4][4]; | 
					
						
							|  |  |  | 		Mat4CpyMat4(matt, mat); // to copy the parts outside of [3][3]
 | 
					
						
							|  |  |  | 		Mat4MulMat34(matt, Trans.mat, mat); | 
					
						
							|  |  |  | 		mymultmatrix(matt); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		glFrontFace( is_mat4_flipped(matt)?GL_CW:GL_CCW); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		glFrontFace( is_mat4_flipped(mat)?GL_CW:GL_CCW); | 
					
						
							|  |  |  | 		mymultmatrix(mat); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	/* axes */ | 
					
						
							|  |  |  | 	if(arcs==0) { | 
					
						
							|  |  |  | 		if(!(G.f & G_PICKSEL)) { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			if( (combo & V3D_MANIP_SCALE)==0) { | 
					
						
							|  |  |  | 				/* axis */ | 
					
						
							|  |  |  | 				glBegin(GL_LINES); | 
					
						
							|  |  |  | 				if( (drawflags & MAN_ROT_X) || (moving && (drawflags & MAN_ROT_Z)) ) { | 
					
						
							|  |  |  | 					manipulator_setcolor('x', colcode); | 
					
						
							|  |  |  | 					glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 					glVertex3f(1.0, 0.0, 0.0); | 
					
						
							|  |  |  | 				}		 | 
					
						
							|  |  |  | 				if( (drawflags & MAN_ROT_Y) || (moving && (drawflags & MAN_ROT_X)) ) { | 
					
						
							|  |  |  | 					manipulator_setcolor('y', colcode); | 
					
						
							|  |  |  | 					glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 					glVertex3f(0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 				}		 | 
					
						
							|  |  |  | 				if( (drawflags & MAN_ROT_Z) || (moving && (drawflags & MAN_ROT_Y)) ) { | 
					
						
							|  |  |  | 					manipulator_setcolor('z', colcode); | 
					
						
							|  |  |  | 					glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 					glVertex3f(0.0, 0.0, 1.0); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				glEnd(); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	/* Trackball center */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	if((drawflags & MAN_ROT_T) && (combo & V3D_MANIP_TRANSLATE)==0) { | 
					
						
							| 
									
										
										
										
											2005-03-20 02:00:16 +00:00
										 |  |  | 		float smat[3][3], imat[3][3]; | 
					
						
							|  |  |  | 		float offset[3]; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_ROT_T); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-19 22:03:14 +00:00
										 |  |  | 		Mat3CpyMat4(smat, mat); | 
					
						
							|  |  |  | 		Mat3Inv(imat, smat); | 
					
						
							| 
									
										
										
										
											2005-03-20 02:00:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		getViewVector(mat[3], offset); | 
					
						
							|  |  |  | 		Mat3MulVecfl(imat, offset); | 
					
						
							| 
									
										
										
										
											2005-03-20 09:45:54 +00:00
										 |  |  | 		Normalise(offset);	// matrix space is such that 1.0 = size of sphere
 | 
					
						
							| 
									
										
										
										
											2005-03-19 22:03:14 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		if(moving) { | 
					
						
							|  |  |  | 			BIF_ThemeColor(TH_TRANSFORM); | 
					
						
							|  |  |  | 			glBegin(GL_LINES); | 
					
						
							|  |  |  | 			glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 			glVertex3fv(offset); | 
					
						
							|  |  |  | 			glEnd(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 		glEnable(GL_LIGHTING); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-20 02:00:16 +00:00
										 |  |  | 		VECCOPY(vec, offset); | 
					
						
							| 
									
										
										
										
											2005-03-19 22:03:14 +00:00
										 |  |  | 		glTranslatef(vec[0], vec[1], vec[2]); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('C', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		gluSphere(qobj, cywid, 8, 6); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		/* restore */ | 
					
						
							| 
									
										
										
										
											2005-03-19 22:03:14 +00:00
										 |  |  | 		glTranslatef(-vec[0], -vec[1], -vec[2]); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 		glDisable(GL_LIGHTING); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(arcs==0 && moving) { | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 		if(arcs) glEnable(GL_CLIP_PLANE0); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 		/* Z circle */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(drawflags & MAN_ROT_Z) { | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Z); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			manipulator_setcolor('z', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			drawcircball(unitmat[3], 1.0, unitmat); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* X circle */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(drawflags & MAN_ROT_X) { | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			if(G.f & G_PICKSEL) glLoadName(MAN_ROT_X); | 
					
						
							|  |  |  | 			glRotatef(90.0, 0.0, 1.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			manipulator_setcolor('x', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			drawcircball(unitmat[3], 1.0, unitmat); | 
					
						
							|  |  |  | 			glRotatef(-90.0, 0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 		}	 | 
					
						
							|  |  |  | 		/* Y circle */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(drawflags & MAN_ROT_Y) { | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Y); | 
					
						
							|  |  |  | 			glRotatef(-90.0, 1.0, 0.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			manipulator_setcolor('y', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			drawcircball(unitmat[3], 1.0, unitmat); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			glRotatef(90.0, 1.0, 0.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if(arcs) glDisable(GL_CLIP_PLANE0); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 	// donut arcs
 | 
					
						
							|  |  |  | 	if(arcs) { | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 		glEnable(GL_LIGHTING); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 		glEnable(GL_CLIP_PLANE0); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 		/* Z circle */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(drawflags & MAN_ROT_Z) { | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Z); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			manipulator_setcolor('Z', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			partial_donut(cusize/3.0, 1.0, 0, 48, 8, 48); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* X circle */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(drawflags & MAN_ROT_X) { | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			if(G.f & G_PICKSEL) glLoadName(MAN_ROT_X); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			glRotatef(90.0, 0.0, 1.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			manipulator_setcolor('X', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			partial_donut(cusize/3.0, 1.0, 0, 48, 8, 48); | 
					
						
							|  |  |  | 			glRotatef(-90.0, 0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 		}	 | 
					
						
							|  |  |  | 		/* Y circle */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(drawflags & MAN_ROT_Y) { | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Y); | 
					
						
							|  |  |  | 			glRotatef(-90.0, 1.0, 0.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			manipulator_setcolor('Y', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			partial_donut(cusize/3.0, 1.0, 0, 48, 8, 48); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			glRotatef(90.0, 1.0, 0.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		glDisable(GL_CLIP_PLANE0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(arcs==0) { | 
					
						
							|  |  |  | 		glEnable(GL_LIGHTING); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* Z handle on X axis */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(drawflags & MAN_ROT_Z) { | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			glPushMatrix(); | 
					
						
							|  |  |  | 			if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Z); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			manipulator_setcolor('Z', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if(G.rt==3) { | 
					
						
							|  |  |  | 				partial_donut(cusize, 1.0, 21, 27, 8, 48); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* Z handle on Y axis */ | 
					
						
							|  |  |  | 				glRotatef(90.0, 0.0, 0.0, 1.0); | 
					
						
							|  |  |  | 				partial_donut(cusize, 1.0, 21, 27, 8, 48); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				partial_donut(cusize, 1.0, 23, 25, 8, 48); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			glPopMatrix(); | 
					
						
							|  |  |  | 		}	 | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Y handle on X axis */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(drawflags & MAN_ROT_Y) { | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			glPushMatrix(); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Y); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			manipulator_setcolor('Y', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			if(G.rt==3) { | 
					
						
							|  |  |  | 				glRotatef(90.0, 1.0, 0.0, 0.0); | 
					
						
							|  |  |  | 				partial_donut(cusize, 1.0, 21, 27, 8, 48); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				/* Y handle on Z axis */ | 
					
						
							|  |  |  | 				glRotatef(90.0, 0.0, 0.0, 1.0); | 
					
						
							|  |  |  | 				partial_donut(cusize, 1.0, 21, 27, 8, 48); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				glRotatef(90.0, 1.0, 0.0, 0.0); | 
					
						
							|  |  |  | 				glRotatef(90.0, 0.0, 0.0, 1.0); | 
					
						
							|  |  |  | 				partial_donut(cusize, 1.0, 23, 25, 8, 48); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			glPopMatrix(); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* X handle on Z axis */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(drawflags & MAN_ROT_X) { | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			glPushMatrix(); | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			if(G.f & G_PICKSEL) glLoadName(MAN_ROT_X); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			manipulator_setcolor('X', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2005-03-20 17:25:00 +00:00
										 |  |  | 			if(G.rt==3) { | 
					
						
							|  |  |  | 				glRotatef(-90.0, 0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 				partial_donut(cusize, 1.0, 21, 27, 8, 48); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				/* X handle on Y axis */ | 
					
						
							|  |  |  | 				glRotatef(90.0, 0.0, 0.0, 1.0); | 
					
						
							|  |  |  | 				partial_donut(cusize, 1.0, 21, 27, 8, 48); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				glRotatef(-90.0, 0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 				glRotatef(90.0, 0.0, 0.0, 1.0); | 
					
						
							|  |  |  | 				partial_donut(cusize, 1.0, 23, 25, 8, 48); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 			glPopMatrix(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	/* restore */ | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	myloadmatrix(G.vd->viewmat); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	glDisable(GL_CULL_FACE); | 
					
						
							|  |  |  | 	glDisable(GL_LIGHTING); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glFrontFace(GL_CCW); | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	gluDeleteQuadric(qobj); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	if(G.zbuf) glEnable(GL_DEPTH_TEST);		// shouldn't be global, tsk!
 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | static void draw_manipulator_scale(float mat[][4], int moving, int drawflags, int combo, int colcode) | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float cywid= 0.33f*0.01f*(float)U.tw_handlesize;	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	float cusize= cywid*0.75, dz; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* when called while moving in mixed mode, do not draw when... */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if((drawflags & MAN_SCALE_C)==0) return; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(moving) { | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		float matt[4][4]; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		Mat4CpyMat4(matt, mat); // to copy the parts outside of [3][3]
 | 
					
						
							|  |  |  | 		Mat4MulMat34(matt, Trans.mat, mat); | 
					
						
							|  |  |  | 		mymultmatrix(matt); | 
					
						
							| 
									
										
										
										
											2005-03-27 19:54:18 +00:00
										 |  |  | 		glFrontFace( is_mat4_flipped(matt)?GL_CW:GL_CCW); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-27 19:54:18 +00:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		mymultmatrix(mat); | 
					
						
							|  |  |  | 		glFrontFace( is_mat4_flipped(mat)?GL_CW:GL_CCW); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	/* axis */ | 
					
						
							|  |  |  | 	if( (G.f & G_PICKSEL)==0 ) { | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		glDisable(GL_DEPTH_TEST); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		/* in combo mode, this is always drawn as first type */ | 
					
						
							|  |  |  | 		draw_manipulator_axes(colcode, drawflags & MAN_SCALE_X, drawflags & MAN_SCALE_Y, drawflags & MAN_SCALE_Z); | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		/* only has to be set when not in picking */ | 
					
						
							|  |  |  | 		glEnable(GL_CULL_FACE);		// backface removal
 | 
					
						
							|  |  |  | 		glEnable(GL_LIGHTING); | 
					
						
							|  |  |  | 		glShadeModel(GL_SMOOTH); | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 	/* not in combo mode */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	if( (combo & (V3D_MANIP_TRANSLATE|V3D_MANIP_ROTATE))==0) { | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 		/* center cube, do not add to selection when shift is pressed (planar constraint)  */ | 
					
						
							|  |  |  | 		if( (G.f & G_PICKSEL) && (G.qual & LR_SHIFTKEY)==0) glLoadName(MAN_SCALE_C); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('C', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 		drawsolidcube(cusize); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		dz= 1.0; | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	else dz= 1.0-3.0*cusize; | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	/* Z cube */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(0.0, 0.0, dz); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_SCALE_Z) { | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_SCALE_Z); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('Z', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		drawsolidcube(cusize); | 
					
						
							|  |  |  | 	}	 | 
					
						
							|  |  |  | 	/* X cube */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(dz, 0.0, -dz); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_SCALE_X) { | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_SCALE_X); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('X', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		drawsolidcube(cusize); | 
					
						
							|  |  |  | 	}	 | 
					
						
							|  |  |  | 	/* Y cube */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(-dz, dz, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_SCALE_Y) { | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_SCALE_Y); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('Y', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		drawsolidcube(cusize); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	glDisable(GL_CULL_FACE); | 
					
						
							|  |  |  | 	glDisable(GL_LIGHTING); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* if shiftkey, center point as last, for selectbuffer order */ | 
					
						
							|  |  |  | 	if(G.f & G_PICKSEL) { | 
					
						
							|  |  |  | 		if(G.qual & LR_SHIFTKEY) { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			glTranslatef(0.0, -dz, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 			glLoadName(MAN_SCALE_C); | 
					
						
							|  |  |  | 			glBegin(GL_POINTS); | 
					
						
							|  |  |  | 			glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 			glEnd(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-27 19:54:18 +00:00
										 |  |  | 	/* restore */ | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	myloadmatrix(G.vd->viewmat); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(G.zbuf) glEnable(GL_DEPTH_TEST);		// shouldn't be global, tsk!
 | 
					
						
							| 
									
										
										
										
											2005-03-27 19:54:18 +00:00
										 |  |  | 	glFrontFace(GL_CCW); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | static void draw_cone(GLUquadricObj *qobj, float len, float width) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(0.0, 0.0, -0.5*len); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 	gluCylinder(qobj, width, 0.0, len, 8, 1); | 
					
						
							|  |  |  | 	gluQuadricOrientation(qobj, GLU_INSIDE); | 
					
						
							|  |  |  | 	gluDisk(qobj, 0.0, width, 8, 1);  | 
					
						
							|  |  |  | 	gluQuadricOrientation(qobj, GLU_OUTSIDE); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(0.0, 0.0, 0.5*len); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | static void draw_cylinder(GLUquadricObj *qobj, float len, float width) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	width*= 0.8;	// just for beauty
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(0.0, 0.0, -0.5*len); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	gluCylinder(qobj, width, width, len, 8, 1); | 
					
						
							|  |  |  | 	gluQuadricOrientation(qobj, GLU_INSIDE); | 
					
						
							|  |  |  | 	gluDisk(qobj, 0.0, width, 8, 1);  | 
					
						
							|  |  |  | 	gluQuadricOrientation(qobj, GLU_OUTSIDE); | 
					
						
							|  |  |  | 	glTranslatef(0.0, 0.0, len); | 
					
						
							|  |  |  | 	gluDisk(qobj, 0.0, width, 8, 1);  | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(0.0, 0.0, -0.5*len); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | static void draw_manipulator_translate(float mat[][4], int moving, int drawflags, int combo, int colcode) | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	GLUquadricObj *qobj = gluNewQuadric();  | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 	float cylen= 0.01f*(float)U.tw_handlesize; | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	float cywid= 0.33f*cylen, dz; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	/* when called while moving in mixed mode, do not draw when... */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if((drawflags & MAN_TRANS_C)==0) return; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(moving) glTranslatef(Trans.vec[0], Trans.vec[1], Trans.vec[2]); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	mymultmatrix(mat); | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	glDisable(GL_DEPTH_TEST); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	/* axis */ | 
					
						
							|  |  |  | 	if( (G.f & G_PICKSEL)==0 ) { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		// translate drawn as last, only axis when no combo
 | 
					
						
							|  |  |  | 		if(combo==V3D_MANIP_TRANSLATE) | 
					
						
							|  |  |  | 			draw_manipulator_axes(colcode, drawflags & MAN_TRANS_X, drawflags & MAN_TRANS_Y, drawflags & MAN_TRANS_Z); | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		/* only has to be set when not in picking */ | 
					
						
							|  |  |  | 		gluQuadricDrawStyle(qobj, GLU_FILL);  | 
					
						
							|  |  |  | 		gluQuadricNormals(qobj, GLU_SMOOTH); | 
					
						
							|  |  |  | 		glEnable(GL_CULL_FACE);		// backface removal
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		glFrontFace( is_mat4_flipped(mat)?GL_CW:GL_CCW); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		glEnable(GL_LIGHTING); | 
					
						
							|  |  |  | 		glShadeModel(GL_SMOOTH); | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* center sphere, do not add to selection when shift is pressed (planar constraint) */ | 
					
						
							|  |  |  | 	if( (G.f & G_PICKSEL) && (G.qual & LR_SHIFTKEY)==0) glLoadName(MAN_TRANS_C); | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	manipulator_setcolor('C', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	gluSphere(qobj, cywid, 8, 6);  | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	/* offset in combo mode */ | 
					
						
							|  |  |  | 	if(combo & (V3D_MANIP_ROTATE|V3D_MANIP_SCALE)) dz= 1.0+cylen; | 
					
						
							|  |  |  | 	else dz= 1.0; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	/* Z Cone */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(0.0, 0.0, dz); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_TRANS_Z) { | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_TRANS_Z); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('Z', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		draw_cone(qobj, cylen, cywid); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	}	 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	/* X Cone */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(dz, 0.0, -dz); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_TRANS_X) { | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_TRANS_X); | 
					
						
							|  |  |  | 		glRotatef(90.0, 0.0, 1.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('X', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		draw_cone(qobj, cylen, cywid); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		glRotatef(-90.0, 0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 	}	 | 
					
						
							| 
									
										
										
										
											2005-03-19 18:54:45 +00:00
										 |  |  | 	/* Y Cone */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(-dz, dz, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_TRANS_Y) { | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_TRANS_Y); | 
					
						
							|  |  |  | 		glRotatef(-90.0, 1.0, 0.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('Y', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		draw_cone(qobj, cylen, cywid); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	/* restore */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	glDisable(GL_CULL_FACE); | 
					
						
							|  |  |  | 	glDisable(GL_LIGHTING); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	gluDeleteQuadric(qobj); | 
					
						
							|  |  |  | 	myloadmatrix(G.vd->viewmat); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glFrontFace(GL_CCW); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if(G.zbuf) glEnable(GL_DEPTH_TEST);		// shouldn't be global, tsk!
 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | static void draw_manipulator_rotate_cyl(float mat[][4], int moving, int drawflags, int combo, int colcode) | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	GLUquadricObj *qobj = gluNewQuadric();  | 
					
						
							|  |  |  | 	float vec[3], size; | 
					
						
							|  |  |  | 	float cylen= 0.01f*(float)U.tw_handlesize; | 
					
						
							|  |  |  | 	float cywid= 0.33f*cylen; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* when called while moving in mixed mode, do not draw when... */ | 
					
						
							|  |  |  | 	if((drawflags & MAN_ROT_C)==0) return; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* prepare for screen aligned draw */ | 
					
						
							|  |  |  | 	VECCOPY(vec, mat[0]); | 
					
						
							|  |  |  | 	size= Normalise(vec); | 
					
						
							|  |  |  | 	glPushMatrix(); | 
					
						
							|  |  |  | 	glTranslatef(mat[3][0], mat[3][1], mat[3][2]); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* sets view screen aligned */ | 
					
						
							|  |  |  | 	glRotatef( -360.0*saacos(G.vd->viewquat[0])/M_PI, G.vd->viewquat[1], G.vd->viewquat[2], G.vd->viewquat[3]); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Screen aligned view rot circle */ | 
					
						
							|  |  |  | 	if(drawflags & MAN_ROT_V) { | 
					
						
							|  |  |  | 		float unitmat[4][4]; | 
					
						
							|  |  |  | 		Mat4One(unitmat); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_ROT_V); | 
					
						
							|  |  |  | 		BIF_ThemeColor(TH_TRANSFORM); | 
					
						
							|  |  |  | 		drawcircball(unitmat[3], 1.2*size, unitmat); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if(moving) { | 
					
						
							|  |  |  | 			float vec[3]; | 
					
						
							|  |  |  | 			vec[0]= Trans.imval[0] - Trans.center2d[0]; | 
					
						
							|  |  |  | 			vec[1]= Trans.imval[1] - Trans.center2d[1]; | 
					
						
							|  |  |  | 			vec[2]= 0.0; | 
					
						
							|  |  |  | 			Normalise(vec); | 
					
						
							|  |  |  | 			VecMulf(vec, 1.2*size); | 
					
						
							|  |  |  | 			glBegin(GL_LINES); | 
					
						
							|  |  |  | 			glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 			glVertex3fv(vec); | 
					
						
							|  |  |  | 			glEnd(); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	glPopMatrix(); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	/* apply the transform delta */ | 
					
						
							|  |  |  | 	if(moving) { | 
					
						
							|  |  |  | 		float matt[4][4]; | 
					
						
							|  |  |  | 		Mat4CpyMat4(matt, mat); // to copy the parts outside of [3][3]
 | 
					
						
							|  |  |  | 		Mat4MulMat34(matt, Trans.mat, mat); | 
					
						
							|  |  |  | 		mymultmatrix(matt); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		mymultmatrix(mat); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	glFrontFace( is_mat4_flipped(mat)?GL_CW:GL_CCW); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	glDisable(GL_DEPTH_TEST); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* axis */ | 
					
						
							|  |  |  | 	if( (G.f & G_PICKSEL)==0 ) { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		// only draw axis when combo didn't draw scale axes
 | 
					
						
							|  |  |  | 		if((combo & V3D_MANIP_SCALE)==0) | 
					
						
							|  |  |  | 			draw_manipulator_axes(colcode, drawflags & MAN_ROT_X, drawflags & MAN_ROT_Y, drawflags & MAN_ROT_Z); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		/* only has to be set when not in picking */ | 
					
						
							|  |  |  | 		gluQuadricDrawStyle(qobj, GLU_FILL);  | 
					
						
							|  |  |  | 		gluQuadricNormals(qobj, GLU_SMOOTH); | 
					
						
							|  |  |  | 		glEnable(GL_CULL_FACE);		// backface removal
 | 
					
						
							|  |  |  | 		glEnable(GL_LIGHTING); | 
					
						
							|  |  |  | 		glShadeModel(GL_SMOOTH); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Trackball */ | 
					
						
							|  |  |  | 	if((drawflags & MAN_ROT_T) && (combo & V3D_MANIP_TRANSLATE)==0) { | 
					
						
							|  |  |  | 		float smat[3][3], imat[3][3]; | 
					
						
							|  |  |  | 		float offset[3]; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		Mat3CpyMat4(smat, mat); | 
					
						
							|  |  |  | 		Mat3Inv(imat, smat); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		getViewVector(mat[3], offset); | 
					
						
							|  |  |  | 		Mat3MulVecfl(imat, offset); | 
					
						
							|  |  |  | 		Normalise(offset);	// matrix space is such that 1.0 = size of sphere
 | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if(moving) { | 
					
						
							|  |  |  | 			glDisable(GL_LIGHTING); | 
					
						
							|  |  |  | 			BIF_ThemeColor(TH_TRANSFORM); | 
					
						
							|  |  |  | 			glBegin(GL_LINES); | 
					
						
							|  |  |  | 			glVertex3f(0.0, 0.0, 0.0); | 
					
						
							|  |  |  | 			glVertex3fv(offset); | 
					
						
							|  |  |  | 			glEnd(); | 
					
						
							|  |  |  | 			glEnable(GL_LIGHTING); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* center sphere, do not add to selection when shift is pressed (planar constraint) */ | 
					
						
							|  |  |  | 		if( (G.f & G_PICKSEL) && (G.qual & LR_SHIFTKEY)==0) glLoadName(MAN_ROT_T); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		VECCOPY(vec, offset); | 
					
						
							|  |  |  | 		glTranslatef(vec[0], vec[1], vec[2]); | 
					
						
							|  |  |  | 		manipulator_setcolor('C', colcode); | 
					
						
							|  |  |  | 		gluSphere(qobj, cywid, 8, 6); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* restore */ | 
					
						
							|  |  |  | 		glTranslatef(-vec[0], -vec[1], -vec[2]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* Z cyl */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(0.0, 0.0, 1.0); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_ROT_Z) { | 
					
						
							|  |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Z); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('Z', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		draw_cylinder(qobj, cylen, cywid); | 
					
						
							|  |  |  | 	}	 | 
					
						
							|  |  |  | 	/* X cyl */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(1.0, 0.0, -1.0); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_ROT_X) { | 
					
						
							|  |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_ROT_X); | 
					
						
							|  |  |  | 		glRotatef(90.0, 0.0, 1.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('X', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		draw_cylinder(qobj, cylen, cywid); | 
					
						
							|  |  |  | 		glRotatef(-90.0, 0.0, 1.0, 0.0); | 
					
						
							|  |  |  | 	}	 | 
					
						
							|  |  |  | 	/* Y cylinder */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glTranslatef(-1.0, 1.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	if(drawflags & MAN_ROT_Y) { | 
					
						
							|  |  |  | 		if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Y); | 
					
						
							|  |  |  | 		glRotatef(-90.0, 1.0, 0.0, 0.0); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		manipulator_setcolor('Y', colcode); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		draw_cylinder(qobj, cylen, cywid); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	/* restore */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	glDisable(GL_CULL_FACE); | 
					
						
							|  |  |  | 	glDisable(GL_LIGHTING); | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	glFrontFace(GL_CCW); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	gluDeleteQuadric(qobj); | 
					
						
							|  |  |  | 	myloadmatrix(G.vd->viewmat); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(G.zbuf) glEnable(GL_DEPTH_TEST);		// shouldn't be global, tsk!
 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | static float get_manipulator_drawsize(ScrArea *sa) | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	View3D *v3d= sa->spacedata.first; | 
					
						
							|  |  |  | 	float size, vec[3], len1, len2; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* size calculus, depending ortho/persp settings, like initgrabz() */ | 
					
						
							|  |  |  | 	size= v3d->persmat[0][3]*v3d->twmat[3][0]+ v3d->persmat[1][3]*v3d->twmat[3][1]+ v3d->persmat[2][3]*v3d->twmat[3][2]+ v3d->persmat[3][3]; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	VECCOPY(vec, v3d->persinv[0]); | 
					
						
							|  |  |  | 	len1= Normalise(vec); | 
					
						
							|  |  |  | 	VECCOPY(vec, v3d->persinv[1]); | 
					
						
							|  |  |  | 	len2= Normalise(vec); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	size*= (0.01f*(float)U.tw_size)*(len1>len2?len1:len2); | 
					
						
							|  |  |  | 	if(U.tw_flag & U_TW_ABSOLUTE) { | 
					
						
							|  |  |  | 		/* correct for relative window size */ | 
					
						
							|  |  |  | 		if(sa->winx > sa->winy) size*= 1000.0f/(float)sa->winx; | 
					
						
							|  |  |  | 		else size*= 1000.0f/(float)sa->winy; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* exported to transform_constraints.c */ | 
					
						
							|  |  |  | /* mat, vec = default orientation and location */ | 
					
						
							|  |  |  | /* type = transform type */ | 
					
						
							|  |  |  | /* axis = x, y, z, c */ | 
					
						
							|  |  |  | /* col: 0 = colored, 1 = moving, 2 = ghost */ | 
					
						
							|  |  |  | void draw_manipulator_ext(ScrArea *sa, int type, char axis, int col, float vec[3], float mat[][3]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int drawflags= 0; | 
					
						
							|  |  |  | 	float mat4[4][4]; | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	int colcode; | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	Mat4CpyMat3(mat4, mat); | 
					
						
							|  |  |  | 	VECCOPY(mat4[3], vec); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	Mat4MulFloat3((float *)mat4, get_manipulator_drawsize(sa)); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	glEnable(GL_BLEND);	// let's do it transparent by default
 | 
					
						
							|  |  |  | 	if(col==0) colcode= MAN_RGB; | 
					
						
							|  |  |  | 	else if(col==1) colcode= MAN_MOVECOL; | 
					
						
							|  |  |  | 	else colcode= MAN_GREY; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if(type==TFM_ROTATION) { | 
					
						
							|  |  |  | 		if(axis=='x') drawflags= MAN_ROT_X; | 
					
						
							|  |  |  | 		else if(axis=='y') drawflags= MAN_ROT_Y; | 
					
						
							|  |  |  | 		else if(axis=='z') drawflags= MAN_ROT_Z; | 
					
						
							|  |  |  | 		else drawflags= MAN_ROT_C; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		draw_manipulator_rotate_cyl(mat4, col, drawflags, V3D_MANIP_ROTATE, colcode); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	}	 | 
					
						
							|  |  |  | 	else if(type==TFM_RESIZE) { | 
					
						
							|  |  |  | 		if(axis=='x') drawflags= MAN_SCALE_X; | 
					
						
							|  |  |  | 		else if(axis=='y') drawflags= MAN_SCALE_Y; | 
					
						
							|  |  |  | 		else if(axis=='z') drawflags= MAN_SCALE_Z; | 
					
						
							|  |  |  | 		else drawflags= MAN_SCALE_C; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		draw_manipulator_scale(mat4, col, drawflags, V3D_MANIP_SCALE, colcode); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	}	 | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		if(axis=='x') drawflags= MAN_TRANS_X; | 
					
						
							|  |  |  | 		else if(axis=='y') drawflags= MAN_TRANS_Y; | 
					
						
							|  |  |  | 		else if(axis=='z') drawflags= MAN_TRANS_Z; | 
					
						
							|  |  |  | 		else drawflags= MAN_TRANS_C; | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		draw_manipulator_translate(mat4, 0, drawflags, V3D_MANIP_TRANSLATE, colcode); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	}	 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	glDisable(GL_BLEND); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | /* main call, does calc centers & orientation too */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | /* uses global G.moving */ | 
					
						
							|  |  |  | static int drawflags= 0xFFFF;		// only for the calls below, belongs in scene...?
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | void BIF_draw_manipulator(ScrArea *sa) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	View3D *v3d= sa->spacedata.first; | 
					
						
							|  |  |  | 	int totsel; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 20:27:13 +00:00
										 |  |  | 	if(!(v3d->twflag & V3D_USE_MANIPULATOR)) return; | 
					
						
							|  |  |  | 	if(G.moving && (G.moving & G_TRANSFORM_MANIP)==0) return; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if(G.moving==0) { | 
					
						
							|  |  |  | 		v3d->twflag &= ~V3D_DRAW_MANIPULATOR; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		totsel= calc_manipulator(sa); | 
					
						
							|  |  |  | 		if(totsel==0) return; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		v3d->twflag |= V3D_DRAW_MANIPULATOR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* now we can define centre */ | 
					
						
							|  |  |  | 		switch(v3d->around) { | 
					
						
							|  |  |  | 		case V3D_CENTRE: | 
					
						
							|  |  |  | 		case V3D_LOCAL: | 
					
						
							|  |  |  | 			v3d->twmat[3][0]= (G.scene->twmin[0] + G.scene->twmax[0])/2.0; | 
					
						
							|  |  |  | 			v3d->twmat[3][1]= (G.scene->twmin[1] + G.scene->twmax[1])/2.0; | 
					
						
							|  |  |  | 			v3d->twmat[3][2]= (G.scene->twmin[2] + G.scene->twmax[2])/2.0; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case V3D_CENTROID: | 
					
						
							|  |  |  | 			VECCOPY(v3d->twmat[3], G.scene->twcent); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case V3D_CURSOR: | 
					
						
							|  |  |  | 			VECCOPY(v3d->twmat[3], G.scene->cursor); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		Mat4MulFloat3((float *)v3d->twmat, get_manipulator_drawsize(sa)); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(v3d->twflag & V3D_DRAW_MANIPULATOR) { | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		if(v3d->twtype & V3D_MANIP_ROTATE) { | 
					
						
							|  |  |  | 			/* rotate has special ghosting draw, for pie chart */ | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 			if(G.moving) draw_manipulator_rotate_ghost(v3d->twmat, drawflags); | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			if(G.moving) glEnable(GL_BLEND); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			if(G.rt==4) { | 
					
						
							|  |  |  | 				if(G.moving) draw_manipulator_rotate_cyl(v3d->twmat, 1, drawflags, v3d->twtype, MAN_MOVECOL); | 
					
						
							|  |  |  | 				else draw_manipulator_rotate_cyl(v3d->twmat, 0, drawflags, v3d->twtype, MAN_RGB); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else draw_manipulator_rotate(v3d->twmat, G.moving, drawflags, v3d->twtype); | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 			glDisable(GL_BLEND); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 		if(v3d->twtype & V3D_MANIP_SCALE) { | 
					
						
							|  |  |  | 			if(G.moving) { | 
					
						
							|  |  |  | 				glEnable(GL_BLEND); | 
					
						
							|  |  |  | 				draw_manipulator_scale(v3d->twmat, 0, drawflags, v3d->twtype, MAN_GREY); | 
					
						
							|  |  |  | 				draw_manipulator_scale(v3d->twmat, 1, drawflags, v3d->twtype, MAN_MOVECOL); | 
					
						
							|  |  |  | 				glDisable(GL_BLEND); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else draw_manipulator_scale(v3d->twmat, 0, drawflags, v3d->twtype, MAN_RGB); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(v3d->twtype & V3D_MANIP_TRANSLATE) { | 
					
						
							|  |  |  | 			if(G.moving) { | 
					
						
							|  |  |  | 				glEnable(GL_BLEND); | 
					
						
							|  |  |  | 				draw_manipulator_translate(v3d->twmat, 0, drawflags, v3d->twtype, MAN_GREY); | 
					
						
							|  |  |  | 				draw_manipulator_translate(v3d->twmat, 1, drawflags, v3d->twtype, MAN_MOVECOL); | 
					
						
							|  |  |  | 				glDisable(GL_BLEND); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else draw_manipulator_translate(v3d->twmat, 0, drawflags, v3d->twtype, MAN_RGB); | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | static int manipulator_selectbuf(ScrArea *sa, float hotspot) | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	View3D *v3d= sa->spacedata.first; | 
					
						
							|  |  |  | 	rctf rect; | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	GLuint buffer[64];		// max 4 items per select, so large enuf
 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	short hits, mval[2]; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	G.f |= G_PICKSEL; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	getmouseco_areawin(mval); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	rect.xmin= mval[0]-hotspot; | 
					
						
							|  |  |  | 	rect.xmax= mval[0]+hotspot; | 
					
						
							|  |  |  | 	rect.ymin= mval[1]-hotspot; | 
					
						
							|  |  |  | 	rect.ymax= mval[1]+hotspot; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* get rid of overlay button matrix */ | 
					
						
							|  |  |  | 	persp(PERSP_VIEW); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	setwinmatrixview3d(&rect); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	Mat4MulMat4(v3d->persmat, v3d->viewmat, sa->winmat); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	glSelectBuffer( 64, buffer); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	glRenderMode(GL_SELECT); | 
					
						
							|  |  |  | 	glInitNames();	/* these two calls whatfor? It doesnt work otherwise */ | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	glPushName(-2); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* do the drawing */ | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	if(v3d->twtype & V3D_MANIP_ROTATE) { | 
					
						
							|  |  |  | 		if(G.rt==4) draw_manipulator_rotate_cyl(v3d->twmat, 0, MAN_ROT_C, v3d->twtype, MAN_RGB); | 
					
						
							|  |  |  | 		else draw_manipulator_rotate(v3d->twmat, 0, MAN_ROT_C, v3d->twtype); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 	if(v3d->twtype & V3D_MANIP_SCALE) | 
					
						
							|  |  |  | 		draw_manipulator_scale(v3d->twmat, 0, MAN_SCALE_C, v3d->twtype, MAN_RGB); | 
					
						
							|  |  |  | 	if(v3d->twtype & V3D_MANIP_TRANSLATE) | 
					
						
							|  |  |  | 		draw_manipulator_translate(v3d->twmat, 0, MAN_TRANS_C, v3d->twtype, MAN_RGB); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-21 16:36:43 +00:00
										 |  |  | 	glPopName(); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	hits= glRenderMode(GL_RENDER); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	G.f &= ~G_PICKSEL; | 
					
						
							|  |  |  | 	setwinmatrixview3d(0); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	Mat4MulMat4(v3d->persmat, v3d->viewmat, sa->winmat); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	persp(PERSP_WIN); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	if(hits==1) return buffer[3]; | 
					
						
							|  |  |  | 	else if(hits>1) { | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 		GLuint mindep, minval; | 
					
						
							|  |  |  | 		int a; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 		/* we compare the hits in buffer, but value centers highest */ | 
					
						
							|  |  |  | 		mindep= buffer[1]; | 
					
						
							|  |  |  | 		minval= buffer[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for(a=1; a<hits; a++) { | 
					
						
							|  |  |  | 			if(minval==MAN_TRANS_C || minval==MAN_SCALE_C) break; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			if(buffer[4*a + 3]==MAN_TRANS_C || buffer[4*a + 3]==MAN_SCALE_C || buffer[4*a + 1] < mindep) { | 
					
						
							|  |  |  | 				mindep= buffer[4*a + 1]; | 
					
						
							|  |  |  | 				minval= buffer[4*a + 3]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-25 16:59:04 +00:00
										 |  |  | 		return minval; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | /* return 0; nothing happened */ | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | int BIF_do_manipulator(ScrArea *sa) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	View3D *v3d= sa->spacedata.first; | 
					
						
							|  |  |  | 	int val; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(!(v3d->twflag & V3D_USE_MANIPULATOR)) return 0; | 
					
						
							|  |  |  | 	if(!(v3d->twflag & V3D_DRAW_MANIPULATOR)) return 0; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	// find the hotspots first test narrow hotspot
 | 
					
						
							| 
									
										
										
										
											2005-03-21 14:20:04 +00:00
										 |  |  | 	val= manipulator_selectbuf(sa, 0.5*(float)U.tw_hotspot); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 	if(val) { | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 		short mvalo[2], mval[2]; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		// drawflags still global, for drawing call above
 | 
					
						
							|  |  |  | 		drawflags= manipulator_selectbuf(sa, 0.2*(float)U.tw_hotspot); | 
					
						
							|  |  |  | 		if(drawflags==0) drawflags= val; | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		getmouseco_areawin(mvalo); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		switch(drawflags) { | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 		case MAN_TRANS_C: | 
					
						
							|  |  |  | 			ManipulatorTransform(TFM_TRANSLATION); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MAN_TRANS_X: | 
					
						
							|  |  |  | 			if(G.qual & LR_SHIFTKEY) { | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 				drawflags= MAN_TRANS_Y|MAN_TRANS_Z; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 				BIF_setDualAxisConstraint(v3d->twmat[1], v3d->twmat[2]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 				BIF_setSingleAxisConstraint(v3d->twmat[0], " dX"); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 			ManipulatorTransform(TFM_TRANSLATION); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MAN_TRANS_Y: | 
					
						
							|  |  |  | 			if(G.qual & LR_SHIFTKEY) { | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 				drawflags= MAN_TRANS_X|MAN_TRANS_Z; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 				BIF_setDualAxisConstraint(v3d->twmat[0], v3d->twmat[2]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 				BIF_setSingleAxisConstraint(v3d->twmat[1], " dY"); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 			ManipulatorTransform(TFM_TRANSLATION); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MAN_TRANS_Z: | 
					
						
							|  |  |  | 			if(G.qual & LR_SHIFTKEY) { | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 				drawflags= MAN_TRANS_X|MAN_TRANS_Y; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 				BIF_setDualAxisConstraint(v3d->twmat[0], v3d->twmat[1]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 				BIF_setSingleAxisConstraint(v3d->twmat[2], " dZ"); | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 			ManipulatorTransform(TFM_TRANSLATION); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 		case MAN_SCALE_C: | 
					
						
							|  |  |  | 			ManipulatorTransform(TFM_RESIZE); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MAN_SCALE_X: | 
					
						
							|  |  |  | 			if(G.qual & LR_SHIFTKEY) { | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 				drawflags= MAN_SCALE_Y|MAN_SCALE_Z; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 				BIF_setDualAxisConstraint(v3d->twmat[1], v3d->twmat[2]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 				BIF_setSingleAxisConstraint(v3d->twmat[0], " SizeX"); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 			ManipulatorTransform(TFM_RESIZE); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MAN_SCALE_Y: | 
					
						
							|  |  |  | 			if(G.qual & LR_SHIFTKEY) { | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 				drawflags= MAN_SCALE_X|MAN_SCALE_Z; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 				BIF_setDualAxisConstraint(v3d->twmat[0], v3d->twmat[2]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 				BIF_setSingleAxisConstraint(v3d->twmat[1], " SizeY"); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 			ManipulatorTransform(TFM_RESIZE); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MAN_SCALE_Z: | 
					
						
							|  |  |  | 			if(G.qual & LR_SHIFTKEY) { | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 				drawflags= MAN_SCALE_X|MAN_SCALE_Y; | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 				BIF_setDualAxisConstraint(v3d->twmat[0], v3d->twmat[1]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 				BIF_setSingleAxisConstraint(v3d->twmat[2], " SizeZ"); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 			ManipulatorTransform(TFM_RESIZE); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		case MAN_ROT_X: | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			BIF_setSingleAxisConstraint(v3d->twmat[0], " RotX"); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 			ManipulatorTransform(TFM_ROTATION); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MAN_ROT_Y: | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			BIF_setSingleAxisConstraint(v3d->twmat[1], " RotY"); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 			ManipulatorTransform(TFM_ROTATION); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MAN_ROT_Z: | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 			BIF_setSingleAxisConstraint(v3d->twmat[2], " RotZ"); | 
					
						
							| 
									
										
										
										
											2005-03-19 12:17:06 +00:00
										 |  |  | 			ManipulatorTransform(TFM_ROTATION); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MAN_ROT_T: | 
					
						
							|  |  |  | 			ManipulatorTransform(TFM_TRACKBALL); | 
					
						
							|  |  |  | 			break;			 | 
					
						
							|  |  |  | 		case MAN_ROT_V: | 
					
						
							|  |  |  | 			ManipulatorTransform(TFM_ROTATION); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* cycling orientation modus */ | 
					
						
							|  |  |  | 		getmouseco_areawin(mval); | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 		if(val==MAN_ROT_T || val==MAN_SCALE_C || val==MAN_TRANS_C) { | 
					
						
							| 
									
										
										
										
											2005-03-22 15:01:36 +00:00
										 |  |  | 			if(mvalo[0]==mval[0] && mvalo[1]==mval[1]) { | 
					
						
							| 
									
										
										
										
											2005-03-28 14:00:49 +00:00
										 |  |  | 				if(v3d->twmode==V3D_MANIP_GLOBAL) | 
					
						
							|  |  |  | 					v3d->twmode= V3D_MANIP_LOCAL; | 
					
						
							|  |  |  | 				else if(v3d->twmode==V3D_MANIP_LOCAL) | 
					
						
							|  |  |  | 					if(G.obedit || G.obpose) v3d->twmode= V3D_MANIP_NORMAL; | 
					
						
							|  |  |  | 					else v3d->twmode= V3D_MANIP_GLOBAL; | 
					
						
							|  |  |  | 				else if(v3d->twmode==V3D_MANIP_NORMAL) | 
					
						
							|  |  |  | 					v3d->twmode= V3D_MANIP_GLOBAL; | 
					
						
							| 
									
										
										
										
											2005-03-22 15:01:36 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-03-21 22:51:05 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-23 11:49:54 +00:00
										 |  |  | 	/* after transform, restore drawflags */ | 
					
						
							|  |  |  | 	drawflags= 0xFFFF; | 
					
						
							| 
									
										
										
										
											2005-03-17 21:46:05 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |