Update shaders_julia_set.c

This commit is contained in:
Ray 2019-05-15 12:53:13 +02:00
parent ab44033ed6
commit d878a0aecb

View File

@ -18,8 +18,6 @@
#include "raylib.h" #include "raylib.h"
#include "raymath.h"
// A few good julia sets // A few good julia sets
const float POINTS_OF_INTEREST[6][2] = const float POINTS_OF_INTEREST[6][2] =
{ {
@ -49,6 +47,7 @@ int main()
// Offset and zoom to draw the julia set at. (centered on screen and 1.6 times smaller) // 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 offset[2] = { -(float)screenWidth/2, -(float)screenHeight/2 };
float targetOffset[2] = { offset[0], offset[1] };
float zoom = 1.6f; float zoom = 1.6f;
// Get variable (uniform) locations on the shader to connect with the program // Get variable (uniform) locations on the shader to connect with the program
@ -107,22 +106,26 @@ int main()
if (IsKeyDown(KEY_RIGHT)) incrementSpeed++; if (IsKeyDown(KEY_RIGHT)) incrementSpeed++;
else if (IsKeyDown(KEY_LEFT)) incrementSpeed--; else if (IsKeyDown(KEY_LEFT)) incrementSpeed--;
// Use mouse wheel to change zoom
zoom -= (float)GetMouseWheelMove()/10.f;
SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT);
// Use mouse button to change offset // Use mouse button to change offset
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) if (IsMouseButtonDown(MOUSE_LEFT_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 // TODO: Logic is not correct, the idea is getting zoom focus to pointed area
Vector2 mousePos = GetMousePosition(); Vector2 mousePos = GetMousePosition();
offset[0] = mousePos.x -(float)screenWidth; targetOffset[0] = mousePos.x -(float)screenWidth;
offset[1] = mousePos.y -(float)screenHeight; targetOffset[1] = mousePos.y -(float)screenHeight;
SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2);
} }
// Slowly move camera to targetOffset
offset[0] += GetFrameTime()*2.0f*(targetOffset[0] - offset[0]);
offset[1] += GetFrameTime()*2.0f*(targetOffset[1] - offset[1]);
SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT);
SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2);
// Increment c value with time // Increment c value with time
float amount = GetFrameTime()*incrementSpeed*0.0005f; float amount = GetFrameTime()*incrementSpeed*0.0005f;
c[0] += amount; c[0] += amount;
@ -150,7 +153,7 @@ int main()
EndTextureMode(); EndTextureMode();
// Draw the saved texture (rendered julia set) // Draw the saved texture (rendered julia set)
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, Vector2Zero(), WHITE); DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE);
// Draw information // Draw information
//DrawText( FormatText("cx: %f\ncy: %f\nspeed: %d", c[0], c[1], incrementSpeed), 10, 10, 10, RAYWHITE); //DrawText( FormatText("cx: %f\ncy: %f\nspeed: %d", c[0], c[1], incrementSpeed), 10, 10, 10, RAYWHITE);