Skip to content

Commit d0f635f

Browse files
committed
fix up errors from the catmull-rom impl
1 parent 9194658 commit d0f635f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

scripts/dmodels.dsc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ dmodels_move_to_frame:
162162
- define parentage.<[part_id]>.rotation:<[new_rot]>
163163
- define parentage.<[part_id]>.offset:<[rot_offset].add[<[parent_offset]>]>
164164
- foreach <[root_entity].flag[dmodel_anim_part.<[part_id]>]||<list>> as:ent:
165-
#- teleport <[ent]> <[root_entity].location.add[<[ent].flag[dmodel_def_offset].add[<[new_pos].div[25.6]>]>]>
166165
- teleport <[ent]> <[root_entity].location.add[<[new_pos].div[25.6]>]>
167166
- define radian_rot <[new_rot].add[<[pose]>].xyz.split[,]>
168167
- define pose <[radian_rot].get[1]>,<[radian_rot].get[2]>,<[radian_rot].get[3]>
@@ -180,19 +179,27 @@ dmodels_catmullrom_get_t:
180179
debug: false
181180
definitions: t|p0|p1
182181
script:
183-
# This is more complex for different alpha values, but alpha=1 compresses down to a '.length' call conveniently
184-
- determine <[p1].sub[<[p0]>].length.add[<[t]>]>
182+
# This is more complex for different alpha values, but alpha=1 compresses down to a '.vector_length' call conveniently
183+
- determine <[p1].sub[<[p0]>].vector_length.add[<[t]>]>
185184

186185
dmodels_catmullrom_proc:
187186
type: procedure
188187
debug: false
189188
definitions: p0|p1|p2|p3|t
190189
script:
190+
# Zero distances are impossible to calculate
191+
- if <[p2].sub[<[p1]>].vector_length> < 0.01:
192+
- determine <[p2]>
191193
# TODO: Validate this mess
194+
# Based on https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline#Code_example_in_Unreal_C++
195+
# With safety checks added for impossible situations
192196
- define t0 0
193197
- define t1 <proc[dmodels_catmullrom_get_t].context[0|<[p0]>|<[p1]>]>
194198
- define t2 <proc[dmodels_catmullrom_get_t].context[<[t1]>|<[p1]>|<[p2]>]>
195199
- define t3 <proc[dmodels_catmullrom_get_t].context[<[t2]>|<[p2]>|<[p3]>]>
200+
# Divide-by-zero safety check
201+
- if <[t1].abs> < 0.001 || <[t2].sub[<[t1]>].abs> < 0.001 || <[t2].abs> < 0.001 || <[t3].sub[<[t1]>].abs> < 0.001:
202+
- determine <[p2].sub[<[p1]>].mul[<[t]>].add[<[p1]>]>
196203
- define t <[t2].sub[<[t1]>].mul[<[t]>].add[<[t1]>]>
197204
# ( t1-t )/( t1-t0 )*p0 + ( t-t0 )/( t1-t0 )*p1;
198205
- define a1 <[p0].mul[<[t1].sub[<[t]>].div[<[t1]>]>].add[<[p1].mul[<[t].div[<[t1]>]>]>]>

0 commit comments

Comments
 (0)