spline fixes
This commit is contained in:
parent
a03143463e
commit
e84d3b60af
|
@ -710,18 +710,20 @@ component.edge2d = Object.copy(collider2d, {
|
|||
|
||||
if (Spline.is_bezier(this.type)) {
|
||||
idx = cmd(59, pos, Spline.bezier_nodes(this.cpoints),400);
|
||||
idx *= 3;
|
||||
|
||||
if (idx < 0) return;
|
||||
var adds;
|
||||
|
||||
if (idx === this.cpoints.length)
|
||||
adds = [this.cpoints.at(-1).add([100,0]), pos.add([-100,0]), pos.slice()];
|
||||
else if (idx === 0)
|
||||
adds = [pos.slice(), pos.add([100,0]), this.cpoints[0].add([-100,0])];
|
||||
else
|
||||
adds = [pos.add([-100,0]), pos.slice(), pos.add([100,0])];
|
||||
|
||||
this.cpoints.splice(idx+1, 0, ...adds);
|
||||
if (idx === 0) {
|
||||
this.cpoints.unshift(pos.slice(), pos.add([-100,0]), Vector.reflect_point(this.cpoints[1], this.cpoints[0]));
|
||||
return;
|
||||
}
|
||||
if (idx === Spline.bezier_node_count(this.cpoints)) {
|
||||
this.cpoints.push(Vector.reflect_point(this.cpoints.at(-2), this.cpoints.at(-1)), pos.add([-100,0]), pos.slice());
|
||||
return;
|
||||
}
|
||||
idx = 2 + (idx-1)*3;
|
||||
var adds = [pos.add([100,0]), pos.slice(), pos.add([-100,0])];
|
||||
this.cpoints.splice(idx, 0, ...adds);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -897,6 +899,10 @@ component.circle2d.impl = Object.mix({
|
|||
|
||||
set offset(x) { cmd_circle2d(1,this.id,x); },
|
||||
get offset() { return cmd_circle2d(3,this.id); },
|
||||
|
||||
get pos() { return this.offset; },
|
||||
set pos(x) { this.offset = x; },
|
||||
|
||||
}, collider2d.impl);;
|
||||
|
||||
/* ASSETS */
|
||||
|
|
|
@ -458,7 +458,7 @@ var editor = {
|
|||
var p = x[1].namestr();
|
||||
GUI.text(p, x[1].screenpos().add([0,16]),1,editor.color_depths[depth]);
|
||||
Shape.circle(x[1].screenpos(),10,Color.blue.alpha(0.3));
|
||||
Shape.arrow(x[1].screenpos(), x[1].screenpos().add(x[1].up().scale(15)), Color.red, 10);
|
||||
// Shape.arrow(x[1].screenpos(), x[1].screenpos().add(x[1].up().scale(15)), Color.red, 10);
|
||||
});
|
||||
|
||||
var mg = physics.pos_query(Mouse.worldpos,10);
|
||||
|
@ -614,6 +614,7 @@ editor.inputs.drop = function(str) {
|
|||
console.warn("NOT AN IMAGE");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.sel_comp?.comp === 'sprite') {
|
||||
this.sel_comp.path = str;
|
||||
return;
|
||||
|
@ -1197,6 +1198,24 @@ editor.inputs.g = function() {
|
|||
editor.selectlist = [o];
|
||||
}
|
||||
|
||||
if (editor.sel_comp) {
|
||||
if ('pick' in editor.sel_comp) {
|
||||
editor.grabselect = [editor.sel_comp.pick(Mouse.worldpos)];
|
||||
return;
|
||||
}
|
||||
|
||||
if ('pos' in editor.sel_comp) {
|
||||
var comp = editor.sel_comp;
|
||||
var o = {
|
||||
pos: editor.sel_comp.pos,
|
||||
move(d) { comp.pos = comp.pos.add(d); },
|
||||
sync: comp.sync.bind(comp),
|
||||
};
|
||||
editor.grabselect = [o];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (editor.sel_comp && 'pick' in editor.sel_comp) {
|
||||
var o = editor.sel_comp.pick(Mouse.worldpos);
|
||||
if (o) editor.grabselect = [o];
|
||||
|
|
|
@ -324,6 +324,12 @@ Spline.bezier_loop = function(cp)
|
|||
return cp;
|
||||
}
|
||||
|
||||
Spline.bezier_node_count = function(cp)
|
||||
{
|
||||
if (cp.length === 4) return 2;
|
||||
return 2 + (cp.length-4)/3;
|
||||
}
|
||||
|
||||
Spline.is_bezier = function(t) { return t === Spline.type.bezier; }
|
||||
Spline.is_catmull = function(t) { return t === Spline.type.catmull; }
|
||||
|
||||
|
|
|
@ -365,21 +365,16 @@ struct model *MakeModel(const char *path)
|
|||
HMM_Vec3 eye = {0,0,100};
|
||||
|
||||
void draw_model(struct model *model, HMM_Mat4 amodel) {
|
||||
HMM_Mat4 proj = projection;//HMM_Perspective_RH_ZO(45, (float)mainwin.width / mainwin.height, 0.1, 10000);
|
||||
HMM_Mat4 proj = projection;
|
||||
HMM_Vec3 center = {0.f, 0.f, 0.f};
|
||||
HMM_Vec3 up = {0.f, 1.f, 0.f};
|
||||
HMM_Mat4 view = HMM_LookAt_RH(eye, center, vUP);
|
||||
|
||||
HMM_Mat4 vp = HMM_MulM4(proj, view);
|
||||
HMM_Mat4 mvp = HMM_MulM4(vp, amodel);
|
||||
|
||||
HMM_Vec3 lp = {1, 1, 1};
|
||||
HMM_Vec3 dir_dir = HMM_NormV3(HMM_SubV3(center, dirl_pos));
|
||||
|
||||
vs_p_t vs_p;
|
||||
memcpy(vs_p.vp, view.Elements, sizeof(float)*16);
|
||||
memcpy(vs_p.vp, vp.Elements, sizeof(float)*16);
|
||||
memcpy(vs_p.model, amodel.Elements, sizeof(float)*16);
|
||||
memcpy(vs_p.proj, proj.Elements, sizeof(float)*16);
|
||||
|
||||
sg_apply_pipeline(model_pipe);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_p, SG_RANGE_REF(vs_p));
|
||||
|
|
|
@ -74,9 +74,9 @@ void js_setprop_str(JSValue obj, const char *prop, JSValue v) { JS_SetPropertySt
|
|||
JSValue jstzone()
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
struct tm lt = {0};
|
||||
localtime_r(&t, <);
|
||||
return num2js(lt.tm_gmtoff);
|
||||
time_t local_t = mktime(localtime(&t));
|
||||
double diff = difftime(t, local_t);
|
||||
return num2js(diff/3600);
|
||||
}
|
||||
|
||||
int js2bool(JSValue v) { return JS_ToBool(js, v); }
|
||||
|
@ -86,9 +86,7 @@ JSValue bool2js(int b) { return JS_NewBool(js,b); }
|
|||
JSValue jsdst()
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
struct tm lt = {};
|
||||
localtime_r(&t,<);
|
||||
return bool2js(lt.tm_isdst);
|
||||
return bool2js(localtime(&t)->tm_isdst);
|
||||
}
|
||||
|
||||
JSValue jscurtime()
|
||||
|
|
|
@ -504,7 +504,7 @@ void full_2d_pass(struct window *window)
|
|||
pos.x - zoom * window->rwidth / 2,
|
||||
pos.x + zoom * window->rwidth / 2,
|
||||
pos.y - zoom * window->rheight / 2,
|
||||
pos.y + zoom * window->rheight / 2, -1000.f, 1000.f);
|
||||
pos.y + zoom * window->rheight / 2, -10000.f, 10000.f);
|
||||
|
||||
hudproj = HMM_Orthographic_LH_ZO(0, window->rwidth, 0, window->rheight, -1.f, 1.f);
|
||||
|
||||
|
|
|
@ -7,11 +7,10 @@ out vec2 tex_coords;
|
|||
uniform vs_p {
|
||||
uniform mat4 vp;
|
||||
uniform mat4 model;
|
||||
uniform mat4 proj;
|
||||
};
|
||||
|
||||
void main() {
|
||||
gl_Position = proj * vp * vec4(vec3(model * vec4(a_pos,1.0)), 1.0);
|
||||
gl_Position = vp * vec4(vec3(model * vec4(a_pos,1.0)), 1.0);
|
||||
tex_coords = a_tex_coords;
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue