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
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
You mean, something like this...?
Cheers,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;
}
Graham.
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
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.
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...).
Thanks for your help!