C# WorldToScreen menu

User Tag List

Results 1 to 4 of 4
  1. #1
    bryanunited's Avatar Private
    Reputation
    2
    Join Date
    Jul 2014
    Posts
    2
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    C# WorldToScreen

    Hey guys, feel stupid for having to ask here but I've searched around and can't find a straightforward solution.

    I'm using SharpDX to do some D3D drawing and have my camera struct working, from that point I thought it would be straightforward but my text isn't being rendered on screen.

    Have tried using transforms like:

    Code:
    Device.SetTransform(TransformState.World, Matrix.Translation(player.X, player.Y, player.Z));
    How can I generate screen coordinates from a world object location if I already have the camera position, matrix, fov etc.

    C# WorldToScreen
  2. #2
    Master674's Avatar Elite User
    Reputation
    487
    Join Date
    May 2008
    Posts
    578
    Thanks G/R
    2/23
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Multiply the world-view-projection matrix with the world position and you have the screen position in range -1 to 1.

  3. #3
    andy012345's Avatar Active Member
    Reputation
    59
    Join Date
    Oct 2007
    Posts
    124
    Thanks G/R
    0/7
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Super tired, here's some C++ relevant (I hope) code, ignore formatting I'm just pulling part of the code.

    Code:
            D3DXVECTOR3 pos;        D3DXVECTOR3 screen;
    
            D3DVIEWPORT9 viewport;
            device->GetViewport(&viewport);
    
    
            D3DXMATRIX world, projection, view;
            device->GetTransform(D3DTS_WORLD, &world);
            device->GetTransform(D3DTS_PROJECTION, &projection);
            device->GetTransform(D3DTS_VIEW, &view);
    
    
            D3DXVec3Project(&screen, &pos, &viewport, &projection, &view, &world);
    
    
            if (screen.z >= 1.0f) //probably shouldn't show this stuff, it's generally stuff not visible (example in first person, stuff that is behind you)
                return;
    Last edited by andy012345; 07-31-2014 at 05:18 PM.

  4. #4
    bryanunited's Avatar Private
    Reputation
    2
    Join Date
    Jul 2014
    Posts
    2
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Almost choked on my glass of water, it worked! Thanks guys

    Can't give rep yet sadly

All times are GMT -5. The time now is 09:52 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search