aboutsummaryrefslogtreecommitdiff
path: root/examples/shaders
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2019-05-15 13:10:00 +0200
committerRay <raysan5@gmail.com>2019-05-15 13:10:00 +0200
commit0b18133e46e72d7f51df7ddbbb81e9547bf5f4ba (patch)
treebb9a732ad224bd7440fe6664c4e14baaf811b784 /examples/shaders
parentd878a0aecb762b2f6fe3f444ae9024afc104c8d3 (diff)
downloadraylib-0b18133e46e72d7f51df7ddbbb81e9547bf5f4ba.tar.gz
raylib-0b18133e46e72d7f51df7ddbbb81e9547bf5f4ba.zip
Update shaders_julia_set.c
Diffstat (limited to 'examples/shaders')
-rw-r--r--examples/shaders/shaders_julia_set.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/examples/shaders/shaders_julia_set.c b/examples/shaders/shaders_julia_set.c
index a6df0e84..24bf6f79 100644
--- a/examples/shaders/shaders_julia_set.c
+++ b/examples/shaders/shaders_julia_set.c
@@ -47,9 +47,10 @@ int main()
// Offset and zoom to draw the julia set at. (centered on screen and 1.6 times smaller)
float offset[2] = { -(float)screenWidth/2, -(float)screenHeight/2 };
- float targetOffset[2] = { offset[0], offset[1] };
float zoom = 1.6f;
+ Vector2 offsetSpeed = { 0.0f, 0.0f };
+
// Get variable (uniform) locations on the shader to connect with the program
// NOTE: If uniform variable could not be found in the shader, function returns -1
int cLoc = GetShaderLocation(shader, "c");
@@ -106,23 +107,24 @@ int main()
if (IsKeyDown(KEY_RIGHT)) incrementSpeed++;
else if (IsKeyDown(KEY_LEFT)) incrementSpeed--;
- // Use mouse button to change offset
- if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
+ // TODO: The idea is to zoom and move around with mouse
+ // Probably offset movement should be proportional to zoom level
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) || IsMouseButtonDown(MOUSE_RIGHT_BUTTON))
{
- if (IsKeyDown(KEY_LEFT_SHIFT)) zoom -= 0.002f;
- else zoom += 0.002f;
-
- // TODO: Logic is not correct, the idea is getting zoom focus to pointed area
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) zoom += 0.003f;
+ if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) zoom -= 0.003f;
+
Vector2 mousePos = GetMousePosition();
- targetOffset[0] = mousePos.x -(float)screenWidth;
- targetOffset[1] = mousePos.y -(float)screenHeight;
+ offsetSpeed.x = mousePos.x -(float)screenWidth/2;
+ offsetSpeed.y = mousePos.y -(float)screenHeight/2;
+
+ // Slowly move camera to targetOffset
+ offset[0] += GetFrameTime()*offsetSpeed.x*0.8f;
+ offset[1] += GetFrameTime()*offsetSpeed.y*0.8f;
}
-
- // Slowly move camera to targetOffset
- offset[0] += GetFrameTime()*2.0f*(targetOffset[0] - offset[0]);
- offset[1] += GetFrameTime()*2.0f*(targetOffset[1] - offset[1]);
-
+ else offsetSpeed = (Vector2){ 0.0f, 0.0f };
+
SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT);
SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2);