@@ -67,7 +67,7 @@ int main(void)
6767 models [i ] = LoadModel (voxFileNames [i ]);
6868 double t1 = GetTime ()* 1000.0 ;
6969
70- TraceLog (LOG_WARNING , TextFormat ("[%s] File loaded in %.3f ms" , voxFileNames [i ], t1 - t0 ));
70+ TraceLog (LOG_INFO , TextFormat ("[%s] Model file loaded in %.3f ms" , voxFileNames [i ], t1 - t0 ));
7171
7272 // Compute model translation matrix to center model on draw position (0, 0 , 0)
7373 BoundingBox bb = GetModelBoundingBox (models [i ]);
@@ -80,6 +80,8 @@ int main(void)
8080 }
8181
8282 int currentModel = 0 ;
83+ Vector3 modelpos = { 0 };
84+ Vector3 camerarot = { 0 };
8385
8486 // Load voxel shader
8587 Shader shader = LoadShader (TextFormat ("resources/shaders/glsl%i/voxel_lighting.vs" , GLSL_VERSION ),
@@ -98,11 +100,7 @@ int main(void)
98100 // Assign out lighting shader to model
99101 for (int i = 0 ; i < MAX_VOX_FILES ; i ++ )
100102 {
101- Model m = models [i ];
102- for (int j = 0 ; j < m .materialCount ; j ++ )
103- {
104- m .materials [j ].shader = shader ;
105- }
103+ for (int j = 0 ; j < models [i ].materialCount ; j ++ ) models [i ].materials [j ].shader = shader ;
106104 }
107105
108106 // Create lights
@@ -112,12 +110,8 @@ int main(void)
112110 lights [2 ] = CreateLight (LIGHT_POINT , (Vector3 ) { -20 , 20 , 20 }, Vector3Zero (), GRAY , shader );
113111 lights [3 ] = CreateLight (LIGHT_POINT , (Vector3 ) { 20 , -20 , -20 }, Vector3Zero (), GRAY , shader );
114112
115-
116113 SetTargetFPS (60 ); // Set our game to run at 60 frames-per-second
117-
118114 //--------------------------------------------------------------------------------------
119- Vector3 modelpos = { 0 };
120- Vector3 camerarot = { 0 };
121115
122116 // Main game loop
123117 while (!WindowShouldClose ()) // Detect window close button or ESC key
@@ -137,15 +131,11 @@ int main(void)
137131 }
138132
139133 UpdateCameraPro (& camera ,
140- (Vector3 ) {
141- (IsKeyDown (KEY_W ) || IsKeyDown (KEY_UP ))* 0.1f - // Move forward-backward
142- (IsKeyDown (KEY_S ) || IsKeyDown (KEY_DOWN ))* 0.1f ,
143- (IsKeyDown (KEY_D ) || IsKeyDown (KEY_RIGHT ))* 0.1f - // Move right-left
144- (IsKeyDown (KEY_A ) || IsKeyDown (KEY_LEFT ))* 0.1f ,
145- 0.0f // Move up-down
146- },
147- camerarot ,
148- GetMouseWheelMove ()* -2.0f ); // Move to target (zoom)
134+ (Vector3 ){ (IsKeyDown (KEY_W ) || IsKeyDown (KEY_UP ))* 0.1f - (IsKeyDown (KEY_S ) || IsKeyDown (KEY_DOWN ))* 0.1f , // Move forward-backward
135+ (IsKeyDown (KEY_D ) || IsKeyDown (KEY_RIGHT ))* 0.1f - (IsKeyDown (KEY_A ) || IsKeyDown (KEY_LEFT ))* 0.1f , // Move right-left
136+ 0.0f }, // Move up-down
137+ camerarot , // Camera rotation
138+ GetMouseWheelMove ()* -2.0f ); // Move to target (zoom)
149139
150140 // Cycle between models on mouse click
151141 if (IsMouseButtonPressed (MOUSE_BUTTON_LEFT )) currentModel = (currentModel + 1 ) % MAX_VOX_FILES ;
@@ -156,36 +146,34 @@ int main(void)
156146
157147 // Update light values (actually, only enable/disable them)
158148 for (int i = 0 ; i < MAX_LIGHTS ; i ++ ) UpdateLightValues (shader , lights [i ]);
159-
160149 //----------------------------------------------------------------------------------
150+
161151 // Draw
162152 //----------------------------------------------------------------------------------
163153 BeginDrawing ();
164154
165- ClearBackground (RAYWHITE );
166-
167- // Draw 3D model
168- BeginMode3D (camera );
169-
170- DrawModel (models [currentModel ], modelpos , 1.0f , WHITE );
171- DrawGrid (10 , 1.0 );
172-
173- // Draw spheres to show where the lights are
174- for (int i = 0 ; i < MAX_LIGHTS ; i ++ )
175- {
176- if (lights [i ].enabled ) DrawSphereEx (lights [i ].position , 0.2f , 8 , 8 , lights [i ].color );
177- else DrawSphereWires (lights [i ].position , 0.2f , 8 , 8 , ColorAlpha (lights [i ].color , 0.3f ));
178- }
179-
180- EndMode3D ();
181-
182- // Display info
183- DrawRectangle (10 , 400 , 340 , 60 , Fade (SKYBLUE , 0.5f ));
184- DrawRectangleLines (10 , 400 , 340 , 60 , Fade (DARKBLUE , 0.5f ));
185- DrawText ("MOUSE LEFT BUTTON to CYCLE VOX MODELS" , 40 , 410 , 10 , BLUE );
186- DrawText ("MOUSE MIDDLE BUTTON to ZOOM OR ROTATE CAMERA" , 40 , 420 , 10 , BLUE );
187- DrawText ("UP-DOWN-LEFT-RIGHT KEYS to MOVE CAMERA" , 40 , 430 , 10 , BLUE );
188- DrawText (TextFormat ("File: %s" , GetFileName (voxFileNames [currentModel ])), 10 , 10 , 20 , GRAY );
155+ ClearBackground (RAYWHITE );
156+
157+ // Draw 3D model
158+ BeginMode3D (camera );
159+ DrawModel (models [currentModel ], modelpos , 1.0f , WHITE );
160+ DrawGrid (10 , 1.0 );
161+
162+ // Draw spheres to show where the lights are
163+ for (int i = 0 ; i < MAX_LIGHTS ; i ++ )
164+ {
165+ if (lights [i ].enabled ) DrawSphereEx (lights [i ].position , 0.2f , 8 , 8 , lights [i ].color );
166+ else DrawSphereWires (lights [i ].position , 0.2f , 8 , 8 , ColorAlpha (lights [i ].color , 0.3f ));
167+ }
168+ EndMode3D ();
169+
170+ // Display info
171+ DrawRectangle (10 , 40 , 340 , 70 , Fade (SKYBLUE , 0.5f ));
172+ DrawRectangleLines (10 , 40 , 340 , 70 , Fade (DARKBLUE , 0.5f ));
173+ DrawText ("- MOUSE LEFT BUTTON: CYCLE VOX MODELS" , 20 , 50 , 10 , BLUE );
174+ DrawText ("- MOUSE MIDDLE BUTTON: ZOOM OR ROTATE CAMERA" , 20 , 70 , 10 , BLUE );
175+ DrawText ("- UP-DOWN-LEFT-RIGHT KEYS: MOVE CAMERA" , 20 , 90 , 10 , BLUE );
176+ DrawText (TextFormat ("Model file: %s" , GetFileName (voxFileNames [currentModel ])), 10 , 10 , 20 , GRAY );
189177
190178 EndDrawing ();
191179 //----------------------------------------------------------------------------------
@@ -201,5 +189,3 @@ int main(void)
201189
202190 return 0 ;
203191}
204-
205-
0 commit comments