Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Add function to transform position #1442

Merged
merged 1 commit into from Mar 7, 2019
Merged

Add function to transform position #1442

merged 1 commit into from Mar 7, 2019

Conversation

vessd
Copy link
Member

@vessd vessd commented Mar 4, 2019

Description

Function to transform position from screen space into world space

Additions

  • fn screen_to_world

Copy link
Contributor

@AnneKitsune AnneKitsune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good! I just have a minor comment.

Also, can you add an entry in docs/CHANGELOG.md? There are two lines to add, the description and the link to this pull request. See how the other entries are made. Thanks!

amethyst_utils/src/screen_to_world.rs Outdated Show resolved Hide resolved
@Moxinilian
Copy link
Member

The tests unexpectedly failed, but it probably is a glitch. This will not prevent merging once 24 hours will have passed.

@Moxinilian
Copy link
Member

Actually, come to thing of it, why don't you make this a function on the Camera component?
So we could do something like camera.coordinates_from_screen(screen_coords, screen_dim).
Maybe that would be more convenient.

@AnneKitsune
Copy link
Contributor

AnneKitsune commented Mar 4, 2019

Making it a function of the camera makes sense.

The camera might be a child of another entity, so it would also make sense to use the global transform instead of the translation. However, this will make the math harder, so I don't know if we want that in this PR or not. We don't want to make you work too hard :D

@vessd
Copy link
Member Author

vessd commented Mar 4, 2019

Should I remove the translation argument then?

@Moxinilian
Copy link
Member

Oh right, the translation. Hmmm. Maybe the function could take its own transform or something.
Ah that's a tricky one actually. The reason I would like it to be on the Camera component is because it is an obvious place to look for people coming from non-ECS places. We should look at how Unity is doing it with their ECS.

@Moxinilian
Copy link
Member

Okay so apparently they're using globals, which is not very good. We should not do that.
I guess we should have it be a method on the Camera, to which we pass the camera's transform, the screen position and the ScreenDimension. What do you think?

amethyst_renderer/src/cam.rs Outdated Show resolved Hide resolved
amethyst_renderer/src/cam.rs Show resolved Hide resolved
Copy link
Member

@Moxinilian Moxinilian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work, thank you very much!
Please consider my suggested nitpick, then squash the commits so we can merge it.

amethyst_renderer/src/cam.rs Outdated Show resolved Hide resolved
@Moxinilian
Copy link
Member

Actually, while I'm at it, why not return a Vector3 instead of just X and Y? It can be useful when your camera is not on the Z = 0 plane. Also, why are the input coordinates f64? It could be a Vector2, even.

@vessd
Copy link
Member Author

vessd commented Mar 7, 2019

Also, why are the input coordinates f64? It could be a Vector2, even.

Because the InputHandler::mouse_position() returns the Option<(f64, f64)>.

Also, why are the input coordinates f64? It could be a Vector2, even.

Hmm, I don’t understand how it works clearly, do I need to take Vec3 for this?
I mean, is it ok that screen_point is always equal to 0.0 for the z plane for this? Or do i need to accept it as a parameter?
I didn't test the z coordinate, since I have no idea how to interpret it in my 2D game

@Moxinilian
Copy link
Member

Moxinilian commented Mar 7, 2019

I think introducing a Z coordinate here as input would just shift how "deep" the click is made. It should not really matter here, we only are converting click position, not raycasting.

However, the Z output can be useful if your camera is in 3D space. As we are doing an inverted camera projection, we are effectively taking the screen plane at Z=0 and applying it to the 3D plane orthogonal to the camera's direction. That plane can be a Z=0 plane, but not necessarily, if the camera is in a weird position. Therefore the output Z coordinate might be of use. Try it in a simple 3D world using one of our 3D examples (fly camera would be appropriate I think).

@vessd
Copy link
Member Author

vessd commented Mar 7, 2019

@Moxinilian ok, should I leave a f64 as an input argument?

@Moxinilian
Copy link
Member

I think you should do as little casting as possible in the body of the function so the user does not have to do useless casting if they already work with f32. Set it to f32 in the parameter, and let the user do the casting.

@vessd
Copy link
Member Author

vessd commented Mar 7, 2019

I think it is ready to merge.
r? @Moxinilian @Jojolepro @azriel91

amethyst_renderer/src/cam.rs Outdated Show resolved Hide resolved
amethyst_renderer/src/cam.rs Outdated Show resolved Hide resolved
@azriel91 azriel91 self-requested a review March 7, 2019 20:59
Copy link
Member

@azriel91 azriel91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azriel91
Copy link
Member

azriel91 commented Mar 7, 2019

bors r=jojolepro,Moxinilian,azriel91

bors bot added a commit that referenced this pull request Mar 7, 2019
1442: Add function to transform position r=jojolepro,Moxinilian,azriel91 a=vessd

## Description

Function to transform position from screen space into world space

## Additions

- `fn screen_to_world`


Co-authored-by: Sergey Veselkov <veselkovsd@yandex.ru>
@bors
Copy link
Contributor

bors bot commented Mar 7, 2019

Build succeeded

@bors bors bot merged commit 7809bc7 into amethyst:master Mar 7, 2019
@vessd vessd deleted the utils branch March 7, 2019 23:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants