ID:153794
 
Is there a clever way to quickly translate the world coordinates to client.screen format? I would love to do this without assuming that the mob is in the middle of the viewport, but I have a feeling it's not doable since there is no way to figure out how far away from the screen edges the mob are.

An example how I would like the function to work: the mob is at (5,4). An object is making a noise at (8,8). I would like a noise image to appear in client.screen at the correct coordinates. Any ideas?


/Gazoot
Try this:

for(var/mob/A in view(6))
A.image(src,'image.dmi')


Thats the incomplete and abridged version.
Gazoot wrote:
Is there a clever way to quickly translate the world coordinates to client.screen format? I would love to do this without assuming that the mob is in the middle of the viewport, but I have a feeling it's not doable since there is no way to figure out how far away from the screen edges the mob are.

The client's eye is always in the middle of the viewport--would comparing the coordinates to the eye's coords work?
In response to Hazman
Hazman wrote:
> for(var/mob/A in view(6))
> A.image(src,'image.dmi')
>

It doesn't really work like that. Client.screen coordinates are different from all atom coordinates.


/Gazoot
In response to Leftley
Leftley wrote:
The client's eye is always in the middle of the viewport--would comparing the coordinates to the eye's coords work?

Ah! Forgot about client.eye. Thank you very much! Let's see if I can make something out of it.


/Gazoot
In response to Gazoot
Looking into the help files, it seems that client.eye is stuck to the mob and has no coordinates either. So I don't think it will work. But thanks anyway.


/Gazoot
In response to Gazoot
Gazoot wrote:
Looking into the help files, it seems that client.eye is stuck to the mob and has no coordinates either. So I don't think it will work. But thanks anyway.

By default it is the mob that a client is connected to, which by default is always in the center of the screen! If somehow this has been changed in your game so that the mob is not always in the center of the screen, as you suggest, then it stands to reason that client.eye is set to something else. Even if you're using lazy_eye, the reference implies that this should be handled--it says that a nonzero lazy_eye var will cause the eye to default to the mob's loc, and be adjusted accordingly as the mob moves.
In response to Leftley
I can't use client.eye anyway, since it has no loc variable.
In the end, I think the problems are in my pixel movements. The map is scrolling quite strange when moving a couple of pixels only. I'm gonna assume the mob is always in the middle, and work it out from there. Thanks again!

/Gazoot
In response to Gazoot
Gazoot wrote:
I can't use client.eye anyway, since it has no loc variable.
In the end, I think the problems are in my pixel movements. The map is scrolling quite strange when moving a couple of pixels only. I'm gonna assume the mob is always in the middle, and work it out from there. Thanks again!

Yes, it does, but not directly. Client.eye is usually set to a mob. The following code, for example:

mob/verb/eye_coords()
var/atom/loc = src.client.eye
if(loc)
usr << "[loc.x], [loc.y], [loc.z]"

...will work.
In response to Spuzzum
Spuzzum wrote:
mob/verb/eye_coords()
var/atom/loc = src.client.eye
if(loc)
usr << "[loc.x], [loc.y], [loc.z]"

That solved everything! Thank you very much.


/Gazoot
In response to Gazoot
yay, hail spuzzum!
In response to Maz
Spuzzum is THE man.