aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorvictorfisac <victorfisac@gmail.com>2016-01-11 15:09:23 +0100
committervictorfisac <victorfisac@gmail.com>2016-01-11 15:09:23 +0100
commit8eb6fc5612da86e4fc196ed9719949748ed08d85 (patch)
tree534c4b2f488e6cb0e650316fbee2b9d7a4d12664 /examples
parenta5e79b7663532b4420d91ee9adb7265f06847624 (diff)
parent5e7686695fcfe32bbf956990ced0a02b7c881af1 (diff)
downloadraylib-8eb6fc5612da86e4fc196ed9719949748ed08d85.tar.gz
raylib-8eb6fc5612da86e4fc196ed9719949748ed08d85.zip
Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
Diffstat (limited to 'examples')
-rw-r--r--examples/lighting_blinn_phong.c101
1 files changed, 36 insertions, 65 deletions
diff --git a/examples/lighting_blinn_phong.c b/examples/lighting_blinn_phong.c
index d4ff548a..65dbb4f2 100644
--- a/examples/lighting_blinn_phong.c
+++ b/examples/lighting_blinn_phong.c
@@ -50,29 +50,28 @@ int main()
int lightLoc = GetShaderLocation(shader, "lightPos");
// Light and material definitions
- Light directionalLight;
- Material blinnMaterial;
+ Light light;
+ Material matBlinn;
// Light initialization
- SetLightPosition(&directionalLight, (Vector3){5.0f, 1.0f, 1.0f});
- SetLightRotation(&directionalLight, (Vector3){5.0f, 1.0f, 1.0f});
- SetLightIntensity(&directionalLight, 1);
- SetLightAmbientColor(&directionalLight, (Vector3){0.6f, 0.3f, 0});
- SetLightDiffuseColor(&directionalLight, (Vector3){1, 1, 1});
- SetLightSpecularColor(&directionalLight, (Vector3){1, 1, 1});
- SetLightSpecIntensity(&directionalLight, 1);
+ light.position = (Vector3){ 5.0f, 1.0f, 1.0f };
+ light.direction = (Vector3){ 5.0f, 1.0f, 1.0f };
+ light.intensity = 1.0f;
+ light.diffuse = WHITE;
+ light.ambient = (Color){ 150, 75, 0, 255 };
+ light.specular = WHITE;
+ light.specIntensity = 1.0f;
// Material initialization
- SetMaterialAmbientColor(&blinnMaterial, (Vector3){0.2f, 0.2f, 0.2f});
- SetMaterialDiffuseColor(&blinnMaterial, (Vector3){1.0f, 1.0f, 1.0f});
- SetMaterialSpecularColor(&blinnMaterial, (Vector3){1.0f, 1.0f, 1.0f});
- SetMaterialGlossiness(&blinnMaterial, 50);
+ matBlinn.diffuse = WHITE;
+ matBlinn.ambient = (Color){ 50, 50, 50, 255 };
+ matBlinn.specular = WHITE;
+ matBlinn.glossiness = 50.0f;
// Setup camera
SetCameraMode(CAMERA_FREE); // Set camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
- float cameraPosition[3] = { camera.position.x, camera.position.y, camera.position.z }; // Camera position vector in float array
//--------------------------------------------------------------------------------------
// Main game loop
@@ -81,69 +80,44 @@ int main()
// Update
//----------------------------------------------------------------------------------
- // Update camera position and its float array for shader
+ // Update camera position
UpdateCamera(&camera);
- cameraPosition[0] = camera.position.x;
- cameraPosition[1] = camera.position.y;
- cameraPosition[2] = camera.position.z;
// Glossiness input control
- if(IsKeyDown(KEY_UP))
- {
- blinnMaterial.glossiness[0] += SHININESS_SPEED;
- }
+ if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED;
else if(IsKeyDown(KEY_DOWN))
{
- blinnMaterial.glossiness[0] -= SHININESS_SPEED;
-
- if(blinnMaterial.glossiness[0] < 0) blinnMaterial.glossiness[0] = 0;
+ matBlinn.glossiness -= SHININESS_SPEED;
+ if( matBlinn.glossiness < 0) matBlinn.glossiness = 0.0f;
}
// Light X movement
- if(IsKeyDown(KEY_D))
- {
- directionalLight.position[0] += LIGHT_SPEED;
- }
- else if(IsKeyDown(KEY_A))
- {
- directionalLight.position[0] -= LIGHT_SPEED;
- }
+ if (IsKeyDown(KEY_D)) light.position.x += LIGHT_SPEED;
+ else if(IsKeyDown(KEY_A)) light.position.x -= LIGHT_SPEED;
// Light Y movement
- if(IsKeyDown(KEY_LEFT_SHIFT))
- {
- directionalLight.position[1] += LIGHT_SPEED;
- }
- else if(IsKeyDown(KEY_LEFT_CONTROL))
- {
- directionalLight.position[1] -= LIGHT_SPEED;
- }
+ if (IsKeyDown(KEY_LEFT_SHIFT)) light.position.y += LIGHT_SPEED;
+ else if (IsKeyDown(KEY_LEFT_CONTROL)) light.position.y -= LIGHT_SPEED;
// Light Z movement
- if(IsKeyDown(KEY_S))
- {
- directionalLight.position[2] += LIGHT_SPEED;
- }
- else if(IsKeyDown(KEY_W))
- {
- directionalLight.position[2] -= LIGHT_SPEED;
- }
+ if (IsKeyDown(KEY_S)) light.position.z += LIGHT_SPEED;
+ else if (IsKeyDown(KEY_W)) light.position.z -= LIGHT_SPEED;
// Send light values to shader
- SetShaderValue(shader, lIntensityLoc, directionalLight.intensity, 1);
- SetShaderValue(shader, lAmbientLoc, directionalLight.ambientColor, 3);
- SetShaderValue(shader, lDiffuseLoc, directionalLight.diffuseColor, 3);
- SetShaderValue(shader, lSpecularLoc, directionalLight.specularColor, 3);
- SetShaderValue(shader, lSpecIntensityLoc, directionalLight.specularIntensity, 1);
+ SetShaderValue(shader, lIntensityLoc, &light.intensity, 1);
+ SetShaderValue(shader, lAmbientLoc, ColorToFloat(light.ambient), 3);
+ SetShaderValue(shader, lDiffuseLoc, ColorToFloat(light.diffuse), 3);
+ SetShaderValue(shader, lSpecularLoc, ColorToFloat(light.specular), 3);
+ SetShaderValue(shader, lSpecIntensityLoc, &light.specIntensity, 1);
// Send material values to shader
- SetShaderValue(shader, mAmbientLoc, blinnMaterial.ambientColor, 3);
- SetShaderValue(shader, mSpecularLoc, blinnMaterial.specularColor, 3);
- SetShaderValue(shader, mGlossLoc, blinnMaterial.glossiness, 1);
+ SetShaderValue(shader, mAmbientLoc, ColorToFloat(matBlinn.ambient), 3);
+ SetShaderValue(shader, mSpecularLoc, ColorToFloat(matBlinn.specular), 3);
+ SetShaderValue(shader, mGlossLoc, &matBlinn.glossiness, 1);
// Send camera and light transform values to shader
- SetShaderValue(shader, cameraLoc, cameraPosition, 3);
- SetShaderValue(shader, lightLoc, directionalLight.position, 3);
+ SetShaderValue(shader, cameraLoc, VectorToFloat(camera.position), 3);
+ SetShaderValue(shader, lightLoc, VectorToFloat(light.position), 3);
//----------------------------------------------------------------------------------
// Draw
@@ -154,14 +128,12 @@ int main()
Begin3dMode(camera);
- DrawModel(model, position, 4.0f, (Color){255 * blinnMaterial.diffuseColor[0], 255 * blinnMaterial.diffuseColor[1], 255 * blinnMaterial.diffuseColor[2], 255});
-
- DrawSphere((Vector3){directionalLight.position[0], directionalLight.position[1], directionalLight.position[2]}, 1, YELLOW);
+ DrawModel(model, position, 4.0f, matBlinn.diffuse);
+ DrawSphere(light.position, 1.0f, YELLOW);
End3dMode();
- // Draw FPS
- DrawFPS(10, 10);
+ DrawFPS(10, 10); // Draw FPS
EndDrawing();
//----------------------------------------------------------------------------------
@@ -169,7 +141,6 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- // Unload all loaded data
UnloadShader(shader);
UnloadModel(model);