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 9044559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:01:07+00:00 2026-06-16T11:01:07+00:00

I’ve created a simple engine in DirectX which can load and render models from

  • 0

I’ve created a simple “engine” in DirectX which can load and render models from .obj files. It works ok, for the objects I’ve created, e.g. a simple cube with coordinates within -1.0 to 1.0 range. However loading a model which uses different units and has coordinates within -2k to 2k range results in a huge something which doesn’t even entirely fit in the depth buffer, so I see like one huge leg or a similar effect.

I remember reading somewhere about it, but as I went through a lot of DX stuff recently I can’t remember where or what it was. So my question is, assuming I want to be able to load different models, which use different units, what is the best way to ensure they all have a similar size and fit nicely on the screen?

I could try to convert the values upon loading the object, but maybe there is some more DirectX way which uses transformation matrices or shaders?

  • 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-16T11:01:08+00:00Added an answer on June 16, 2026 at 11:01 am

    The simplest way is to find on which component the model contains the largest range, and use that value to scale the model uniformly. To find the largest range, compute the model bounding box (unless wavefront obj. files provide it already, but maybe you’d like to verify it anyway), and use the box dimension as the range to compare. This would scale all imported models down to the unit range.

    For instance, if you have a model with a bounding box covering 374 * 820 * 512 units, the largest one is the Y axis with 820, so you just have to scale it down by 820 (divide all the components by 820). This can be conveniently achieved with a uniform scaling matrix, which can be initialized with the D3DXMatrixScaling, if I am not mistaken.
    Assuming that the bounding box is given by 2 vectors (max and min vertices), compute the difference of these vectors, then pick the largest value, and use its inverse as scaling factor for your matrix.

    D3DMatrix mScale;
    D3DVector mx, mn;
    obj->getBoundingBox(&mn,&mx);
    float scale = 1.0 / max(mx.x - mn.x, max(mx.y - mn.y, mx.z -mn.z));
    D3DXMatrixScaling( &mScale, scale, scale,scale);
    

    All is left to do is to insert the matrix in your rendering pipeline.

    Regarding the computation of bounding box, a simple loop on all the vertices of the model, keeping the minimun and maximum components (independently of each others), should do it.

    D3DVector mn, mx;
    mn.x = mn.y = mn.z = MAX_FLOAT;
    mx.x = mx.y = mx.z = - MAX_FLOAT;
    for (int i = 0; i < numVertices ; i++) {
       mn.x = min(mn.x, vertex[i].x);
       mn.y = min(mn.y, vertex[i].y);
       mn.z = min(mn.z, vertex[i].z);
      // same for mx using max
    }
    

    Of course, you might need to use some scaling factor if your view covers a larger area than the unit box (but apparently this is what you are using).

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.