make glider look nice
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_tornado.c
1 #include "world.h"
2 #include "particle.h"
3
4 static f32 k_tornado_strength = 0.0f,
5 k_tornado_ratio = 0.5f,
6 k_tornado_range = 10.f;
7
8 static void ent_tornado_init(void){
9 vg_console_reg_var( "k_tonado_strength", &k_tornado_strength,
10 k_var_dtype_f32, VG_VAR_PERSISTENT|VG_VAR_CHEAT );
11 vg_console_reg_var( "k_tonado_ratio", &k_tornado_ratio,
12 k_var_dtype_f32, VG_VAR_PERSISTENT|VG_VAR_CHEAT );
13 vg_console_reg_var( "k_tonado_range", &k_tornado_range,
14 k_var_dtype_f32, VG_VAR_PERSISTENT|VG_VAR_CHEAT );
15 }
16
17 static void ent_tornado_debug(void) {
18 world_instance *world = world_current_instance();
19 for( u32 i=0; i<mdl_arrcount(&world->ent_marker); i ++ ){
20 ent_marker *marker = mdl_arritm( &world->ent_marker, i );
21
22 if( MDL_CONST_PSTREQ( &world->meta, marker->pstr_alias, "tornado" ) ){
23 v3f p1;
24 v3_add( marker->transform.co, (v3f){0,20,0}, p1 );
25 vg_line( marker->transform.co, p1, VG__RED );
26
27 m4x3f mmdl;
28 m4x3_identity( mmdl );
29 v3_copy( marker->transform.co, mmdl[3] );
30 vg_line_sphere( mmdl, k_tornado_range, 0 );
31 }
32 }
33 }
34
35 static void ent_tornado_forces( v3f co, v3f cv, v3f out_a ){
36 world_instance *world = world_current_instance();
37 v3_zero( out_a );
38
39 for( u32 i=0; i<mdl_arrcount(&world->ent_marker); i ++ ){
40 ent_marker *marker = mdl_arritm( &world->ent_marker, i );
41
42 if( MDL_CONST_PSTREQ( &world->meta, marker->pstr_alias, "tornado" ) ){
43 v3f d, dir;
44 v3_sub( co, marker->transform.co, d );
45 d[1] = 0.0f;
46
47 f32 dist = v3_length( d );
48 v3_normalize( d );
49
50 v3_cross( d, (v3f){0,1,0}, dir );
51 if( v3_dot( dir, cv ) < 0.0f )
52 v3_negate( dir, dir );
53
54 f32 s = vg_maxf(0.0f, 1.0f-dist/k_tornado_range),
55 F0 = s*k_tornado_strength,
56 F1 = s*s*k_tornado_strength;
57
58 v3_muladds( out_a, dir, F0 * k_tornado_ratio, out_a );
59 v3_muladds( out_a, d, F1 * -(1.0f-k_tornado_ratio), out_a );
60 }
61 }
62 }
63
64 static void ent_tornado_pre_update(void){
65 world_instance *world = world_current_instance();
66 for( u32 i=0; i<mdl_arrcount(&world->ent_marker); i ++ ){
67 ent_marker *marker = mdl_arritm( &world->ent_marker, i );
68
69 if( MDL_CONST_PSTREQ( &world->meta, marker->pstr_alias, "tornado" ) ){
70 v3f co;
71 vg_rand_sphere( &vg.rand, co );
72
73 v3f tangent = { co[2], 0, co[0] };
74
75 f32 s = vg_signf( co[1] );
76 v3_muls( tangent, s*10.0f, tangent );
77 co[1] *= s;
78
79 v3_muladds( marker->transform.co, co, k_tornado_range, co );
80 particle_spawn( &particles_env, co, tangent, 2.0f, 0xffffffff );
81 }
82 }
83 }