1 /* AxisGL.c */
2 /**********************************************************************************************************
3 Copyright (c) 2002-2013 Abdul-Rahman Allouche. All rights reserved
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 documentation files (the Gabedit), to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
10 The above copyright notice and this permission notice shall be included in all copies or substantial portions
11 of the Software.
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
14 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
16 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 DEALINGS IN THE SOFTWARE.
18 ************************************************************************************************************/
19
20
21 #include "../../Config.h"
22 #include "GlobalOrb.h"
23 #include "../Geometry/GeomGlobal.h"
24 #include "../Utils/Vector3d.h"
25 #include "../Utils/Transformation.h"
26 #include "../Utils/Constants.h"
27 #include "../Utils/UtilsInterface.h"
28 #include "../Utils/UtilsGL.h"
29 #include "../Utils/Utils.h"
30 #include "../Common/Windows.h"
31 #include "GLArea.h"
32 #include "../Display/UtilsOrb.h"
33
34 #define Deg_Rad 180.0/PI
35
36 /************************************************************************/
37 typedef struct _AxisDef
38 {
39 gboolean show;
40 gboolean negative;
41 gdouble origin[3];
42 gdouble radius;
43 gdouble scal;
44 gdouble xColor[3];
45 gdouble yColor[3];
46 gdouble zColor[3];
47 }AxisDef;
48
49 static AxisDef axis;
50 /************************************************************************/
getAxisProperties(gboolean * show,gboolean * negative,gdouble origin[],gdouble * radius,gdouble * scal,gdouble xColor[],gdouble yColor[],gdouble zColor[])51 void getAxisProperties(gboolean* show, gboolean* negative, gdouble origin[], gdouble* radius, gdouble* scal, gdouble xColor[], gdouble yColor[], gdouble zColor[])
52 {
53 gint i;
54 *show = axis.show;
55 *negative = axis.negative;
56 for(i=0;i<3;i++) origin [i] = axis.origin[i];
57 *radius = axis.radius;
58 *scal = axis.scal;
59 for(i=0;i<3;i++)
60 {
61 xColor[i] = axis.xColor[i];
62 yColor[i] = axis.yColor[i];
63 zColor[i] = axis.zColor[i];
64 }
65 }
66 /************************************************************************/
initAxis()67 void initAxis()
68 {
69 axis.show = FALSE;
70 axis.negative = FALSE;
71 axis.origin[0] = 0;
72 axis.origin[1] = 0;
73 axis.origin[2] = 0;
74 axis.radius = 0.25;
75 axis.scal = 5;
76 axis.xColor[0] = 1.0;
77 axis.xColor[1] = 0.0;
78 axis.xColor[2] = 0.0;
79 axis.yColor[0] = 0.0;
80 axis.yColor[1] = 1.0;
81 axis.yColor[2] = 0.0;
82 axis.zColor[0] = 0.0;
83 axis.zColor[1] = 1.0;
84 axis.zColor[2] = 1.0;
85 }
86 /******************************************************************/
save_axis_properties()87 void save_axis_properties()
88 {
89 gchar *axesfile;
90 FILE *file;
91
92 axesfile = g_strdup_printf("%s%saxes",gabedit_directory(),G_DIR_SEPARATOR_S);
93
94 file = fopen(axesfile, "w");
95
96 fprintf(file,"%d\n",axis.show);
97 fprintf(file,"%d\n",axis.negative);
98 fprintf(file,"%lf %lf %lf\n",axis.origin[0],axis.origin[1],axis.origin[2]);
99 fprintf(file,"%lf\n",axis.radius);
100 fprintf(file,"%lf\n",axis.scal);
101 fprintf(file,"%lf %lf %lf\n",axis.xColor[0],axis.xColor[1],axis.xColor[2]);
102 fprintf(file,"%lf %lf %lf\n",axis.yColor[0],axis.yColor[1],axis.yColor[2]);
103 fprintf(file,"%lf %lf %lf\n",axis.zColor[0],axis.zColor[1],axis.zColor[2]);
104
105 fclose(file);
106
107 g_free(axesfile);
108 }
109 /******************************************************************/
read_axis_properties()110 void read_axis_properties()
111 {
112 gchar *axesfile;
113 FILE *file;
114 gint n;
115
116 initAxis();
117 axesfile = g_strdup_printf("%s%saxes",gabedit_directory(),G_DIR_SEPARATOR_S);
118
119 file = fopen(axesfile, "rb");
120 if(!file) return;
121
122 n = fscanf(file,"%d\n",&axis.show);
123 if(n != 1) { initAxis(); return ; fclose(file); g_free(axesfile);}
124 n = fscanf(file,"%d\n",&axis.negative);
125 if(n != 1) { initAxis(); return ; fclose(file); g_free(axesfile);}
126 n = fscanf(file,"%lf %lf %lf\n",&axis.origin[0],&axis.origin[1],&axis.origin[2]);
127 if(n != 3) { initAxis(); return ; fclose(file); g_free(axesfile);}
128 n = fscanf(file,"%lf\n",&axis.radius);
129 if(n != 1) { initAxis(); return ; fclose(file); g_free(axesfile);}
130 n = fscanf(file,"%lf\n",&axis.scal);
131 if(n != 1) { initAxis(); return ; fclose(file); g_free(axesfile);}
132 n = fscanf(file,"%lf %lf %lf\n",&axis.xColor[0],&axis.xColor[1],&axis.xColor[2]);
133 if(n != 3) { initAxis(); return ; fclose(file); g_free(axesfile);}
134 n = fscanf(file,"%lf %lf %lf\n",&axis.yColor[0],&axis.yColor[1],&axis.yColor[2]);
135 if(n != 3) { initAxis(); return ; fclose(file); g_free(axesfile);}
136 n = fscanf(file,"%lf %lf %lf\n",&axis.zColor[0],&axis.zColor[1],&axis.zColor[2]);
137 if(n != 3) { initAxis(); return ; fclose(file); g_free(axesfile);}
138
139 fclose(file);
140
141 g_free(axesfile);
142 }
143 /******************************************************************/
set_axis(GtkWidget * fp,gpointer data)144 static void set_axis(GtkWidget* fp,gpointer data)
145 {
146 GtkWidget** entrys = (GtkWidget**)data;
147 gdouble *vX = g_object_get_data(G_OBJECT (fp), "XColor");
148 gdouble *vY = g_object_get_data(G_OBJECT (fp), "YColor");
149 gdouble *vZ = g_object_get_data(G_OBJECT (fp), "ZColor");
150 gboolean *negative = g_object_get_data(G_OBJECT (fp), "Negative");
151 G_CONST_RETURN gchar* tentry;
152 gint i;
153
154 tentry = gtk_entry_get_text(GTK_ENTRY(entrys[0]));
155 axis.scal = atof(tentry);
156 if(axis.scal<1e-6) axis.scal = 1.0;
157 for(i=1;i<4;i++)
158 {
159 tentry = gtk_entry_get_text(GTK_ENTRY(entrys[i]));
160 axis.origin[i-1] = atof(tentry)*ANG_TO_BOHR;
161 }
162
163 tentry = gtk_entry_get_text(GTK_ENTRY(entrys[4]));
164 axis.radius = atof(tentry)*ANG_TO_BOHR;
165
166 if(axis.radius<1e-6) axis.radius = 0.1;
167
168 for(i=0;i<3;i++)
169 {
170 axis.xColor[i] = vX[i];
171 axis.yColor[i] = vY[i];
172 axis.zColor[i] = vZ[i];
173 }
174 axis.negative = *negative;
175 rafresh_window_orb();
176 }
177 /******************************************************************/
set_negative(GtkWidget * button,gpointer data)178 static void set_negative(GtkWidget* button,gpointer data)
179 {
180 gboolean *negative= g_object_get_data(G_OBJECT (button), "Negative");
181 *negative = !(*negative);
182 }
183 /******************************************************************/
set_axis_color(GtkColorSelection * Sel,gpointer * d)184 static void set_axis_color(GtkColorSelection *Sel,gpointer *d)
185 {
186 GdkColor color;
187 gdouble *v = g_object_get_data(G_OBJECT (Sel), "Color");
188
189 gtk_color_selection_get_current_color(Sel, &color);
190
191 v[0] =color.red/65535.0;
192 v[1] =color.green/65535.0;
193 v[2] =color.blue/65535.0;
194 }
195 /******************************************************************/
set_axis_button_color(GtkObject * button,gpointer * data)196 static void set_axis_button_color(GtkObject *button,gpointer *data)
197 {
198 GtkStyle *style = g_object_get_data(G_OBJECT (button), "Style");
199 gdouble *v = g_object_get_data(G_OBJECT (button), "Color");
200 GtkWidget *OldButton = g_object_get_data(G_OBJECT (button), "Button");
201 style = gtk_style_copy(style);
202 style->bg[0].red=(gushort)(v[0]*65535.0);
203 style->bg[0].green=(gushort)(v[1]*65535.0);
204 style->bg[0].blue=(gushort)(v[2]*65535.0);
205 gtk_widget_set_style(OldButton, style);
206 }
207 /******************************************************************/
open_color_dlg_axis(GtkWidget * button,gpointer data)208 static void open_color_dlg_axis(GtkWidget *button,gpointer data)
209 {
210
211 GtkColorSelectionDialog *colorDlg;
212 GtkStyle* style = g_object_get_data(G_OBJECT (button), "Style");
213 GtkWidget *win = g_object_get_data(G_OBJECT (button), "Win");
214 gdouble* v = g_object_get_data(G_OBJECT (button), "Color");;
215 GdkColor color;
216
217 colorDlg = (GtkColorSelectionDialog *)gtk_color_selection_dialog_new("Set Axis Color");
218 color.red = (gushort)(v[0]*65535);
219 color.green = (gushort)(v[1]*65535);
220 color.blue = (gushort)(v[2]*65535);
221 gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (colorDlg->colorsel), &color);
222 gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (colorDlg->colorsel), &color);
223 gtk_window_set_transient_for(GTK_WINDOW(colorDlg),GTK_WINDOW(win));
224 gtk_window_set_position(GTK_WINDOW(colorDlg),GTK_WIN_POS_CENTER);
225 gtk_window_set_modal (GTK_WINDOW (colorDlg), TRUE);
226 g_signal_connect(G_OBJECT(colorDlg), "delete_event",(GCallback)destroy_button_windows,NULL);
227 g_signal_connect(G_OBJECT(colorDlg), "delete_event",G_CALLBACK(gtk_widget_destroy),NULL);
228
229 g_object_set_data(G_OBJECT (colorDlg->colorsel), "Color", v);
230 gtk_widget_hide(colorDlg->help_button);
231 g_signal_connect_swapped(G_OBJECT(colorDlg->ok_button),"clicked",
232 (GCallback)set_axis_color,GTK_OBJECT(colorDlg->colorsel));
233
234 g_object_set_data(G_OBJECT (colorDlg->ok_button), "Color", v);
235 g_object_set_data(G_OBJECT (colorDlg->ok_button), "Button", button);
236 g_object_set_data(G_OBJECT (colorDlg->ok_button), "Style", style);
237 g_signal_connect(G_OBJECT(colorDlg->ok_button),"clicked", (GCallback)set_axis_button_color,NULL);
238
239 g_signal_connect_swapped(G_OBJECT(colorDlg->ok_button), "clicked",
240 (GCallback)destroy_button_windows,GTK_OBJECT(colorDlg));
241 g_signal_connect_swapped(G_OBJECT(colorDlg->ok_button),"clicked",
242 (GCallback)gtk_widget_destroy,GTK_OBJECT(colorDlg));
243
244 g_signal_connect_swapped(G_OBJECT(colorDlg->cancel_button), "clicked",
245 (GCallback)destroy_button_windows,GTK_OBJECT(colorDlg));
246 g_signal_connect_swapped(G_OBJECT(colorDlg->cancel_button),"clicked",
247 (GCallback)gtk_widget_destroy,GTK_OBJECT(colorDlg));
248
249 add_button_windows(" Set Color ",GTK_WIDGET(colorDlg));
250 gtk_widget_show(GTK_WIDGET(colorDlg));
251
252 }
253 /*********************************************************************/
set_axis_dialog()254 void set_axis_dialog ()
255 {
256 GtkWidget *fp;
257 GtkWidget *frame;
258 GtkWidget *vboxall;
259 GtkWidget *vboxframe;
260 GtkWidget *hbox;
261 GtkWidget *button;
262 GtkStyle *style;
263 static GtkWidget* entrys[5];
264 static gdouble vX[3];
265 static gdouble vY[3];
266 static gdouble vZ[3];
267 static gboolean negative;
268 gchar* tlabel[5]={"Factor","X Origin (Ang)","Y Origin (Ang)","Z Origin (Ang)","Radius"};
269 gint i;
270 GtkWidget* table;
271
272 /* principal Window */
273 fp = gtk_window_new(GTK_WINDOW_TOPLEVEL);
274 gtk_window_set_modal(GTK_WINDOW(fp),TRUE);
275 gtk_window_set_title(GTK_WINDOW(fp),_("Set the axis parameters"));
276 gtk_container_set_border_width (GTK_CONTAINER (fp), 5);
277
278 gtk_window_set_position(GTK_WINDOW(fp),GTK_WIN_POS_CENTER);
279 gtk_window_set_modal (GTK_WINDOW (fp), TRUE);
280 gtk_window_set_transient_for(GTK_WINDOW(fp),GTK_WINDOW(PrincipalWindow));
281
282 g_signal_connect(G_OBJECT(fp),"delete_event",(GCallback)gtk_widget_destroy,NULL);
283
284 vboxall = create_vbox(fp);
285 frame = gtk_frame_new (NULL);
286 gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
287 gtk_container_add (GTK_CONTAINER (vboxall), frame);
288 gtk_widget_show (frame);
289
290 vboxframe = create_vbox(frame);
291 table = gtk_table_new(9,3,FALSE);
292 gtk_box_pack_start(GTK_BOX(vboxframe), table,TRUE,TRUE,0);
293
294 for(i=0;i<5;i++)
295 {
296 add_label_table(table,tlabel[i],(gushort)i,0);
297 add_label_table(table," : ",(gushort)i,1);
298
299 entrys[i] = gtk_entry_new ();
300 gtk_table_attach(GTK_TABLE(table),entrys[i],2,2+1,i,i+1,
301 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
302 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
303 3,3);
304
305 if(i!=0)
306 {
307 if(i==4)
308 {
309 gchar* t = g_strdup_printf("%lf",axis.radius*BOHR_TO_ANG);
310 gtk_entry_set_text(GTK_ENTRY(entrys[i]),t);
311 g_free(t);
312 }
313 else
314 {
315 gchar* t = g_strdup_printf("%lf",axis.origin[i-1]*BOHR_TO_ANG);
316 gtk_entry_set_text(GTK_ENTRY(entrys[i]),t);
317 g_free(t);
318 }
319 }
320 else
321 {
322 gchar* t = g_strdup_printf("%lf",axis.scal);
323 gtk_entry_set_text(GTK_ENTRY(entrys[i]),t);
324 g_free(t);
325 }
326 }
327
328 i = 5;
329 add_label_table(table,_("Color for the X axis"),(gushort)i,0);
330 add_label_table(table," : ",(gushort)i,1);
331 style = gtk_widget_get_style(fp);
332 button = gtk_button_new_with_label(" ");
333 style = gtk_style_copy(style);
334 style->bg[0].red=axis.xColor[0]*65535.0;
335 style->bg[0].green=axis.xColor[1]*65535.0;
336 style->bg[0].blue=axis.xColor[2]*65535.0;
337
338 vX[0] = axis.xColor[0];
339 vX[1] = axis.xColor[1];
340 vX[2] = axis.xColor[2];
341
342 gtk_widget_set_style(button, style );
343 gtk_table_attach(GTK_TABLE(table),button,2,2+1,i,i+1,
344 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
345 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
346 3,3);
347 gtk_widget_show (button);
348
349 g_object_set_data(G_OBJECT (button), "Style", style);
350 g_object_set_data(G_OBJECT (button), "Win", fp);
351 g_object_set_data(G_OBJECT (button), "Color", vX);
352 g_signal_connect(G_OBJECT(button), "clicked", (GCallback)open_color_dlg_axis, NULL);
353
354 i++;
355 add_label_table(table,_("Color for the Y axis"),(gushort)i,0);
356 add_label_table(table," : ",(gushort)i,1);
357 style = gtk_widget_get_style(fp);
358 button = gtk_button_new_with_label(" ");
359 style = gtk_style_copy(style);
360 style->bg[0].red=axis.yColor[0]*65535.0;
361 style->bg[0].green=axis.yColor[1]*65535.0;
362 style->bg[0].blue=axis.yColor[2]*65535.0;
363
364 vY[0] = axis.yColor[0];
365 vY[1] = axis.yColor[1];
366 vY[2] = axis.yColor[2];
367
368 gtk_widget_set_style(button, style );
369 gtk_table_attach(GTK_TABLE(table),button,2,2+1,i,i+1,
370 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
371 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
372 3,3);
373 gtk_widget_show (button);
374
375 g_object_set_data(G_OBJECT (button), "Style", style);
376 g_object_set_data(G_OBJECT (button), "Win", fp);
377 g_object_set_data(G_OBJECT (button), "Color", vY);
378 g_signal_connect(G_OBJECT(button), "clicked", (GCallback)open_color_dlg_axis, NULL);
379
380 hbox = gtk_hbox_new (TRUE, 0);
381 gtk_widget_show (hbox);
382 gtk_box_pack_start (GTK_BOX (vboxframe), hbox, FALSE, FALSE, 1);
383
384 i++;
385 add_label_table(table,_("Color for the Z axis"),(gushort)i,0);
386 add_label_table(table," : ",(gushort)i,1);
387 style = gtk_widget_get_style(fp);
388 button = gtk_button_new_with_label(" ");
389 style = gtk_style_copy(style);
390 style->bg[0].red=axis.zColor[0]*65535.0;
391 style->bg[0].green=axis.zColor[1]*65535.0;
392 style->bg[0].blue=axis.zColor[2]*65535.0;
393
394 vZ[0] = axis.zColor[0];
395 vZ[1] = axis.zColor[1];
396 vZ[2] = axis.zColor[2];
397
398 gtk_widget_set_style(button, style );
399 gtk_widget_set_style(button, style );
400 gtk_table_attach(GTK_TABLE(table),button,2,2+1,i,i+1,
401 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
402 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
403 3,3);
404 gtk_widget_show (button);
405 g_object_set_data(G_OBJECT (button), "Style", style);
406 g_object_set_data(G_OBJECT (button), "Win", fp);
407 g_object_set_data(G_OBJECT (button), "Color", vZ);
408 g_signal_connect(G_OBJECT(button), "clicked", (GCallback)open_color_dlg_axis, NULL);
409
410 i++;
411 button = gtk_check_button_new_with_label (_("Show the negative part of the axes"));
412 negative = axis.negative;
413 g_object_set_data(G_OBJECT (button), "Negative", &negative);
414 gtk_table_attach(GTK_TABLE(table),button,0,3,i,i+1,
415 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
416 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
417 3,3);
418 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), negative);
419 g_signal_connect(G_OBJECT(button), "clicked", (GCallback)set_negative, NULL);
420
421 hbox = create_hbox(vboxall);
422
423 button = create_button(PrincipalWindow,"Close");
424 gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
425 g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(gtk_widget_destroy),GTK_OBJECT(fp));
426 gtk_widget_show (button);
427
428 button = create_button(PrincipalWindow,"Apply");
429 gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
430 g_object_set_data(G_OBJECT (button), "XColor", vX);
431 g_object_set_data(G_OBJECT (button), "YColor", vY);
432 g_object_set_data(G_OBJECT (button), "ZColor", vZ);
433 g_object_set_data(G_OBJECT (button), "Negative", &negative);
434 g_signal_connect(G_OBJECT(button), "clicked",G_CALLBACK(set_axis),(gpointer)entrys);
435 gtk_widget_show (button);
436
437 button = create_button(PrincipalWindow,"OK");
438 gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
439 g_object_set_data(G_OBJECT (button), "XColor", vX);
440 g_object_set_data(G_OBJECT (button), "YColor", vY);
441 g_object_set_data(G_OBJECT (button), "ZColor", vZ);
442 g_object_set_data(G_OBJECT (button), "Negative", &negative);
443 g_signal_connect(G_OBJECT(button), "clicked",G_CALLBACK(set_axis),(gpointer)entrys);
444 g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(gtk_widget_destroy),GTK_OBJECT(fp));
445 gtk_widget_show (button);
446
447
448
449 gtk_widget_show_all(fp);
450 }
451 /************************************************************************/
testShowAxis()452 gboolean testShowAxis()
453 {
454 return axis.show;
455 }
456 /************************************************************************/
showAxis()457 void showAxis()
458 {
459 axis.show = TRUE;
460 }
461 /************************************************************************/
hideAxis()462 void hideAxis()
463 {
464 axis.show = FALSE;
465 }
466 /************************************************************************/
rotatedVector(V3d v)467 static void rotatedVector(V3d v)
468 {
469 V3d vz={0.0,0.0,1.0};
470 V3d vert;
471 gdouble angle;
472
473
474 v3d_cross(vz,v,vert);
475 angle = acos(v3d_dot(vz,v)/v3d_length(v))*Deg_Rad;
476
477 if(fabs(angle)<1e-6)
478 return;
479 if(fabs(angle-180)<1e-6)
480 glRotated(angle, 1.0, 0.0, 0.0);
481 else
482 glRotated(angle, vert[0],vert[1],vert[2]);
483
484 }
485 /************************************************************************/
drawPrism(GLdouble radius,V3d Base1Pos,V3d Base2Pos)486 static void drawPrism(GLdouble radius,V3d Base1Pos,V3d Base2Pos)
487 {
488 V3d Direction;
489 double lengt;
490 GLUquadricObj *obj;
491 glPushMatrix();
492 glTranslated(Base1Pos[0],Base1Pos[1],Base1Pos[2]);
493 Direction[0] = Base2Pos[0]-Base1Pos[0];
494 Direction[1] = Base2Pos[1]-Base1Pos[1];
495 Direction[2] = Base2Pos[2]-Base1Pos[2];
496 lengt = v3d_length(Direction);
497
498 rotatedVector(Direction);
499 obj = gluNewQuadric();
500 gluQuadricNormals(obj, GL_SMOOTH);
501 gluQuadricDrawStyle(obj, GLU_FILL);
502 gluCylinder (obj,radius,radius/5,lengt,10,10);
503 gluDeleteQuadric(obj);
504 glPopMatrix();
505 }
506
507 /***************************************************************************************************************/
drawPrismColor(GLdouble radius,V3d Base1Pos,V3d Base2Pos,V4d Specular,V4d Diffuse,V4d Ambiant)508 static void drawPrismColor(GLdouble radius,V3d Base1Pos,V3d Base2Pos, V4d Specular,V4d Diffuse,V4d Ambiant)
509 {
510 glMaterialdv(GL_FRONT_AND_BACK,GL_SPECULAR,Specular);
511 glMaterialdv(GL_FRONT_AND_BACK,GL_DIFFUSE,Diffuse);
512 glMaterialdv(GL_FRONT_AND_BACK,GL_AMBIENT,Ambiant);
513 glMateriali(GL_FRONT_AND_BACK,GL_SHININESS,50);
514 drawPrism(radius,Base1Pos,Base2Pos);
515 }
516 /***************************************************************************************************************/
drawAxis(V3d vector,GLdouble radius,V3d origin,V4d specular,V4d diffuse,V4d ambiant)517 static void drawAxis(V3d vector, GLdouble radius,V3d origin, V4d specular,V4d diffuse,V4d ambiant)
518 {
519 V3d top;
520 V3d bottom;
521 V3d center;
522 double lengt;
523 gint i;
524 V4d diffuseFleche;
525 V4d ambiantFleche;
526
527 bottom[0] = origin[0];
528 bottom[1] = origin[1];
529 bottom[2] = origin[2];
530 if(axis.negative)
531 {
532 bottom[0] -= vector[0];
533 bottom[1] -= vector[1];
534 bottom[2] -= vector[2];
535 }
536
537
538 top[0] = origin[0] + vector[0];
539 top[1] = origin[1] + vector[1];
540 top[2] = origin[2] + vector[2];
541
542 lengt = v3d_length(vector);
543
544 if(radius<0.1) radius = 0.1;
545
546 if(axis.negative) lengt *=2;
547
548 center[0] = top[0];
549 center[1] = top[1];
550 center[2] = top[2];
551
552 top[0] += (top[0]-bottom[0])/lengt*2*radius;
553 top[1] += (top[1]-bottom[1])/lengt*2*radius;
554 top[2] += (top[2]-bottom[2])/lengt*2*radius;
555
556
557 Cylinder_Draw_Color(radius/2,bottom,center,specular,diffuse,ambiant);
558 for(i=0;i<3;i++)
559 {
560 diffuseFleche[i] = diffuse[i] *0.6;
561 ambiantFleche[i] = ambiant[i] *0.6;
562 }
563 diffuseFleche[3] = diffuse[3];
564 ambiantFleche[3] = ambiant[3];
565
566 drawPrismColor(radius/1.5,center,top,specular,diffuseFleche,ambiantFleche);
567 }
568 /************************************************************************/
axisGenList(GLuint axisList)569 GLuint axisGenList(GLuint axisList)
570 {
571 V4d specular = {1.0f,1.0f,1.0f,1.0f};
572 V4d xDiffuse = {1.0f,1.0f,1.0f,1.0f};
573 V4d xAmbiant = {1.0f,1.0f,1.0f,1.0f};
574 V4d yDiffuse = {1.0f,1.0f,1.0f,1.0f};
575 V4d yAmbiant = {1.0f,1.0f,1.0f,1.0f};
576 V4d zDiffuse = {1.0f,1.0f,1.0f,1.0f};
577 V4d zAmbiant = {1.0f,1.0f,1.0f,1.0f};
578 V3d vectorX = {1,0,0};
579 V3d vectorY = {0,1,0};
580 V3d vectorZ = {0,0,1};
581 GLdouble radius = axis.radius;
582 gint i;
583
584 for(i=0;i<3;i++)
585 {
586 xDiffuse[i] = axis.xColor[i];
587 yDiffuse[i] = axis.yColor[i];
588 zDiffuse[i] = axis.zColor[i];
589
590 xAmbiant[i] = xDiffuse[i]/10;
591 yAmbiant[i] = yDiffuse[i]/10;
592 zAmbiant[i] = zDiffuse[i]/10;
593 }
594 xDiffuse[3] = 1;
595 yDiffuse[3] = 1;
596 zDiffuse[3] = 1;
597
598 for(i=0;i<3;i++)
599 {
600 vectorX[i] *= axis.scal;
601 vectorY[i] *= axis.scal;
602 vectorZ[i] *= axis.scal;
603 }
604
605
606 if (glIsList(axisList) == GL_TRUE) glDeleteLists(axisList,1);
607
608 axisList = glGenLists(1);
609 glNewList(axisList, GL_COMPILE);
610 drawAxis(vectorX, radius, axis.origin, specular, xDiffuse, xAmbiant);
611 drawAxis(vectorY, radius, axis.origin, specular, yDiffuse, yAmbiant);
612 drawAxis(vectorZ, radius, axis.origin, specular, zDiffuse, zAmbiant);
613 glEndList();
614 return axisList;
615 }
616 /************************************************************************/
axisShowList(GLuint axisList)617 void axisShowList(GLuint axisList)
618 {
619 if(TypeGeom==GABEDIT_TYPEGEOM_NO) return;
620
621 if(!axis.show) return;
622
623 if (glIsList(axisList) == GL_TRUE) glCallList(axisList);
624
625 }
626 /************************************************************************/
627
628
629