Blender V5.3
draw_shape.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "gpu_shader_compat.hh"
12
18
19/* ---------------------------------------------------------------------- */
22
23struct Circle {
25 float radius;
26};
27
28Circle shape_circle(float2 center, float radius)
29{
30 Circle circle;
31 circle.center = center;
32 circle.radius = radius;
33 return circle;
34}
35
37
38/* ---------------------------------------------------------------------- */
41
42struct Sphere {
44 float radius;
45};
46
47Sphere shape_sphere(float3 center, float radius)
48{
49 Sphere sphere;
50 sphere.center = center;
51 sphere.radius = radius;
52 return sphere;
53}
54
56
57/* ---------------------------------------------------------------------- */
60
61struct Box {
63};
64
65/* Construct box from 4 basis points. */
66Box shape_box(float3 v000, float3 v100, float3 v010, float3 v001)
67{
68 v100 -= v000;
69 v010 -= v000;
70 v001 -= v000;
71 Box box;
72 box.corners[0] = v000;
73 box.corners[1] = v000 + v100;
74 box.corners[2] = v000 + v010 + v100;
75 box.corners[3] = v000 + v010;
76 box.corners[4] = box.corners[0] + v001;
77 box.corners[5] = box.corners[1] + v001;
78 box.corners[6] = box.corners[2] + v001;
79 box.corners[7] = box.corners[3] + v001;
80 return box;
81}
82
84
85/* ---------------------------------------------------------------------- */
88
89struct Pyramid {
90 /* Apex is the first. Base vertices are in clockwise order from front view. */
92};
93
118 float3 base_corner_00,
119 float3 base_corner_01,
120 float3 base_corner_10)
121{
122 Pyramid pyramid;
123 pyramid.corners[0] = apex;
124 pyramid.corners[1] = base_corner_00;
125 pyramid.corners[2] = base_corner_01;
126 pyramid.corners[3] = base_corner_10 + (base_corner_01 - base_corner_00);
127 pyramid.corners[4] = base_corner_10;
128 return pyramid;
129}
130
152 float3 base_center,
153 float3 base_center_pos_x,
154 float3 base_center_pos_y)
155{
156 Pyramid pyramid;
157 pyramid.corners[0] = apex;
158 pyramid.corners[1] = base_center - base_center_pos_x - base_center_pos_y;
159 pyramid.corners[2] = base_center + base_center_pos_x - base_center_pos_y;
160 pyramid.corners[3] = base_center + base_center_pos_x + base_center_pos_y;
161 pyramid.corners[4] = base_center - base_center_pos_x + base_center_pos_y;
162 return pyramid;
163}
164
166
167/* ---------------------------------------------------------------------- */
170
171struct Frustum {
173};
174
195{
196 Frustum frustum;
197 for (int i = 0; i < 8; i++) {
198 frustum.corners[i] = corners[i];
199 }
200 return frustum;
201}
202
204
205/* ---------------------------------------------------------------------- */
208
209/* Cone at origin with no height. */
210struct Cone {
213};
214
215Cone shape_cone(float3 direction, float angle_cosine)
216{
217 return {direction, angle_cosine};
218}
219
Sphere shape_sphere(float3 center, float radius)
Cone shape_cone(float3 direction, float angle_cosine)
Frustum shape_frustum(float3 corners[8])
Pyramid shape_pyramid(float3 apex, float3 base_corner_00, float3 base_corner_01, float3 base_corner_10)
Box shape_box(float3 v000, float3 v100, float3 v010, float3 v001)
Pyramid shape_pyramid_non_oblique(float3 apex, float3 base_center, float3 base_center_pos_x, float3 base_center_pos_y)
Circle shape_circle(float2 center, float radius)
VecBase< float, 2 > float2
VecBase< float, 3 > float3
float3 corners[8]
float radius
float2 center
float angle_cos
float3 direction
float3 corners[8]
float3 corners[5]
float3 center
float radius