From 5af1b4a7c9119cf438e4cb5303009fbe9a25c6d7 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 9 Oct 2016 20:56:58 +0200 Subject: Added simulated head-tracking on VR simulator A simple 1st person camera... still requires some work... --- examples/core_oculus_rift.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 88e411d4..3d8bb278 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -37,6 +37,8 @@ int main() Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; + SetCameraMode(camera, CAMERA_FIRST_PERSON); + SetTargetFPS(90); // Set our game to run at 90 frames-per-second //-------------------------------------------------------------------------------------- @@ -45,7 +47,8 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateVrTracking(); + if (IsVrSimulator()) UpdateCamera(&camera); + else UpdateVrTracking(); if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); //---------------------------------------------------------------------------------- @@ -61,7 +64,7 @@ int main() DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); - DrawGrid(10, 1.0f); + DrawGrid(40, 1.0f); End3dMode(); -- cgit v1.2.3 From 648676f46b01327f0fbd6f017292a3159ea9ab2f Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 10 Oct 2016 19:43:27 +0200 Subject: Update examples to new camera system --- examples/core_3d_camera_first_person.c | 2 +- examples/core_3d_camera_free.c | 2 +- examples/core_3d_picking.c | 8 +++----- examples/core_oculus_rift.c | 12 ++++++------ examples/core_world_screen.c | 9 +++------ examples/models_billboard.c | 11 ++++------- examples/models_cubicmap.c | 2 +- examples/models_heightmap.c | 11 +++++------ examples/shaders_custom_uniform.c | 6 ++---- examples/shaders_model_shader.c | 5 ++++- examples/shaders_postprocessing.c | 8 +++----- examples/shaders_standard_lighting.c | 6 ++---- 12 files changed, 35 insertions(+), 47 deletions(-) (limited to 'examples') diff --git a/examples/core_3d_camera_first_person.c b/examples/core_3d_camera_first_person.c index 27ff5135..3998af81 100644 --- a/examples/core_3d_camera_first_person.c +++ b/examples/core_3d_camera_first_person.c @@ -47,7 +47,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update camera and player position + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/core_3d_camera_free.c b/examples/core_3d_camera_free.c index c798f225..d446e14a 100644 --- a/examples/core_3d_camera_free.c +++ b/examples/core_3d_camera_free.c @@ -39,7 +39,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; //---------------------------------------------------------------------------------- diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c index 7f904f7f..bd5c3347 100644 --- a/examples/core_3d_picking.c +++ b/examples/core_3d_picking.c @@ -22,7 +22,7 @@ int main() // Define the camera to look into our 3d world Camera camera; - camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position + camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 45.0f; // Camera field-of-view Y @@ -34,9 +34,7 @@ int main() bool collision = false; - SetCameraMode(CAMERA_FREE); // Set a free camera mode - SetCameraPosition(camera.position); // Set internal camera position to match our camera position - SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y + SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -46,7 +44,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 3d8bb278..7276e3de 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -30,14 +30,14 @@ int main() // Define the camera to look into our 3d world Camera camera; - camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position - camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point + camera.position = (Vector3){ 5.0f, 2.0f, 5.0f }; // Camera position + camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 60.0f; // Camera field-of-view Y Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; - SetCameraMode(camera, CAMERA_FIRST_PERSON); + SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set first person camera mode SetTargetFPS(90); // Set our game to run at 90 frames-per-second //-------------------------------------------------------------------------------------- @@ -47,10 +47,10 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsVrSimulator()) UpdateCamera(&camera); - else UpdateVrTracking(); + if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode) + else UpdateVrTracking(&camera); // Update camera with device tracking data - if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); + if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode //---------------------------------------------------------------------------------- // Draw diff --git a/examples/core_world_screen.c b/examples/core_world_screen.c index aa9505e8..f8c53c70 100644 --- a/examples/core_world_screen.c +++ b/examples/core_world_screen.c @@ -21,16 +21,13 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 10.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; Vector2 cubeScreenPosition; - SetCameraMode(CAMERA_FREE); // Set a free 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 - SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y + SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -40,7 +37,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera // Calculate cube screen space position (with a little offset to be in top) cubeScreenPosition = GetWorldToScreen((Vector3){cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera); diff --git a/examples/models_billboard.c b/examples/models_billboard.c index 654b3618..bca9faf8 100644 --- a/examples/models_billboard.c +++ b/examples/models_billboard.c @@ -26,20 +26,17 @@ int main() Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard - SetCameraMode(CAMERA_ORBITAL); // Set an orbital 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 - SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode - SetTargetFPS(60); // Set our game to run at 60 frames-per-second + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key + while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/models_cubicmap.c b/examples/models_cubicmap.c index df700d65..0e613029 100644 --- a/examples/models_cubicmap.c +++ b/examples/models_cubicmap.c @@ -45,7 +45,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/models_heightmap.c b/examples/models_heightmap.c index 90e5f5bb..10069e03 100644 --- a/examples/models_heightmap.c +++ b/examples/models_heightmap.c @@ -29,20 +29,19 @@ int main() map.material.texDiffuse = texture; // Set map diffuse texture Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!) - UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM + UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM - SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode - SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode - SetTargetFPS(60); // Set our game to run at 60 frames-per-second + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key + while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/shaders_custom_uniform.c b/examples/shaders_custom_uniform.c index c4f87259..89f87df9 100644 --- a/examples/shaders_custom_uniform.c +++ b/examples/shaders_custom_uniform.c @@ -51,9 +51,7 @@ int main() RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); // Setup orbital camera - SetCameraMode(CAMERA_ORBITAL); // Set an orbital 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 + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -71,7 +69,7 @@ int main() // Send new value to the shader to be used on drawing SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2); - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/shaders_model_shader.c b/examples/shaders_model_shader.c index a5516eba..26de4922 100644 --- a/examples/shaders_model_shader.c +++ b/examples/shaders_model_shader.c @@ -42,7 +42,7 @@ int main() Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode + SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -70,6 +70,9 @@ int main() End3dMode(); DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY); + + DrawText(FormatText("Camera position: (%.2f, %.2f, %.2f)", camera.position.x, camera.position.y, camera.position.z), 600, 20, 10, BLACK); + DrawText(FormatText("Camera target: (%.2f, %.2f, %.2f)", camera.target.x, camera.target.y, camera.target.z), 600, 40, 10, GRAY); DrawFPS(10, 10); diff --git a/examples/shaders_postprocessing.c b/examples/shaders_postprocessing.c index 43d21e08..43d1af72 100644 --- a/examples/shaders_postprocessing.c +++ b/examples/shaders_postprocessing.c @@ -45,9 +45,7 @@ int main() RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); // Setup orbital camera - SetCameraMode(CAMERA_ORBITAL); // Set an orbital 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 + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -57,7 +55,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw @@ -67,7 +65,7 @@ int main() ClearBackground(RAYWHITE); BeginTextureMode(target); // Enable drawing to texture - + Begin3dMode(camera); DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture diff --git a/examples/shaders_standard_lighting.c b/examples/shaders_standard_lighting.c index f2b35171..e539ec47 100644 --- a/examples/shaders_standard_lighting.c +++ b/examples/shaders_standard_lighting.c @@ -64,9 +64,7 @@ int main() pointLight->radius = 3.0f; // Setup orbital camera - SetCameraMode(CAMERA_ORBITAL); // Set an orbital 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 + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -76,7 +74,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw -- cgit v1.2.3 From 97e3277d58060df96cd002b1377a51ca4adcbb9e Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 11 Oct 2016 00:39:07 +0200 Subject: Updated standard shader Corrects weird artifacts on web --- examples/resources/shaders/glsl100/standard.fs | 17 ++++------------- examples/resources/shaders/glsl330/standard.fs | 8 ++++---- 2 files changed, 8 insertions(+), 17 deletions(-) (limited to 'examples') diff --git a/examples/resources/shaders/glsl100/standard.fs b/examples/resources/shaders/glsl100/standard.fs index 6ce2a186..fe604e2a 100644 --- a/examples/resources/shaders/glsl100/standard.fs +++ b/examples/resources/shaders/glsl100/standard.fs @@ -38,7 +38,6 @@ uniform Light lights[maxLights]; vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s) { -/* vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1.0)); vec3 surfaceToLight = l.position - surfacePos; @@ -51,17 +50,14 @@ vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s) if (diff > 0.0) { vec3 h = normalize(-l.direction + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } return (diff*l.diffuse.rgb + spec*colSpecular.rgb); -*/ - return vec3(0.5); } vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s) { -/* vec3 lightDir = normalize(-l.direction); // Diffuse shading @@ -72,18 +68,15 @@ vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s) if (diff > 0.0) { vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } // Combine results return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb); -*/ - return vec3(0.5); } vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s) { -/* vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1)); vec3 lightToSurface = normalize(surfacePos - l.position); vec3 lightDir = normalize(-l.direction); @@ -108,12 +101,10 @@ vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s) if (diffAttenuation > 0.0) { vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb)); -*/ - return vec3(0.5); } void main() @@ -140,7 +131,7 @@ void main() // Calculate specular texture color fetching or set to maximum specular value by default float spec = 1.0; - if (useSpecular == 1) spec *= normalize(texture2D(texture2, fragTexCoord).r); + if (useSpecular == 1) spec = texture2D(texture2, fragTexCoord).r; for (int i = 0; i < maxLights; i++) { diff --git a/examples/resources/shaders/glsl330/standard.fs b/examples/resources/shaders/glsl330/standard.fs index 14497839..0d461484 100644 --- a/examples/resources/shaders/glsl330/standard.fs +++ b/examples/resources/shaders/glsl330/standard.fs @@ -50,7 +50,7 @@ vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s) if (diff > 0.0) { vec3 h = normalize(-l.direction + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } return (diff*l.diffuse.rgb + spec*colSpecular.rgb); @@ -68,7 +68,7 @@ vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s) if (diff > 0.0) { vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } // Combine results @@ -101,7 +101,7 @@ vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s) if (diffAttenuation > 0.0) { vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb)); @@ -131,7 +131,7 @@ void main() // Calculate specular texture color fetching or set to maximum specular value by default float spec = 1.0; - if (useSpecular == 1) spec *= normalize(texture(texture2, fragTexCoord).r); + if (useSpecular == 1) spec = texture(texture2, fragTexCoord).r; for (int i = 0; i < maxLights; i++) { -- cgit v1.2.3