Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:10:01+00:00 2026-06-04T06:10:01+00:00

I am trying to convert from world space to screen space. However, due to

  • 0

I am trying to convert from world space to screen space. However, due to the way the library I am using handles matrices, I am only able to retrieve the culmination of the world, view, and projection matrices; I cannot inspect either on its own. Here is an example matrix:

(1.65879, -0.000909163, -1.4656, -1721.39)
(1.20199, -1.64605, 1.36146, 3048.55)
(0.450536, 0.75107, 0.510306, 9264.52)
(0.444465, 0.740951, 0.50343, 9339.69)

I had assumed that finding the location of the object in screen space would be a simple matter of transforming the origin [a point at (0, 0, 0)] by this value. However, this is distinctly wrong:

D3DMATRIX matrix;
D3DXVECTOR4 position;
D3DXVECTOR4 input;
D3DVIEWPORT9 viewport;

GetVertexShaderConstantF(0, (float *)&matrix, 4);
GetViewport(&viewport);

input.x = 0.0f;
input.y = 0.0f;
input.z = 0.0f;
input.w = 1.0f;

D3DXVec4Transform(&position, &input, (D3DXMATRIX *)&matrix);
float x = ((position.x / position.w) * 0.5f + 0.5f) * viewport.Width + viewport.X;
float y = (1.0f - ((position.y / position.w) * 0.5f + 0.5f)) * viewport.Height + viewport.Y;

This method only returns the result of 450, 375 (+/- a few decimals), with the viewport being double that in size; basically, it gives the dead center of the viewport.

What am I doing wrong in the above code snippet?

(A side note, I am simply trying to debug a program I do not have the source to. Therefore, when the shader receives its inputs, this is the only point at which I can intercept the position of a model in screen space).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:10:04+00:00Added an answer on June 4, 2026 at 6:10 am

    After

    GetVertexShaderConstantF(0, (float *)&matrix, 4);
    

    you have to call

    D3DXMatrixTranspose(&matrix, &matrix);
    

    because DirectX uses row-major matrices in the code and column-major ones in shaders (or the other way around, I don’t remember now).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert my site from using tables to just using css and
I'm trying to convert a simple Spring 2.5 hello world project (from Spring Recipes)
There is some code that I'm trying to convert from IList to IEnumerable :
I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in
I am trying to convert some pages from my app to use cfc's, and
I'm trying to convert some code from Richfaces 4 showcase to use CDI instead
I'm trying to convert my data layer from Linq2Sql to nHibernate. I think Xml
I'm trying to convert a xml document from one format to another and while
I am trying to convert the following two interfaces from a C header file
I'm trying to convert a FOR loop from C to Delphi, but I'm with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.