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

  • Home
  • SEARCH
  • 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 3348506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:33:03+00:00 2026-05-18T01:33:03+00:00

I want to display models of different sizes fitted into a view, so that

  • 0

I want to display models of different sizes fitted into a view, so that the whole model is visible inside the screen.
What is the best way to do it?
I tried scaling (using glScale) the model using this formula

scaleFactor = ( screenSize / (maxModelSize * constant) )

Where size is height or width, depending on what is bigger.
Constant is 1 / (length of one screen pixel in OpenGL units)
There are two problems with this:
1. After doing some transformations, I want to be able to return to this initial scale (model is scaled to fit window) using Identity. Currently calling identity will bring the model to its original dimensions (before the “fixing” scale).
2. The “constant” is something I got by trial and error, I feels wrong method to me. I also suspect that it is not a constant at all, and depends on screen resolution and god knows what else.

  • 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-05-18T01:33:04+00:00Added an answer on May 18, 2026 at 1:33 am

    Section 8.070:

    The following is from a posting by
    Dave Shreiner on setting up a basic
    viewing system:

    First, compute a bounding sphere for
    all objects in your scene. This should
    provide you with two bits of
    information: the center of the sphere
    (let ( c.x, c.y, c.z ) be that point)
    and its diameter (call it “diam”).

    Next, choose a value for the zNear
    clipping plane. General guidelines are
    to choose something larger than, but
    close to 1.0. So, let’s say you set

    zNear = 1.0; zFar = zNear + diam; 
    

    Structure your matrix calls in this
    order (for an Orthographic
    projection):

    GLdouble left = c.x - diam; 
    GLdouble right = c.x + diam;
    GLdouble bottom c.y - diam; 
    GLdouble top = c.y + diam; 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glOrtho(left, right, bottom, top, zNear, zFar); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
    

    This approach should center your
    objects in the middle of the window
    and stretch them to fit (i.e., its
    assuming that you’re using a window
    with aspect ratio = 1.0). If your
    window isn’t square, compute left,
    right, bottom, and top, as above, and
    put in the following logic before the
    call to glOrtho():

    GLdouble aspect = (GLdouble) windowWidth / windowHeight; 
    if ( aspect < 1.0 ) { 
        // window taller than wide 
        bottom /= aspect; 
        top /= aspect; 
    } else { 
        left *= aspect; 
        right *= aspect;
    } 
    

    The above code should position the
    objects in your scene appropriately.
    If you intend to manipulate (i.e.
    rotate, etc.), you need to add a
    viewing transform to it.

    A typical viewing transform will go on
    the ModelView matrix and might look
    like this:

    GluLookAt (0., 0., 2.*diam, c.x, c.y, c.z, 0.0, 1.0, 0.0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display different forms in change_form depending on some model field's values.
I'm trying to set up a view that displays two different models. For example,
I want to display error messages in my view. What is the best way
I have a model that looks like this: and want to display it in
I want to use the same template to display records from different models in
If i have two tables Books, CDs with corresponding models. I want to display
Ultimately, I want to add an <iframe> to the display of a particular model
I want to try something different, and am attempting to display an overlay on
I have to display different views for mobile devices and I want to provide
I have a model that has a CharField and in the admin I want

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.