Update shaders_julia_set.c
This commit is contained in:
parent
d878a0aecb
commit
0b18133e46
@ -47,9 +47,10 @@ 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;
|
||||||
|
|
||||||
|
Vector2 offsetSpeed = { 0.0f, 0.0f };
|
||||||
|
|
||||||
// Get variable (uniform) locations on the shader to connect with the program
|
// 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
|
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||||
int cLoc = GetShaderLocation(shader, "c");
|
int cLoc = GetShaderLocation(shader, "c");
|
||||||
@ -106,22 +107,23 @@ 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 button to change offset
|
// TODO: The idea is to zoom and move around with mouse
|
||||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
|
// 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;
|
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) zoom += 0.003f;
|
||||||
else zoom += 0.002f;
|
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) zoom -= 0.003f;
|
||||||
|
|
||||||
// TODO: Logic is not correct, the idea is getting zoom focus to pointed area
|
|
||||||
Vector2 mousePos = GetMousePosition();
|
Vector2 mousePos = GetMousePosition();
|
||||||
|
|
||||||
targetOffset[0] = mousePos.x -(float)screenWidth;
|
offsetSpeed.x = mousePos.x -(float)screenWidth/2;
|
||||||
targetOffset[1] = mousePos.y -(float)screenHeight;
|
offsetSpeed.y = mousePos.y -(float)screenHeight/2;
|
||||||
}
|
|
||||||
|
|
||||||
// Slowly move camera to targetOffset
|
// Slowly move camera to targetOffset
|
||||||
offset[0] += GetFrameTime()*2.0f*(targetOffset[0] - offset[0]);
|
offset[0] += GetFrameTime()*offsetSpeed.x*0.8f;
|
||||||
offset[1] += GetFrameTime()*2.0f*(targetOffset[1] - offset[1]);
|
offset[1] += GetFrameTime()*offsetSpeed.y*0.8f;
|
||||||
|
}
|
||||||
|
else offsetSpeed = (Vector2){ 0.0f, 0.0f };
|
||||||
|
|
||||||
SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT);
|
SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT);
|
||||||
SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2);
|
SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2);
|
||||||
|
Loading…
Reference in New Issue
Block a user