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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:34:28+00:00 2026-05-25T03:34:28+00:00

I’m trying to implement a basic physics engine in Java and I’m using the

  • 0

I’m trying to implement a basic physics engine in Java and I’m using the JOGL bindings so I can visualize the results. I can create and rotate shapes easily enough, but have run into problems whilst manipulating the viewport and whilst moving the shapes.

I don’t think a clipping issue – I’ve tried using the gluPerspective method with a massive range (0.0001f – 10000f) with no success. When I move the camera further away from my objects or move the objects themselves, they disappear.

Tutorials about JOGL are few and far between and many also use different versions of OpenGL, so I turn to the only friend I have left: the wonderful users of stack overflow. 🙂

Flattery aside, the code follows:

public class JoglEventListener implements GLEventListener, KeyListener, MouseListener, MouseMotionListener {
// keep pointer to associated canvas so we can refresh the screen (equivalent to glutPostRedisplay())     
public GLCanvas canvas;
public Particle triforce;
public float x;

// constructor
public JoglEventListener(GLCanvas canvas) {
    this.canvas = canvas;
}

@Override
public void display(GLAutoDrawable drawable) {
    update();
    render(drawable);
}

@Override
public void init(GLAutoDrawable drawable) {
    triforce = new Particle();
    x = 0;
}

private void update() {
    triforce.integrate(0.0001);
    x = x + 0.25f;
}

 private void render(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    GLU glu = new GLU();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL2.GL_PROJECTION);        
    gl.glLoadIdentity();
    //gl.glFrustum (.5f, -.5f, -.5f * 1080, .5f * 960, 1.f, 500.f);
    glu.gluPerspective(0, 1, 0.1f, 100f);        


    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glHint(GL2.GL_CLIP_VOLUME_CLIPPING_HINT_EXT,GL2.GL_FASTEST);
    glu.gluLookAt(0, 0, 1.5, 0, 0, -10, 0, 1, 0);        
    //gl.glRotatef(90, 0f , 1f , 0f );
    //Draw some scale lines
    gl.glBegin(GL.GL_LINES);
    gl.glColor3f(0.75f, 0.75f, 0.75f);
    for (int i = 0; i < 20; i += 1)
    {
        gl.glVertex3f(-5.0f, 0.0f, i + 0.5f);
        gl.glVertex3f(5.0f, 0.0f, i + 0.5f);
    }
    gl.glEnd();

    //gl.glRotatef(x, 1f , 1f , 1f );         

    gl.glPushMatrix();
    gl.glTranslated(triforce.position.x, triforce.position.y, triforce.position.z);
    gl.glBegin(GL.GL_TRIANGLE_STRIP);                       
    gl.glColor3f(1f, 0f, 0f);                       
    gl.glVertex3d(0, 0, -2);
    gl.glColor3f(0f, 1f, 0f);                       
    gl.glVertex3d(0, 0.25d, -2);                
    gl.glColor3f(0f, 0f, 1f);                       
    gl.glVertex3d(0.25d, 0, -2);
    gl.glColor3f(1f, 1f, 0f);                       
    gl.glVertex3d(0.25d, 0.25d, -2.25d);
    gl.glEnd();                                       
    gl.glPopMatrix();

    gl.glFlush();
}

// (empty overridden methods omitted)

public Particle () {
    setMass(200d);
    velocity = new Vector3(0d, 30d, 40d);
    acceleration = new Vector3(0d, -20d, 0d);
    position = new Vector3(0d, 0d, 0d);
    damping = 0.99d;
}

public void integrate (double duration) {
    if (inverseMass <= 0.0d) {
        return;
    }
    assert (duration > 0.0);
    position.addScaledVector(velocity, duration);
    Vector3 resultingAcc = new Vector3(acceleration.x, acceleration.y, acceleration.z);
    velocity.addScaledVector(resultingAcc, duration);
    velocity.multEquals(Math.pow(damping, duration));
    //clearAccumulator();
}

public void setMass(double mass)
{
    assert(mass != 0);
    inverseMass = (1.0d)/mass;
}    

Before movement / starting position:

Before

The shape drifts upward and is obscured from the right and top, becoming invisible:

During

Any help would be greatly appreciated! Thanks!

  • 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-25T03:34:29+00:00Added an answer on May 25, 2026 at 3:34 am

    In the end, I was never able to track down the issue, and started again from scratch. I didn’t run into any further clipping issues on my new build.

    My best guess as to my initial failure is an improperly used glHint or glClear call, or perhaps some problem with the version of JOGL I was referencing.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.