Add phys2d raycasting
This commit is contained in:
parent
c3aa598300
commit
204aa19c50
11
Makefile
11
Makefile
|
@ -14,6 +14,11 @@ OPT ?= 0
|
|||
INFO :=
|
||||
LD = $(CC)
|
||||
|
||||
STEAM = steam/sdk
|
||||
STEAMAPI = steam_api
|
||||
|
||||
LDFLAGS += -Wl,-rpath=./
|
||||
|
||||
ifeq ($(CC), x86_64-w64-mingw32-gcc)
|
||||
AR = x86_64-w64-mingw32-ar
|
||||
endif
|
||||
|
@ -93,7 +98,9 @@ endif
|
|||
INFO :=$(INFO)_$(ARCH)
|
||||
|
||||
ifeq ($(OS), Windows_NT) # then WINDOWS
|
||||
PLATFORM := win64
|
||||
DEPS += resource.o
|
||||
STEAMAPI := steam_api64
|
||||
LDFLAGS += -mwin32 -static
|
||||
CPPFLAGS += -mwin32
|
||||
LDLIBS += mingw32 kernel32 d3d11 user32 shell32 dxgi gdi32 ws2_32 ole32 winmm setupapi m pthread
|
||||
|
@ -122,6 +129,7 @@ else
|
|||
UNAME != uname -s
|
||||
ifeq ($(UNAME), Linux) # then LINUX
|
||||
OS := Linux
|
||||
PLATFORM := linux64
|
||||
LDFLAGS += -pthread -rdynamic
|
||||
LDLIBS += GL pthread c m dl X11 Xi Xcursor EGL asound
|
||||
INFO :=$(INFO)_linux
|
||||
|
@ -147,7 +155,6 @@ OBJS := $(patsubst %.cpp, %$(INFO).o, $(OBJS))
|
|||
OBJS := $(patsubst %.c, %$(INFO).o,$(OBJS))
|
||||
OBJS := $(patsubst %.m, %$(INFO).o, $(OBJS))
|
||||
|
||||
STEAM = steam/sdk
|
||||
|
||||
engineincs != find source/engine -maxdepth 1 -type d
|
||||
includeflag != find source -type d -name include
|
||||
|
@ -163,7 +170,7 @@ NAME = $(APP)$(INFO)$(EXT)
|
|||
SEM != git describe --tags --abbrev=0
|
||||
COM != git rev-parse --short HEAD
|
||||
|
||||
LDLIBS += steam_api
|
||||
LDLIBS += $(STEAMAPI)
|
||||
LDLIBS := $(addprefix -l, $(LDLIBS))
|
||||
LDPATHS := $(STEAM)/redistributable_bin/$(PLATFORM)
|
||||
LDPATHS := $(addprefix -L, $(LDPATHS))
|
||||
|
|
|
@ -116,7 +116,6 @@ Object.mixin(os.sprite(true), {
|
|||
stop = sp.gameobject.delay(advance, playing.frames[f].time);
|
||||
}
|
||||
this.tex(game.texture(playing.path));
|
||||
console.info(`playing anim: ${json.encode(playing)}`);
|
||||
advance();
|
||||
},
|
||||
stop() {
|
||||
|
|
|
@ -69,7 +69,7 @@ void bbhit(cpShape *shape, int *data)
|
|||
qhit++;
|
||||
}
|
||||
|
||||
static cpShapeFilter ff = {
|
||||
cpShapeFilter allfilter = {
|
||||
.group = CP_NO_GROUP,
|
||||
.mask = CP_ALL_CATEGORIES,
|
||||
.categories = CP_ALL_CATEGORIES,
|
||||
|
@ -79,7 +79,7 @@ int query_point(HMM_Vec2 pos)
|
|||
{
|
||||
qhit = 0;
|
||||
// cpSpacePointQuery(space, pos.cp, 0, filter, qpoint, &qhit);
|
||||
cpSpaceBBQuery(space, cpBBNewForCircle(pos.cp, 2), ff, bbhit, &qhit);
|
||||
cpSpaceBBQuery(space, cpBBNewForCircle(pos.cp, 2), allfilter, bbhit, &qhit);
|
||||
return qhit;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ extern struct rgba kinematic_color;
|
|||
extern struct rgba static_color;
|
||||
extern struct rgba sleep_color;
|
||||
|
||||
extern cpShapeFilter allfilter;
|
||||
|
||||
typedef struct constraint {
|
||||
cpConstraint *c;
|
||||
JSValue break_cb; /* function called when it is forcibly broken */
|
||||
|
@ -102,6 +104,7 @@ void phys2d_edge_set_enabled(struct phys2d_edge *edge, int enabled);
|
|||
void phys2d_init();
|
||||
void phys2d_update(float deltaT);
|
||||
cpShape *phys2d_query_pos(cpVect pos);
|
||||
void phys2d_query_ray(HMM_Vec2 start, HMM_Vec2 end, float radius, cpShapeFilter filter, JSValue cb);
|
||||
gameobject **phys2d_query_box(HMM_Vec2 pos, HMM_Vec2 wh);
|
||||
|
||||
struct shape_cb {
|
||||
|
|
|
@ -1079,11 +1079,28 @@ JSC_CCALL(physics_collide_rm, phys2d_rm_go_handlers(js2gameobject(argv[0])))
|
|||
JSC_CCALL(physics_collide_separate, js2gameobject(argv[1])->cbs.separate = JS_DupValue(js,argv[0]))
|
||||
JSC_CCALL(physics_collide_shape, gameobject_add_shape_collider(js2gameobject(argv[1]), JS_DupValue(js,argv[0]), js2ptr(argv[2])))
|
||||
|
||||
static void ray_query_fn(cpShape *shape, float t, cpVect n, float a, JSValue *cb)
|
||||
{
|
||||
JSValue argv[3] = {
|
||||
JS_DupValue(js, shape2go(shape)->ref),
|
||||
vec22js((HMM_Vec2)n),
|
||||
number2js(a)
|
||||
};
|
||||
script_call_sym(*cb, 3, argv);
|
||||
for (int i = 0; i < 3; i++)
|
||||
JS_FreeValue(js, argv[i]);
|
||||
}
|
||||
|
||||
JSC_CCALL(physics_ray_query,
|
||||
cpSpaceSegmentQuery(space, js2vec2(argv[0]).cp, js2vec2(argv[1]).cp, js2number(argv[2]), allfilter, ray_query_fn, &argv[3]);
|
||||
);
|
||||
|
||||
static const JSCFunctionListEntry js_physics_funcs[] = {
|
||||
MIST_FUNC_DEF(physics, sgscale, 2),
|
||||
MIST_FUNC_DEF(physics, set_cat_mask, 2),
|
||||
MIST_FUNC_DEF(physics, box_query, 2),
|
||||
MIST_FUNC_DEF(physics, pos_query, 2),
|
||||
MIST_FUNC_DEF(physics, ray_query, 2),
|
||||
MIST_FUNC_DEF(physics, box_point_query, 3),
|
||||
MIST_FUNC_DEF(physics, query_shape, 1),
|
||||
MIST_FUNC_DEF(physics, closest_point, 3),
|
||||
|
|
Loading…
Reference in a new issue