atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
d_bonds.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'd_bonds.c'
24*
25* Contains:
26*
27
28 - The functions to prepare the OpenGL rendering of bond(s) and clone bond(s)
29
30*
31* List of functions:
32
33 int cylinder_vertices (int qual);
34 int cylinder_indices (int qual);
35 int cap_vertices (int qual);
36 int cap_indices (int qual);
37 int find_bond_vertices (gboolean to_pick, int sty, int sa, int sb, int bi, int cap);
38 int create_bond_lists (gboolean to_pick);
39
40 float get_bond_radius (int sty, int ac, int at, int bt, int sel);
41
42 void setup_line_vertice (float * vertices, vec3_t pos, ColRGBA col, float alpha);
43 void setup_cylinder_vertice (float * vertices, vec3_t pos_a, vec3_t pos_b, ColRGBA col, float rad, float alpha, float delta);
44 void setup_cap_vertice (float * vertices, vec3_t pos_a, vec3_t pos_b, ColRGBA col, float rad, float alpha);
45 void setup_this_bond (int sty, gboolean to_pick, gboolean picked, int cap, int bi, int pi, atom * at, atom * bt, float al, float * vertices);
46 void prepare_bond (int sty, gboolean to_pick, gboolean picked, int cap, int bi, int pi, int bid, atom * at, atom * bt, float * vertices);
47 void setup_all_cylinder_vertices (int style, gboolean to_pick, int cap, int bi, float * vertices);
48 void setup_line_vertices (int style, int cap, int bi, int sa, int sb, float * vertices);
49
50 vec4_t rotate_bond (vec3_t a, vec3_t b);
51
52 object_3d * draw_cylinder (int quality, float ra, float rb);
53 object_3d * draw_cylinder_cap (int quality, float rad, gboolean picked);
54
55*/
56
57#include "global.h"
58#include "glview.h"
59#include "dlp_field.h"
60
61extern ColRGBA get_atom_color (int i, int j, double al, int picked, gboolean to_picked);
63extern int nbs;
64
73{
74 return 2*qual;
75}
76
85{
86 return 2*(qual + 1);
87}
88
98object_3d * draw_cylinder (int quality, float ra, float rb)
99{
100 int i, j;
101 object_3d * new_cylinder = g_malloc0 (sizeof*new_cylinder);
102 new_cylinder -> quality = quality;
103 new_cylinder -> num_vertices = cylinder_vertices (quality);
104 new_cylinder -> vert_buffer_size = 3;
105 new_cylinder -> vertices = allocfloat (3*new_cylinder -> num_vertices);
106 new_cylinder -> num_indices = cylinder_indices (quality);
107 new_cylinder -> ind_buffer_size = 1;
108 new_cylinder -> indices = allocint (cylinder_indices (quality));
109
110 float step = 2.0 * pi / (quality-1);
111 float x, y;
112 j = 0;
113 // Vertex
114 for(i = 0; i < quality; i++)
115 {
116 x = cos (i*step);
117 y = sin (i*step);
118 new_cylinder -> vertices[j] = ra*x;
119 new_cylinder -> vertices[j+1] = ra*y;
120 new_cylinder -> vertices[j+2] = 0.5;
121 j += 3;
122 new_cylinder -> vertices[j] = rb*x;
123 new_cylinder -> vertices[j+1] = rb*y;
124 new_cylinder -> vertices[j+2] = -0.5;
125 j += 3;
126 }
127
128 for (i = 0; i < 2*quality; i++)
129 {
130 new_cylinder -> indices[i] = i % (2*quality-2);
131 }
132
133 return new_cylinder;
134}
135
144{
145 return qual + 1;
146}
147
156{
157 return qual + 2;
158}
159
169object_3d * draw_cylinder_cap (int quality, float rad, gboolean picked)
170{
171 int i, j;
172
173 object_3d * new_cap = g_malloc0 (sizeof*new_cap);
174 new_cap -> quality = quality;
175 new_cap -> num_vertices = cap_vertices(quality);
176 new_cap -> vert_buffer_size = 3;
177 new_cap -> vertices = allocfloat (3*new_cap -> num_vertices);
178 new_cap -> num_indices = cap_indices(quality);
179 new_cap -> ind_buffer_size = 1;
180 new_cap -> indices = allocint (new_cap -> num_indices);
181
182 float delta = (picked) ? 0.05 : 0.0;
183 float step = 2.0 * pi / (quality - 1);
184 float x, y;
185 j = 0;
186 // Center
187 new_cap -> vertices[j] = 0.0;
188 new_cap -> vertices[j+1] = 0.0;
189 new_cap -> vertices[j+2] = 0.0 - delta;
190 j += 3;
191 for(i = 0; i < quality; i++)
192 {
193 x = cos (i*step);
194 y = sin (i*step);
195 new_cap -> vertices[j] = rad*x;
196 new_cap -> vertices[j+1] = rad*y;
197 new_cap -> vertices[j+2] = 0.0 - delta;
198 j += 3;
199 }
200
201 for (i=0; i <= quality; i++)
202 {
203 new_cap -> indices[i] = i % (quality + 1);
204 }
205 return new_cap;
206}
207
217{
218 vec3_t c, f, raxis;
219 c = v3_sub (vec3(b.x, b.y, b.z), vec3(a.x, a.y, a.z));
220 f = vec3 (0.0, 0.0, 1.0);
221 double rangle;
222 raxis = v3_cross (f, c);
223 //rangle = 180.0 / pi * acos(v3_dot(f, c) / v3_length(c));
224 rangle = acos(v3_dot(f, c) / v3_length(c));
225 return axis_to_quat (raxis, rangle);
226}
227
239float get_bond_radius (int sty, int ac, int at, int bt, int sel)
240{
241 if (sty == BALL_AND_STICK)
242 {
243 return plot -> bondrad[at][bt] + 0.05*sel;
244 }
245 else if (sty == CYLINDERS)
246 {
247 return plot -> radall[ac] + 0.05*sel;
248 }
249 else
250 {
251 return plot -> linerad[at][bt] + 4.0*sel;
252 }
253}
254
265void setup_line_vertice (float * vertices, vec3_t pos, ColRGBA col, float alpha)
266{
267 int s = nbs*LINE_BUFF_SIZE;
268 vertices[s] = pos.x;
269 vertices[s+1] = pos.y;
270 vertices[s+2] = pos.z;
271 vertices[s+3] = col.red;
272 vertices[s+4] = col.green;
273 vertices[s+5] = col.blue;
274 vertices[s+6] = col.alpha * alpha;
275 nbs ++;
276}
277
291void setup_cylinder_vertice (float * vertices, vec3_t pos_a, vec3_t pos_b, ColRGBA col, float rad, float alpha, float delta)
292{
293 int s = nbs*CYLI_BUFF_SIZE;
294 vertices[s] = (pos_a.x + pos_b.x)/2.0;
295 vertices[s+1] = (pos_a.y + pos_b.y)/2.0;
296 vertices[s+2] = (pos_a.z + pos_b.z)/2.0;
297 vertices[s+3] = v3_length(v3_sub(pos_a, pos_b)) + delta;
298 vertices[s+4] = rad;
299 vec4_t quat = rotate_bond (pos_b, pos_a);
300 vertices[s+5] = quat.w;
301 vertices[s+6] = quat.x;
302 vertices[s+7] = quat.y;
303 vertices[s+8] = quat.z;
304 vertices[s+9] = col.red;
305 vertices[s+10] = col.green;
306 vertices[s+11] = col.blue;
307 vertices[s+12] = col.alpha * alpha;
308 nbs ++;
309}
310
323void setup_cap_vertice (float * vertices, vec3_t pos_a, vec3_t pos_b, ColRGBA col, float rad, float alpha)
324{
325 int s = nbs*CAPS_BUFF_SIZE;
326 vertices[s] = pos_b.x;
327 vertices[s+1] = pos_b.y;
328 vertices[s+2] = pos_b.z;
329 vertices[s+3] = rad;
330 vec4_t quat = rotate_bond (pos_b, pos_a);
331 vertices[s+4] = quat.w;
332 vertices[s+5] = quat.x;
333 vertices[s+6] = quat.y;
334 vertices[s+7] = quat.z;
335 vertices[s+8] = col.red;
336 vertices[s+9] = col.green;
337 vertices[s+10] = col.blue;
338 vertices[s+11] = col.alpha * alpha;
339 nbs ++;
340}
341
343
360void setup_this_bond (int sty, gboolean to_pick, gboolean picked, int cap, int bi, int pi, atom * at, atom * bt, float al, float * vertices)
361{
362 float alpha = 1.0;
363 float delta = 0.0;
364 float shift[3];
365 int p, q, r;
366 vec3_t pos_a, pos_b;
367 ColRGBA col = get_atom_color (at -> sp, at -> id, 1.0, (picked) ? pi + 1 : 0, to_pick);
368 float rad = get_bond_radius ((to_pick) ? BALL_AND_STICK : (sty == NONE) ? plot -> style : sty, bi, at -> sp, bt -> sp, (picked) ? 1.0 : 0.0);
369 if (! cap && picked)
370 {
371 gboolean show_a, show_b;
372 int sta, stb;
373 if (in_movie_encoding && plot -> at_data != NULL)
374 {
375 show_a = plot -> at_data[bt -> id].show[bi];
376 show_b = plot -> at_data[bt -> id].pick[pi];
377 sta = plot -> at_data[at -> id].style;
378 stb = plot -> at_data[bt -> id].style;
379 }
380 else
381 {
382 show_a = bt -> show[bi];
383 show_b = bt -> pick[pi];
384 sta = at -> style;
385 stb = bt -> style;
386 }
387 delta = ((show_a && show_b) && (sta == stb)) ? 0.0 : 0.1;
388 }
389 for (p=0; p<plot -> extra_cell[0]+1;p++)
390 {
391 for (q=0; q<plot -> extra_cell[1]+1; q++)
392 {
393 for (r=0; r<plot -> extra_cell[2]+1; r++)
394 {
395 shift[0]=p*box_gl -> vect[0][0]+q*box_gl -> vect[1][0]+r*box_gl -> vect[2][0];
396 shift[1]=p*box_gl -> vect[0][1]+q*box_gl -> vect[1][1]+r*box_gl -> vect[2][1];
397 shift[2]=p*box_gl -> vect[0][2]+q*box_gl -> vect[1][2]+r*box_gl -> vect[2][2];
398 at_shift (at, shift);
399 at_shift (bt, shift);
400 pos_a = vec3(at -> x, at -> y, at -> z);
401 pos_b = vec3((at -> x + bt -> x)/2.0, (at -> y + bt -> y)/2.0, (at -> z + bt -> z)/2.0);
402 if (to_pick || ((sty == NONE && (plot -> style == BALL_AND_STICK || plot -> style == CYLINDERS)) || sty == BALL_AND_STICK || sty == CYLINDERS))
403 {
404 if (cap)
405 {
406 setup_cap_vertice (vertices, pos_a, pos_b, col, rad, alpha * al);
407 }
408 else
409 {
410 setup_cylinder_vertice (vertices, pos_a, pos_b, col, rad, (to_pick) ? 1.0 : alpha*al, delta);
411 }
412 }
413 else
414 {
415 setup_line_vertice (vertices, pos_a, col, alpha*al);
416 setup_line_vertice (vertices, pos_b, col, alpha*al);
417 }
418 at_unshift (at, shift);
419 at_unshift (bt, shift);
420 alpha = 0.5;
421 }
422 }
423 }
424}
425
442void prepare_bond (int sty, gboolean to_pick, gboolean picked, int cap, int bi, int pi, int bid, atom * at, atom * bt, float * vertices)
443{
444 if (bi == 0)
445 {
446 setup_this_bond (sty, to_pick, picked, cap, bi, pi, at, bt, 1.0, vertices);
447 }
448 else
449 {
450 atom * tmp_a, * tmp_b;
451 float x, y, z;
452 int sign;
453 sign = 1;
454 if (wingl -> bondid[step][1][bid][0] == at -> id) sign = -1;
455 x = wingl -> clones[step][bid].x;
456 y = wingl -> clones[step][bid].y;
457 z = wingl -> clones[step][bid].z;
458 tmp_a = duplicate_atom (at);
459 tmp_b = duplicate_atom (at);
460 tmp_a -> pick[pi] = bt -> pick[pi];
461 tmp_a -> style = bt -> style;
462 tmp_a -> sp = bt -> sp + proj_sp;
463 tmp_b -> sp += proj_sp;
464 tmp_a -> x += sign * x;
465 tmp_a -> y += sign * y;
466 tmp_a -> z += sign * z;
467 setup_this_bond (sty, to_pick, picked, cap, bi, pi, tmp_b, tmp_a, 0.5, vertices);
468 g_free (tmp_a);
469 g_free (tmp_b);
470
471 tmp_a = duplicate_atom (bt);
472 tmp_b = duplicate_atom (bt);
473 tmp_a -> pick[pi] = at -> pick[pi];
474 tmp_a -> style = at -> style;
475 tmp_a -> sp = at -> sp + proj_sp;
476 tmp_b -> sp += proj_sp;
477 tmp_a -> id = at -> id;
478 tmp_a -> x -= sign * x;
479 tmp_a -> y -= sign * y;
480 tmp_a -> z -= sign * z;
481 setup_this_bond (sty, to_pick, picked, cap, bi, pi, tmp_a, tmp_b, 0.5, vertices);
482 g_free (tmp_a);
483 g_free (tmp_b);
484 }
485}
486
499int find_bond_vertices (gboolean to_pick, int sty, int sa, int sb, int bi, int cap)
500{
501 int i, j, k, l, m, n;
502 gboolean show_a, show_b;
503 l = 0;
504 for (i=0; i < wingl -> bonds[step][bi]; i++)
505 {
506 j = wingl -> bondid[step][bi][i][0];
507 k = wingl -> bondid[step][bi][i][1];
508 if (in_movie_encoding && plot -> at_data != NULL)
509 {
510 show_a = plot -> at_data[j].show[bi];
511 m = plot -> at_data[j].style;
512 show_b = plot -> at_data[k].show[bi];
513 n = plot -> at_data[k].style;
514 }
515 else
516 {
517 show_a = proj_gl -> atoms[step][j].show[bi];
518 m = proj_gl -> atoms[step][j].style;
519 show_b = proj_gl -> atoms[step][k].show[bi];
520 n = proj_gl -> atoms[step][k].style;
521 }
522 if (proj_gl -> atoms[step][j].sp == sa && proj_gl -> atoms[step][k].sp == sb)
523 {
524 if (show_a && (m == sty || to_pick))
525 {
526 if (cap)
527 {
528 if (! show_b || n != sty) l += 1 + bi;
529 }
530 else
531 {
532 l += 1 + bi;
533 }
534 }
535 }
536 if (proj_gl -> atoms[step][j].sp == sb && proj_gl -> atoms[step][k].sp == sa)
537 {
538 if (show_b && (n == sty || to_pick))
539 {
540 if (cap)
541 {
542 if (! show_a || m != sty) l += 1 + bi;
543 }
544 else
545 {
546 l += 1 + bi;
547 }
548 }
549 }
550 }
551 return 2*l;
552}
553
565void setup_all_cylinder_vertices (int style, gboolean to_pick, int cap, int bi, float * vertices)
566{
567 int i, j, k, l, m;
568 gboolean show_a, show_b;
569 for (i=0; i < wingl -> bonds[step][bi]; i++)
570 {
571 j = wingl -> bondid[step][bi][i][0];
572 k = wingl -> bondid[step][bi][i][1];
573 if (in_movie_encoding && plot -> at_data != NULL)
574 {
575 show_a = plot -> at_data[j].show[bi];
576 l = plot -> at_data[j].style;
577 show_b = plot -> at_data[k].show[bi];
578 m = plot -> at_data[k].style;;
579 }
580 else
581 {
582 show_a = proj_gl -> atoms[step][j].show[bi];
583 l = proj_gl -> atoms[step][j].style;
584 show_b = proj_gl -> atoms[step][k].show[bi];
585 m = proj_gl -> atoms[step][k].style;
586 }
587 if (show_a && (l == style || to_pick))
588 {
589 if (cap)
590 {
591 if (! show_b || m != style) prepare_bond (style, to_pick, FALSE, cap, bi, 0, i, & proj_gl -> atoms[step][j], & proj_gl -> atoms[step][k], vertices);
592 }
593 else
594 {
595 prepare_bond (style, to_pick, FALSE, cap, bi, 0, i, & proj_gl -> atoms[step][j], & proj_gl -> atoms[step][k], vertices);
596 }
597 }
598 if (show_b && (m == style || to_pick))
599 {
600 if (cap)
601 {
602 if (! show_a || l != style) prepare_bond (style, to_pick, FALSE, cap, bi, 0, i, & proj_gl -> atoms[step][k], & proj_gl -> atoms[step][j], vertices);
603 }
604 else
605 {
606 prepare_bond (style, to_pick, FALSE, cap, bi, 0, i, & proj_gl -> atoms[step][k], & proj_gl -> atoms[step][j], vertices);
607 }
608 }
609 }
610}
611
624void setup_line_vertices (int style, int cap, int bi, int sa, int sb, float * vertices)
625{
626 int i, j, k, l, m;
627 gboolean show_a, show_b;
628 for (i=0; i < wingl -> bonds[step][bi]; i++)
629 {
630 j = wingl -> bondid[step][bi][i][0];
631 k = wingl -> bondid[step][bi][i][1];
632 if (in_movie_encoding && plot -> at_data != NULL)
633 {
634 show_a = plot -> at_data[j].show[bi];
635 l = plot -> at_data[j].style;
636 show_b = plot -> at_data[k].show[bi];
637 m = plot -> at_data[k].style;
638 }
639 else
640 {
641 show_a = proj_gl -> atoms[step][j].show[bi];
642 l = proj_gl -> atoms[step][j].style;
643 show_b = proj_gl -> atoms[step][k].show[bi];
644 m = proj_gl -> atoms[step][k].style;
645 }
646 if (proj_gl -> atoms[step][j].sp == sa && proj_gl -> atoms[step][k].sp == sb)
647 {
648 if (show_a && l == style)
649 {
650 prepare_bond (style, FALSE, FALSE, cap, bi, 0, i, & proj_gl -> atoms[step][j], & proj_gl -> atoms[step][k], vertices);
651 }
652 }
653 if (proj_gl -> atoms[step][j].sp == sb && proj_gl -> atoms[step][k].sp == sa)
654 {
655 if (show_b && m == style)
656 {
657 prepare_bond (style, FALSE, FALSE, cap, bi, 0, i, & proj_gl -> atoms[step][k], & proj_gl -> atoms[step][j], vertices);
658 }
659 }
660 }
661}
662
670int create_bond_lists (gboolean to_pick)
671{
672 int nshaders = 0;
673 int **** nbonds;
674 int **** ncaps;
675 int nbds[7];
676 int ncap[7];
677 object_3d * cyl, * cap;
678 int f, g, h, i, j, k, l, m;
679
680 if (! to_pick)
681 {
683 wingl -> create_shaders[BONDS] = FALSE;
684 }
685
686 g = (plot -> draw_clones) ? 2 : 1;
687
689 if (! to_pick) ncaps = allocqint (NUM_STYLES, g, proj_sp, proj_sp);
690
691 for (f=0; f<NUM_STYLES; f++)
692 {
693 nbds[f] = ncap[f] = 0;
694 k = l = m = 0;
695 if (to_pick || (! f && (plot -> style != SPHERES && plot -> style != PUNT)) || (f && f-1 != SPHERES && f-1 != PUNT))
696 {
697 for (h=0; h<g; h++)
698 {
699 for (i=0; i<proj_sp; i++)
700 {
701 for (j=0; j<proj_sp; j++)
702 {
703 nbonds[f][h][i][j] = find_bond_vertices (to_pick, f-1, i, j, h, 0);
704 k += nbonds[f][h][i][j];
705 if (nbonds[f][h][i][j] > 0) l ++;
706 if (! to_pick && ((! f && (plot -> style == BALL_AND_STICK || plot -> style == CYLINDERS)) || (f && (f-1 == BALL_AND_STICK || f-1 == CYLINDERS))))
707 {
708 ncaps[f][h][i][j] = find_bond_vertices (to_pick, f-1, i, j, h, 1);
709 m += ncaps[f][h][i][j];
710 }
711 }
712 }
713 }
714 nbds[f] = k;
715 ncap[f] = m;
716 if (to_pick || (((! f && (plot -> style == BALL_AND_STICK || plot -> style == CYLINDERS)) || (f && (f-1 == BALL_AND_STICK || f-1 == CYLINDERS)))))
717 {
718 if (k > 0)
719 {
720 nshaders ++;
721 if (m > 0 && ! to_pick) nshaders ++;
722 }
723 }
724 else
725 {
726 nshaders += l;
727 }
728 }
729 if (to_pick) break;
730 }
731#ifdef DEBUG
732 g_debug ("Bond LIST:: to_pick= %s, shaders= %d", (to_pick) ? "true" : "false", nshaders);
733#endif
734 if (nshaders == 0) return nshaders;
735 if (! to_pick) wingl -> ogl_glsl[BONDS][step] = g_malloc0 (nshaders*sizeof*wingl -> ogl_glsl[BONDS][step]);
736 l = 0;
737 for (f=0; f<NUM_STYLES; f++)
738 {
739 if (nbds[f])
740 {
741 if (to_pick || (! f && (plot -> style == BALL_AND_STICK || plot -> style == CYLINDERS)) || (f && (f-1 == BALL_AND_STICK || f-1 == CYLINDERS)))
742 {
743 cyl = draw_cylinder (plot -> quality, 1.0, 1.0);
744 cyl -> num_instances = (nbds[f]/2) * (plot -> extra_cell[0]+1)*(plot -> extra_cell[1]+1)*(plot -> extra_cell[2]+1);
745 cyl -> inst_buffer_size = CYLI_BUFF_SIZE;
746 cyl -> instances = allocfloat (CYLI_BUFF_SIZE*cyl -> num_instances);
747 nbs = 0;
748 for (h=0; h<g; h++)
749 {
750 setup_all_cylinder_vertices (f-1, to_pick, 0, h, cyl -> instances);
751 if (to_pick && h==0) wingl -> bonds_to_be_picked = wingl -> to_be_picked;
752 }
753 if (! to_pick)
754 {
755 wingl -> ogl_glsl[BONDS][step][l] = init_shader_program (BONDS, GLSL_CYLINDERS, cylinder_vertex, NULL, full_color, GL_TRIANGLE_STRIP, 6, 1, TRUE, cyl);
756 g_free (cyl);
757 l ++;
758 if (ncap[f] > 0)
759 {
760 cap = draw_cylinder_cap (plot -> quality, 1.0, FALSE);
761 cap -> num_instances = (ncap[f]/2) * (plot -> extra_cell[0]+1)*(plot -> extra_cell[1]+1)*(plot -> extra_cell[2]+1);
762 cap -> inst_buffer_size = CAPS_BUFF_SIZE;
763 cap -> instances = allocfloat (CAPS_BUFF_SIZE*cap -> num_instances);
764 nbs = 0;
765 for (h=0; h<g; h++)
766 {
767 setup_all_cylinder_vertices (f-1, FALSE, 1, h, cap -> instances);
768 }
769 wingl -> ogl_glsl[BONDS][step][l] = init_shader_program (BONDS, GLSL_CAPS, cap_vertex, NULL, full_color, GL_TRIANGLE_FAN, 5, 1, TRUE, cap);
770 g_free (cap);
771 l ++;
772 }
773 }
774 else
775 {
776 wingl -> ogl_glsl[PICKS][0][1] = init_shader_program (PICKS, GLSL_CYLINDERS, cylinder_vertex, NULL, full_color, GL_TRIANGLE_STRIP, 6, 1, FALSE, cyl);
777 g_free (cyl);
778 }
779 }
780 else if ((! f && (plot -> style != SPHERES && plot -> style != PUNT)) || (f && f-1 != SPHERES && f-1 != PUNT))
781 {
782 for (h=0; h<g; h++)
783 {
784 for (i=0; i<proj_sp; i++)
785 {
786 for (j=0; j<proj_sp; j++)
787 {
788 if (nbonds[f][h][i][j])
789 {
790 cyl = g_malloc0 (sizeof*cyl);
791 cyl -> vert_buffer_size = LINE_BUFF_SIZE;
792 cyl -> num_vertices = nbonds[f][h][i][j] * (plot -> extra_cell[0]+1)*(plot -> extra_cell[1]+1)*(plot -> extra_cell[2]+1);
793 cyl -> vertices = allocfloat (cyl -> vert_buffer_size*cyl -> num_vertices);
794 nbs = 0;
795 setup_line_vertices (f-1, 0, h, i, j, cyl -> vertices);
796 wingl -> ogl_glsl[BONDS][step][l] = init_shader_program (BONDS, GLSL_LINES, line_vertex, NULL, line_color, GL_LINES, 2, 1, FALSE, cyl);
797 wingl -> ogl_glsl[BONDS][step][l] -> line_width = get_bond_radius (WIREFRAME, h, i+proj_sp*h, j+proj_sp*h, FALSE);
798 g_free (cyl);
799 l++;
800 }
801 }
802 }
803 }
804 }
805 }
806 if (to_pick) break;
807 }
808 g_free (nbonds);
809 if (! to_pick) g_free (ncaps);
810 return nshaders;
811}
int cylinder_indices(int qual)
return the number of OpenGL indices to render a cylinder
Definition d_bonds.c:84
int create_bond_lists(gboolean to_pick)
prepare bond(s) and clone bond(s) OpenGL rendering
Definition d_bonds.c:670
int find_bond_vertices(gboolean to_pick, int sty, int sa, int sb, int bi, int cap)
find bond(s) and clone bond(s) to render
Definition d_bonds.c:499
int cylinder_vertices(int qual)
return the number of OpenGL vertices to render a cylinder
Definition d_bonds.c:72
int cap_vertices(int qual)
return the number of OpenGL vertices to render a cylinder cap
Definition d_bonds.c:143
int vs_bid
Definition d_bonds.c:342
void setup_this_bond(int sty, gboolean to_pick, gboolean picked, int cap, int bi, int pi, atom *at, atom *bt, float al, float *vertices)
prepare the OpenGL rendering data of a bond / clone bond
Definition d_bonds.c:360
int nbs
Definition d_atoms.c:176
vec4_t rotate_bond(vec3_t a, vec3_t b)
rotate a bond based on the proper orientation
Definition d_bonds.c:216
void setup_line_vertices(int style, int cap, int bi, int sa, int sb, float *vertices)
prepare line bond(s) and clone bond(s) to render
Definition d_bonds.c:624
void setup_cylinder_vertice(float *vertices, vec3_t pos_a, vec3_t pos_b, ColRGBA col, float rad, float alpha, float delta)
fill the OpenGL data buffer for a cylinder bond (or clone bond) to render
Definition d_bonds.c:291
void setup_line_vertice(float *vertices, vec3_t pos, ColRGBA col, float alpha)
fill the OpenGL data buffer for a line bond (or clone bond) to render
Definition d_bonds.c:265
object_3d * draw_cylinder_cap(int quality, float rad, gboolean picked)
OpenGL 3D cylinder cap object rendering.
Definition d_bonds.c:169
ColRGBA get_atom_color(int i, int j, double al, int picked, gboolean to_picked)
get atom (or clone) color
Definition d_atoms.c:74
object_3d * draw_cylinder(int quality, float ra, float rb)
OpenGL 3D cylinder object rendering.
Definition d_bonds.c:98
void setup_cap_vertice(float *vertices, vec3_t pos_a, vec3_t pos_b, ColRGBA col, float rad, float alpha)
fill the OpenGL data buffer for a cylinder cap bond (or clone bond) to render
Definition d_bonds.c:323
int cap_indices(int qual)
return the number of OpenGL indices to render a cylinder cap
Definition d_bonds.c:155
vec3_t model_position
void setup_all_cylinder_vertices(int style, gboolean to_pick, int cap, int bi, float *vertices)
prepare cylinder bond(s) and clone bond(s) to render
Definition d_bonds.c:565
void prepare_bond(int sty, gboolean to_pick, gboolean picked, int cap, int bi, int pi, int bid, atom *at, atom *bt, float *vertices)
prepare a bond OpenGL rendering
Definition d_bonds.c:442
float get_bond_radius(int sty, int ac, int at, int bt, int sel)
get bond (clone bond) radius
Definition d_bonds.c:239
ColRGBA col
Definition d_measures.c:77
atom_in_selection * tmp_a
Definition d_measures.c:69
atom_in_selection * tmp_b
Definition d_measures.c:69
int * shift
Definition d_measures.c:72
int atoms[NUM_STYLES][2]
int *** nbonds[NUM_STYLES][2]
int bonds[NUM_STYLES][2]
GtkTreeSelection * sel
Definition datab.c:102
Variable declarations for the creation of the DL_POLY input file(s)
double pi
Definition global.c:195
gboolean in_movie_encoding
Definition global.c:180
int * allocint(int val)
allocate an int * pointer
Definition global.c:326
int **** allocqint(int wal, int xal, int yal, int zal)
allocate an int **** pointer
Definition global.c:389
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:410
Global variable declarations Global convenience function declarations Global data structure defin...
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
image * plot
Definition ogl_draw.c:66
void at_unshift(atom *at, float *shift)
correct atomic coordinates modified to display image in cell replica
Definition ogl_draw.c:447
project * proj_gl
Definition ogl_draw.c:60
glwin * wingl
Definition ogl_draw.c:59
gboolean pick
int proj_sp
Definition ogl_draw.c:61
void at_shift(atom *at, float *shift)
modify atomic coordinates to display image in cell replica
Definition ogl_draw.c:432
box_info * box_gl
Definition ogl_draw.c:64
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
int qual
Definition ogl_draw.c:67
#define NUM_STYLES
Definition glview.h:168
int step
Definition ogl_draw.c:70
atom * duplicate_atom(atom *at)
copy (partially) an atom data structure
Definition ogl_draw.c:396
glsl_program * init_shader_program(int object, int object_id, const GLchar *vertex, const GLchar *geometry, const GLchar *fragment, GLenum type_of_vertices, int narray, int nunif, gboolean lightning, object_3d *obj)
create an OpenGL shader program
@ SPHERES
Definition glview.h:176
@ BALL_AND_STICK
Definition glview.h:173
@ CYLINDERS
Definition glview.h:177
@ WIREFRAME
Definition glview.h:174
@ NONE
Definition glview.h:172
@ PUNT
Definition glview.h:178
@ BONDS
Definition glwin.h:90
@ PICKS
Definition glwin.h:97
double z
Definition ogl_draw.c:57
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
const GLchar * full_color
const GLchar * cylinder_vertex
const GLchar * line_color
const GLchar * cap_vertex
const GLchar * line_vertex
Definition ogl_shaders.c:80
#define LINE_BUFF_SIZE
Definition ogl_shading.h:49
#define CAPS_BUFF_SIZE
Definition ogl_shading.h:51
#define CYLI_BUFF_SIZE
Definition ogl_shading.h:50
@ GLSL_CAPS
Definition ogl_shading.h:42
@ GLSL_LINES
Definition ogl_shading.h:40
@ GLSL_CYLINDERS
Definition ogl_shading.h:41
float blue
Definition global.h:118
float alpha
Definition global.h:119
float red
Definition global.h:116
float green
Definition global.h:117
Definition global.h:839
int style
Definition glwin.h:427
float y
Definition math_3d.h:130
float x
Definition math_3d.h:130
float z
Definition math_3d.h:130
float w
Definition math_3d.h:149
float y
Definition math_3d.h:149
float x
Definition math_3d.h:149
float z
Definition math_3d.h:149
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
gchar * al[3]
Definition w_axis.c:67