MousePick() on Plane is unusable...

Everything related to 3D programming
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

MousePick() on Plane is unusable...

Post by Mijikai »

A MousePick() on a plane seems to be tested against a bounding box which is just stupid.
Is there a solution?

Example:

Code: Select all


EnableExplicit

Procedure.i Main(Width.i = 960,Height.i = 600)
  Protected flags.i
  If InitEngine3D() And InitSprite()
    flags|#PB_Window_SystemMenu|#PB_Window_ScreenCentered
    flags|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
    If OpenWindow(0,0,0,Width,Height,#Null$,flags)
      WindowBounds(0,Width,Height,#PB_Ignore,#PB_Ignore)
      If OpenWindowedScreen(WindowID(0),0,0,Width,Height,#True,0,0)
        SetFrameRate(60)
        ;------------------------------------------------------ setup scene
        AmbientColor(RGB(0,0,20))
        CreateLight(#PB_Any,RGB(160,160,180),0,100,0,#PB_Light_Point)
        CreateLight(#PB_Any,RGB(160,120,100),-100,100,-50,#PB_Light_Point)
        CreateCamera(0,0,0,100,100)
        MoveCamera(0,0,2,-4,#PB_Absolute|#PB_Local)
        CameraLookAt(0,0,0,0)
        CreatePlane(0,1,1,1,1,0,0)
        CreateEntity(0,MeshID(0),#PB_Material_None,0,0,0,1 << 1)
        CreateSphere(1,0.05)
        CreateEntity(1,MeshID(1),#PB_Material_None,0,0,0,1 << 2)
        ;------------------------------------------------------
        Repeat
          Repeat
            Select WindowEvent()
              Case #PB_Event_CloseWindow
                Break 2 
              Case #Null
                Break
            EndSelect
          ForEver
          ;------------------------------------------------------ mouse pick -.-
          ResizeCamera(0,0,0,100,100)
          If MousePick(0,WindowMouseX(0),WindowMouseY(0),1 << 1) >= 0
            MoveEntity(1,PickX(),PickY(),PickZ(),#PB_Absolute)
          EndIf
          ;------------------------------------------------------
          RenderWorld()
          FlipBuffers()
        ForEver
      EndIf
      CloseWindow(0)
    EndIf
  EndIf
  ProcedureReturn
EndProcedure

Main()

End

User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: MousePick() on Plane is unusable...

Post by DK_PETER »

Simple solution if you want the y-position to stay fixed in your example.

Code: Select all

MoveEntity(1,PickX(),0,PickZ(),#PB_Absolute)
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: MousePick() on Plane is unusable...

Post by Mijikai »

Thx, but that is just a visual fix.
Ogre is selecting the wrong and slower intersection test... pretty dissapointing to say the least.
The only way i see to fix this mess is by also checking the normal of the intersection point.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: MousePick() on Plane is unusable...

Post by DK_PETER »

then use MouseRayCast() instead.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: MousePick() on Plane is unusable...

Post by Mijikai »

DK_PETER wrote:then use MouseRayCast() instead.
That works thx :)
Post Reply