Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KX_Camera.getScreenRay not working if cam is Ortographic #765

Closed
UnidayStudio opened this issue Jul 27, 2018 · 6 comments
Closed

KX_Camera.getScreenRay not working if cam is Ortographic #765

UnidayStudio opened this issue Jul 27, 2018 · 6 comments

Comments

@UnidayStudio
Copy link
Collaborator

This function:
https://pythonapi.upbge.org/bge.types.KX_Camera.html#bge.types.KX_Camera.getScreenRay

Doesn't work if the camera are Ortographic. I made a small example:
http://pasteall.org/blend/index.php?id=50026

Press P and nothing will happen. But if you change the camera mode to Perspective and then press P, if you mouse over the cube it will start rotating (what I programmed to do).

This function is very important right now, since we will not have logic bricks to get the mouse over object and things like this.

Thanks! 😄

@RomStef
Copy link

RomStef commented Jul 28, 2018

there'is a "mouse" brick in logic editor that trigger "mouseover" and "mouseoverany" event of the object you select

@panzergame
Copy link
Contributor

getScreenRay is using internally getScreenVectwhich from the code and documentation just computes an un-projected point in view and get the vector from the camera origin to this point. Then this vector is used as ray cast direction and the ray cast always start from the camera origin.
Such behaviour is appropriate only for perspective camera.

The idea to solve this issue is to forget about getScreenVect in getScreenRay and instead un-project two points to compute the ray direction and use the first for the ray origin.

Is this solution acceptable ?

@UnidayStudio
Copy link
Collaborator Author

@RomStef the problem is when you're not using logic bricks.

@panzergame Yes. But from the point of view of the user, the best option is to automatically decided what solver to use (one for the perspective camera and other for the ortographic) inside the getScreenRay (or inside the getScreenVect). By doing this, the user (that in most case will not know the math behind the scenes) will not have to care about this and will be able to use these functions no matter if the camera is ortho or persp.

@panzergame
Copy link
Contributor

@UnidayStudio : The two points solution is general to any kind of cameras and could be optimized in case of perspective camera by using the camera origin as first point to get the ray direction.

Concerning getScreenVect, the documentation is:
Gets the vector from the camera position in the screen coordinate direction.
And this is applied properly currently even if it is not interesting for orthographic as the camera is not a "pyramid".

@UnidayStudio
Copy link
Collaborator Author

@panzergame ok! :)

panzergame added a commit that referenced this issue Aug 8, 2018
Previously the function getScreenRay was adapted to only perspective
cameras because the ray cast was always starting from the center of
the camera.
In case of orthographic the ray cast should start from a point unprojected
from the near plane and continue to in the direction of the camera
(-Z orientation axis).
This is proceeded in getScreenRay and the indirect call to getScreenVect
is removed.

Fix issue #765.
panzergame added a commit that referenced this issue Aug 19, 2018
Previously the function getScreenRay was adapted to only perspective
cameras because the ray cast was always starting from the center of
the camera.
In case of orthographic the ray cast should start from a point unprojected
from the near plane and continue to in the direction of the camera
(-Z orientation axis).
This is proceeded in getScreenRay and the indirect call to getScreenVect
is removed.

Fix issue #765.
panzergame added a commit that referenced this issue Aug 30, 2018
Previously the function getScreenRay was adapted to only perspective
cameras because the ray cast was always starting from the center of
the camera.
In case of orthographic the ray cast should start from a point unprojected
from the near plane and continue to in the direction of the camera
(-Z orientation axis).
This is proceeded in getScreenRay and the indirect call to getScreenVect
is removed.

Fix issue #765.
@panzergame
Copy link
Contributor

Fixed in #781.

youle31 added a commit that referenced this issue Sep 11, 2021
It was fixing #765

Still needs to be tested with getScreenRay files
youle31 added a commit that referenced this issue Sep 11, 2021
…1551 from UPBGE/recover_765)

It was fixing #765

There was an issue with property not taken into account.

I tested with this file:

[getScreenRay.zip](https://github.com/UPBGE/upbge/files/7147430/getScreenRay.zip)

and it sounds ok then I merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants