Blender V4.3
gpu_immediate_util.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstdio>
12#include <cstring>
13
14#include "BLI_math_rotation.h"
15#include "BLI_utildefines.h"
16
17#include "GPU_immediate.hh"
18
19#include "UI_resources.hh"
20
21static const float cube_coords[8][3] = {
22 {-1, -1, -1},
23 {-1, -1, +1},
24 {-1, +1, -1},
25 {-1, +1, +1},
26 {+1, -1, -1},
27 {+1, -1, +1},
28 {+1, +1, -1},
29 {+1, +1, +1},
30};
31static const int cube_quad_index[6][4] = {
32 {0, 1, 3, 2},
33 {0, 2, 6, 4},
34 {0, 4, 5, 1},
35 {1, 5, 7, 3},
36 {2, 3, 7, 6},
37 {4, 6, 7, 5},
38};
39static const int cube_line_index[12][2] = {
40 {0, 1},
41 {0, 2},
42 {0, 4},
43 {1, 3},
44 {1, 5},
45 {2, 3},
46 {2, 6},
47 {3, 7},
48 {4, 5},
49 {4, 6},
50 {5, 7},
51 {6, 7},
52};
53
54void immRectf(uint pos, float x1, float y1, float x2, float y2)
55{
57 immVertex2f(pos, x1, y1);
58 immVertex2f(pos, x2, y1);
59 immVertex2f(pos, x2, y2);
60 immVertex2f(pos, x1, y2);
61 immEnd();
62}
63
64void immRecti(uint pos, int x1, int y1, int x2, int y2)
65{
67 immVertex2i(pos, x1, y1);
68 immVertex2i(pos, x2, y1);
69 immVertex2i(pos, x2, y2);
70 immVertex2i(pos, x1, y2);
71 immEnd();
72}
73
74void immRectf_fast(uint pos, float x1, float y1, float x2, float y2)
75{
76 immVertex2f(pos, x1, y1);
77 immVertex2f(pos, x2, y1);
78 immVertex2f(pos, x2, y2);
79
80 immVertex2f(pos, x1, y1);
81 immVertex2f(pos, x2, y2);
82 immVertex2f(pos, x1, y2);
83}
84
86 uint pos, uint col, float x1, float y1, float x2, float y2, const float color[4])
87{
89 immVertex2f(pos, x1, y1);
91 immVertex2f(pos, x2, y1);
93 immVertex2f(pos, x2, y2);
94
96 immVertex2f(pos, x1, y1);
98 immVertex2f(pos, x2, y2);
100 immVertex2f(pos, x1, y2);
101}
102
104 uint pos, uint col, int x1, int y1, int x2, int y2, const float color[4])
105{
107 immVertex2i(pos, x1, y1);
109 immVertex2i(pos, x2, y1);
111 immVertex2i(pos, x2, y2);
112
114 immVertex2i(pos, x1, y1);
116 immVertex2i(pos, x2, y2);
118 immVertex2i(pos, x1, y2);
119}
120
121#if 0 /* more complete version in case we want that */
122void immRecti_complete(int x1, int y1, int x2, int y2, const float color[4])
123{
125 uint pos = add_attr(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
128 immRecti(pos, x1, y1, x2, y2);
130}
131#endif
132
134{
135 immUniformColor3ub(((x) & 0xFF), (((x) >> 8) & 0xFF), (((x) >> 16) & 0xFF));
136}
137
138static void imm_draw_circle(GPUPrimType prim_type,
139 const uint shdr_pos,
140 float x,
141 float y,
142 float radius_x,
143 float radius_y,
144 int nsegments)
145{
146 if (prim_type == GPU_PRIM_LINE_LOOP) {
147 /* NOTE(Metal/AMD): For small primitives, line list more efficient than line strip.. */
148 immBegin(GPU_PRIM_LINES, nsegments * 2);
149
150 immVertex2f(shdr_pos, x + (radius_x * cosf(0.0f)), y + (radius_y * sinf(0.0f)));
151 for (int i = 1; i < nsegments; i++) {
152 const float angle = float(2 * M_PI) * (float(i) / float(nsegments));
153 immVertex2f(shdr_pos, x + (radius_x * cosf(angle)), y + (radius_y * sinf(angle)));
154 immVertex2f(shdr_pos, x + (radius_x * cosf(angle)), y + (radius_y * sinf(angle)));
155 }
156 immVertex2f(shdr_pos, x + (radius_x * cosf(0.0f)), y + (radius_y * sinf(0.0f)));
157 immEnd();
158 }
159 else {
160 immBegin(prim_type, nsegments);
161 for (int i = 0; i < nsegments; i++) {
162 const float angle = float(2 * M_PI) * (float(i) / float(nsegments));
163 immVertex2f(shdr_pos, x + (radius_x * cosf(angle)), y + (radius_y * sinf(angle)));
164 }
165 immEnd();
166 }
167}
168
169void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
170{
171 imm_draw_circle(GPU_PRIM_LINE_LOOP, shdr_pos, x, y, radius, radius, nsegments);
172}
173
174void imm_draw_circle_fill_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
175{
176 imm_draw_circle(GPU_PRIM_TRI_FAN, shdr_pos, x, y, radius, radius, nsegments);
177}
178
180 uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments)
181{
182 imm_draw_circle(GPU_PRIM_LINE_LOOP, shdr_pos, x, y, radius_x, radius_y, nsegments);
183}
184
186 uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments)
187{
188 imm_draw_circle(GPU_PRIM_TRI_FAN, shdr_pos, x, y, radius_x, radius_y, nsegments);
189}
190
192 uint pos,
193 float x,
194 float y,
195 float radius,
196 int nsegments,
197 float start,
198 float sweep)
199{
200 /* shift & reverse angle, increase 'nsegments' to match gluPartialDisk */
201 const float angle_start = -DEG2RADF(start) + float(M_PI_2);
202 const float angle_end = -(DEG2RADF(sweep) - angle_start);
203 nsegments += 1;
204 immBegin(prim_type, nsegments);
205 for (int i = 0; i < nsegments; i++) {
206 const float angle = interpf(angle_start, angle_end, (float(i) / float(nsegments - 1)));
207 const float angle_sin = sinf(angle);
208 const float angle_cos = cosf(angle);
209 immVertex2f(pos, x + radius * angle_cos, y + radius * angle_sin);
210 }
211 immEnd();
212}
213
215 uint pos,
216 float x,
217 float y,
218 float z,
219 float rad,
220 int nsegments,
221 float start,
222 float sweep)
223{
224 /* shift & reverse angle, increase 'nsegments' to match gluPartialDisk */
225 const float angle_start = -DEG2RADF(start) + float(M_PI / 2);
226 const float angle_end = -(DEG2RADF(sweep) - angle_start);
227 nsegments += 1;
228 immBegin(prim_type, nsegments);
229 for (int i = 0; i < nsegments; i++) {
230 const float angle = interpf(angle_start, angle_end, (float(i) / float(nsegments - 1)));
231 const float angle_sin = sinf(angle);
232 const float angle_cos = cosf(angle);
233 immVertex3f(pos, x + rad * angle_cos, y + rad * angle_sin, z);
234 }
235 immEnd();
236}
237
239 uint pos, float x, float y, float radius, int nsegments, float start, float sweep)
240{
241 imm_draw_circle_partial(GPU_PRIM_LINE_STRIP, pos, x, y, radius, nsegments, start, sweep);
242}
243
245 uint pos, float x, float y, float z, float radius, int nsegments, float start, float sweep)
246{
247 imm_draw_circle_partial_3d(GPU_PRIM_LINE_STRIP, pos, x, y, z, radius, nsegments, start, sweep);
248}
249
250static void imm_draw_disk_partial(GPUPrimType prim_type,
251 uint pos,
252 float x,
253 float y,
254 float rad_inner,
255 float rad_outer,
256 int nsegments,
257 float start,
258 float sweep)
259{
260 /* to avoid artifacts */
261 const float max_angle = 3 * 360;
262 CLAMP(sweep, -max_angle, max_angle);
263
264 /* shift & reverse angle, increase 'nsegments' to match gluPartialDisk */
265 const float angle_start = -DEG2RADF(start) + float(M_PI_2);
266 const float angle_end = -(DEG2RADF(sweep) - angle_start);
267 nsegments += 1;
268 immBegin(prim_type, nsegments * 2);
269 for (int i = 0; i < nsegments; i++) {
270 const float angle = interpf(angle_start, angle_end, (float(i) / float(nsegments - 1)));
271 const float angle_sin = sinf(angle);
272 const float angle_cos = cosf(angle);
273 immVertex2f(pos, x + rad_inner * angle_cos, y + rad_inner * angle_sin);
274 immVertex2f(pos, x + rad_outer * angle_cos, y + rad_outer * angle_sin);
275 }
276 immEnd();
277}
278
280 uint pos,
281 float x,
282 float y,
283 float z,
284 float rad_inner,
285 float rad_outer,
286 int nsegments,
287 float start,
288 float sweep)
289{
290 /* to avoid artifacts */
291 const float max_angle = 3 * 360;
292 CLAMP(sweep, -max_angle, max_angle);
293
294 /* shift & reverse angle, increase 'nsegments' to match gluPartialDisk */
295 const float angle_start = -DEG2RADF(start) + float(M_PI_2);
296 const float angle_end = -(DEG2RADF(sweep) - angle_start);
297 nsegments += 1;
298 immBegin(prim_type, nsegments * 2);
299 for (int i = 0; i < nsegments; i++) {
300 const float angle = interpf(angle_start, angle_end, (float(i) / float(nsegments - 1)));
301 const float angle_sin = sinf(angle);
302 const float angle_cos = cosf(angle);
303 immVertex3f(pos, x + rad_inner * angle_cos, y + rad_inner * angle_sin, z);
304 immVertex3f(pos, x + rad_outer * angle_cos, y + rad_outer * angle_sin, z);
305 }
306 immEnd();
307}
308
310 float x,
311 float y,
312 float rad_inner,
313 float rad_outer,
314 int nsegments,
315 float start,
316 float sweep)
317{
319 GPU_PRIM_TRI_STRIP, pos, x, y, rad_inner, rad_outer, nsegments, start, sweep);
320}
322 float x,
323 float y,
324 float z,
325 float rad_inner,
326 float rad_outer,
327 int nsegments,
328 float start,
329 float sweep)
330{
332 GPU_PRIM_TRI_STRIP, pos, x, y, z, rad_inner, rad_outer, nsegments, start, sweep);
333}
334
335static void imm_draw_circle_3D(GPUPrimType prim_type,
336 uint pos,
337 float x,
338 float y,
339 float radius_x,
340 float radius_y,
341 int nsegments)
342{
343 if (prim_type == GPU_PRIM_LINE_LOOP) {
344 /* NOTE(Metal/AMD): For small primitives, line list more efficient than line strip. */
345 immBegin(GPU_PRIM_LINES, nsegments * 2);
346
347 const float angle = float(2 * M_PI) / float(nsegments);
348 float xprev = cosf(-angle) * radius_x;
349 float yprev = sinf(-angle) * radius_y;
350 const float alpha = 2.0f * cosf(angle);
351
352 float xr = radius_x;
353 float yr = 0;
354
355 for (int i = 0; i < nsegments; i++) {
356 immVertex3f(pos, x + xr, y + yr, 0.0f);
357 if (i) {
358 immVertex3f(pos, x + xr, y + yr, 0.0f);
359 }
360 /* `cos[(n + 1)a] = 2cos(a)cos(na) - cos[(n - 1)a]`. */
361 const float xnext = alpha * xr - xprev;
362 /* `sin[(n + 1)a] = 2cos(a)sin(na) - sin[(n - 1)a]`. */
363 const float ynext = alpha * yr - yprev;
364 xprev = xr;
365 yprev = yr;
366 xr = xnext;
367 yr = ynext;
368 }
369 immVertex3f(pos, x + radius_x, y, 0.0f);
370 immEnd();
371 }
372 else {
373 immBegin(prim_type, nsegments);
374 for (int i = 0; i < nsegments; i++) {
375 float angle = float(2 * M_PI) * (float(i) / float(nsegments));
376 immVertex3f(pos, x + radius_x * cosf(angle), y + radius_y * sinf(angle), 0.0f);
377 }
378 immEnd();
379 }
380}
381
382void imm_draw_circle_wire_3d(uint pos, float x, float y, float radius, int nsegments)
383{
384 imm_draw_circle_3D(GPU_PRIM_LINE_LOOP, pos, x, y, radius, radius, nsegments);
385}
386
388 uint pos, float x, float y, float radius_x, float radius_y, int nsegments)
389{
390 imm_draw_circle_3D(GPU_PRIM_LINE_LOOP, pos, x, y, radius_x, radius_y, nsegments);
391}
392
393void imm_draw_circle_dashed_3d(uint pos, float x, float y, float radius, int nsegments)
394{
395 imm_draw_circle_3D(GPU_PRIM_LINES, pos, x, y, radius, radius, nsegments / 2);
396}
397
398void imm_draw_circle_fill_3d(uint pos, float x, float y, float radius, int nsegments)
399{
400 imm_draw_circle_3D(GPU_PRIM_TRI_FAN, pos, x, y, radius, radius, nsegments);
401}
402
404 uint pos, float x, float y, float radius_x, float radius_y, int nsegments)
405{
406 imm_draw_circle_3D(GPU_PRIM_TRI_FAN, pos, x, y, radius_x, radius_y, nsegments);
407}
408
409void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
410{
411 /* NOTE(Metal/AMD): For small primitives, line list more efficient than line-strip. */
413 immVertex2f(pos, x1, y1);
414 immVertex2f(pos, x1, y2);
415
416 immVertex2f(pos, x1, y2);
417 immVertex2f(pos, x2, y2);
418
419 immVertex2f(pos, x2, y2);
420 immVertex2f(pos, x2, y1);
421
422 immVertex2f(pos, x2, y1);
423 immVertex2f(pos, x1, y1);
424 immEnd();
425}
426
427void imm_draw_box_wire_3d(uint pos, float x1, float y1, float x2, float y2)
428{
429 /* use this version when GPUVertFormat has a vec3 position */
430 /* NOTE(Metal/AMD): For small primitives, line list more efficient than line-strip. */
432 immVertex3f(pos, x1, y1, 0.0f);
433 immVertex3f(pos, x1, y2, 0.0f);
434
435 immVertex3f(pos, x1, y2, 0.0f);
436 immVertex3f(pos, x2, y2, 0.0f);
437
438 immVertex3f(pos, x2, y2, 0.0f);
439 immVertex3f(pos, x2, y1, 0.0f);
440
441 immVertex3f(pos, x2, y1, 0.0f);
442 immVertex3f(pos, x1, y1, 0.0f);
443 immEnd();
444}
445
447 float y1,
448 float x2,
449 float y2,
450 const float color_primary[4],
451 const float color_secondary[4],
452 int checker_size)
453{
455
457
458 immUniform4fv("color1", color_primary);
459 immUniform4fv("color2", color_secondary);
460 immUniform1i("size", checker_size);
461
462 immRectf(pos, x1, y1, x2, y2);
463
465}
466void imm_draw_box_checker_2d(float x1, float y1, float x2, float y2)
467{
468 float checker_primary[4];
469 float checker_secondary[4];
473 imm_draw_box_checker_2d_ex(x1, y1, x2, y2, checker_primary, checker_secondary, checker_size);
474}
475
476void imm_draw_cube_fill_3d(uint pos, const float center[3], const float aspect[3])
477{
478 float coords[ARRAY_SIZE(cube_coords)][3];
479
480 for (int i = 0; i < ARRAY_SIZE(cube_coords); i++) {
481 madd_v3_v3v3v3(coords[i], center, cube_coords[i], aspect);
482 }
483
485 for (int i = 0; i < ARRAY_SIZE(cube_quad_index); i++) {
486 immVertex3fv(pos, coords[cube_quad_index[i][0]]);
487 immVertex3fv(pos, coords[cube_quad_index[i][1]]);
488 immVertex3fv(pos, coords[cube_quad_index[i][2]]);
489
490 immVertex3fv(pos, coords[cube_quad_index[i][0]]);
491 immVertex3fv(pos, coords[cube_quad_index[i][2]]);
492 immVertex3fv(pos, coords[cube_quad_index[i][3]]);
493 }
494 immEnd();
495}
496
497void imm_draw_cube_wire_3d(uint pos, const float center[3], const float aspect[3])
498{
499 float coords[ARRAY_SIZE(cube_coords)][3];
500
501 for (int i = 0; i < ARRAY_SIZE(cube_coords); i++) {
502 madd_v3_v3v3v3(coords[i], center, cube_coords[i], aspect);
503 }
504
506 for (int i = 0; i < ARRAY_SIZE(cube_line_index); i++) {
507 immVertex3fv(pos, coords[cube_line_index[i][0]]);
508 immVertex3fv(pos, coords[cube_line_index[i][1]]);
509 }
510 immEnd();
511}
512
514 const float center[3],
515 const float aspect[3],
516 const float factor)
517{
518 float coords[ARRAY_SIZE(cube_coords)][3];
519
520 for (int i = 0; i < ARRAY_SIZE(cube_coords); i++) {
521 madd_v3_v3v3v3(coords[i], center, cube_coords[i], aspect);
522 }
523
525 for (int i = 0; i < ARRAY_SIZE(cube_line_index); i++) {
526 float vec[3], co[3];
527 sub_v3_v3v3(vec, coords[cube_line_index[i][1]], coords[cube_line_index[i][0]]);
528 mul_v3_fl(vec, factor);
529
530 copy_v3_v3(co, coords[cube_line_index[i][0]]);
531 immVertex3fv(pos, co);
532 add_v3_v3(co, vec);
533 immVertex3fv(pos, co);
534
535 copy_v3_v3(co, coords[cube_line_index[i][1]]);
536 immVertex3fv(pos, co);
537 sub_v3_v3(co, vec);
538 immVertex3fv(pos, co);
539 }
540 immEnd();
541}
542
544 uint pos, uint nor, float base, float top, float height, int slices, int stacks)
545{
546 immBegin(GPU_PRIM_TRIS, 6 * slices * stacks);
547 for (int i = 0; i < slices; i++) {
548 const float angle1 = float(2 * M_PI) * (float(i) / float(slices));
549 const float angle2 = float(2 * M_PI) * (float(i + 1) / float(slices));
550 const float cos1 = cosf(angle1);
551 const float sin1 = sinf(angle1);
552 const float cos2 = cosf(angle2);
553 const float sin2 = sinf(angle2);
554
555 for (int j = 0; j < stacks; j++) {
556 float fac1 = float(j) / float(stacks);
557 float fac2 = float(j + 1) / float(stacks);
558 float r1 = base * (1.0f - fac1) + top * fac1;
559 float r2 = base * (1.0f - fac2) + top * fac2;
560 float h1 = height * (float(j) / float(stacks));
561 float h2 = height * (float(j + 1) / float(stacks));
562
563 const float v1[3] = {r1 * cos2, r1 * sin2, h1};
564 const float v2[3] = {r2 * cos2, r2 * sin2, h2};
565 const float v3[3] = {r2 * cos1, r2 * sin1, h2};
566 const float v4[3] = {r1 * cos1, r1 * sin1, h1};
567 float n1[3], n2[3];
568
569 /* calc normals */
570 sub_v3_v3v3(n1, v2, v1);
571 normalize_v3(n1);
572 n1[0] = cos1;
573 n1[1] = sin1;
574 n1[2] = 1 - n1[2];
575
576 sub_v3_v3v3(n2, v3, v4);
577 normalize_v3(n2);
578 n2[0] = cos2;
579 n2[1] = sin2;
580 n2[2] = 1 - n2[2];
581
582 /* first tri */
583 immAttr3fv(nor, n2);
584 immVertex3fv(pos, v1);
586 immAttr3fv(nor, n1);
587 immVertex3fv(pos, v3);
588
589 /* second tri */
590 immVertex3fv(pos, v3);
591 immVertex3fv(pos, v4);
592 immAttr3fv(nor, n2);
593 immVertex3fv(pos, v1);
594 }
595 }
596 immEnd();
597}
598
600 uint pos, float base, float top, float height, int slices, int stacks)
601{
602 immBegin(GPU_PRIM_LINES, 6 * slices * stacks);
603 for (int i = 0; i < slices; i++) {
604 const float angle1 = float(2 * M_PI) * (float(i) / float(slices));
605 const float angle2 = float(2 * M_PI) * (float(i + 1) / float(slices));
606 const float cos1 = cosf(angle1);
607 const float sin1 = sinf(angle1);
608 const float cos2 = cosf(angle2);
609 const float sin2 = sinf(angle2);
610
611 for (int j = 0; j < stacks; j++) {
612 float fac1 = float(j) / float(stacks);
613 float fac2 = float(j + 1) / float(stacks);
614 float r1 = base * (1.0f - fac1) + top * fac1;
615 float r2 = base * (1.0f - fac2) + top * fac2;
616 float h1 = height * (float(j) / float(stacks));
617 float h2 = height * (float(j + 1) / float(stacks));
618
619 const float v1[3] = {r1 * cos2, r1 * sin2, h1};
620 const float v2[3] = {r2 * cos2, r2 * sin2, h2};
621 const float v3[3] = {r2 * cos1, r2 * sin1, h2};
622 const float v4[3] = {r1 * cos1, r1 * sin1, h1};
623
624 immVertex3fv(pos, v1);
626
628 immVertex3fv(pos, v3);
629
630 immVertex3fv(pos, v1);
631 immVertex3fv(pos, v4);
632 }
633 }
634 immEnd();
635}
636
638 uint pos, float base, float top, float height, int slices, int stacks)
639{
640 immBegin(GPU_PRIM_TRIS, 6 * slices * stacks);
641 for (int i = 0; i < slices; i++) {
642 const float angle1 = float(2 * M_PI) * (float(i) / float(slices));
643 const float angle2 = float(2 * M_PI) * (float(i + 1) / float(slices));
644 const float cos1 = cosf(angle1);
645 const float sin1 = sinf(angle1);
646 const float cos2 = cosf(angle2);
647 const float sin2 = sinf(angle2);
648
649 for (int j = 0; j < stacks; j++) {
650 float fac1 = float(j) / float(stacks);
651 float fac2 = float(j + 1) / float(stacks);
652 float r1 = base * (1.0f - fac1) + top * fac1;
653 float r2 = base * (1.0f - fac2) + top * fac2;
654 float h1 = height * (float(j) / float(stacks));
655 float h2 = height * (float(j + 1) / float(stacks));
656
657 const float v1[3] = {r1 * cos2, r1 * sin2, h1};
658 const float v2[3] = {r2 * cos2, r2 * sin2, h2};
659 const float v3[3] = {r2 * cos1, r2 * sin1, h2};
660 const float v4[3] = {r1 * cos1, r1 * sin1, h1};
661
662 /* first tri */
663 immVertex3fv(pos, v1);
665 immVertex3fv(pos, v3);
666
667 /* second tri */
668 immVertex3fv(pos, v3);
669 immVertex3fv(pos, v4);
670 immVertex3fv(pos, v1);
671 }
672 }
673 immEnd();
674}
675
676/* Circle Drawing - Tables for Optimized Drawing Speed */
677#define CIRCLE_RESOL 32
678
679static void circball_array_fill(const float verts[CIRCLE_RESOL][3],
680 const float cent[3],
681 const float radius,
682 const float tmat[4][4])
683{
684 /* 32 values of sin function (still same result!) */
685 const float sinval[CIRCLE_RESOL] = {
686 0.00000000, 0.20129852, 0.39435585, 0.57126821, 0.72479278, 0.84864425, 0.93775213,
687 0.98846832, 0.99871650, 0.96807711, 0.89780453, 0.79077573, 0.65137248, 0.48530196,
688 0.29936312, 0.10116832, -0.10116832, -0.29936312, -0.48530196, -0.65137248, -0.79077573,
689 -0.89780453, -0.96807711, -0.99871650, -0.98846832, -0.93775213, -0.84864425, -0.72479278,
690 -0.57126821, -0.39435585, -0.20129852, 0.00000000,
691 };
692
693 /* 32 values of cos function (still same result!) */
694 const float cosval[CIRCLE_RESOL] = {
695 1.00000000, 0.97952994, 0.91895781, 0.82076344, 0.68896691, 0.52896401, 0.34730525,
696 0.15142777, -0.05064916, -0.25065253, -0.44039415, -0.61210598, -0.75875812, -0.87434661,
697 -0.95413925, -0.99486932, -0.99486932, -0.95413925, -0.87434661, -0.75875812, -0.61210598,
698 -0.44039415, -0.25065253, -0.05064916, 0.15142777, 0.34730525, 0.52896401, 0.68896691,
699 0.82076344, 0.91895781, 0.97952994, 1.00000000,
700 };
701
702 float vx[3], vy[3];
703 float *viter = (float *)verts;
704
705 mul_v3_v3fl(vx, tmat[0], radius);
706 mul_v3_v3fl(vy, tmat[1], radius);
707
708 for (uint a = 0; a < CIRCLE_RESOL; a++, viter += 3) {
709 viter[0] = cent[0] + sinval[a] * vx[0] + cosval[a] * vy[0];
710 viter[1] = cent[1] + sinval[a] * vx[1] + cosval[a] * vy[1];
711 viter[2] = cent[2] + sinval[a] * vx[2] + cosval[a] * vy[2];
712 }
713}
714
715void imm_drawcircball(const float cent[3], float radius, const float tmat[4][4], uint pos)
716{
717 float verts[CIRCLE_RESOL][3];
718
719 circball_array_fill(verts, cent, radius, tmat);
720
722 for (int i = 0; i < CIRCLE_RESOL; i++) {
724 }
725 immEnd();
726}
#define M_PI_2
MINLINE float interpf(float target, float origin, float t)
#define M_PI
#define DEG2RADF(_deg)
MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3(float n[3])
unsigned int uint
#define CLAMP(a, b, c)
#define ARRAY_SIZE(arr)
void immEnd()
void immUnbindProgram()
void immAttr4fv(uint attr_id, const float data[4])
void immUniformColor3ub(unsigned char r, unsigned char g, unsigned char b)
void immVertex2f(uint attr_id, float x, float y)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immVertex3f(uint attr_id, float x, float y, float z)
void immUniform1i(const char *name, int x)
void immVertex2i(uint attr_id, int x, int y)
GPUVertFormat * immVertexFormat()
void immUniformColor4fv(const float rgba[4])
void immUniform4fv(const char *name, const float data[4])
void immAttr3fv(uint attr_id, const float data[3])
void immVertex3fv(uint attr_id, const float data[3])
void immBegin(GPUPrimType, uint vertex_len)
GPUPrimType
@ GPU_PRIM_TRI_FAN
@ GPU_PRIM_LINE_LOOP
@ GPU_PRIM_LINES
@ GPU_PRIM_LINE_STRIP
@ GPU_PRIM_TRI_STRIP
@ GPU_PRIM_TRIS
@ GPU_SHADER_2D_CHECKER
@ GPU_SHADER_3D_UNIFORM_COLOR
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ GPU_COMP_I32
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:125
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
@ TH_TRANSPARENT_CHECKER_PRIMARY
@ TH_TRANSPARENT_CHECKER_SECONDARY
@ TH_TRANSPARENT_CHECKER_SIZE
void UI_GetThemeColor4fv(int colorid, float col[4])
int UI_GetThemeValue(int colorid)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
#define sinf(x)
#define cosf(x)
#define CIRCLE_RESOL
draw_view in_light_buf[] float
static float verts[][3]
uint col
uint top
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
void imm_draw_box_checker_2d(float x1, float y1, float x2, float y2)
void imm_draw_cylinder_wire_3d(uint pos, float base, float top, float height, int slices, int stacks)
static void circball_array_fill(const float verts[CIRCLE_RESOL][3], const float cent[3], const float radius, const float tmat[4][4])
void imm_draw_disk_partial_fill_3d(uint pos, float x, float y, float z, float rad_inner, float rad_outer, int nsegments, float start, float sweep)
static void imm_draw_disk_partial_3d(GPUPrimType prim_type, uint pos, float x, float y, float z, float rad_inner, float rad_outer, int nsegments, float start, float sweep)
void imm_draw_circle_fill_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
void imm_draw_cylinder_fill_3d(uint pos, float base, float top, float height, int slices, int stacks)
void imm_draw_circle_partial_wire_2d(uint pos, float x, float y, float radius, int nsegments, float start, float sweep)
void imm_draw_cylinder_fill_normal_3d(uint pos, uint nor, float base, float top, float height, int slices, int stacks)
void imm_draw_box_checker_2d_ex(float x1, float y1, float x2, float y2, const float color_primary[4], const float color_secondary[4], int checker_size)
void imm_draw_circle_wire_aspect_3d(uint pos, float x, float y, float radius_x, float radius_y, int nsegments)
static void imm_draw_disk_partial(GPUPrimType prim_type, uint pos, float x, float y, float rad_inner, float rad_outer, int nsegments, float start, float sweep)
void imm_draw_circle_fill_aspect_2d(uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments)
void imm_draw_circle_partial_wire_3d(uint pos, float x, float y, float z, float radius, int nsegments, float start, float sweep)
void imm_draw_circle_wire_3d(uint pos, float x, float y, float radius, int nsegments)
void imm_draw_circle_dashed_3d(uint pos, float x, float y, float radius, int nsegments)
void imm_drawcircball(const float cent[3], float radius, const float tmat[4][4], uint pos)
void imm_draw_circle_fill_3d(uint pos, float x, float y, float radius, int nsegments)
void immRectf_fast(uint pos, float x1, float y1, float x2, float y2)
void immRecti(uint pos, int x1, int y1, int x2, int y2)
static const int cube_quad_index[6][4]
void imm_draw_circle_wire_aspect_2d(uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments)
void immRectf_fast_with_color(uint pos, uint col, float x1, float y1, float x2, float y2, const float color[4])
static void imm_draw_circle_partial(GPUPrimType prim_type, uint pos, float x, float y, float radius, int nsegments, float start, float sweep)
void imm_draw_box_wire_3d(uint pos, float x1, float y1, float x2, float y2)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
static void imm_draw_circle_partial_3d(GPUPrimType prim_type, uint pos, float x, float y, float z, float rad, int nsegments, float start, float sweep)
static const float cube_coords[8][3]
static const int cube_line_index[12][2]
void imm_draw_cube_corners_3d(uint pos, const float center[3], const float aspect[3], const float factor)
void imm_draw_cube_wire_3d(uint pos, const float center[3], const float aspect[3])
static void imm_draw_circle_3D(GPUPrimType prim_type, uint pos, float x, float y, float radius_x, float radius_y, int nsegments)
void imm_draw_cube_fill_3d(uint pos, const float center[3], const float aspect[3])
void imm_cpack(uint x)
void imm_draw_circle_fill_aspect_3d(uint pos, float x, float y, float radius_x, float radius_y, int nsegments)
void imm_draw_disk_partial_fill_2d(uint pos, float x, float y, float rad_inner, float rad_outer, int nsegments, float start, float sweep)
void immRecti_fast_with_color(uint pos, uint col, int x1, int y1, int x2, int y2, const float color[4])
static void imm_draw_circle(GPUPrimType prim_type, const uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments)
void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
format
Frequency::GEOMETRY nor[]