# Rotate Screen Strange Transform

Hello everybody !

I don’t understand why a little rotation distord my image like that :

This is the code I use :

``````-- SetContextExperiment

displayMode(FULLSCREEN)

function setup()
img = image(WIDTH-5,HEIGHT-4)
end

function draw2()
pushMatrix()
perspective(40, WIDTH/HEIGHT)
camera(WIDTH/2,HEIGHT/2,150,WIDTH/2,HEIGHT/2,0,0,1,0)
translate(0,0,-900)
rotate(65,0,1,0)
sprite("Documents:CodeaRotateTest0",WIDTH/2, HEIGHT/2)
viewMatrix(matrix())
ortho()
popMatrix()
end

function draw()
background(255, 255, 255, 255)
draw2()
end

``````

If someone have an explanation, I’m really interested !

Doubt it would be anything to do with the perspective? I haven’t got my iPad here at the moment so I can’t experiment with it.

@hyrovitaliprotago i’ve made this little tweak to your program to see what is happening. Looks like some ‘build-in bug’ with 3D. I can see the sprite is split in 2 triangles, but this makes a bilinear interpolation of the texture that is not visually correct.
Solution: create a mesh of 10x10 rectangles filled with your sprite as a texture. Then it may look better…
Other solution: dont use 3d, manage the transform yourself…

``````-- SetContextExperiment

displayMode(FULLSCREEN)

function setup()
img = image(WIDTH-5,HEIGHT-4)
setContext(img)
resetMatrix()
background(255)
fill(0)
stroke(0)
strokeWidth(4)
local n = 20
local x1,y1,x2,y2
local w,h = img.width,img.height
y1,y2 = 0,h
for i=1,n do
x1 = i*w/n
x2 = x1
line(x1,y1,x2,y2)
end
x1,x2 = 0,w
for i=1,n do
y1 = i*h/n
y2 = y1
line(x1,y1,x2,y2)
end
setContext()
end

function draw2()
pushMatrix()
perspective(40, WIDTH/HEIGHT)
camera(WIDTH/2,HEIGHT/2,500,WIDTH/2,HEIGHT/2,0,0,1,0)
translate(0,0,-900)
rotate(65*math.sin(ElapsedTime/3),0,1,0)
sprite(img,WIDTH/2, HEIGHT/2)
viewMatrix(matrix())
ortho()
popMatrix()
end

function draw()
background(128)
draw2()
end

``````

here is a video from the code above (the flat image is a simple rectangular grid)
you can also note a strange bug on top of the video recording: (@simeon) the first few lines have a ghosting effect (not present on the real display)

thaks!

Wow !! `spriteBatching` is a really nice feature !