diff --git a/tools/qfcc/test/Makemodule.am b/tools/qfcc/test/Makemodule.am index fdd500dbe..eca0d5376 100644 --- a/tools/qfcc/test/Makemodule.am +++ b/tools/qfcc/test/Makemodule.am @@ -51,6 +51,7 @@ test_progs_dat=\ tools/qfcc/test/ptrfunc.dat \ tools/qfcc/test/ptrstructcast.dat \ tools/qfcc/test/motor-point.dat \ + tools/qfcc/test/motor-xform.dat \ tools/qfcc/test/quaternion.dat \ tools/qfcc/test/return-ivar.dat \ tools/qfcc/test/return-postop.dat \ @@ -621,6 +622,16 @@ tools/qfcc/test/motor-point.run: $(qfcc_test_run_deps) include $(motor_point_dep) # am--include-marker r_depfiles_remade += $(motor_point_dep) +tools_qfcc_test_motor_xform_dat_SOURCES=tools/qfcc/test/motor-xform.r +motor_xform_obj=$(tools_qfcc_test_motor_xform_dat_SOURCES:.r=.o) +motor_xform_dep=$(call qcautodep,$(tools_qfcc_test_motor_xform_dat_SOURCES)) +tools/qfcc/test/motor-xform.dat$(EXEEXT): $(motor_xform_obj) $(QFCC_DEP) + $(V_QFCCLD)$(QLINK) -o $@ $(motor_xform_obj) +tools/qfcc/test/motor-xform.run: $(qfcc_test_run_deps) + @$(top_srcdir)/tools/qfcc/test/build-run $@ +include $(motor_xform_dep) # am--include-marker +r_depfiles_remade += $(motor_xform_dep) + tools_qfcc_test_quaternion_dat_SOURCES=tools/qfcc/test/quaternion.r quaternion_obj=$(tools_qfcc_test_quaternion_dat_SOURCES:.r=.o) quaternion_dep=$(call qcautodep,$(tools_qfcc_test_quaternion_dat_SOURCES)) diff --git a/tools/qfcc/test/motor-xform.r b/tools/qfcc/test/motor-xform.r new file mode 100644 index 000000000..9254f1ef5 --- /dev/null +++ b/tools/qfcc/test/motor-xform.r @@ -0,0 +1,86 @@ +#include "test-harness.h" + +typedef @algebra(float(3,0,1)) PGA; +typedef PGA.group_mask(0xa) bivector_t; +typedef PGA.group_mask(0x1e) motor_t; +typedef PGA.tvec point_t; +typedef PGA.vec plane_t; + +typedef struct { + vec4 trans; + vec4 rot; +} xform_t; + +motor_t +make_motor (vec4 translation, vec4 rotation) +{ + @algebra(PGA) { + auto dt = (PGA.group_mask (0x18)) translation; + auto q = (PGA.group_mask(0x06)) rotation; + motor_t t = { .scalar = 1, .bvecp = -dt.bvecp / 2 }; + motor_t r = { .scalar = q.scalar, .bvect = q.bvect }; + motor_t m = t * r; + return m; + } +} + +xform_t +set_transform (motor_t m, int p) +{ + @algebra (PGA) { + auto r = ⋆(m * e0123); + auto t = (m * ⋆(m * e0123)).bvecp; + vec4 rot = (vec4) r; + vec4 trans = [(vec3)t * -2, 1]; + if (p) printf ("set_transform: %q %q\n", rot, trans); + return {trans, rot}; + } +} + +PGA.scalar rh = 0.7071067811865476; + +int +main() +{ + motor_t start = make_motor ({ 10, 4, -1.5, 0 }, { 0, 0, 0, 1 }); + vec3 bvt = { 0, 0, rh }; + vec3 bvp = { 0, -6*rh, 0 }; + motor_t delta = { + .scalar = rh, + .bvect = (PGA.bvect) bvt, + .bvecp = (PGA.bvecp) bvp, + }; + motor_t testm = delta * start; + printf ("start: %g %v %v %g\n", + start.scalar, start.bvect, start.bvecp, start.qvec); + printf ("delta: %g %v %v %g\n", + delta.scalar, delta.bvect, delta.bvecp, delta.qvec); + printf ("testm: %g %v %v %g\n", + testm.scalar, testm.bvect, testm.bvecp, testm.qvec); + auto xform = set_transform (testm, 1); + printf ("xform: %.9q %.9q\n", xform.trans, xform.rot); + if (start.scalar != 1 || (vec3) start.bvect != '0 0 0' + || (vec3) start.bvecp != '-5 -2 0.75' + || (PGA.scalar) start.qvec != 0) { + printf ("start incorrect\n"); + return 1; + } + if (delta.scalar != rh || (vec3) delta.bvect != '0 0 0.7071067811865476' + || (vec3) delta.bvecp != '0 -4.242640687119285 0' + || (PGA.scalar) delta.qvec != 0) { + printf ("delta incorrect\n"); + return 1; + } + if (testm.scalar != rh || (vec3) testm.bvect != '0 0 0.7071067811865476' + || (vec3) testm.bvecp != '-4.949747468305833 -2.1213203435596424 0.5303300858899106' + || (PGA.scalar) testm.qvec != 0.5303300858899106) { + printf ("testm incorrect\n"); + return 1; + } + if (xform.trans != '10 -4 -1.49999988 1' + || xform.rot != '0 0 -0.7071067811865476 0.7071067811865476') { + printf ("xform incorrect\n"); + return 1; + } + return 0; +}