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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:43:48+00:00 2026-06-06T11:43:48+00:00

I am writing a little game with the Java 3D API and I use

  • 0

I am writing a little game with the Java 3D API and I use objects of javax.media.j3d.BoundingBox to store the Bounds of a model.

The constructor of the BoundingBox is the following one:

public BoundingBox(Point3d lower, Point3d upper) {
    boundId = BOUNDING_BOX;
    this.lower = new Point3d(lower);
    this.upper = new Point3d(upper);
    updateBoundsStates();
}

Now I want to translate and rotate the BoundingBox because the model itself does and I use the following method of BoundingBox:

/** 
 * Transforms this bounding box by the given matrix.
 * @param matrix a transformation matrix
 */
public void transform(Transform3D matrix) {
    if(boundsIsInfinite)
        return;

    if (tmpP3d == null) 
        tmpP3d = new Point3d();

    double ux, uy, uz, lx, ly, lz;
    ux = upper.x; 
    uy = upper.y; 
    uz = upper.z;

    lx = lower.x; 
    ly = lower.y; 
    lz = lower.z;

    tmpP3d.set(ux, uy, uz);
    matrix.transform( tmpP3d );

    upper.x = tmpP3d.x;
    upper.y = tmpP3d.y;
    upper.z = tmpP3d.z;

    lower.x = tmpP3d.x;
    lower.y = tmpP3d.y;
    lower.z = tmpP3d.z;

    tmpP3d.set(lx, uy, uz);
    matrix.transform( tmpP3d );

    if ( tmpP3d.x  > upper.x ) upper.x = tmpP3d.x;
    if ( tmpP3d.y  > upper.y ) upper.y = tmpP3d.y;
    if ( tmpP3d.z  > upper.z ) upper.z = tmpP3d.z;

    if ( tmpP3d.x  < lower.x ) lower.x = tmpP3d.x;
    if ( tmpP3d.y  < lower.y ) lower.y = tmpP3d.y;
    if ( tmpP3d.z  < lower.z ) lower.z = tmpP3d.z;

    tmpP3d.set(lx, ly, uz);
    matrix.transform( tmpP3d );

    if ( tmpP3d.x  > upper.x ) upper.x = tmpP3d.x;
    if ( tmpP3d.y  > upper.y ) upper.y = tmpP3d.y;
    if ( tmpP3d.z  > upper.z ) upper.z = tmpP3d.z;

    if ( tmpP3d.x  < lower.x ) lower.x = tmpP3d.x;
    if ( tmpP3d.y  < lower.y ) lower.y = tmpP3d.y;
    if ( tmpP3d.z  < lower.z ) lower.z = tmpP3d.z;

    tmpP3d.set(ux, ly, uz);
    matrix.transform( tmpP3d );

    if ( tmpP3d.x > upper.x ) upper.x = tmpP3d.x;
    if ( tmpP3d.y > upper.y ) upper.y = tmpP3d.y;
    if ( tmpP3d.z > upper.z ) upper.z = tmpP3d.z;

    if ( tmpP3d.x < lower.x ) lower.x = tmpP3d.x;
    if ( tmpP3d.y < lower.y ) lower.y = tmpP3d.y;
    if ( tmpP3d.z < lower.z ) lower.z = tmpP3d.z;

    tmpP3d.set(lx, uy, lz);
    matrix.transform( tmpP3d );

    if ( tmpP3d.x > upper.x ) upper.x = tmpP3d.x;
    if ( tmpP3d.y > upper.y ) upper.y = tmpP3d.y;
    if ( tmpP3d.z > upper.z ) upper.z = tmpP3d.z;

    if ( tmpP3d.x < lower.x ) lower.x = tmpP3d.x;
    if ( tmpP3d.y < lower.y ) lower.y = tmpP3d.y;
    if ( tmpP3d.z < lower.z ) lower.z = tmpP3d.z;

    tmpP3d.set(ux, uy, lz);
    matrix.transform( tmpP3d );

    if ( tmpP3d.x > upper.x ) upper.x = tmpP3d.x;
    if ( tmpP3d.y > upper.y ) upper.y = tmpP3d.y;
    if ( tmpP3d.z > upper.z ) upper.z = tmpP3d.z;

    if ( tmpP3d.x < lower.x ) lower.x = tmpP3d.x;
    if ( tmpP3d.y < lower.y ) lower.y = tmpP3d.y;
    if ( tmpP3d.z < lower.z ) lower.z = tmpP3d.z;

    tmpP3d.set(lx, ly, lz);
    matrix.transform( tmpP3d );

    if ( tmpP3d.x > upper.x ) upper.x = tmpP3d.x;
    if ( tmpP3d.y > upper.y ) upper.y = tmpP3d.y;
    if ( tmpP3d.z > upper.z ) upper.z = tmpP3d.z;

    if ( tmpP3d.x < lower.x ) lower.x = tmpP3d.x;
    if ( tmpP3d.y < lower.y ) lower.y = tmpP3d.y;
    if ( tmpP3d.z < lower.z ) lower.z = tmpP3d.z;

    tmpP3d.set(ux, ly, lz);
    matrix.transform( tmpP3d );

    if ( tmpP3d.x > upper.x ) upper.x = tmpP3d.x;
    if ( tmpP3d.y > upper.y ) upper.y = tmpP3d.y;
    if ( tmpP3d.z > upper.z ) upper.z = tmpP3d.z;

    if ( tmpP3d.x < lower.x ) lower.x = tmpP3d.x;
    if ( tmpP3d.y < lower.y ) lower.y = tmpP3d.y;
    if ( tmpP3d.z < lower.z ) lower.z = tmpP3d.z;

    if (VirtualUniverse.mc.releaseBoundingBoxMemory) {
        // Free memory
        tmpP3d = null;
    }
}

But: if you use this method to rotate the BoundingBox it produces a new BoundingBox that may be larger in volume than the old one. It only delivers the same volume if you rotate exactly by 90, 180, 270 or 360 degrees.

Additional information: I must calculate the BoundingBox manually because I use manual bounds (and not the too large automatically calculated Bounds) by calling setAutoComputeBounds(false) and setBounds(XYZ) on the model (in this case it is actually an instance of javax.media.j3d which points to a javax.media.j3d.SharedGroup) and it seems that the Java 3d Engine (at least in this scenario) doesn’t recalculate your manual bounds automatically in the case of translation/rotation of the corresponding model.

My question is: how must I (re-)implement the above shown method transform() to get BoundingBoxes which have always the same volume?

  • 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-06T11:43:50+00:00Added an answer on June 6, 2026 at 11:43 am

    BoundingBox actually always remains aligned with the axes, no matter where its two points are. Two points cannot define an arbitrary cube. No matter how you rewrite the transform function, it will not work.

    You might consider the BoundingPolytope class. It provides more general bounds, formed from planes, though it does have a constructor which accepts another Bounds object, so you need not actually define the planes yourself.

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

Sidebar

Related Questions

I've got a little game that a friend and I are writing in Java.
I'm writing a little Java application that I want to use to search RSS
I'm trying to learn to use SDL for a little game I'm writing ,
I'm kind of writing a little game engine -- purely to understand how these
I'm writing myself a little game in JavaScript, using jQuery. The game has a
A little background: I'm writing a small word based maze game starting with a
I'm writing a little genetic algorithm in Java, as a school assignment. Up until
I'm writing an interactive fiction game in java from scratch. I'm currently storing all
So, I'm writing a game engine. I have a little example (see http://qrcode.kaywa.com/img.php?s=8&d=http://rokonandroid.com/rd.apk ),
I am writing a little game which has many circles moving on the screen.

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.