af0507fafc0db0f33b0a4f33e6ba0a10d6b3f9f3
3 static int ray_world( v3f pos
, v3f dir
, ray_hit
*hit
);
12 #include "rigidbody.h"
16 #include "shaders/standard.h"
21 submodel sm_road
, sm_terrain
;
26 teleport_gate gates
[64];
29 rigidbody temp_rbs
[128];
36 static void render_world( m4x4f projection
, m4x3f camera
)
40 m4x3f identity_matrix
;
41 m4x3_identity( identity_matrix
);
43 render_terrain( projection
, camera
[3] );
44 scene_bind( &world
.geo
);
45 scene_draw( &world
.geo
);
47 glDisable(GL_CULL_FACE
);
48 scene_bind( &world
.foliage
);
49 scene_draw( &world
.foliage
);
50 glEnable(GL_CULL_FACE
);
52 vg_line_boxf( world
.geo
.bbx
, 0xff00ff00 );
55 static void ray_world_get_tri( ray_hit
*hit
, v3f tri
[3] )
57 for( int i
=0; i
<3; i
++ )
58 v3_copy( world
.geo
.verts
[ hit
->tri
[i
] ].co
, tri
[i
] );
61 static int ray_world( v3f pos
, v3f dir
, ray_hit
*hit
)
63 return scene_raycast( &world
.geo
, pos
, dir
, hit
);
66 static int ray_hit_is_ramp( ray_hit
*hit
)
68 return hit
->tri
[0] < world
.sm_road
.vertex_count
;
71 static void world_load(void)
74 scene_init( &world
.geo
);
75 model
*mworld
= vg_asset_read( "models/mp_dev.mdl" );
77 for( int i
=0; i
<mworld
->layer_count
; i
++ )
79 submodel
*sm
= model_get_submodel( mworld
, i
);
80 if( !strcmp( sm
->material
, "surf" ) )
81 scene_add_model( &world
.geo
, mworld
, sm
, sm
->pivot
, 0.0f
, 1.0f
);
84 scene_copy_slice( &world
.geo
, &world
.sm_road
);
86 for( int i
=0; i
<mworld
->layer_count
; i
++ )
88 submodel
*sm
= model_get_submodel( mworld
, i
);
89 if( !strcmp( sm
->material
, "terrain" ) )
90 scene_add_model( &world
.geo
, mworld
, sm
, sm
->pivot
, 0.0f
, 1.0f
);
93 scene_copy_slice( &world
.geo
, &world
.sm_terrain
);
95 vg_info( "BBX: %.3f %.3f %.3f -> %.3f %.3f %.3f\n",
96 world
.geo
.bbx
[0][0], world
.geo
.bbx
[0][1], world
.geo
.bbx
[0][2],
97 world
.geo
.bbx
[1][0], world
.geo
.bbx
[1][1], world
.geo
.bbx
[1][2] );
100 * TODO: Parametric marker import
102 v3_copy( model_marker_get( mworld
, "start" )->co
, world
.tutorial
);
108 world
.gate_count
= 0;
109 for( int i
=0; i
<mworld
->marker_count
; i
++ )
111 model_marker
*ga
= model_get_marker( mworld
, i
);
113 if( ga
->classtype
== k_classtype_gate
)
115 struct classtype_gate
*data
= get_entdata_raw( mworld
, ga
);
119 model_marker
*gb
= model_get_marker( mworld
, data
->target
);
121 teleport_gate
*gate
= &world
.gates
[ world
.gate_count
++ ];
123 v3_copy( ga
->co
, gate
->co
[0] );
124 v3_copy( gb
->co
, gate
->co
[1] );
125 v4_copy( ga
->q
, gate
->q
[0] );
126 v4_copy( gb
->q
, gate
->q
[1] );
127 v2_copy( ga
->s
, gate
->dims
);
129 gate_transform_update( gate
);
135 * Load water mesh (1 per world)
137 for( int i
=0; i
<mworld
->layer_count
; i
++ )
139 submodel
*sm
= model_get_submodel( mworld
, i
);
140 if( !strcmp( sm
->material
, "water" ) )
143 model_unpack_submodel( mworld
, &surf
, sm
);
146 water_set_surface( &surf
, sm
->pivot
[1] );
148 vg_info( "%.3f\n", sm
->pivot
[1] );
154 scene_upload( &world
.geo
);
155 scene_bh_create( &world
.geo
);
157 water_compute_depth( world
.geo
.bbx
);
159 scene_init( &world
.foliage
);
160 model
*mfoliage
= vg_asset_read("models/rs_foliage.mdl");
163 * TODO: Load any other meshes into the foliage scene, and create rbs for
169 for( int i
=0; i
<mworld
->layer_count
; i
++ )
171 submodel
*sm
= model_get_submodel( mworld
, i
);
172 if( !strcmp( sm
->material
, "surf" ) ||
173 !strcmp( sm
->material
, "terrain" ) ||
174 !strcmp( sm
->material
, "water" ) )
178 q_m3x3( sm
->q
, transform
);
179 v3_copy( sm
->pivot
, transform
[3] );
180 scene_add_foliage( &world
.foliage
, mworld
, sm
, transform
);
182 rigidbody
*rb
= &world
.temp_rbs
[ world
.rb_count
++ ];
184 box_copy( sm
->bbx
, rb
->bbx
);
185 v3_copy( sm
->pivot
, rb
->co
);
187 v4_copy( sm
->q
, rb
->q
);
188 rb_update_transform( rb
);
194 v3_sub( world
.geo
.bbx
[1], world
.geo
.bbx
[0], volume
);
199 submodel
*sm_blob
= submodel_get( mfoliage
, "blob" ),
200 *sm_tree
= submodel_get( mfoliage
, "tree" );
202 for( int i
=0;i
<100000;i
++ )
205 v3_mul( volume
, (v3f
){ vg_randf(), 1000.0f
, vg_randf() }, pos
);
207 v3_add( pos
, world
.geo
.bbx
[0], pos
);
212 if( ray_world( pos
, (v3f
){0.0f
,-1.0f
,0.0f
}, &hit
))
214 if( hit
.normal
[1] > 0.8f
&& !ray_hit_is_ramp(&hit
) &&
215 hit
.pos
[1] > water_height()+10.0f
)
217 v4f qsurface
, qrandom
;
220 v3_cross( (v3f
){0.0f
,1.0f
,0.0f
}, hit
.normal
, axis
);
222 float angle
= v3_dot(hit
.normal
,(v3f
){0.0f
,1.0f
,0.0f
});
223 q_axis_angle( qsurface
, axis
, angle
);
224 q_axis_angle( qrandom
, (v3f
){0.0f
,1.0f
,0.0f
}, vg_randf()*VG_TAUf
);
225 q_mul( qsurface
, qrandom
, qsurface
);
226 q_m3x3( qsurface
, transform
);
228 v3_copy( hit
.pos
, transform
[3] );
230 if( vg_randf() < 0.0006f
)
232 m3x3_identity( transform
);
233 scene_add_foliage( &world
.foliage
, mfoliage
, sm_tree
, transform
);
236 scene_add_foliage( &world
.foliage
, mfoliage
, sm_blob
, transform
);
242 scene_upload( &world
.foliage
);
244 bh_create( &world
.bhcubes
,
245 &bh_system_rigidbodies
, world
.temp_rbs
, world
.rb_count
);