×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    4

    Post Convert world to screen coordinates

    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. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Convert world to screen coordinates

    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. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    4

    Re: Convert world to screen coordinates

    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. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Convert world to screen coordinates

    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. #5
    Nokia Developer Champion
    Join Date
    Feb 2006
    Location
    Santiago, Chile
    Posts
    83

    Re: Convert world to screen coordinates

    Quote Originally Posted by grahamhughes View Post
    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. #6
    Registered User
    Join Date
    Aug 2008
    Posts
    4

    Re: Convert world to screen coordinates

    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!

Similar Threads

  1. Force portrait screen in CWsScreenDevice from executable (service)
    By lukedau in forum Symbian User Interface
    Replies: 4
    Last Post: 2010-09-17, 22:47
  2. Custom window in ALL screen modes
    By PawelDefee in forum Symbian
    Replies: 11
    Last Post: 2009-02-11, 09:19
  3. Error on running multiple screen
    By thephong in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2005-05-16, 17:40
  4. how to change Screen from Form to FullCanvas
    By ihadreampp in forum Mobile Java General
    Replies: 3
    Last Post: 2003-08-15, 08:50
  5. Replies: 0
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×