I wonder if anyone can help to resolve this for me? I am seeing a jittering movement when moving the camera in the y direction.
The code is based off one of the Raylib demos for virtual screen implementation.
If you comment out this line you can see that the x direction is very smooth, but for me the y movement jitters and jumps a little.
cam.y=math.sin(counter)*20.0
package ray_virtual
import rl "vendor:raylib"
import "core:math"
WIN_W :: 720
WIN_H :: 450
VIRT_W :: 200
VIRT_H :: 110
VRATIO :f32: WIN_W/VIRT_W
main :: proc(){
using rl
InitWindow(WIN_W,WIN_H,"Raylib virtual screen res")
worldcam:=Camera2D{}
worldcam.zoom=1
screencam:=Camera2D{}
screencam.zoom=1
target:=LoadRenderTexture(VIRT_W,VIRT_H)
rec1:=Rectangle{70,35,20,20}
rec2:=Rectangle{90,55,30,10}
rec3:=Rectangle{80,65,15,25}
srcRec:=Rectangle{0,0,f32(target.texture.width),f32(target.texture.height)}
dstRec:=Rectangle{-VRATIO,-VRATIO,WIN_W+VRATIO*2,WIN_H+VRATIO*2}
origin:=Vector2{}
cam:=Vector2{}
rot,counter:f32
SetTargetFPS(60)
// main loop
for !WindowShouldClose(){
rot+=60*GetFrameTime()
counter+=0.02
cam.x=math.cos(counter)*50.0
cam.y=math.sin(counter)*20.0
screencam.target=cam
worldcam.target.x=math.trunc(screencam.target.x)
screencam.target.x-=worldcam.target.x
screencam.target.x*=VRATIO
worldcam.target.y=math.trunc(screencam.target.y)
screencam.target.y-=worldcam.target.y
screencam.target.y*=VRATIO
BeginTextureMode(target)
ClearBackground(RAYWHITE)
BeginMode2D(worldcam)
DrawRectanglePro(rec1,origin,rot,BLACK)
DrawRectanglePro(rec2,origin,-rot,RED)
DrawRectanglePro(rec3,origin,rot+45,BLUE)
EndMode2D()
EndTextureMode()
BeginDrawing()
ClearBackground(RED)
BeginMode2D(screencam)
DrawTexturePro(target.texture,srcRec,dstRec,origin,0,WHITE)
EndMode2D()
DrawText(TextFormat("Screen res: %ix%i",WIN_W,WIN_H),10,10,20,DARKBLUE)
DrawText(TextFormat("World res: %ix%i", VIRT_W,VIRT_H),10,40,20,DARKGREEN)
DrawFPS(WIN_W-95,10)
EndDrawing()
}
UnloadRenderTexture(target)
CloseWindow()
}