11#include " xEntMotion.h"
2+ #include " xMath.h"
23
34#include < types.h>
45
@@ -12,3 +13,148 @@ void xMat3x3RMulVec(xVec3* o, const xMat3x3* m, const xVec3* v)
1213 o->y = y;
1314 o->z = z;
1415}
16+
17+ // Artificial
18+ enum en_MOTIONTYPE
19+ {
20+ MOTION_TYPE_EXRT,
21+ MOTION_TYPE_ORBT,
22+ MOTION_TYPE_SPLN,
23+ MOTION_TYPE_MVPT,
24+ MOTION_TYPE_MECH,
25+ MOTION_TYPE_PEND
26+ };
27+
28+ void xEntMotionInit (xEntMotion* a, xEnt* b, xEntMotionAsset* c)
29+ {
30+ a->asset = c;
31+ a->type = c->type ;
32+ a->flags = c->flags ;
33+
34+ if (a->type == MOTION_TYPE_EXRT)
35+ {
36+ xVec3Copy (&a->er .a , &c->er .ret_pos );
37+ xVec3Add (&a->er .b , &c->er .ret_pos , &c->er .ext_dpos );
38+
39+ a->er .et = c->er .ext_tm ;
40+ a->er .wet = c->er .ext_wait_tm ;
41+ a->er .rt = c->er .ret_tm ;
42+ a->er .wrt = c->er .ret_wait_tm ;
43+
44+ if (a->er .p <= 0 )
45+ {
46+ a->er .p = 10 .0f ;
47+ }
48+
49+ a->er .brt = a->er .et + a->er .wet ;
50+ a->er .ert = a->er .brt + a->er .rt ;
51+ a->er .p = a->er .ert + a->er .wrt ;
52+ }
53+ else if (a->type == MOTION_TYPE_ORBT)
54+ {
55+ xVec3Copy ((xVec3*)(&a->er .b ), &c->er .ret_pos );
56+
57+ a->orb .a = c->orb .w ;
58+ a->orb .b = c->orb .h ;
59+
60+ if (c->orb .period <= 0 .0f )
61+ {
62+ c->orb .period = 10 .0f ;
63+ }
64+
65+ a->orb .p = c->orb .period ;
66+ a->orb .w = (2 * PI) / c->orb .period ;
67+ }
68+ else if (a->type == MOTION_TYPE_MVPT)
69+ {
70+ // literally nothing
71+ }
72+ else if (a->type == MOTION_TYPE_PEND)
73+ {
74+ if (c->pen .period <= 1e-5f )
75+ {
76+ c->pen .period = 0 ;
77+ }
78+
79+ a->pen .w = (2 * PI) / c->pen .period ;
80+ }
81+ else if (a->type == MOTION_TYPE_MECH)
82+ {
83+ if (c->mp .speed < 1e-5f )
84+ {
85+ c->mp .speed = 0 ;
86+ }
87+
88+ if (c->mech .sld_acc_tm + c->mech .sld_dec_tm > c->mech .sld_tm )
89+ {
90+ c->mech .sld_dec_tm =
91+ c->mech .sld_acc_tm =
92+ c->mech .sld_tm * 0 .5f ;
93+ }
94+
95+ if (c->mech .rot_tm < 3 .0f )
96+ {
97+ c->mech .rot_tm = 1 .0f ;
98+ }
99+
100+ if (c->mech .type == 2 )
101+ {
102+ if ( c->mech .rot_tm != c->mech .sld_tm )
103+ {
104+ c->mech .rot_tm = c->mech .sld_tm ;
105+ }
106+ }
107+ if (c->mech .rot_acc_tm + c->mech .rot_dec_tm > c->mech .rot_tm )
108+ {
109+ c->mech .rot_dec_tm =
110+ c->mech .rot_acc_tm =
111+ c->mech .rot_tm * 0 .5f ;
112+ }
113+ }
114+
115+ a->owner = b;
116+ a->target = NULL ;
117+
118+ xEntMotionDebugAdd (a);
119+ }
120+
121+ void xEntMechForward (xEntMotion* motion)
122+ {
123+ xEntMotionMechData* mech = &(motion->asset ->mech );
124+ xEntMotionAsset* mkasst = motion->asset ;
125+
126+ xEntMotionRun (motion);
127+
128+ if ((motion->mech .state != 0 ) && (motion->mech .state != 1 ) && (motion->mech .state != 2 ))
129+ {
130+ if (motion->mech .state == 3 )
131+ {
132+ motion->mech .ss = -motion->mech .ss ;
133+ motion->mech .sr = -motion->mech .sr ;
134+ motion->tmr = mkasst->mech .sld_tm - motion->tmr ;
135+ motion->mech .state = 0 ;
136+ }
137+ else if (motion->mech .state == 4 )
138+ {
139+ motion->mech .ss = -motion->mech .ss ;
140+ motion->mech .sr = -motion->mech .sr ;
141+ motion->tmr = mkasst->mech .rot_tm - motion->tmr ;
142+ motion->mech .state = 1 ;
143+ }
144+ else if ((motion->mech .state != 5 ) && (motion->mech .state != 6 ) && (motion->mech .state == 7 ))
145+ {
146+ motion->mech .ss = -motion->mech .ss ;
147+ motion->mech .sr = -motion->mech .sr ;
148+ motion->tmr = 0 .0f ;
149+
150+ if ((mech->type == 0 ) || (mech->type == 2 ) || (mech->type == 4 ))
151+ {
152+ motion->mech .state = 0 ;
153+ }
154+ else
155+ {
156+ motion->mech .state = 1 ;
157+ }
158+ }
159+ }
160+ }
0 commit comments