paint: physics cleanup
This commit is contained in:
@@ -530,7 +530,7 @@ void sim_init();
|
||||
void sim_update();
|
||||
void sim_play();
|
||||
void sim_stop();
|
||||
void sim_add_body(object_t *o, asim_shape_t shape, f32 mass);
|
||||
void sim_add_body(object_t *o, physics_shape_t shape, f32 mass);
|
||||
mesh_object_t *sim_duplicate_object(mesh_object_t *so);
|
||||
void sim_duplicate();
|
||||
void sim_delete();
|
||||
|
||||
@@ -320,7 +320,7 @@ void export_arm_run_project() {
|
||||
g_project->mesh_physics_shapes = i32_array_create(g_project->_->paint_objects->length);
|
||||
g_project->mesh_physics_masses = f32_array_create(g_project->_->paint_objects->length);
|
||||
for (i32 i = 0; i < g_project->mesh_physics_shapes->length; ++i) {
|
||||
asim_body_t *pb = g_project->_->paint_objects->buffer[i]->base->_->body;
|
||||
physics_body_t *pb = g_project->_->paint_objects->buffer[i]->base->_->body;
|
||||
g_project->mesh_physics_shapes->buffer[i] = pb != NULL ? pb->shape : -1; // No physics
|
||||
g_project->mesh_physics_masses->buffer[i] = pb != NULL ? pb->mass : 0.0;
|
||||
}
|
||||
|
||||
@@ -672,7 +672,7 @@ void import_arm_run_project(char *path) {
|
||||
continue; // No physics
|
||||
}
|
||||
f32 mass = g_project->mesh_physics_masses != NULL && i < g_project->mesh_physics_masses->length ? g_project->mesh_physics_masses->buffer[i] : 0.0;
|
||||
sim_add_body(g_project->_->paint_objects->buffer[i]->base, (asim_shape_t)shape, mass);
|
||||
sim_add_body(g_project->_->paint_objects->buffer[i]->base, (physics_shape_t)shape, mass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -434,7 +434,7 @@ void minic_register_builtins() {
|
||||
|
||||
MINIC_ENUM("gpu_texture_format_t", "GPU_TEXTURE_FORMAT_RGBA32", "GPU_TEXTURE_FORMAT_RGBA64", "GPU_TEXTURE_FORMAT_RGBA128", "GPU_TEXTURE_FORMAT_R8",
|
||||
"GPU_TEXTURE_FORMAT_R16", "GPU_TEXTURE_FORMAT_R32", "GPU_TEXTURE_FORMAT_D32", "GPU_TEXTURE_FORMAT_RGBA32_BC7");
|
||||
MINIC_ENUM("asim_shape_t", "ASIM_SHAPE_BOX", "ASIM_SHAPE_SPHERE", "ASIM_SHAPE_TERRAIN", "ASIM_SHAPE_MESH");
|
||||
MINIC_ENUM("physics_shape_t", "PHYSICS_SHAPE_BOX", "PHYSICS_SHAPE_SPHERE", "PHYSICS_SHAPE_TERRAIN", "PHYSICS_SHAPE_MESH");
|
||||
MINIC_ENUM("tool_type_t", "TOOL_TYPE_BRUSH", "TOOL_TYPE_ERASER", "TOOL_TYPE_FILL", "TOOL_TYPE_DECAL", "TOOL_TYPE_TEXT", "TOOL_TYPE_CLONE", "TOOL_TYPE_BLUR",
|
||||
"TOOL_TYPE_PARTICLE", "TOOL_TYPE_COLORID", "TOOL_TYPE_PICKER", "TOOL_TYPE_MATERIAL", "TOOL_TYPE_CURSOR", "TOOL_TYPE_SELECT", "TOOL_TYPE_BAKE");
|
||||
|
||||
|
||||
+13
-13
@@ -635,7 +635,7 @@ object_t *script_object_duplicate(object_t *o) {
|
||||
return dup->base;
|
||||
}
|
||||
|
||||
static asim_body_t *script_physics_body(object_t *o) {
|
||||
static physics_body_t *script_physics_body(object_t *o) {
|
||||
return o != NULL && o->_ != NULL ? o->_->body : NULL;
|
||||
}
|
||||
|
||||
@@ -644,45 +644,45 @@ void script_physics_set_shape(object_t *o, i32 shape) {
|
||||
return;
|
||||
}
|
||||
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
physics_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_remove(body);
|
||||
physics_body_remove(body);
|
||||
}
|
||||
g_project->mesh_physics_shapes = i32_array_create(0);
|
||||
if (shape < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool dynamic = shape == ASIM_SHAPE_BOX || shape == ASIM_SHAPE_SPHERE;
|
||||
sim_add_body(o, (asim_shape_t)shape, dynamic ? 1.0 : 0.0);
|
||||
bool dynamic = shape == PHYSICS_SHAPE_BOX || shape == PHYSICS_SHAPE_SPHERE;
|
||||
sim_add_body(o, (physics_shape_t)shape, dynamic ? 1.0 : 0.0);
|
||||
}
|
||||
|
||||
void script_physics_set_mass(object_t *o, f32 mass) {
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
physics_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_set_mass(body, mass);
|
||||
physics_body_set_mass(body, mass);
|
||||
g_project->mesh_physics_shapes = i32_array_create(0);
|
||||
}
|
||||
}
|
||||
|
||||
void script_physics_apply_impulse(object_t *o, f32 x, f32 y, f32 z) {
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
physics_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_apply_impulse(body->_body, (vec4_t){x, y, z, 0.0});
|
||||
physics_body_apply_impulse(body->_body, (vec4_t){x, y, z, 0.0});
|
||||
}
|
||||
}
|
||||
|
||||
void script_physics_set_velocity(object_t *o, f32 x, f32 y, f32 z) {
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
physics_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_set_velocity(body->_body, x, y, z);
|
||||
physics_body_set_velocity(body->_body, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
void script_physics_sync_transform(object_t *o) {
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
physics_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_sync_transform(body);
|
||||
physics_body_sync_transform(body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,9 +90,9 @@ void render_gizmo_update() {
|
||||
transform_build_matrix(paint_object->transform);
|
||||
ui_header_handle->redraws = 2;
|
||||
|
||||
asim_body_t *pb = paint_object->_->body;
|
||||
physics_body_t *pb = paint_object->_->body;
|
||||
if (pb != NULL) {
|
||||
asim_body_sync_transform(pb);
|
||||
physics_body_sync_transform(pb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -8,7 +8,7 @@ void sim_init() {
|
||||
if (sim_initialized) {
|
||||
return;
|
||||
}
|
||||
asim_world_create();
|
||||
physics_world_create();
|
||||
sim_initialized = true;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ void sim_update() {
|
||||
|
||||
if (sim_running) {
|
||||
trait_update();
|
||||
asim_world_update();
|
||||
physics_world_update();
|
||||
iron_delay_idle_sleep();
|
||||
if (sim_record) {
|
||||
render_target_t *rt = any_map_get(render_path_render_targets, "last");
|
||||
@@ -68,16 +68,16 @@ void sim_stop() {
|
||||
mesh_object_t_array_t *pos = g_project->_->paint_objects;
|
||||
for (i32 i = 0; i < pos->length; ++i) {
|
||||
transform_set_matrix(pos->buffer[i]->base->transform, *(mat4_t *)sim_transforms->buffer[i]);
|
||||
asim_body_t *pb = pos->buffer[i]->base->_->body;
|
||||
physics_body_t *pb = pos->buffer[i]->base->_->body;
|
||||
if (pb != NULL) {
|
||||
asim_body_sync_transform(pb);
|
||||
physics_body_sync_transform(pb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sim_add_body(object_t *o, asim_shape_t shape, f32 mass) {
|
||||
void sim_add_body(object_t *o, physics_shape_t shape, f32 mass) {
|
||||
sim_init();
|
||||
asim_body_create(o, shape, mass);
|
||||
physics_body_create(o, shape, mass);
|
||||
}
|
||||
|
||||
mesh_object_t *sim_duplicate_object(mesh_object_t *so) {
|
||||
@@ -110,9 +110,9 @@ mesh_object_t *sim_duplicate_object(mesh_object_t *so) {
|
||||
}
|
||||
|
||||
// Physics
|
||||
asim_body_t *pb = so->base->_->body;
|
||||
physics_body_t *pb = so->base->_->body;
|
||||
if (pb != NULL) {
|
||||
asim_body_create(dup->base, pb->shape, pb->mass);
|
||||
physics_body_create(dup->base, pb->shape, pb->mass);
|
||||
}
|
||||
|
||||
return dup;
|
||||
|
||||
@@ -50,7 +50,7 @@ static bool pac_inside(pac_rect_t *r, vec4_t p) {
|
||||
return p.x > r->min_x && p.x < r->max_x && p.y > r->min_y && p.y < r->max_y;
|
||||
}
|
||||
|
||||
static void pac_gather_rects(asim_body_t *self) {
|
||||
static void pac_gather_rects(physics_body_t *self) {
|
||||
pac_rect_count = 0;
|
||||
f32 grow = math_sqrt(self->dimx * self->dimx + self->dimy * self->dimy) / 2.0 + PAC_CLEARANCE;
|
||||
|
||||
@@ -60,8 +60,8 @@ static void pac_gather_rects(asim_body_t *self) {
|
||||
if (o->_ == NULL || string_equals(o->name, PAC_TERRAIN)) {
|
||||
continue;
|
||||
}
|
||||
asim_body_t *body = o->_->body;
|
||||
if (body == NULL || body == self || body->shape != ASIM_SHAPE_BOX || body->mass > 0.0) {
|
||||
physics_body_t *body = o->_->body;
|
||||
if (body == NULL || body == self || body->shape != PHYSICS_SHAPE_BOX || body->mass > 0.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -252,9 +252,9 @@ static bool pac_search() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pac_plan(asim_body_t *body, vec4_t goal) {
|
||||
static bool pac_plan(physics_body_t *body, vec4_t goal) {
|
||||
vec4_t pos;
|
||||
asim_body_get_pos(body->_body, &pos);
|
||||
physics_body_get_pos(body->_body, &pos);
|
||||
|
||||
pac_gather_rects(body);
|
||||
vec4_t start = pac_push_out((vec4_t){pos.x, pos.y, 0.0, 1.0});
|
||||
@@ -293,7 +293,7 @@ static void trait_point_and_click_controller_set_moving(object_t *o, bool moving
|
||||
run->visible = moving;
|
||||
}
|
||||
|
||||
static void trait_point_and_click_controller_place(asim_body_t *body) {
|
||||
static void trait_point_and_click_controller_place(physics_body_t *body) {
|
||||
if (!trait_point_and_click_controller_moving) {
|
||||
return;
|
||||
}
|
||||
@@ -303,7 +303,7 @@ static void trait_point_and_click_controller_place(asim_body_t *body) {
|
||||
}
|
||||
|
||||
vec4_t pos;
|
||||
asim_body_get_pos(body->_body, &pos);
|
||||
physics_body_get_pos(body->_body, &pos);
|
||||
quat_t rot = trait_point_and_click_controller_rot;
|
||||
vec4_t off = vec4_apply_quat(body->offset, rot);
|
||||
|
||||
@@ -318,9 +318,9 @@ static void trait_point_and_click_controller_terrain() {
|
||||
if (o == NULL || o->_ == NULL) {
|
||||
return;
|
||||
}
|
||||
asim_body_t *body = o->_->body;
|
||||
if (body == NULL || body->shape != ASIM_SHAPE_TERRAIN) {
|
||||
script_physics_set_shape(o, ASIM_SHAPE_TERRAIN);
|
||||
physics_body_t *body = o->_->body;
|
||||
if (body == NULL || body->shape != PHYSICS_SHAPE_TERRAIN) {
|
||||
script_physics_set_shape(o, PHYSICS_SHAPE_TERRAIN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,20 +333,20 @@ static bool trait_point_and_click_controller_pick(vec4_t *target) {
|
||||
|
||||
trait_point_and_click_controller_terrain();
|
||||
ray_t *ray = raycast_get_ray(mx, my, scene_camera);
|
||||
return asim_terrain_raycast(ray->origin, ray->dir, target);
|
||||
return physics_terrain_raycast(ray->origin, ray->dir, target);
|
||||
}
|
||||
|
||||
static bool trait_point_and_click_controller_move(asim_body_t *body) {
|
||||
static bool trait_point_and_click_controller_move(physics_body_t *body) {
|
||||
vec4_t vel;
|
||||
asim_body_get_velocity(body->_body, &vel);
|
||||
physics_body_get_velocity(body->_body, &vel);
|
||||
vec4_t pos;
|
||||
asim_body_get_pos(body->_body, &pos);
|
||||
physics_body_get_pos(body->_body, &pos);
|
||||
|
||||
while (pac_path_index < pac_path_count && pac_dist(pac_path[pac_path_index], pos) <= PAC_ARRIVE) {
|
||||
pac_path_index++;
|
||||
}
|
||||
if (pac_path_index >= pac_path_count) {
|
||||
asim_body_set_velocity(body->_body, 0.0, 0.0, vel.z);
|
||||
physics_body_set_velocity(body->_body, 0.0, 0.0, vel.z);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -359,19 +359,19 @@ static bool trait_point_and_click_controller_move(asim_body_t *body) {
|
||||
if (pac_path_index == pac_path_count - 1 && delta > 0.0 && dist / delta < speed) {
|
||||
speed = dist / delta;
|
||||
}
|
||||
asim_body_set_velocity(body->_body, dir.x * speed, dir.y * speed, vel.z);
|
||||
physics_body_set_velocity(body->_body, dir.x * speed, dir.y * speed, vel.z);
|
||||
|
||||
trait_point_and_click_controller_rot = trait_point_and_click_controller_facing(dir);
|
||||
asim_body_set_rotation(body, trait_point_and_click_controller_rot);
|
||||
physics_body_set_rotation(body, trait_point_and_click_controller_rot);
|
||||
return true;
|
||||
}
|
||||
|
||||
static asim_body_t *trait_point_and_click_controller_body(object_t *o) {
|
||||
asim_body_t *body = o->_->body;
|
||||
if (body != NULL && body->shape == ASIM_SHAPE_BOX && body->mass > 0.0) {
|
||||
static physics_body_t *trait_point_and_click_controller_body(object_t *o) {
|
||||
physics_body_t *body = o->_->body;
|
||||
if (body != NULL && body->shape == PHYSICS_SHAPE_BOX && body->mass > 0.0) {
|
||||
return body;
|
||||
}
|
||||
script_physics_set_shape(o, ASIM_SHAPE_BOX);
|
||||
script_physics_set_shape(o, PHYSICS_SHAPE_BOX);
|
||||
return o->_->body;
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ void trait_point_and_click_controller_run() {
|
||||
return;
|
||||
}
|
||||
|
||||
asim_body_t *body = trait_point_and_click_controller_body(o);
|
||||
physics_body_t *body = trait_point_and_click_controller_body(o);
|
||||
if (body == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ static void trait_third_person_controller_set_moving(object_t *o, bool moving) {
|
||||
run->visible = moving;
|
||||
}
|
||||
|
||||
static void trait_third_person_controller_place(asim_body_t *body) {
|
||||
static void trait_third_person_controller_place(physics_body_t *body) {
|
||||
if (!trait_third_person_controller_moving) {
|
||||
return;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ static void trait_third_person_controller_place(asim_body_t *body) {
|
||||
}
|
||||
|
||||
vec4_t pos;
|
||||
asim_body_get_pos(body->_body, &pos);
|
||||
physics_body_get_pos(body->_body, &pos);
|
||||
quat_t rot = trait_third_person_controller_facing();
|
||||
vec4_t off = vec4_apply_quat(body->offset, rot);
|
||||
|
||||
@@ -84,7 +84,7 @@ static void trait_third_person_controller_place(asim_body_t *body) {
|
||||
transform_build_matrix(t);
|
||||
}
|
||||
|
||||
static bool trait_third_person_controller_move(asim_body_t *body) {
|
||||
static bool trait_third_person_controller_move(physics_body_t *body) {
|
||||
f32 s = math_sin(trait_third_person_controller_yaw);
|
||||
f32 c = math_cos(trait_third_person_controller_yaw);
|
||||
vec4_t forward = (vec4_t){-s, c, 0.0, 0.0};
|
||||
@@ -105,23 +105,23 @@ static bool trait_third_person_controller_move(asim_body_t *body) {
|
||||
}
|
||||
|
||||
vec4_t vel;
|
||||
asim_body_get_velocity(body->_body, &vel);
|
||||
physics_body_get_velocity(body->_body, &vel);
|
||||
bool moving = dir.x != 0.0 || dir.y != 0.0;
|
||||
if (moving) {
|
||||
dir = vec4_norm(dir);
|
||||
asim_body_set_velocity(body->_body, dir.x * TPC_SPEED, dir.y * TPC_SPEED, vel.z);
|
||||
physics_body_set_velocity(body->_body, dir.x * TPC_SPEED, dir.y * TPC_SPEED, vel.z);
|
||||
}
|
||||
else {
|
||||
asim_body_set_velocity(body->_body, 0.0, 0.0, vel.z);
|
||||
physics_body_set_velocity(body->_body, 0.0, 0.0, vel.z);
|
||||
}
|
||||
|
||||
asim_body_set_rotation(body, trait_third_person_controller_facing());
|
||||
physics_body_set_rotation(body, trait_third_person_controller_facing());
|
||||
return moving;
|
||||
}
|
||||
|
||||
static void trait_third_person_controller_follow(asim_body_t *body) {
|
||||
static void trait_third_person_controller_follow(physics_body_t *body) {
|
||||
vec4_t pos;
|
||||
asim_body_get_pos(body->_body, &pos);
|
||||
physics_body_get_pos(body->_body, &pos);
|
||||
|
||||
f32 size = math_sqrt(body->dimx * body->dimx + body->dimy * body->dimy + body->dimz * body->dimz);
|
||||
f32 dist = (size > 0.0 ? size : 1.0) * TPC_CAMERA_DIST;
|
||||
@@ -136,12 +136,12 @@ static void trait_third_person_controller_follow(asim_body_t *body) {
|
||||
g_context->ddirty = 2;
|
||||
}
|
||||
|
||||
static asim_body_t *trait_third_person_controller_body(object_t *o) {
|
||||
asim_body_t *body = o->_->body;
|
||||
if (body != NULL && body->shape == ASIM_SHAPE_BOX && body->mass > 0.0) {
|
||||
static physics_body_t *trait_third_person_controller_body(object_t *o) {
|
||||
physics_body_t *body = o->_->body;
|
||||
if (body != NULL && body->shape == PHYSICS_SHAPE_BOX && body->mass > 0.0) {
|
||||
return body;
|
||||
}
|
||||
script_physics_set_shape(o, ASIM_SHAPE_BOX);
|
||||
script_physics_set_shape(o, PHYSICS_SHAPE_BOX);
|
||||
return o->_->body;
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ void trait_third_person_controller_run() {
|
||||
return;
|
||||
}
|
||||
|
||||
asim_body_t *body = trait_third_person_controller_body(o);
|
||||
physics_body_t *body = trait_third_person_controller_body(o);
|
||||
if (body == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ typedef struct context {
|
||||
f32 last_particle_hit_x;
|
||||
f32 last_particle_hit_y;
|
||||
f32 last_particle_hit_z;
|
||||
struct asim_body *paint_body;
|
||||
struct physics_body *paint_body;
|
||||
struct {
|
||||
f32 hit_x;
|
||||
f32 hit_y;
|
||||
@@ -410,7 +410,7 @@ typedef struct context {
|
||||
f32 hit_nor_z;
|
||||
f32 contact_time;
|
||||
struct tween_anim *timer;
|
||||
struct asim_body *body;
|
||||
struct physics_body *body;
|
||||
struct object *bullet;
|
||||
} particles[32];
|
||||
i32 particle_index;
|
||||
|
||||
@@ -392,7 +392,7 @@ void tab_meshes_draw_context_menu() {
|
||||
|
||||
// Physics
|
||||
if (g_config->experimental) {
|
||||
asim_body_t *pb = o->base->_->body;
|
||||
physics_body_t *pb = o->base->_->body;
|
||||
string_array_t *phys_combo = string_array_create(0);
|
||||
string_array_push(phys_combo, ""); // Empty = no physics
|
||||
string_array_push(phys_combo, tr("Box"));
|
||||
@@ -405,12 +405,12 @@ void tab_meshes_draw_context_menu() {
|
||||
ui_combo(hphys, phys_combo, tr("Physics"), true, UI_ALIGN_LEFT, false);
|
||||
if (hphys->changed) {
|
||||
if (pb != NULL) {
|
||||
asim_body_remove(pb);
|
||||
physics_body_remove(pb);
|
||||
pb = NULL;
|
||||
}
|
||||
if (hphys->i > 0) {
|
||||
asim_shape_t shape = (asim_shape_t)(hphys->i - 1);
|
||||
bool dynamic = shape == ASIM_SHAPE_BOX || shape == ASIM_SHAPE_SPHERE;
|
||||
physics_shape_t shape = (physics_shape_t)(hphys->i - 1);
|
||||
bool dynamic = shape == PHYSICS_SHAPE_BOX || shape == PHYSICS_SHAPE_SPHERE;
|
||||
sim_add_body(o->base, shape, dynamic ? 1.0 : 0.0);
|
||||
pb = o->base->_->body;
|
||||
}
|
||||
@@ -422,7 +422,7 @@ void tab_meshes_draw_context_menu() {
|
||||
hmass->f = pb->mass;
|
||||
ui_slider(hmass, tr("Mass"), 0.0, 10.0, true, 100, true, UI_ALIGN_LEFT, true);
|
||||
if (hmass->changed) {
|
||||
asim_body_set_mass(pb, hmass->f); // Zero mass = static
|
||||
physics_body_set_mass(pb, hmass->f); // Zero mass = static
|
||||
g_project->mesh_physics_shapes = i32_array_create(0);
|
||||
ui_menu_keep_open = true;
|
||||
}
|
||||
|
||||
@@ -388,16 +388,16 @@ static void tab_timeline_save_mesh_origins() {
|
||||
}
|
||||
|
||||
static void tab_timeline_sync_mesh_body(mesh_object_t *o) {
|
||||
asim_body_t *body = o->base->_->body;
|
||||
physics_body_t *body = o->base->_->body;
|
||||
if (body == NULL) {
|
||||
return;
|
||||
}
|
||||
asim_body_set_velocity(body->_body, 0.0f, 0.0f, 0.0f);
|
||||
asim_body_sync_transform(body);
|
||||
physics_body_set_velocity(body->_body, 0.0f, 0.0f, 0.0f);
|
||||
physics_body_sync_transform(body);
|
||||
}
|
||||
|
||||
static bool tab_timeline_dynamic_body(mesh_object_t *o) {
|
||||
asim_body_t *body = o->base->_->body;
|
||||
physics_body_t *body = o->base->_->body;
|
||||
return body != NULL && body->mass > 0.0;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,35 +58,35 @@ void ui_header_particle_menu_draw() {
|
||||
hfriction->f = g_context->particle_friction;
|
||||
g_context->particle_friction = ui_slider(hfriction, tr("Friction"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_RIGHT, true);
|
||||
if (hfriction->changed) {
|
||||
asim_set_friction(g_context->particle_friction);
|
||||
physics_set_friction(g_context->particle_friction);
|
||||
}
|
||||
|
||||
ui_handle_t *hbounciness = ui_handle(__ID__);
|
||||
hbounciness->f = g_context->particle_bounciness;
|
||||
g_context->particle_bounciness = ui_slider(hbounciness, tr("Bounce"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_RIGHT, true);
|
||||
if (hbounciness->changed) {
|
||||
asim_set_bounciness(g_context->particle_bounciness);
|
||||
physics_set_bounciness(g_context->particle_bounciness);
|
||||
}
|
||||
|
||||
ui_handle_t *hgravx = ui_handle(__ID__);
|
||||
hgravx->f = g_context->particle_gravity_x;
|
||||
g_context->particle_gravity_x = ui_slider(hgravx, tr("Gravity X"), -10.0, 10.0, true, 100.0, true, UI_ALIGN_RIGHT, true);
|
||||
if (hgravx->changed) {
|
||||
asim_set_gravity(g_context->particle_gravity_x, g_context->particle_gravity_y, g_context->particle_gravity_z);
|
||||
physics_set_gravity(g_context->particle_gravity_x, g_context->particle_gravity_y, g_context->particle_gravity_z);
|
||||
}
|
||||
|
||||
ui_handle_t *hgravy = ui_handle(__ID__);
|
||||
hgravy->f = g_context->particle_gravity_y;
|
||||
g_context->particle_gravity_y = ui_slider(hgravy, tr("Gravity Y"), -10.0, 10.0, true, 100.0, true, UI_ALIGN_RIGHT, true);
|
||||
if (hgravy->changed) {
|
||||
asim_set_gravity(g_context->particle_gravity_x, g_context->particle_gravity_y, g_context->particle_gravity_z);
|
||||
physics_set_gravity(g_context->particle_gravity_x, g_context->particle_gravity_y, g_context->particle_gravity_z);
|
||||
}
|
||||
|
||||
ui_handle_t *hgravz = ui_handle(__ID__);
|
||||
hgravz->f = g_context->particle_gravity_z;
|
||||
g_context->particle_gravity_z = ui_slider(hgravz, tr("Gravity Z"), -10.0, 10.0, true, 100.0, true, UI_ALIGN_RIGHT, true);
|
||||
if (hgravz->changed) {
|
||||
asim_set_gravity(g_context->particle_gravity_x, g_context->particle_gravity_y, g_context->particle_gravity_z);
|
||||
physics_set_gravity(g_context->particle_gravity_x, g_context->particle_gravity_y, g_context->particle_gravity_z);
|
||||
}
|
||||
|
||||
if (g_ui->changed || g_ui->is_typing) {
|
||||
|
||||
@@ -119,7 +119,7 @@ f32 uniforms_ext_f32_link(object_t *object, material_data_t *mat, char *link) {
|
||||
}
|
||||
else if (string_equals(link, "_particle_radius")) {
|
||||
i32 idx = g_context->particle_index;
|
||||
f32 speed = g_context->particles[idx].body != NULL ? asim_body_get_speed(g_context->particles[idx].body) : 0.0f;
|
||||
f32 speed = g_context->particles[idx].body != NULL ? physics_body_get_speed(g_context->particles[idx].body) : 0.0f;
|
||||
f32 vel_scale = fminf(speed / 0.12f, 1.0f);
|
||||
f32 contact_scale = 1.0f - fminf(g_context->particles[idx].contact_time, 1.0f);
|
||||
return fmaxf(g_context->brush_radius * vel_scale * contact_scale, 0.1f);
|
||||
|
||||
@@ -9,7 +9,7 @@ void util_particle_init_mesh() {
|
||||
util_mesh_merge(NULL);
|
||||
}
|
||||
|
||||
g_context->paint_body = asim_body_create(g_context->merged_object->base, ASIM_SHAPE_MESH, 0.0);
|
||||
g_context->paint_body = physics_body_create(g_context->merged_object->base, PHYSICS_SHAPE_MESH, 0.0);
|
||||
}
|
||||
|
||||
void util_particle_init_physics() {
|
||||
@@ -24,11 +24,11 @@ void util_particle_update() {
|
||||
|
||||
util_particle_init_physics();
|
||||
make_particle_get_bullet_material();
|
||||
asim_world_update();
|
||||
physics_world_update();
|
||||
|
||||
for (i32 i = 0; i < 32; ++i) {
|
||||
if (g_context->particles[i].timer != NULL && g_context->particles[i].timer->delay <= 0) {
|
||||
asim_body_remove(g_context->particles[i].body);
|
||||
physics_body_remove(g_context->particles[i].body);
|
||||
mesh_object_remove((mesh_object_t *)g_context->particles[i].bullet->ext);
|
||||
memset(&g_context->particles[i], 0, sizeof(g_context->particles[i]));
|
||||
}
|
||||
@@ -82,7 +82,7 @@ void util_particle_update() {
|
||||
mo->base->transform->scale = (vec4_t){g_context->brush_radius * 0.2, g_context->brush_radius * 0.2, g_context->brush_radius * 0.2, 1.0};
|
||||
transform_build_matrix(mo->base->transform);
|
||||
|
||||
asim_body_t *body = asim_body_create(mo->base, ASIM_SHAPE_SPHERE, g_context->particle_mass);
|
||||
physics_body_t *body = physics_body_create(mo->base, PHYSICS_SHAPE_SPHERE, g_context->particle_mass);
|
||||
|
||||
// Random direction
|
||||
f32 rx = math_random() * 2.0f - 1.0f;
|
||||
@@ -104,7 +104,7 @@ void util_particle_update() {
|
||||
f32 dy = ny + (ry - ny) * r;
|
||||
f32 dz = nz + (rz - nz) * r;
|
||||
f32 impulse = g_context->particle_spawn_distance * 30.0f;
|
||||
asim_body_apply_impulse(body->_body, (vec4_t){dx * impulse, dy * impulse, dz * impulse, 0.0});
|
||||
physics_body_apply_impulse(body->_body, (vec4_t){dx * impulse, dy * impulse, dz * impulse, 0.0});
|
||||
|
||||
g_context->particles[slot].body = body;
|
||||
g_context->particles[slot].bullet = mo->base;
|
||||
@@ -123,9 +123,9 @@ void util_particle_update() {
|
||||
if (g_context->particles[i].timer == NULL) {
|
||||
continue;
|
||||
}
|
||||
asim_pair_t_array_t *pairs = asim_get_contact_pairs(g_context->particles[i].body);
|
||||
physics_pair_t_array_t *pairs = physics_get_contact_pairs(g_context->particles[i].body);
|
||||
if (pairs != NULL && pairs->length > 0) {
|
||||
asim_pair_t *p = pairs->buffer[0];
|
||||
physics_pair_t *p = pairs->buffer[0];
|
||||
g_context->particles[i].hit_last_x = g_context->particles[i].hit_x != 0 ? g_context->particles[i].hit_x : p->pos_a_x;
|
||||
g_context->particles[i].hit_last_y = g_context->particles[i].hit_y != 0 ? g_context->particles[i].hit_y : p->pos_a_y;
|
||||
g_context->particles[i].hit_last_z = g_context->particles[i].hit_z != 0 ? g_context->particles[i].hit_z : p->pos_a_z;
|
||||
|
||||
Reference in New Issue
Block a user