3 void ent_traffic_update( world_instance
*world
, v3f pos
)
5 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_traffic
); i
++ ){
6 ent_traffic
*traffic
= mdl_arritm( &world
->ent_traffic
, i
);
8 u32 i1
= traffic
->index
,
12 if( i1
== 0 ) i0
= traffic
->node_count
-1;
15 if( i2
>= traffic
->node_count
) i2
= 0;
17 i0
+= traffic
->start_node
;
18 i1
+= traffic
->start_node
;
19 i2
+= traffic
->start_node
;
23 ent_route_node
*rn0
= mdl_arritm( &world
->ent_route_node
, i0
),
24 *rn1
= mdl_arritm( &world
->ent_route_node
, i1
),
25 *rn2
= mdl_arritm( &world
->ent_route_node
, i2
);
27 v3_copy( rn1
->co
, h
[1] );
28 v3_lerp( rn0
->co
, rn1
->co
, 0.5f
, h
[0] );
29 v3_lerp( rn1
->co
, rn2
->co
, 0.5f
, h
[2] );
31 float const k_sample_dist
= 0.0025f
;
33 eval_bezier3( h
[0], h
[1], h
[2], traffic
->t
, pc
);
34 eval_bezier3( h
[0], h
[1], h
[2], traffic
->t
+k_sample_dist
, pd
);
38 float length
= vg_maxf( 0.0001f
, v3_length( v0
) );
39 v3_muls( v0
, 1.0f
/length
, v0
);
41 float mod
= k_sample_dist
/ length
;
43 traffic
->t
+= traffic
->speed
* vg
.time_delta
* mod
;
45 if( traffic
->t
> 1.0f
){
48 if( traffic
->t
> 1.0f
) traffic
->t
= 0.0f
;
52 if( traffic
->index
>= traffic
->node_count
)
56 v3_copy( pc
, traffic
->transform
.co
);
58 float a
= atan2f( -v0
[0], v0
[2] );
59 q_axis_angle( traffic
->transform
.q
, (v3f
){0.0f
,1.0f
,0.0f
}, -a
);
61 vg_line_point( traffic
->transform
.co
, 0.3f
, VG__BLUE
);