1- use super :: object:: * ;
2- use super :: physics;
1+ use crate :: object:: * ;
2+ use crate :: physics;
33use macroquad:: prelude:: * ;
44use std:: vec;
5+ use crate :: screen:: { get_mouse_pos, Ray } ;
56
67pub struct World {
78 pub grav_const : f32 ,
@@ -15,7 +16,7 @@ pub struct World {
1516impl World {
1617 pub fn new ( grav_const : f32 , update_interval : f32 ) -> Self {
1718 let cam = Camera3D {
18- position : vec3 ( 15 ., 10. , 0 .) ,
19+ position : vec3 ( 0 ., 10. , - 15 .) ,
1920 up : vec3 ( 0. , 1. , 0. ) ,
2021 target : vec3 ( 0. , 0. , 0. ) ,
2122 ..Default :: default ( )
@@ -44,8 +45,8 @@ impl World {
4445 } ;
4546
4647 let obj_mat = load_material ( shader, params) . unwrap ( ) ;
47- obj_mat. set_uniform ( "light_pos" , vec3 ( 0. , 10. , 10. ) ) ;
48- obj_mat. set_uniform ( "ambient_light" , 0.3f32 ) ;
48+ obj_mat. set_uniform ( "light_pos" , Vec3 :: ONE ) ;
49+ obj_mat. set_uniform ( "ambient_light" , 0.25f32 ) ;
4950
5051 World {
5152 grav_const,
@@ -112,6 +113,14 @@ impl World {
112113
113114 self . objects . draw_all ( & self . obj_mat ) ;
114115
116+ let ray = Ray :: new_from_cam ( & self . cam , get_mouse_pos ( ) , 100. ) ;
117+
118+ for obj in self . objects . iter ( ) {
119+ if ray. raycast ( obj. position , 0.5 ) {
120+ draw_sphere ( obj. position , 0.5 , None , WHITE ) ;
121+ }
122+ }
123+
115124 #[ cfg( debug_assertions) ]
116125 for obj in self . objects . iter ( ) {
117126 draw_line_3d (
@@ -141,28 +150,28 @@ impl World {
141150
142151 fn handle_input ( & mut self ) {
143152 if get_keys_down ( ) . contains ( & KeyCode :: W ) {
144- self . cam . position . x - = 0.4 ;
145- self . cam . target . x - = 0.4 ;
153+ self . cam . position . z + = 0.4 ;
154+ self . cam . target . z + = 0.4 ;
146155 }
147156 if get_keys_down ( ) . contains ( & KeyCode :: S ) {
148- self . cam . position . x + = 0.4 ;
149- self . cam . target . x + = 0.4 ;
157+ self . cam . position . z - = 0.4 ;
158+ self . cam . target . z - = 0.4 ;
150159 }
151160 if get_keys_down ( ) . contains ( & KeyCode :: LeftControl ) {
152161 self . cam . position . y -= 0.4 ;
153- self . cam . target . y -= 0.4 ;
162+ self . cam . target . y -= 0.4 ;
154163 }
155164 if get_keys_down ( ) . contains ( & KeyCode :: LeftShift ) {
156165 self . cam . position . y += 0.4 ;
157- self . cam . target . y += 0.4 ;
166+ self . cam . target . y += 0.4 ;
158167 }
159168 if get_keys_down ( ) . contains ( & KeyCode :: D ) {
160- self . cam . position . z -= 0.4 ;
161- self . cam . target . z -= 0.4 ;
169+ self . cam . position . x -= 0.4 ;
170+ self . cam . target . x -= 0.4 ;
162171 }
163172 if get_keys_down ( ) . contains ( & KeyCode :: A ) {
164- self . cam . position . z += 0.4 ;
165- self . cam . target . z += 0.4 ;
173+ self . cam . position . x += 0.4 ;
174+ self . cam . target . x += 0.4 ;
166175 }
167176 }
168177}
0 commit comments