|
30 | 30 |
|
31 | 31 | import raylib as rl
|
32 | 32 |
|
33 |
| - |
34 | 33 | from raylib.colors import *
|
35 | 34 | from dataclasses import dataclass
|
36 | 35 | from enum import Enum
|
|
43 | 42 | # lighting system
|
44 | 43 | from light_system import *
|
45 | 44 |
|
46 |
| -#// Initialization |
47 |
| -#//-------------------------------------------------------------------------------------- |
48 |
| -screenWidth = 1200; |
49 |
| -screenHeight = 720; |
| 45 | +# Initialization |
| 46 | +# -------------------------------------------------------------------------------------- |
| 47 | +screenWidth = 1200 |
| 48 | +screenHeight = 720 |
50 | 49 |
|
51 |
| -rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available) |
| 50 | +rl.SetConfigFlags( |
| 51 | + rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available) |
52 | 52 | rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
|
53 | 53 |
|
54 | 54 | camera = rl.ffi.new('struct Camera3D *', [
|
|
59 | 59 | rl.CAMERA_PERSPECTIVE
|
60 | 60 | ])
|
61 | 61 |
|
62 |
| -#// Load models |
| 62 | +# Load models |
63 | 63 | modelA = rl.LoadModelFromMesh(rl.GenMeshTorus(0.4, 1.0, 16, 32))
|
64 | 64 | modelB = rl.LoadModelFromMesh(rl.GenMeshCube(1.0, 1.0, 1.0))
|
65 | 65 | modelC = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))
|
66 | 66 |
|
67 |
| -#// Load models texture |
| 67 | +# Load models texture |
68 | 68 | texture = rl.LoadTexture(b"resources/texel_checker.png")
|
69 | 69 |
|
70 |
| -#// Assign texture to default model material |
| 70 | +# Assign texture to default model material |
71 | 71 | modelA.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
72 | 72 | modelB.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
73 | 73 | modelC.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
74 | 74 |
|
75 |
| -angle = 6.282; |
| 75 | +angle = 6.282 |
76 | 76 |
|
77 |
| -#// Using 4 point lights, white, red, green and blue |
| 77 | +# Using 4 point lights, white, red, green and blue |
78 | 78 |
|
79 |
| -lights0 = Light(LIGHT_POINT, [ 4, 2, 4 ], Vector3Zero(), WHITE) |
80 |
| -lights1 = Light(LIGHT_POINT, [4, 2, 4 ], Vector3Zero(), RED) |
81 |
| -lights2 = Light(LIGHT_POINT, [ 0, 4, 2 ], Vector3Zero(), GREEN) |
82 |
| -lights3 = Light(LIGHT_POINT, [ 0, 4, 2 ], Vector3Zero(), BLUE) |
| 79 | +lights0 = Light(LIGHT_POINT, [4, 2, 4], Vector3Zero(), WHITE) |
| 80 | +lights1 = Light(LIGHT_POINT, [4, 2, 4], Vector3Zero(), RED) |
| 81 | +lights2 = Light(LIGHT_POINT, [0, 4, 2], Vector3Zero(), GREEN) |
| 82 | +lights3 = Light(LIGHT_POINT, [0, 4, 2], Vector3Zero(), BLUE) |
83 | 83 |
|
84 |
| -lightSystem = LightSystem([ 0.2, 0.2, 0.2, 1.0 ], lights0, lights1, lights2, lights3) |
| 84 | +lightSystem = LightSystem([0.2, 0.2, 0.2, 1.0], lights0, lights1, lights2, lights3) |
85 | 85 | fogD = rl.GetShaderLocation(lightSystem.shader, b'FogDensity')
|
86 | 86 | fogDensity = 0.0
|
87 | 87 |
|
88 |
| -#// All models use the same shader - which lights them |
| 88 | +# All models use the same shader - which lights them |
89 | 89 | modelA.materials[0].shader = lightSystem.shader
|
90 | 90 | modelB.materials[0].shader = lightSystem.shader
|
91 | 91 | modelC.materials[0].shader = lightSystem.shader
|
92 | 92 |
|
93 | 93 | rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL) # Set an orbital camera mode
|
94 | 94 |
|
95 |
| -rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second |
96 |
| -#//-------------------------------------------------------------------------------------- |
| 95 | +rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second |
| 96 | +# -------------------------------------------------------------------------------------- |
97 | 97 |
|
98 |
| -#// Main game loop |
99 |
| -while not rl.WindowShouldClose(): #// Detect window close button or ESC key |
100 |
| - #// Update |
101 |
| - #//---------------------------------------------------------------------------------- |
| 98 | +# Main game loop |
| 99 | +while not rl.WindowShouldClose(): # Detect window close button or ESC key |
| 100 | + # Update |
| 101 | + # ---------------------------------------------------------------------------------- |
102 | 102 | if rl.IsKeyPressed(rl.KEY_W): lights0.enabled = not lights0.enabled
|
103 | 103 | if rl.IsKeyPressed(rl.KEY_R): lights1.enabled = not lights1.enabled
|
104 | 104 | if rl.IsKeyPressed(rl.KEY_G): lights2.enabled = not lights2.enabled
|
105 | 105 | if rl.IsKeyPressed(rl.KEY_B): lights3.enabled = not lights3.enabled
|
106 | 106 |
|
107 |
| - rl.UpdateCamera(camera) #// Update camera |
| 107 | + rl.UpdateCamera(camera) # Update camera |
108 | 108 |
|
109 |
| - #// Make the lights do differing orbits |
| 109 | + # Make the lights do differing orbits |
110 | 110 | angle -= 0.02
|
111 |
| - lights0.position.x = math.cos(angle)*4.0 |
112 |
| - lights0.position.z = math.sin(angle)*4.0 |
113 |
| - lights1.position.x = math.cos(-angle*0.6)*4.0 |
114 |
| - lights1.position.z = math.sin(-angle*0.6)*4.0 |
115 |
| - lights2.position.y = math.cos(angle*0.2)*4.0 |
116 |
| - lights2.position.z = math.sin(angle*0.2)*4.0 |
117 |
| - lights3.position.y = math.cos(-angle*0.35)*4.0 |
118 |
| - lights3.position.z = math.sin(-angle*0.35)*4.0 |
| 111 | + lights0.position.x = math.cos(angle) * 4.0 |
| 112 | + lights0.position.z = math.sin(angle) * 4.0 |
| 113 | + lights1.position.x = math.cos(-angle * 0.6) * 4.0 |
| 114 | + lights1.position.z = math.sin(-angle * 0.6) * 4.0 |
| 115 | + lights2.position.y = math.cos(angle * 0.2) * 4.0 |
| 116 | + lights2.position.z = math.sin(angle * 0.2) * 4.0 |
| 117 | + lights3.position.y = math.cos(-angle * 0.35) * 4.0 |
| 118 | + lights3.position.z = math.sin(-angle * 0.35) * 4.0 |
119 | 119 |
|
120 |
| - #// Update the light shader with the camera view position |
| 120 | + # Update the light shader with the camera view position |
121 | 121 |
|
122 | 122 | lightSystem.update(camera.position)
|
123 | 123 |
|
124 |
| - |
125 |
| -# ffi.cast('wchar_t', x) |
126 |
| -# modelA.transform = ffi.cast('Matrix *', MatrixRotateY(angle*1.7))[0] |
127 |
| -# modelA.transform = MatrixRotateY(angle*1.7) |
128 |
| - #// Rotate the torus |
129 |
| -# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)[0])[0] |
130 |
| -# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)[0])[0] |
| 124 | + # ffi.cast('wchar_t', x) |
| 125 | + # modelA.transform = ffi.cast('Matrix *', MatrixRotateY(angle*1.7))[0] |
| 126 | + # modelA.transform = MatrixRotateY(angle*1.7) |
| 127 | + # Rotate the torus |
| 128 | + # modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)[0])[0] |
| 129 | + # modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)[0])[0] |
131 | 130 | modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)))[0]
|
132 | 131 | modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)))[0]
|
133 | 132 |
|
134 | 133 | if (rl.IsKeyPressed(rl.KEY_F)):
|
135 | 134 | rl.ToggleFullscreen()
|
136 | 135 |
|
| 136 | + # ---------------------------------------------------------------------------------- |
137 | 137 |
|
138 |
| - #//---------------------------------------------------------------------------------- |
139 |
| - |
140 |
| - #// Draw |
141 |
| - #//---------------------------------------------------------------------------------- |
| 138 | + # Draw |
| 139 | + # ---------------------------------------------------------------------------------- |
142 | 140 | rl.BeginDrawing()
|
143 | 141 |
|
144 | 142 | rl.ClearBackground(RAYWHITE)
|
145 | 143 |
|
146 | 144 | rl.BeginMode3D(camera[0])
|
147 | 145 |
|
148 |
| - #// Draw the three models |
149 |
| - rl.DrawModel(modelA, [0,0,0], 1.0, WHITE) |
150 |
| - rl.DrawModel(modelB, [-1.6,0,0], 1.0, WHITE) |
151 |
| - rl.DrawModel(modelC, [ 1.6,0,0], 1.0, WHITE) |
| 146 | + # Draw the three models |
| 147 | + rl.DrawModel(modelA, [0, 0, 0], 1.0, WHITE) |
| 148 | + rl.DrawModel(modelB, [-1.6, 0, 0], 1.0, WHITE) |
| 149 | + rl.DrawModel(modelC, [1.6, 0, 0], 1.0, WHITE) |
152 | 150 |
|
153 |
| - #// Draw markers to show where the lights are |
| 151 | + # Draw markers to show where the lights are |
154 | 152 | lightSystem.draw()
|
155 | 153 |
|
156 |
| - |
157 | 154 | rl.DrawGrid(10, 1.0)
|
158 | 155 |
|
159 | 156 | rl.EndMode3D()
|
|
163 | 160 | rl.DrawText(b"Keys RGB & W toggle lights", 10, 30, 20, DARKGRAY)
|
164 | 161 |
|
165 | 162 | rl.EndDrawing()
|
166 |
| -#//---------------------------------------------------------------------------------- |
| 163 | +# ---------------------------------------------------------------------------------- |
167 | 164 |
|
168 | 165 |
|
169 |
| -#// De-Initialization |
170 |
| -#//-------------------------------------------------------------------------------------- |
171 |
| -rl.UnloadModel(modelA) # // Unload the modelA |
172 |
| -rl.UnloadModel(modelB) # // Unload the modelB |
173 |
| -rl.UnloadModel(modelC) # // Unload the modelC |
| 166 | +# De-Initialization |
| 167 | +# -------------------------------------------------------------------------------------- |
| 168 | +rl.UnloadModel(modelA) # Unload the modelA |
| 169 | +rl.UnloadModel(modelB) # Unload the modelB |
| 170 | +rl.UnloadModel(modelC) # Unload the modelC |
174 | 171 |
|
175 |
| -rl.UnloadTexture(texture) #// Unload the texture |
| 172 | +rl.UnloadTexture(texture) # Unload the texture |
176 | 173 |
|
177 | 174 | rl.UnloadShader(lightSystem.shader)
|
178 | 175 |
|
179 |
| -rl.CloseWindow() #// Close window and OpenGL context |
| 176 | +rl.CloseWindow() # Close window and OpenGL context |
0 commit comments