Update shape from immediate_body
This commit is contained in:
parent
d816e96c3e
commit
aa1dab6079
@ -1,6 +1,9 @@
|
||||
package halfedge
|
||||
|
||||
import lg "core:math/linalg"
|
||||
import "core:hash/xxhash"
|
||||
import "core:slice"
|
||||
import "core:mem"
|
||||
|
||||
Vec3 :: [3]f32
|
||||
|
||||
@ -290,3 +293,15 @@ iterate_next_vertex_edge :: proc(
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
hash :: proc(mesh: Half_Edge_Mesh) -> u32 {
|
||||
state: xxhash.XXH32_state
|
||||
xxhash.XXH32_reset_state(&state)
|
||||
|
||||
_ = xxhash.XXH32_update(&state, mem.any_to_bytes(mesh.center))
|
||||
_ = xxhash.XXH32_update(&state, slice.to_bytes(mesh.vertices))
|
||||
_ = xxhash.XXH32_update(&state, slice.to_bytes(mesh.faces))
|
||||
_ = xxhash.XXH32_update(&state, slice.to_bytes(mesh.edges))
|
||||
|
||||
return xxhash.XXH32_digest(&state)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ immediate_body :: proc(
|
||||
) -> (
|
||||
handle: Body_Handle,
|
||||
) {
|
||||
sim_state := get_sim_state(scene)
|
||||
if id in state.immedate_bodies {
|
||||
body := &state.immedate_bodies[id]
|
||||
if body.last_ref != state.simulation_frame {
|
||||
@ -24,10 +25,10 @@ immediate_body :: proc(
|
||||
state.num_referenced_bodies += 1
|
||||
}
|
||||
handle = body.handle
|
||||
update_body_from_config(get_body(get_sim_state(scene), handle), config)
|
||||
update_body_from_config(sim_state, get_body(sim_state, handle), config)
|
||||
} else {
|
||||
state.num_referenced_bodies += 1
|
||||
handle = add_body(get_sim_state(scene), config)
|
||||
handle = add_body(sim_state, config)
|
||||
state.immedate_bodies[id] = {
|
||||
handle = handle,
|
||||
last_ref = state.simulation_frame,
|
||||
|
@ -157,7 +157,7 @@ get_body :: proc(sim_state: ^Sim_State, handle: Body_Handle) -> Body_Ptr {
|
||||
return &sim_state.bodies_slice[index]
|
||||
}
|
||||
|
||||
remove_shape :: proc(sim_state: ^Sim_State, shape: ^Collision_Shape) {
|
||||
remove_shape :: proc(sim_state: ^Sim_State, shape: Collision_Shape) {
|
||||
switch &s in shape {
|
||||
case Shape_Box:
|
||||
case Internal_Shape_Convex:
|
||||
@ -240,9 +240,11 @@ initialize_body_from_config :: proc(sim_state: ^Sim_State, body: ^Body, config:
|
||||
body.inv_mass, body.inv_inertia_tensor = calculate_body_params_from_config(config)
|
||||
}
|
||||
|
||||
update_body_from_config :: proc(body: Body_Ptr, config: Body_Config) {
|
||||
// TODO: Figure out how to update shape
|
||||
// body.shape = config.shape
|
||||
update_body_from_config :: proc(sim_state: ^Sim_State, body: Body_Ptr, config: Body_Config) {
|
||||
// Inefficient, but eh
|
||||
remove_shape(sim_state, body.shape)
|
||||
body.shape = add_shape(sim_state, config.shape)
|
||||
|
||||
body.inv_mass, body.inv_inertia_tensor = calculate_body_params_from_config(config)
|
||||
}
|
||||
|
||||
@ -291,7 +293,7 @@ remove_body :: proc(sim_state: ^Sim_State, handle: Body_Handle) {
|
||||
|
||||
body.alive = false
|
||||
|
||||
remove_shape(sim_state, &body.shape)
|
||||
remove_shape(sim_state, body.shape)
|
||||
|
||||
body.next_plus_one = sim_state.first_free_body_plus_one
|
||||
sim_state.first_free_body_plus_one = i32(handle)
|
||||
|
@ -48,6 +48,8 @@ prepare_next_sim_state :: proc(scene: ^Scene) {
|
||||
current_state := get_sim_state(scene)
|
||||
next_state := get_next_sim_state(scene)
|
||||
|
||||
convex_container_reconcile(¤t_state.convex_container)
|
||||
|
||||
next_state.first_free_body_plus_one = current_state.first_free_body_plus_one
|
||||
next_state.first_free_suspension_constraint_plus_one =
|
||||
current_state.first_free_suspension_constraint_plus_one
|
||||
|
Loading…
x
Reference in New Issue
Block a user