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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:06:23+00:00 2026-06-14T15:06:23+00:00

As with my previous question i managed to create little solar system in opengl

  • 0

As with my previous question i managed to create little solar system in opengl and jogl 🙂
Now i want to rotate the camera to show it from different angles.
I managed to rotate the cubes, but their plane of movement remains unchanged.

GL3 gl = drawable.getGL().getGL3();

    gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);
    //Model View Matrix

    //Mat4 mv = new Mat4();
    Mat4 mv = MatrixMath.lookAt(this.eyeX,this.eyeY,this.eyeZ,this.at,this.up);
    mv = mv.mul(MatrixMath.rotationZ(satellite));
    mv.set(2, 2, 0.0f);
    mv.set(2, 3, 0.0f);

    cubeprogram.passUniformMatrix(gl, "model_view", mv);

    gl.glDrawArrays( GL3.GL_TRIANGLES, 0, numVertices );

    angle += 2.0f;
    satellite = angle + 8.0f;
    if (angle > 360.0f)
    angle -= 360.0f;

    float positionX = setMovementX(angle, 0.8f);
    float positionZ = setMovementZ(angle, 0.8f);
   // mv = MatrixMath.lookAt(this.eyeX,this.eyeY,this.eyeZ,this.at,this.up);
    mv = mv.mul(MatrixMath.rotationZ(satellite));
    mv.set(0, 3, positionX);
    mv.set(2, 3, positionZ);
    cubeprogram.passUniformMatrix(gl, "model_view", mv);
    gl.glDrawArrays( GL3.GL_TRIANGLES, 0, numVertices );
    positionX = setMovementX(satellite, 0.2f);
    positionZ = setMovementZ(satellite, 0.2f);
    Mat4 sm = new Mat4( 1.0f,    0.0f,  0.0f,   positionX, 
            0.0f,    1.0f,  0.0f,   0.0f, 
            0.0f,    0.0f,  1.0f,   positionZ, 
            0.0f,    0.0f,  0.0f,   1.0f);
    mv = mv.mul(sm);
    mv = mv.mul(MatrixMath.rotationZ(angle));
    cubeprogram.use(gl);
    cubeprogram.passUniformMatrix(gl, "model_view", mv);
    gl.glDrawArrays( GL3.GL_TRIANGLES, 0, numVertices );
    cubeprogram.setUniformMatrix("projection", projection);`

// definitions

public static Mat4 lookAt(Vec4 eye, Vec4 at, Vec4 up) {
    final Vec4 eyeneg = eye.neg();

    final Vec4 n = VectorMath.normalize(eye.sub(at));
    final Vec4 u = VectorMath.normalize(VectorMath.cross(up, n));
    final Vec4 v = VectorMath.normalize(VectorMath.cross(n, u));
    final Vec4 t = new Vec4(0, 0, 0, 1);
    final Mat4 c = new Mat4(u, v, n, t);

    return c.mul(MatrixMath.translate(eyeneg));
}
public static Mat4 lookAt(float x, float y, float z, Vec4 at, Vec4 up) {
    final Vec4 eye = new Vec4(x, y, z, 1.0f);
    return lookAt(eye, at, up);
}
  • 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-14T15:06:24+00:00Added an answer on June 14, 2026 at 3:06 pm

    Check jogl’s pmvMatrix

    for camera:

    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.gluPerspective(fov, aspect, zNear, zFar);
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glRotatef(-pitch, 1, 0, 0);
    pmvMatrix.glRotatef(-yaw, 0, 1, 0);
    pmvMatrix.glRotatef(-roll, 0, 0, 1);
    pmvMatrix.glTranslatef(-position.x, -position.y, -position.z);
    pmvMatrix.update();
    

    Fixed functions:

    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    gl.glLoadMatrixf(pmvMatrix.glGetPMatrixf());
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glLoadMatrixf(pmvMatrix.glGetMvMatrixf());
    

    Shaders:

    GLUniformData pmvMatrixUniform;
    

    init code…

    PMVMatrix pmvMatrix = ...;
    state.attachObject("pmvMatrix", pmvMatrix);
    pmvMatrixUniform = new GLUniformData("pmvMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
    state.ownUniform(pmvMatrixUniform);
    state.uniform(gl, pmvMatrixUniform);
    

    display code…

    state.uniform(gl, pmvMatrixUniform);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from my previous question , I have now managed to rotate my
I managed to get some help from a previous question and I have the
This is a follow up question from a previous SO question . Now I
This question follows on from a previous question, that has raised a further issue.
It seems I am not clear on my previous question about managed bean. So,
After my previous question I have managed to Add and Ad banner to my
This question is based on a previous , but that's just FYI. I've managed
Following up from my previous question. Can anyone explain why the following code compiles
In a previous question , I managed to get some text replacement working for
This question is continuation to my previous question over stack overflow how-to-download-images-asynchronously-from-web-server . I

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.