-
Notifications
You must be signed in to change notification settings - Fork 0
/
world.rs
89 lines (73 loc) · 2.71 KB
/
world.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use super::*;
//use ::r3d::draw;
use window as w;
use window::Window as ws;
type V3= (f32,f32,f32);
pub struct FlyMode{
pos:V3,
hdg:f32,
}
pub fn new<A:'static>()->sto<window::Window<A>>{
sto::new(FlyMode{
pos:(0.0f32,0.0f32,0.0f32),
hdg:0.0f32
})
}
trait Render{
fn sphere(&self,a:&V3,r:f32,c:u32);
fn line(&self,a:&V3,b:&V3,c:u32);
fn arrow(&self,a:&V3,b:&V3,r:f32,c:u32);
}
impl<A:'static> window::Window<A> for FlyMode {
fn win_key(&mut self, a:&mut A, kp:w::KeyAt,wc:&window::WinCursor)->window::Flow<A>{
println!("{:?}",kp);
match (kp.0,kp.2) {
(window::WinKey::KeyCode('e'),window::KeyTransition::KeyDown)=>Flow::Push(editor::make_editor_window::<A,edscene::Scene>()),
_=>Flow::Continue()
}
}
fn win_update(&mut self,a:&mut A, dt:f32)->window::Flow<A> {
let r = 30.0f32;
let movespeed = 0.1f32;
let rotspeed = 0.025f32;
//let js = gtexi0_joystick;
let (mut dx, mut dz) = (0.0f32, 0.0f32);//(js.0 .0, js.0 .1);
let axiskeys = |a,b|{if w::key(a) { -1.0f32 } else if w::key(b) { 1.0f32 } else { 0.0f32 }};
self.hdg += axiskeys('a', 'd') * rotspeed;
dz += axiskeys('s', 'w') * movespeed;
dx += axiskeys(',', '.') * movespeed;
let (ax, ay) = (sin(self.hdg), cos(self.hdg));
self.pos = (self.pos.0 + ax * dz + ay * dx,
self.pos.1 + ay * dz - ax * dx,
self.pos.2);
// let at = Vec3(0.0f32,0.0f32,0.0f32);
window::Flow::Continue()
}
fn win_render(&self, a:&A, wc:&window::WinCursor) {
let eye: Vec3f = self.pos.to_vec3();//into();
let (ax, ay) = (sin(self.hdg), cos(self.hdg));
let at = vec3(eye.x + ax, eye.y + ay, eye.z);
let cam = Camera::look_along(
&Frustum(1.0f32, 1.0f32, (0.1f32, 1000.0f32)),
&vec3(eye.x, eye.y, eye.z),
&vec3(ax, ay, 0.0f32),
&vec3(0.0f32, 0.0f32, 1.0f32));
unsafe {
glutSetCursor(GLUT_CURSOR_CROSSHAIR as i32);
// g_ypos-=0.1f32;
glSetMatrix(GL_PROJECTION, &cam.projection.ax.x);
//glMatrixMode(GL_PROJECTION);
// glLoadMatrixf(&cam.projection.ax.x);
glSetMatrix(GL_MODELVIEW,&cam.view.ax.x);
// draw::grid_xz();
draw::grid_xy_at((0.0f32, 0.0f32, -10.0f32));
draw::grid_xy_at((0.0f32, 0.0f32, 10.0f32));
draw::cuboid_aabb_at(&(0.0, 0.0, 0.0), &(1.0, 4.0, 9.0), 0xff00ff00);
draw::string_at(&(0.0,0.0,0.0),0xff00ffff,"hello world");
draw::main_mode_text("flymode- use WASD, < >");
}
}
}
// numVertex
fn render_scene(r:&Render){
}