screen2world

Previous topic - Next topic

neseir

Hi

Looking through the forum and testing different parameters to the screen2world command I ended up with this that works perfect on Windows but on iPad the Y-coord is wrong making the lines miss by a significant distance (to high). I can add the difference but why does this behave different on iPad vs Windows when the screen is in both tests set to 1024x768 (portrait) ? The aspect ratio of the height and width seems correct in both cases compared to 1024 x 768 screen).

(the test-program just draws a line from 0,0,0 to mousepointer on windows. On iPad it draws a line/polygon using the multitouch feature).

Code (glbasic) Select

// --------------------------------- //
// Project: MyTest
// Start: Saturday, January 14, 2012
// IDE Version: 10.231


SETCURRENTDIR("Media")

SYSTEMPOINTER TRUE

CLEARSCREEN

LOCAL points#[]
DIM points#[20][3]

WHILE TRUE
X_MAKE3D 1, 1000, 45
X_CAMERA 0, 0, 100, 0, 0, 0

LOCAL mouse%, mx%, my%, b1%, b2%, maxMouse%, currentMouse%
LOCAL wx#, wy#, wz#, lastX%, lastY%

maxMouse = GETMOUSECOUNT()
currentMouse = 0
FOR mouse = 0 TO  maxMouse - 1
      SETACTIVEMOUSE mouse
      MOUSESTATE mx, my, b1, b2
      IF b1
      lastX = mx
      lastY = my
      X_SCREEN2WORLD mx, my, 1, wx#, wy#, wz#
      points[currentMouse][0] = wx# / 10.0
      points[currentMouse][1] = wy# / 10.0
      points[currentMouse][2] = wz#
      INC currentMouse, 1
      ENDIF
    NEXT

LOCAL drawMouse%
IF currentMouse > 1
FOR drawMouse = 0 TO currentMouse - 2
X_LINE points[drawMouse][0], points[drawMouse][1], 0, points[drawMouse+1][0], points[drawMouse+1][1], 0, 5, RGB(255, 0, 0)
NEXT
X_LINE points[currentMouse - 1][0], points[currentMouse - 1][1], 0, points[0][0], points[0][1], 0, 5, RGB(255, 0, 0)
ELSE
X_LINE points[currentMouse - 1][0], points[currentMouse - 1][1], 0, 0,0,0, 5, RGB(0, 255, 0)
ENDIF

X_MAKE2D
PRINT "Mouse   : " + maxMouse, 10, 10
PRINT "Current : " + currentMouse, 10, 20
PRINT "Last    : " + lastX + ", " + lastY, 10, 30
LOCAL index%
FOR index = 0 TO currentMouse - 1
PRINT "Coords : " + points[index][0] + " , " + points[index][1] + ", " + points[index][2], 10, 40 + index * 10
NEXT
SHOWSCREEN
WEND

END





Regards
Eirik


Qube

X_WORLD2SCREEN was recently fixed on the iPad but X_SCREEN2WORLD still does not work on the iPad.

You'll need to give Gernot a poke.

Kitty Hello

hm. Can you try if this is a matter of Setorientation?

neseir

Thanks

Willl check this later today when I back on my mac and XCode installation. I tried to configure the direction the application where allowed to run in the project settings but this command looks more promising.

BTW what is exactly the sz parameter in the screen2world command ? I thougt it was the distance to the far clip-plane (or is it the distance to a plane to project the coordinates on ?) but I'm not sure (ended up with using 1.0 and divide the coordinates in x and y axis by 10 to get it right on windows but I think this only works now since I have placed the camera along the z-axis (just to keep things simple) and have a static camera pointing at 0, 0, 0).

Regards
Eirik





Kitty Hello

sz is the "screen depth" parameter. It's just because the math requires 3d to 3d point conversion.

neseir

Hi

Finally got to test this on my iPad tonight. Setting the setorientation to what I thought i should be (1 for landscape) did not do anything god BUT setting it to 0 made the app start in portrait mode and now it is correct ! I will have to check a little bit to se what impact this gives on my app but anyway I'm a huge step further.

Will investigate further to see if I can get this working too on my Acer A500 Android tab with the same settings (and preferably with the orientation in landscape mode).

Thanks

Regards
Eirik


Qube

Cool, so it looks like a SETORIENTATION bug. Should be an easy fix for Gernot then  :good: