fix draw.image
Some checks failed
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
Some checks failed
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
This commit is contained in:
@@ -58,7 +58,7 @@ render.image = function(image, rect, rotation, anchor, shear, info)
|
||||
{
|
||||
rect.width = image.rect_px.width;
|
||||
rect.height = image.rect_px.height;
|
||||
context.texture(image.texture, image.rect_px, rect, rotation * 360, anchor);
|
||||
context.texture(image.texture, image.rect_px, rect, rotation, anchor);
|
||||
}
|
||||
|
||||
render.clip = function(rect)
|
||||
|
||||
@@ -1674,9 +1674,6 @@ shader_globals camera_globals(JSContext *js, JSValue camera)
|
||||
bottom, top,
|
||||
-1.0f, 1.0f
|
||||
);
|
||||
|
||||
proj.Columns[3].x += size.x * anchor.x;
|
||||
proj.Columns[3].y += size.y * anchor.y;
|
||||
}
|
||||
else {
|
||||
proj = HMM_Perspective_RH_NO(fov, size.x/size.y,near_z,far_z);
|
||||
@@ -2725,18 +2722,28 @@ static inline SDL_FPoint renderer_world_to_screen(renderer_ctx *ctx, HMM_Vec2 p)
|
||||
return (SDL_FPoint){ scr_x, scr_y };
|
||||
}
|
||||
|
||||
static inline rect renderer_worldrect_to_screen(renderer_ctx *ctx, rect r)
|
||||
static inline rect renderer_worldrect_to_screen(renderer_ctx *ctx, rect r_world)
|
||||
{
|
||||
SDL_FPoint tl = renderer_world_to_screen(ctx, (HMM_Vec2){r.x, r.y});
|
||||
SDL_FPoint br = renderer_world_to_screen(ctx, (HMM_Vec2){r.x+r.w, r.y+r.h});
|
||||
SDL_FPoint bl = renderer_world_to_screen(
|
||||
ctx, (HMM_Vec2){ r_world.x,
|
||||
r_world.y });
|
||||
|
||||
r.x = tl.x;
|
||||
r.y = tl.y;
|
||||
r.w = br.x-tl.x;
|
||||
r.h = br.y-tl.y;
|
||||
return r;
|
||||
SDL_FPoint tr = renderer_world_to_screen(
|
||||
ctx, (HMM_Vec2){ r_world.x + r_world.w,
|
||||
r_world.y + r_world.h });
|
||||
|
||||
/* SDL wants the *top-left* corner, and y grows down. */
|
||||
rect out;
|
||||
out.x = SDL_min(bl.x, tr.x); /* left edge */
|
||||
out.y = SDL_min(bl.y, tr.y); /* top edge */
|
||||
|
||||
/* always positive width / height */
|
||||
out.w = fabsf(tr.x - bl.x);
|
||||
out.h = fabsf(tr.y - bl.y);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
JSC_CCALL(SDL_Renderer_clear,
|
||||
SDL_Renderer *renderer = js2renderer_ctx(js,self)->sdl;
|
||||
SDL_RenderClear(renderer);
|
||||
@@ -3059,9 +3066,17 @@ JSC_CCALL(renderer_texture,
|
||||
SDL_Texture *tex = js2SDL_Texture(js,argv[0]);
|
||||
rect src = js2rect(js,argv[1]);
|
||||
rect dst = js2rect(js,argv[2]);
|
||||
dst = renderer_worldrect_to_screen(ctx, dst);
|
||||
double angle;
|
||||
JS_ToFloat64(js, &angle, argv[3]);
|
||||
angle *= -360;
|
||||
HMM_Vec2 anchor = js2vec2(js, argv[4]);
|
||||
anchor.y = dst.h - anchor.y*dst.h;
|
||||
anchor.x *= dst.w;
|
||||
// anchor.x *= dst.w;
|
||||
// anchor.y *= dst.h;
|
||||
// anchor.x += dst.x;
|
||||
// anchor.y += dst.y;
|
||||
SDL_RenderTextureRotated(ctx->sdl, tex, &src, &dst, angle, &anchor, SDL_FLIP_NONE);
|
||||
)
|
||||
|
||||
|
||||
@@ -35,8 +35,10 @@ var hudcam = {
|
||||
anchor:[0,0],
|
||||
}
|
||||
|
||||
var angle = 0
|
||||
function loop()
|
||||
{
|
||||
angle += 1/240
|
||||
render.clear(Color.red)
|
||||
render.camera(hudcam)
|
||||
/* draw.line([[0,0],[100,50]])
|
||||
@@ -48,8 +50,10 @@ function loop()
|
||||
draw.ellipse([100,80], [40,25], {thickness:1,color:Color.blue})
|
||||
draw.rectangle({x:150,y:150,width:50,height:50})
|
||||
draw.rectangle({x:100, y:60, width:200, height:60}, {radius: 20, thickness:-3})
|
||||
draw.rectangle({x:350, y:60, width:200, height:120}, {radius:10,thickness:3})*/
|
||||
draw.image("button_grey", [100,100],0.25)
|
||||
draw.rectangle({x:350, y:60, width:200, height:120}, {radius:10,thickness:3})
|
||||
*/
|
||||
draw.image("diddy", [0,0], angle, [0,0])
|
||||
draw.image("panel_beige", [300,300])
|
||||
render.present()
|
||||
$_.delay(loop, 1/60)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user