Hotfix for glitchy camera
Super small fix that was causing the camera to glitch every x amount of seconds/pixels. Works much better now, 3/4 lines changed.
This commit is contained in:
parent
232378ed2d
commit
17eaca46d7
|
|
@ -25,7 +25,7 @@ int main(void)
|
|||
const int virualScreenWidth = 160;
|
||||
const int virtualScreenHeight = 90;
|
||||
|
||||
const float virtualRatio = (float)screenWidth/(float)virualScreenWidth;
|
||||
const float virtualRatio = (float)screenWidth / (float)virualScreenWidth;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - smooth pixel-perfect camera");
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ int main(void)
|
|||
|
||||
//The renderTexture's height is flipped (in the source Rectangle), due to OpenGL reasons.
|
||||
Rectangle renderTextureSource = { 0.0f, 0.0f, (float)renderTexture.texture.width, (float)-renderTexture.texture.height };
|
||||
Rectangle renderTextureDest = { -virtualRatio, -virtualRatio, screenWidth + (virtualRatio*2), screenHeight + (virtualRatio*2) };
|
||||
Rectangle renderTextureDest = { -virtualRatio, -virtualRatio, screenWidth + (virtualRatio * 2), screenHeight + (virtualRatio * 2) };
|
||||
|
||||
Vector2 origin = { 0.0f, 0.0f };
|
||||
|
||||
|
|
@ -61,30 +61,24 @@ int main(void)
|
|||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
rotation += degreesPerSecond*GetFrameTime(); // Rotate the rectangles.
|
||||
rotation += degreesPerSecond * GetFrameTime(); // Rotate the rectangles.
|
||||
|
||||
// Make the camera move to demonstrate the effect.
|
||||
cameraX = (sinf(GetTime())*50.0f) - 10.0f;
|
||||
cameraY = cosf(GetTime())*30.0f;
|
||||
cameraX = (sinf(GetTime()) * 50.0f) - 10.0f;
|
||||
cameraY = cosf(GetTime()) * 30.0f;
|
||||
|
||||
// Set the camera's target to the values computed above.
|
||||
screenSpaceCamera.target = (Vector2){ cameraX, cameraY };
|
||||
|
||||
// Round worldCamera's X, keep the decimals on screenSpaceCamera.
|
||||
if (screenSpaceCamera.target.x >= 1 || screenSpaceCamera.target.x <= -1)
|
||||
{
|
||||
//Round worldSpace coordinates, keep decimals into screenSpace coordinates.
|
||||
worldSpaceCamera.target.x = (int)screenSpaceCamera.target.x;
|
||||
screenSpaceCamera.target.x -= worldSpaceCamera.target.x;
|
||||
screenSpaceCamera.target.x *= virtualRatio;
|
||||
}
|
||||
|
||||
// Round worldCamera's Y, keep the decimals on screenSpaceCamera.
|
||||
if (screenSpaceCamera.target.y >= 1 || screenSpaceCamera.target.y <= -1)
|
||||
{
|
||||
worldSpaceCamera.target.y = (int)screenSpaceCamera.target.y;
|
||||
screenSpaceCamera.target.y -= worldSpaceCamera.target.y;
|
||||
screenSpaceCamera.target.y *= virtualRatio;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user