MCPcopy Create free account
hub / github.com/electronstudio/raylib-python-cffi / CameraFly

Class CameraFly

examples/extra/extra_camera.py:8–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class CameraFly:
9 def __init__(self, x=0, y=0, z=0, fov=70.0):
10 self.last_mouse = ffi.new("struct Vector2 *", [0, 0])
11 self.fov = fov
12 self.yaw = -46.33
13 self.pitch = 0.0
14 self.front = glm.vec3()
15 self.up = glm.vec3()
16 self.right = glm.vec3()
17 self.position = glm.vec3(x, y, z)
18 self.world_up = glm.vec3(0, 1, 0)
19 self.fps_facing = glm.vec3()
20 self.movement_speed = 10
21 self.mouse_sensitivity = 0.002
22 self.last_time = rl.GetFrameTime()
23
24 def get_camera(self):
25 return ffi.new(
26 "struct Camera3D *",
27 [
28 self.get_ray_front(),
29 self.get_ray_position(),
30 self.get_ray_up(),
31 self.fov,
32 rl.CAMERA_PERSPECTIVE
33 ]
34 )
35
36 def get_ray_front(self):
37 return list(self.position + self.front)
38
39 def get_ray_up(self):
40 return list(self.up)
41
42 def get_ray_position(self):
43 return list(self.position)
44
45 def update_keyboard(self):
46 boost = 4 if rl.IsKeyDown(rl.KEY_LEFT_SHIFT) else 1
47 velocity = self.movement_speed * boost * rl.GetFrameTime()
48
49 if rl.IsKeyDown(rl.KEY_W):
50 self.position = self.position - self.fps_facing * velocity
51
52 if rl.IsKeyDown(rl.KEY_S):
53 self.position = self.position + self.fps_facing * velocity
54
55 if rl.IsKeyDown(rl.KEY_D):
56 dirr = glm.normalize(glm.cross(self.fps_facing, self.world_up))
57 self.position = self.position - dirr * velocity
58
59 if rl.IsKeyDown(rl.KEY_A):
60 dirr = glm.normalize(glm.cross(self.fps_facing, self.world_up))
61 self.position = self.position + dirr * velocity
62
63 if rl.IsKeyDown(rl.KEY_SPACE):
64 self.position = self.position + self.world_up * velocity
65

Callers 1

camera_testFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected