World To Screen transformation menu

User Tag List

Results 1 to 3 of 3
  1. #1
    newbiehacker's Avatar Private
    Reputation
    1
    Join Date
    Jan 2013
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    World To Screen transformation

    Hello,

    I am trying to convert 3D World Coordinates to 2D Screen Coordiantes. Basically I am trying to draw boxes around ennemy players...

    So far I have achieved to get the following data: FOV, My ViewAngle, My Position in 3D, Ennemy Position in 3D

    How can I calculate where to draw the box on the Screen now so it is drawn on the ennemy player?

    World To Screen transformation
  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)
    Originally Posted by newbiehacker View Post
    Hello,

    I am trying to convert 3D World Coordinates to 2D Screen Coordiantes. Basically I am trying to draw boxes around ennemy players...

    So far I have achieved to get the following data: FOV, My ViewAngle, My Position in 3D, Ennemy Position in 3D

    How can I calculate where to draw the box on the Screen now so it is drawn on the ennemy player?
    You will need camera position, camera look at vector, fov, aspect ratio, nearclip and farclip.

    With this data build a right handed look at and perspective matrix:

    look at rh
    Code:
    zaxis = normal(Eye - At)
    xaxis = normal(cross(Up, zaxis))
    yaxis = cross(zaxis, xaxis)
        
     xaxis.x           yaxis.x           zaxis.x          0
     xaxis.y           yaxis.y           zaxis.y          0
     xaxis.z           yaxis.z           zaxis.z          0
     dot(xaxis, eye)   dot(yaxis, eye)   dot(zaxis, eye)  1
    perspective rh
    Code:
    xScale     0          0              0
    0        yScale       0              0
    0        0        zf/(zn-zf)        -1
    0        0        zn*zf/(zn-zf)      0
    where:
    yScale = cot(fovY/2)
        
    xScale = yScale / aspect ratio
    Then calculate the current transformation matrix with Identity (World) * View * Projection.

    Code:
    Utils::Matrix44 mTransform = mWorld * mView * mProjection;
    Utils::Vector3 vScreen = mTransform * vPosition;
    The screen vector will contain normalized positions between -1 (most left point on screen) to +1 (most right point on screen) so you need to scale that with your viewport and you're good.

    EDIT:

    For screen to world just do it the other way round. Take your screen position vectors and bring it to a -1 / +1 format then multiply it by the inverse projection:

    Code:
    Utils::Matrix44 mInverse = mWorld.inverse() * mView.inverse() * mProjection.inverse();
    Utils::Vector3 vPosition = mInverse * vScreen;
    Last edited by Master674; 01-19-2013 at 01:31 PM.

  3. #3
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Careful with that last bit...
    Code:
    Utils::Matrix44 mTransform = mWorld * mView * mProjection;
    Utils::Matrix44 mInverse1 = mWorld.inverse() * mView.inverse() * mProjection.inverse();
    Utils::Matrix44 mInverse2 = mProjection.inverse() * mView.inverse() * mWorld.inverse();
    
    
    assert(mInverse1 != mTransform.inverse());
    assert(mInverse2 == mTransform.inverse());
    (A*B)^(-1) = B^(-1)*A^(-1)

    Edit: Btw. Master... I like your sig
    Last edited by Bananenbrot; 01-20-2013 at 04:21 AM.

Similar Threads

  1. World to screen
    By uncledolan in forum WoW Memory Editing
    Replies: 7
    Last Post: 12-03-2016, 08:34 AM
  2. [Tool] World to Screen
    By WiNiFiX in forum WoW Memory Editing
    Replies: 9
    Last Post: 09-27-2015, 02:08 AM
  3. direct3d for world to screen
    By mnbvc in forum WoW Memory Editing
    Replies: 11
    Last Post: 12-29-2011, 01:54 AM
  4. world to screen
    By mnbvc in forum WoW Memory Editing
    Replies: 16
    Last Post: 01-29-2010, 08:08 AM
  5. [Version Independent] World to Screen
    By ramey in forum WoW Memory Editing
    Replies: 1
    Last Post: 09-13-2009, 04:17 PM
All times are GMT -5. The time now is 12:05 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