debug draw fix

This commit is contained in:
2023-05-26 02:55:55 +00:00
parent 9045f435a0
commit 8172620214
10 changed files with 182 additions and 194 deletions

View File

@@ -32,6 +32,7 @@ struct rgba kinematic_color = {255, 194, 64, 255};
struct rgba static_color = {73,209,80,255};
static const unsigned char col_alpha = 40;
static const float sensor_seg = 10;
unsigned int category_masks[32];
@@ -338,7 +339,12 @@ void phys2d_dbgdrawbox(struct phys2d_box *box) {
for (int i = 0; i < n; i++)
points[i] = bodytransformpoint(cpShapeGetBody(box->shape.shape), cpPolyShapeGetVert(box->shape.shape, i));
draw_poly(points, n, shape_color(box->shape.shape), shape_color(box->shape.shape), 0);
struct rgba c = shape_color(box->shape.shape);
struct rgba cl = c;
cl.a = col_alpha;
float seglen = cpShapeGetSensor(box->shape.shape) ? sensor_seg : 0;
draw_line(points, n, cl,seglen, 1, 0);
draw_poly(points, n, c);
}
/************** POLYGON ************/
@@ -404,7 +410,9 @@ void phys2d_dbgdrawpoly(struct phys2d_poly *poly) {
for (int i = 0; i < n; i++)
points[i] = bodytransformpoint(cpShapeGetBody(poly->shape.shape), cpPolyShapeGetVert(poly->shape.shape, i));
draw_poly(points, n, color, line_color, 0);
draw_poly(points, n, color);
float seglen = cpShapeGetSensor(poly->shape.shape) ? sensor_seg : 0;
draw_line(points, n, line_color, seglen, 1, 0);
}
}
/****************** EDGE 2D**************/
@@ -529,7 +537,7 @@ void phys2d_dbgdrawedge(struct phys2d_edge *edge) {
drawpoints[i] = bodytransformpoint(cpShapeGetBody(edge->shapes[0]), drawpoints[i]);
}
float seglen = cpShapeGetSensor(edge->shapes[0]) ? 10 : 1;
float seglen = cpShapeGetSensor(edge->shapes[0]) ? sensor_seg : 0;
struct rgba color = shape_color(edge->shapes[0]);
struct rgba line_color = color;
color.a = col_alpha;

View File

@@ -40,6 +40,7 @@ struct line_vert {
float dist;
struct rgba color;
float seg_len;
float seg_speed;
};
static int line_c = 0;
static int line_v = 0;
@@ -186,7 +187,8 @@ void debugdraw_init()
[0].format = SG_VERTEXFORMAT_FLOAT2, /* pos */
[1].format = SG_VERTEXFORMAT_FLOAT, /* dist */
[2].format = SG_VERTEXFORMAT_UBYTE4N, /* color */
[3].format = SG_VERTEXFORMAT_FLOAT /* seg length */
[3].format = SG_VERTEXFORMAT_FLOAT, /* seg length */
[4].format = SG_VERTEXFORMAT_FLOAT /* dashed line speed */
}
},
.primitive_type = SG_PRIMITIVETYPE_LINES,
@@ -306,7 +308,7 @@ void debugdraw_init()
});
}
void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int closed)
void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int closed, float seg_speed)
{
if (a_n < 2) return;
@@ -325,6 +327,7 @@ void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int
v[i].dist = dist;
v[i].color = color;
v[i].seg_len = seg_len;
v[i].seg_speed = seg_speed;
dist += cpvdist(points[i], points[i+1]);
}
@@ -332,6 +335,7 @@ void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int
v[n-1].dist = dist;
v[n-1].color = color;
v[n-1].seg_len = seg_len;
v[n-1].seg_speed = seg_speed;
int i_c = (n-1)*2;
@@ -483,7 +487,7 @@ void draw_edge(cpVect *points, int n, struct rgba color, int thickness, int clos
/* Now drawing the line outlines */
if (thickness == 1) {
draw_line(points,n,line_color,line_seg, 0);
draw_line(points,n,line_color,line_seg, 0, 0);
} else {
/* Draw inside and outside lines */
cpVect in_p[n];
@@ -495,48 +499,43 @@ void draw_edge(cpVect *points, int n, struct rgba color, int thickness, int clos
for (int i = 1, v = 0; i < n*2; i+=2,v++)
out_p[v] = vertices[i].pos;
draw_line(in_p,n,line_color,line_seg,1);
draw_line(out_p,n,line_color,line_seg,1);
draw_line(in_p,n,line_color,line_seg,1,0);
draw_line(out_p,n,line_color,line_seg,1,0);
}
}
void draw_circle(int x, int y, float radius, float pixels, struct rgba color, float segsize)
void draw_circle(int x, int y, float radius, float pixels, struct rgba color, float seg)
{
struct circle_vertex cv;
cv.pos[0] = x;
cv.pos[1] = y;
cv.radius = radius;
cv.color = color;
cv.segsize = segsize/radius;
cv.segsize = seg/radius;
cv.fill = pixels/radius;
memcpy(circle_b+circle_count, &cv, sizeof(struct circle_vertex));
circle_count++;
}
void draw_rect(int x, int y, int w, int h, struct rgba color)
{
float hw = w / 2.f;
float hh = h / 2.f;
cpVect verts[4] = {
{ .x = x-hw, .y = y-hh },
{ .x = x+hw, .y = y-hh },
{ .x = x+hw, .y = y+hh },
{ .x = x-hw, .y = y+hh }
};
draw_poly(verts, 4, color, color, 0);
}
void draw_box(struct cpVect c, struct cpVect wh, struct rgba color)
{
draw_rect(c.x, c.y, wh.x, wh.y, color);
float hw = wh.x / 2.f;
float hh = wh.y / 2.f;
cpVect verts[4] = {
{ .x = c.x-hw, .y = c.y-hh },
{ .x = c.x+hw, .y = c.y-hh },
{ .x = c.x+hw, .y = c.y+hh },
{ .x = c.x-hw, .y = c.y+hh }
};
draw_poly(verts, 4, color);
}
void draw_arrow(struct cpVect start, struct cpVect end, struct rgba color, int capsize)
{
cpVect points[2] = {start, end};
draw_line(points, 2, color, 0, 0);
draw_line(points, 2, color, 0, 0,0);
draw_cppoint(end, capsize, color);
}
@@ -580,10 +579,8 @@ void draw_points(struct cpVect *points, int n, float size, struct rgba color)
draw_cppoint(points[i], size, color);
}
void draw_poly(cpVect *points, int n, struct rgba color, struct rgba line_color, float line_seg)
void draw_poly(cpVect *points, int n, struct rgba color)
{
draw_line(points, n, line_color, line_seg, 1);
/* Find polygon mesh */
int tric = n - 2;

View File

@@ -8,16 +8,14 @@ void debugdraw_init();
void draw_cppoint(struct cpVect point, float r, struct rgba color);
void draw_points(struct cpVect *points, int n, float size, struct rgba color);
void draw_line(cpVect *points, int n, struct rgba color, float seg_len, int closed);
void draw_line(cpVect *points, int n, struct rgba color, float seg_len, int closed, float seg_speed);
void draw_arrow(struct cpVect start, struct cpVect end, struct rgba, int capsize);
void draw_edge(struct cpVect *points, int n, struct rgba color, int thickness, int closed, int flags, struct rgba line_color, float line_seg);
/* pixels - how many pixels thick, segsize - dashed line seg len */
void draw_circle(int x, int y, float radius, float pixels, struct rgba color, float segsize);
void draw_rect(int x, int y, int w, int h, struct rgba color);
void draw_circle(int x, int y, float radius, float pixels, struct rgba color, float seg);
void draw_box(struct cpVect c, struct cpVect wh, struct rgba color);
void draw_poly(cpVect *points, int n, struct rgba color, struct rgba line_color, float line_seg);
void draw_poly(cpVect *points, int n, struct rgba color);
void draw_grid(int width, int span, struct rgba color);

View File

@@ -52,7 +52,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char
log_print(buffer);
if (priority >= 2)
if (category == 1 && priority >= 2)
js_stacktrace();
}
#endif

View File

@@ -968,6 +968,29 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
case 102:
eye = HMM_AddV3(eye,(HMM_Vec3){0,0,0.01});
break;
case 103:
return num2js(js2go(argv[1])->scale);
case 104:
return bool2js(js2go(argv[1])->flipx);
case 105:
return bool2js(js2go(argv[1])->flipy);
case 106:
js2go(argv[1])->e = js2num(argv[2]);
break;
case 107:
return num2js(js2go(argv[1])->e);
case 108:
js2go(argv[1])->f = js2num(argv[2]);
break;
case 109:
return num2js(js2go(argv[1])->f);
case 110:
return num2js(js2go(argv[1])
}
if (str)
@@ -1355,6 +1378,12 @@ JSValue duk_cmd_circle2d(JSContext *js, JSValueConst this, int argc, JSValueCons
case 1:
circle->offset = js2vec2(argv[2]);
break;
case 2:
return num2js(circle->radius);
case 3:
return vec2js(circle->offset);
}
phys2d_applycircle(circle);

View File

@@ -226,17 +226,16 @@ struct sFont *MakeFont(const char *fontfile, int height) {
static int curchar = 0;
void draw_char_box(struct Character c, float cursor[2], float scale, float color[3]) {
int x, y, w, h;
void draw_char_box(struct Character c, cpVect cursor, float scale, struct rgba color)
{
cpVect wh;
wh.x = 8 * scale;
wh.y = 14;
cursor.x += wh.x / 2.f;
cursor.y += wh.y / 2.f;
x = cursor[0];
y = cursor[1];
w = 8 * scale;
h = 14;
x += w / 2.f;
y += h / 2.f;
draw_rect(x, y, w, h, color);
draw_box(cursor, wh, color);
}
void text_flush() {