Selecting 3D polygon

I’m trying to do polygon selection in 3D:

Begin Alg.

mouseObjectPos = Unproject(mouseScreenPos) using current modelview and projection matrix

Origin = (0, 0, 0)
ray = Vector(Origin, mouseObjectPos)

p = RayPlaneIntersect(ray, polygon.Plane)

if (isPointInPolygon(polygon, p)) then:
polygonSelected = true
else
false

End Alg.

Am I doing it correctly, it does not seem to work?

Thanks

It is very difficult to determine what it is in your program that is not working properly when you don’t explain what the function is supposed to do or what arguments it takes and only give us pseudo code. The difficult parts in your program is not this pseudo code, but how every function that is called in this code is implemented.

Issue may come from the definition of your ray.

mouseObjectPos0 = Unproject(mouseScreenPos.x,mouseScreenPos.y,0)
mouseObjectPos1 = Unproject(mouseScreenPos.x,mouseScreenPos.y,1)

From these two unproject point, construct your ray

ray = Vector(mouseObjectPos0,mouseObjectPos1)

I hope this can help!