12 #include "shaders/standard.h"
17 submodel sm_road
, sm_terrain
;
24 static void render_world( m4x4f projection
, m4x3f camera
)
28 m4x3f identity_matrix
;
29 m4x3_identity( identity_matrix
);
31 render_terrain( projection
, camera
[3] );
32 scene_bind( &world
.geo
);
33 scene_draw( &world
.geo
);
35 glDisable(GL_CULL_FACE
);
36 scene_bind( &world
.foliage
);
37 scene_draw( &world
.foliage
);
38 glEnable(GL_CULL_FACE
);
41 static void ray_world_get_tri( ray_hit
*hit
, v3f tri
[3] )
43 for( int i
=0; i
<3; i
++ )
44 v3_copy( world
.geo
.verts
[ hit
->tri
[i
] ].co
, tri
[i
] );
47 __attribute__((always_inline
))
48 static int ray_world( v3f pos
, v3f dir
, ray_hit
*hit
)
50 return bvh_raycast( &world
.geo
, pos
, dir
, hit
);
53 static int ray_hit_is_ramp( ray_hit
*hit
)
55 return hit
->tri
[0] < world
.sm_road
.vertex_count
;
58 static void world_load(void)
61 scene_init( &world
.geo
);
62 model
*mworld
= vg_asset_read( "models/mp_dev.mdl" );
64 scene_add_model( &world
.geo
, mworld
, submodel_get( mworld
, "mp_dev" ),
65 (v3f
){0.0f
,0.0f
,0.0f
}, 0.0f
, 1.0f
);
66 scene_copy_slice( &world
.geo
, &world
.sm_road
);
68 scene_add_model( &world
.geo
, mworld
, submodel_get( mworld
, "terrain" ),
69 (v3f
){0.0f
,0.0f
,0.0f
}, 0.0f
, 1.0f
);
70 scene_copy_slice( &world
.geo
, &world
.sm_terrain
);
72 v3_copy( model_marker_get( mworld
, "mp_dev_tutorial" )->co
, world
.tutorial
);
78 model_marker
*ga
= model_marker_get(mworld
,"gate_a"),
79 *gb
= model_marker_get(mworld
,"gate_a_recv");
81 v3_copy( ga
->co
, gate_a
.co
);
82 v3_copy( gb
->co
, gate_b
.co
);
83 v4_copy( ga
->q
, gate_a
.q
);
84 v4_copy( gb
->q
, gate_b
.q
);
85 v2_copy( ga
->s
, gate_a
.dims
);
86 v2_copy( gb
->s
, gate_b
.dims
);
88 gate_a
.other
= &gate_b
;
89 gate_b
.other
= &gate_a
;
91 gate_transform_update( &gate_a
);
92 gate_transform_update( &gate_b
);
99 submodel
*sm
= submodel_get(mworld
,"mp_dev_water");
100 model_unpack_submodel( mworld
, &surf
, sm
);
103 water_set_surface( &surf
, sm
->pivot
[1] );
107 scene_upload( &world
.geo
);
108 bvh_create( &world
.geo
);
110 water_compute_depth( world
.geo
.bbx
);
112 scene_init( &world
.foliage
);
113 model
*mfoliage
= vg_asset_read("models/rs_foliage.mdl");
116 v3_sub( world
.geo
.bbx
[1], world
.geo
.bbx
[0], volume
);
121 submodel
*sm_blob
= submodel_get( mfoliage
, "blob" ),
122 *sm_tree
= submodel_get( mfoliage
, "tree" );
124 for( int i
=0;i
<100000;i
++ )
127 v3_mul( volume
, (v3f
){ vg_randf(), 1000.0f
, vg_randf() }, pos
);
128 v3_add( pos
, world
.geo
.bbx
[0], pos
);
133 if( ray_world( pos
, (v3f
){0.0f
,-1.0f
,0.0f
}, &hit
))
135 if( hit
.normal
[1] > 0.8f
&& !ray_hit_is_ramp(&hit
) &&
136 hit
.pos
[1] > wrender
.height
)
138 v4f qsurface
, qrandom
;
141 v3_cross( (v3f
){0.0f
,1.0f
,0.0f
}, hit
.normal
, axis
);
143 float angle
= v3_dot(hit
.normal
,(v3f
){0.0f
,1.0f
,0.0f
});
144 q_axis_angle( qsurface
, axis
, angle
);
145 q_axis_angle( qrandom
, (v3f
){0.0f
,1.0f
,0.0f
}, vg_randf()*VG_TAUf
);
146 q_mul( qsurface
, qrandom
, qsurface
);
147 q_m3x3( qsurface
, transform
);
149 v3_copy( hit
.pos
, transform
[3] );
151 if( vg_randf() < 0.00000006f
)
153 m3x3_identity( transform
);
154 scene_add_foliage( &world
.foliage
, mfoliage
, sm_tree
, transform
);
157 scene_add_foliage( &world
.foliage
, mfoliage
, sm_blob
, transform
);
163 scene_upload( &world
.foliage
);