# Thread: Convert world to screen coordinates

1. Hi!

I'm trying to convert some world to screen coordinates,
so that I can display an animated sprite in the exact point of the world,
but in screen coordinates.
I'm not that good with matrix algebra so any help is really welcome.

Thanks

2. You mean, something like this...?

PHP Code:
``` // define world size public static final int WORLD_WIDTH = 1024; public static final int WORLD_HEIGHT = 1024; // position of thing in world private int worldX; private int worldY; public void paint(Graphics g) {     // get the run-time screen size (don't use constants!!)     int screenWidth = getWidth();     int screenHeight = getHeight();     // convert world x,y to screen x,y     int screenX = (worldX * screenWidth) / WORLD_WIDTH;     int screenY = (worldY * screenHeight) / WORLD_HEIGHT; }  ```
Cheers,
Graham.

3. No, it wasn't that.
I mean, how can I convert a 3d world coodinate (x,y,z),
directly into a screen coordinate (x,y)?

Best Regards,
Ricardo

4. That can vary from reasonably simple, to somewhat hideous, depending on what you want. Do you need to be able to move and rotate the camera? Or is the object always in front of the camera, with Z being the distance in front?

If you need full 3D, use the 3D API (JSR184) to do the work for you. Trying to produce full 3D on a device without the 3D API (and to get it to run at a reasonable speed) is not for the faint-hearted. Remember that Java can be sloooooooooooooow.

Cheers,
Graham.

5. Originally Posted by grahamhughes
That can vary from reasonably simple, to somewhat hideous, depending on what you want. Do you need to be able to move and rotate the camera? Or is the object always in front of the camera, with Z being the distance in front?

If you need full 3D, use the 3D API (JSR184) to do the work for you. Trying to produce full 3D on a device without the 3D API (and to get it to run at a reasonable speed) is not for the faint-hearted. Remember that Java can be sloooooooooooooow.

Cheers,
Graham.

Yep, you would be replicating what DOOM did in the 90 with the very old CPUs. What is your plan? Are you trying to render some simple shapes? What is the target cellphone?

6. I think that I didn't put my question clearly.

My problem has to do with the M3G API.
My application is in 3D.
I can move a certain cursor in that world in X, Y and Z.
When FIRE is pressed, I need to put in that exact place of the screen
an animated explosion (a sprite).
My problem is to convert precisely the position of that cursor in the M3G world (X,Y,Z),
to one in the screen coordinates (240/320...).