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

Conversion function for screen coords to local Canvas coords #4854

Merged
merged 1 commit into from
Jul 11, 2016

Conversation

Razzlegames
Copy link
Contributor

@Razzlegames Razzlegames commented May 28, 2016

  • Useful if you need to Convert screen coords to the coordinate space of a CanvasItem, but don't have an
    associated InputEvent to use in #make_event_local.

For example, if you have a particular point on the screen you'd like to project into World Space, for various reasons, you would use this function on the root of the scene. This is analogous to ray casting from screen space in 3D.

@Razzlegames
Copy link
Contributor Author

Razzlegames commented May 28, 2016

Use as so:

var local_coord = make_screen_coord_local(screen_coord)

func useCoord(screen_coord):
   var local_coord = make_canvas_pos_local(screen_coord)
   # Do whatever you want with coord that is now local to
   #      the CanvasItem you called this in!

@reduz
Copy link
Member

reduz commented Jun 6, 2016

there is get_global_transform_with_canvas().affine_inverse() * pos

but i guess this is probably a little easier to use, maybe you could rename it to make_canvas_pos_local()

@Razzlegames
Copy link
Contributor Author

Razzlegames commented Jun 7, 2016

Yes I can rename however you'd like for the SDK. Yes, I think users new to
Linear Algebra don't really know what the meaning of that math is.

On Mon, Jun 6, 2016 at 4:42 PM, Juan Linietsky notifications@github.com
wrote:

there is get_global_transform_with_canvas().affine_inverse() * pos

but i guess this is probably a little easier to use, maybe you could
rename it to make_canvas_pos_local()


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#4854 (comment),
or mute the thread
/~https://github.com/notifications/unsubscribe/AIWVf80WJGNJzMj7b7qbKVqhNGrh24H1ks5qJLBxgaJpZM4IpBX1
.

@reduz
Copy link
Member

reduz commented Jun 7, 2016

yeah agreed, forcing them to use linear algebra may be too much

@reduz
Copy link
Member

reduz commented Jun 11, 2016

if you manage to rename it, let me know and I will merge

@EdwardAngeles
Copy link

Thanks for get_global_transform_with_canvas().affine_inverse() * pos to get the ScreenToWorld coords.

I have to ask: What would be a way to get the WorldToScreen coords?

- Useful if you need to Convert screen coords to the coordinate space of a
  CanvasItem, but don't have an associated InputEvent to use in
  #make_event_local.

For example, if you have a particular point on the screen you'd like to project
into World Space, for various reasons, you would use this function on the root
of the scene. This is analogous to ray casting from screen space in 3D.
@Razzlegames
Copy link
Contributor Author

Razzlegames commented Jul 10, 2016

Sorry for the delay in editing this.

@EdwardAngeles You'd just make, the root of your Scene, a Canvas2D node and call the inverse of this. It would be:

var screen_pos = (get_canvas_transform() * get_global_transform())* world_pos

@reduz Does it make sense to make a function for this? It could be make_local_pos_canvas_pos or something similar.

@Razzlegames
Copy link
Contributor Author

@EdwardAngeles if you'd like a convenience function make_local_pos_canvas_pos I'll add it in another commit.

@reduz reduz merged commit b41be2d into godotengine:master Jul 11, 2016
@akien-mga akien-mga added this to the 2.1 milestone Jul 11, 2016
@EdwardAngeles
Copy link

@Razzlegames That sounds like a good idea. Thanks!

@@ -7328,6 +7328,22 @@
</description>
</method>
<method name="update">
Copy link
Contributor

Choose a reason for hiding this comment

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

Breaks the XML, @akien-mga (found by @vnen )

Copy link
Member

Choose a reason for hiding this comment

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

Fixed by 98eec17.

vnen added a commit that referenced this pull request Jul 14, 2016
Fix the addition in #4854 which added elements in the wrong place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants