line inflation
This commit is contained in:
parent
570169ff15
commit
e3100e0221
|
@ -177,7 +177,9 @@ void init_phys2dshape(struct phys2d_shape *shape, int go, void *data)
|
||||||
|
|
||||||
void phys2d_shape_del(struct phys2d_shape *shape)
|
void phys2d_shape_del(struct phys2d_shape *shape)
|
||||||
{
|
{
|
||||||
|
if (!shape->shape) return;
|
||||||
cpSpaceRemoveShape(space, shape->shape);
|
cpSpaceRemoveShape(space, shape->shape);
|
||||||
|
cpShapeFree(shape->shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************** CIRCLE2D *****************/
|
/***************** CIRCLE2D *****************/
|
||||||
|
@ -249,15 +251,14 @@ struct phys2d_box *Make2DBox(int go)
|
||||||
new->r = 0.f;
|
new->r = 0.f;
|
||||||
new->offset[0] = 0.f;
|
new->offset[0] = 0.f;
|
||||||
new->offset[1] = 0.f;
|
new->offset[1] = 0.f;
|
||||||
|
new->shape.go = go;
|
||||||
new->shape.shape = cpSpaceAddShape(space, cpBoxShapeNew(id2go(go)->body, new->w, new->h, new->r));
|
|
||||||
new->shape.debugdraw = phys2d_dbgdrawbox;
|
|
||||||
init_phys2dshape(&new->shape, go, new);
|
|
||||||
phys2d_applybox(new);
|
phys2d_applybox(new);
|
||||||
|
new->shape.debugdraw = phys2d_dbgdrawbox;
|
||||||
|
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void phys2d_boxdel(struct phys2d_box *box)
|
void phys2d_boxdel(struct phys2d_box *box)
|
||||||
{
|
{
|
||||||
phys2d_shape_del(&box->shape);
|
phys2d_shape_del(&box->shape);
|
||||||
|
@ -274,19 +275,24 @@ void box_gui(struct phys2d_box *box)
|
||||||
|
|
||||||
void phys2d_applybox(struct phys2d_box *box)
|
void phys2d_applybox(struct phys2d_box *box)
|
||||||
{
|
{
|
||||||
|
phys2d_boxdel(box);
|
||||||
|
struct gameobject *go = id2go(box->shape.go);
|
||||||
float s = id2go(box->shape.go)->scale;
|
float s = id2go(box->shape.go)->scale;
|
||||||
cpTransform T = { 0 };
|
cpTransform T = { 0 };
|
||||||
T.a = s * cos(box->rotation);
|
T.a = s * cos(box->rotation);
|
||||||
T.b = -sin(box->rotation);
|
T.b = s * -sin(box->rotation);
|
||||||
T.c = sin(box->rotation);
|
T.c = s * sin(box->rotation);
|
||||||
T.d = s * cos(box->rotation);
|
T.d = s * cos(box->rotation);
|
||||||
T.tx = box->offset[0] * s;
|
T.tx = box->offset[0] * s * go->flipx;
|
||||||
T.ty = box->offset[1] * s;
|
T.ty = box->offset[1] * s * go->flipy;
|
||||||
float hh = box->h / 2.f;
|
float hh = box->h / 2.f;
|
||||||
float hw = box->w / 2.f;
|
float hw = box->w / 2.f;
|
||||||
cpVect verts[4] = { { -hw, -hh }, { hw, -hh }, { hw, hh }, { -hw, hh } };
|
cpVect verts[4] = { { -hw, -hh }, { hw, -hh }, { hw, hh }, { -hw, hh } };
|
||||||
cpPolyShapeSetVerts(box->shape.shape, 4, verts, T);
|
box->shape.shape = cpSpaceAddShape(space, cpPolyShapeNew(go->body, 4, verts, T, box->r));
|
||||||
cpPolyShapeSetRadius(box->shape.shape, box->r);
|
init_phys2dshape(&box->shape, box->shape.go, box);
|
||||||
|
// cpPolyShapeSetVerts(box->shape.shape, 4, verts, T);
|
||||||
|
// cpPolyShapeSetRadius(box->shape.shape, box->r);
|
||||||
|
|
||||||
}
|
}
|
||||||
void phys2d_dbgdrawbox(struct phys2d_box *box)
|
void phys2d_dbgdrawbox(struct phys2d_box *box)
|
||||||
{
|
{
|
||||||
|
@ -512,7 +518,7 @@ void phys2d_dbgdrawedge(struct phys2d_edge *edge)
|
||||||
drawpoints[i].y = p.y + d*sin(a);
|
drawpoints[i].y = p.y + d*sin(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_edge(drawpoints, arrlen(edge->points), trigger_color);
|
draw_edge(drawpoints, arrlen(edge->points), trigger_color, edge->thickness*2);
|
||||||
draw_points(drawpoints, arrlen(edge->points), 2, kinematic_color);
|
draw_points(drawpoints, arrlen(edge->points), 2, kinematic_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,13 +64,40 @@ void draw_line(int x1, int y1, int x2, int y2, float *color)
|
||||||
draw_poly(verts, 2, color);
|
draw_poly(verts, 2, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_edge(cpVect *points, int n, float *color)
|
cpVect center_of_vects(cpVect *v, int n)
|
||||||
|
{
|
||||||
|
cpVect c;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
c.x += v[i].x;
|
||||||
|
c.y += v[i].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
c.x /= n;
|
||||||
|
c.y /= n;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
float vecs2m(cpVect a, cpVect b)
|
||||||
|
{
|
||||||
|
return (b.y-a.y)/(b.x-a.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpVect inflateline(cpVect a, cpVect b, float d)
|
||||||
|
{
|
||||||
|
cpVect c;
|
||||||
|
float m = vecs2m(a, b);
|
||||||
|
c.x = d/sqrt(1/(pow(m,2)+1));
|
||||||
|
c.y = d/sqrt(1+pow(m,2));
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_edge(cpVect *points, int n, float *color, int thickness)
|
||||||
{
|
{
|
||||||
static_assert(sizeof(cpVect) == 2*sizeof(float));
|
static_assert(sizeof(cpVect) == 2*sizeof(float));
|
||||||
|
|
||||||
shader_use(rectShader);
|
shader_use(rectShader);
|
||||||
shader_setvec3(rectShader, "linecolor", color);
|
shader_setvec3(rectShader, "linecolor", color);
|
||||||
glLineWidth(20);
|
if (thickness <= 1) {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * n * 2, points, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * n * 2, points, GL_DYNAMIC_DRAW);
|
||||||
glBindVertexArray(rectVAO);
|
glBindVertexArray(rectVAO);
|
||||||
|
@ -79,7 +106,9 @@ void draw_edge(cpVect *points, int n, float *color)
|
||||||
|
|
||||||
shader_setfloat(rectShader, "alpha", 1.f);
|
shader_setfloat(rectShader, "alpha", 1.f);
|
||||||
glDrawArrays(GL_LINE_STRIP, 0, n);
|
glDrawArrays(GL_LINE_STRIP, 0, n);
|
||||||
glLineWidth(1);
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_circle(int x, int y, float radius, int pixels, float *color, int fill)
|
void draw_circle(int x, int y, float radius, int pixels, float *color, int fill)
|
||||||
|
|
|
@ -5,7 +5,7 @@ struct cpVect;
|
||||||
|
|
||||||
void debugdraw_init();
|
void debugdraw_init();
|
||||||
void draw_line(int x1, int y1, int x2, int y2, float *color);
|
void draw_line(int x1, int y1, int x2, int y2, float *color);
|
||||||
void draw_edge(struct cpVect *points, int n, float *color);
|
void draw_edge(struct cpVect *points, int n, float *color, int thickness);
|
||||||
void draw_points(struct cpVect *points, int n, float size, float *color);
|
void draw_points(struct cpVect *points, int n, float size, float *color);
|
||||||
void draw_circle(int x, int y, float radius, int pixels, float *color, int fill);
|
void draw_circle(int x, int y, float radius, int pixels, float *color, int fill);
|
||||||
void draw_grid(int width, int span);
|
void draw_grid(int width, int span);
|
||||||
|
|
|
@ -234,6 +234,10 @@ duk_ret_t duk_nuke(duk_context *duk)
|
||||||
nuke_edit_str(textbox);
|
nuke_edit_str(textbox);
|
||||||
duk_push_string(duk, textbox);
|
duk_push_string(duk, textbox);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
nuke_img(duk_to_string(duk, 1));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -402,7 +406,7 @@ static int duk2path(const char *path, const struct stat *sb, int typeflag)
|
||||||
if (typeflag == FTW_F) {
|
if (typeflag == FTW_F) {
|
||||||
char *ext = strrchr(path, '.');
|
char *ext = strrchr(path, '.');
|
||||||
if (ext && !strcmp(ext, dukext)) {
|
if (ext && !strcmp(ext, dukext)) {
|
||||||
duk_push_string(duk, path);
|
duk_push_string(duk, &path[2]);
|
||||||
duk_put_prop_index(duk, dukarr, dukidx++);
|
duk_put_prop_index(duk, dukarr, dukidx++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -916,7 +920,6 @@ duk_ret_t duk_make_sprite(duk_context *duk) {
|
||||||
int go = duk_to_int(duk, 0);
|
int go = duk_to_int(duk, 0);
|
||||||
const char *path = duk_to_string(duk, 1);
|
const char *path = duk_to_string(duk, 1);
|
||||||
cpVect pos = duk2vec2(duk, 2);
|
cpVect pos = duk2vec2(duk, 2);
|
||||||
|
|
||||||
int sprite = make_sprite(go);
|
int sprite = make_sprite(go);
|
||||||
struct sprite *sp = id2sprite(sprite);
|
struct sprite *sp = id2sprite(sprite);
|
||||||
sprite_loadtex(sp, path);
|
sprite_loadtex(sp, path);
|
||||||
|
|
|
@ -84,16 +84,7 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go)
|
||||||
{
|
{
|
||||||
cpShapeSetFriction(shape, go->f);
|
cpShapeSetFriction(shape, go->f);
|
||||||
cpShapeSetElasticity(shape, go->e);
|
cpShapeSetElasticity(shape, go->e);
|
||||||
|
|
||||||
cpTransform T = {0};
|
|
||||||
T.a = go->flipx;
|
|
||||||
T.d = go->flipy;
|
|
||||||
cpShapeUpdate(shape, T);
|
|
||||||
|
|
||||||
if (go->flipx == -1) YughInfo("Flipped one");
|
|
||||||
// cpShapeSetFilter(shape, go->filter);
|
// cpShapeSetFilter(shape, go->filter);
|
||||||
|
|
||||||
// YughLog("Set filter; %d", go->filter.mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gameobject_apply(struct gameobject *go)
|
void gameobject_apply(struct gameobject *go)
|
||||||
|
|
|
@ -140,9 +140,12 @@ void call_input_signal(char *signal) {
|
||||||
if (pawns[i] == NULL) arrdel(pawns, i);
|
if (pawns[i] == NULL) arrdel(pawns, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < arrlen(pawns); i++) {
|
int len = arrlen(pawns);
|
||||||
if (!pawns[i]) continue;
|
void *framepawns[len];
|
||||||
script_eval_w_env(signal, pawns[i]);
|
memcpy(framepawns, pawns, len*sizeof(*pawns));
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
script_eval_w_env(signal, framepawns[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "texture.h"
|
||||||
|
|
||||||
#define MAX_VERTEX_BUFFER 512 * 1024
|
#define MAX_VERTEX_BUFFER 512 * 1024
|
||||||
#define MAX_ELEMENT_BUFFER 128 * 1024
|
#define MAX_ELEMENT_BUFFER 128 * 1024
|
||||||
|
@ -89,6 +90,12 @@ int nuke_btn(const char *lbl) {
|
||||||
return nk_button_label(ctx, lbl);
|
return nk_button_label(ctx, lbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nuke_img(char *path) {
|
||||||
|
struct Texture *t = texture_pullfromfile(path);
|
||||||
|
nk_layout_row_static(ctx, t->height, t->width, 1);
|
||||||
|
nk_image(ctx, nk_image_id(t->id));
|
||||||
|
}
|
||||||
|
|
||||||
void nuke_property_int(const char *lbl, int min, int *val, int max, int step) {
|
void nuke_property_int(const char *lbl, int min, int *val, int max, int step) {
|
||||||
nk_property_int(ctx, lbl, min, val, max, step, step);
|
nk_property_int(ctx, lbl, min, val, max, step, step);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ void nuke_nel(int cols);
|
||||||
void nuke_label(const char *s);
|
void nuke_label(const char *s);
|
||||||
void nuke_prop_float(const char *label, float min, float *val, float max, float step, float dragstep);
|
void nuke_prop_float(const char *label, float min, float *val, float max, float step, float dragstep);
|
||||||
void nuke_edit_str(char *str);
|
void nuke_edit_str(char *str);
|
||||||
|
void nuke_img(char *path);
|
||||||
|
|
||||||
int nuke_push_tree_id(const char *name, int id);
|
int nuke_push_tree_id(const char *name, int id);
|
||||||
void nuke_tree_pop();
|
void nuke_tree_pop();
|
||||||
|
|
|
@ -33,7 +33,6 @@ struct vec *c_vec = NULL;
|
||||||
|
|
||||||
char pathbuf[MAXPATH];
|
char pathbuf[MAXPATH];
|
||||||
|
|
||||||
|
|
||||||
void resources_init()
|
void resources_init()
|
||||||
{
|
{
|
||||||
prefabs = vec_make(MAXNAME, 25);
|
prefabs = vec_make(MAXNAME, 25);
|
||||||
|
|
Loading…
Reference in a new issue