forked from bartvdbraak/blender
New debug element "circle" for simulations, which is quite useful for
visualizing scalar fields.
This commit is contained in:
parent
7dda1ea396
commit
c37de38716
@ -150,6 +150,7 @@ typedef struct SimDebugElement {
|
||||
|
||||
typedef enum eSimDebugElement_Type {
|
||||
SIM_DEBUG_ELEM_DOT,
|
||||
SIM_DEBUG_ELEM_CIRCLE,
|
||||
SIM_DEBUG_ELEM_LINE,
|
||||
SIM_DEBUG_ELEM_VECTOR,
|
||||
} eSimDebugElement_Type;
|
||||
@ -160,6 +161,7 @@ typedef struct SimDebugData {
|
||||
|
||||
struct SimDebugData *BKE_sim_debug_data_new(void);
|
||||
void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, const char *category, int hash);
|
||||
void BKE_sim_debug_data_add_circle(struct SimDebugData *debug_data, const float p[3], const float radius, float r, float g, float b, const char *category, int hash);
|
||||
void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, const char *category, int hash);
|
||||
void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, const char *category, int hash);
|
||||
void BKE_sim_debug_data_remove(struct SimDebugData *debug_data, int hash);
|
||||
|
@ -1089,6 +1089,27 @@ void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3
|
||||
debug_data_insert(debug_data, elem);
|
||||
}
|
||||
|
||||
void BKE_sim_debug_data_add_circle(struct SimDebugData *debug_data, const float p[3], float radius, float r, float g, float b, const char *category, int hash)
|
||||
{
|
||||
int category_hash = (int)BLI_ghashutil_strhash_p(category);
|
||||
SimDebugElement *elem;
|
||||
if (!debug_data)
|
||||
return;
|
||||
|
||||
elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element");
|
||||
elem->type = SIM_DEBUG_ELEM_CIRCLE;
|
||||
elem->category_hash = category_hash;
|
||||
elem->hash = hash;
|
||||
elem->color[0] = r;
|
||||
elem->color[1] = g;
|
||||
elem->color[2] = b;
|
||||
copy_v3_v3(elem->v1, p);
|
||||
elem->v2[0] = radius;
|
||||
elem->v2[1] = elem->v2[2] = 0.0f;
|
||||
|
||||
debug_data_insert(debug_data, elem);
|
||||
}
|
||||
|
||||
void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, const char *category, int hash)
|
||||
{
|
||||
int category_hash = (int)BLI_ghashutil_strhash_p(category);
|
||||
|
@ -52,7 +52,7 @@
|
||||
|
||||
#include "UI_resources.h"
|
||||
|
||||
static void draw_sim_debug_elements(SimDebugData *debug_data)
|
||||
static void draw_sim_debug_elements(SimDebugData *debug_data, float imat[4][4])
|
||||
{
|
||||
GHashIterator iter;
|
||||
|
||||
@ -71,6 +71,38 @@ static void draw_sim_debug_elements(SimDebugData *debug_data)
|
||||
glEnd();
|
||||
glPointSize(1.0f);
|
||||
|
||||
/**** circles ****/
|
||||
|
||||
{
|
||||
float circle[16][2] = {
|
||||
{0.000000, 1.000000}, {0.382683, 0.923880}, {0.707107, 0.707107}, {0.923880, 0.382683},
|
||||
{1.000000, -0.000000}, {0.923880, -0.382683}, {0.707107, -0.707107}, {0.382683, -0.923880},
|
||||
{-0.000000, -1.000000}, {-0.382683, -0.923880}, {-0.707107, -0.707107}, {-0.923879, -0.382684},
|
||||
{-1.000000, 0.000000}, {-0.923879, 0.382684}, {-0.707107, 0.707107}, {-0.382683, 0.923880} };
|
||||
for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
|
||||
SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
|
||||
float radius = elem->v2[0];
|
||||
float co[3];
|
||||
int i;
|
||||
|
||||
if (elem->type != SIM_DEBUG_ELEM_CIRCLE)
|
||||
continue;
|
||||
|
||||
glColor3f(elem->color[0], elem->color[1], elem->color[2]);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
for (i = 0; i < 16; ++i) {
|
||||
co[0] = radius * circle[i][0];
|
||||
co[1] = radius * circle[i][1];
|
||||
co[2] = 0.0f;
|
||||
mul_mat3_m4_v3(imat, co);
|
||||
add_v3_v3(co, elem->v1);
|
||||
|
||||
glVertex3f(co[0], co[1], co[2]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/**** lines ****/
|
||||
|
||||
glBegin(GL_LINES);
|
||||
@ -119,19 +151,20 @@ void draw_sim_debug_data(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar,
|
||||
{
|
||||
RegionView3D *rv3d = ar->regiondata;
|
||||
/*Object *ob = base->object;*/
|
||||
/*float imat[4][4];*/
|
||||
float imat[4][4];
|
||||
|
||||
/*invert_m4_m4(imat, rv3d->viewmatob);*/
|
||||
if (!debug_data)
|
||||
return;
|
||||
|
||||
invert_m4_m4(imat, rv3d->viewmatob);
|
||||
|
||||
// glDepthMask(GL_FALSE);
|
||||
// glEnable(GL_BLEND);
|
||||
|
||||
glPushMatrix();
|
||||
glLoadMatrixf(rv3d->viewmat);
|
||||
|
||||
if (debug_data) {
|
||||
draw_sim_debug_elements(debug_data);
|
||||
}
|
||||
glLoadMatrixf(rv3d->viewmat);
|
||||
draw_sim_debug_elements(debug_data, imat);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user