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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:46:43+00:00 2026-06-09T17:46:43+00:00

As a beginner to android and openGL 2.0 es, I’m testing simple things and

  • 0

As a beginner to android and openGL 2.0 es, I’m testing simple things and see how it goes.

I downloaded the sample at http://developer.android.com/training/graphics/opengl/touch.html .

I changed the code to check if I could animate a rotation of the camera around the (0,0,0) point, the center of the square.

So i did this:

public void onDrawFrame(GL10 unused) {
    // Draw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    // Set the camera position (View matrix)
    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = ((float) (2*Math.PI)/ (float) 4000) * ((int) time);
    Matrix.setLookAtM(mVMatrix, 0, (float) (3*Math.sin(angle)), 0, (float) (3.0f*Math.cos(angle)),     0 ,0, 0,     0f, 1.0f, 0.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

    // Draw square
    mSquare.draw(mMVPMatrix);
}

I expected the camera to look always to the center of the square (the (0,0,0) point) but that’s not what happens. The camera is indeed rotating around the square but the square does not stay in the center of the screen.. instead it is moving along the X axis…:
enter image description here
enter image description here

I also expected that if we gave the eyeX and eyeY the same values as centerX and centerY,like this:

Matrix.setLookAtM(mVMatrix, 0, 1, 1, -3,     1 ,1, 0,     0f, 1.0f, 0.0f);

the square would keep it’s shape (I mean, your field of vision would be dragged but along a plane which would be paralel to the square), but that’s also not what happens:

enter image description here

This is my projection matrix:

float ratio = (float) width / height;

// this projection matrix is applied to object coordinates
// in the onDrawFrame() method
Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 2, 7);

What is going on here?

  • 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-09T17:46:44+00:00Added an answer on June 9, 2026 at 5:46 pm

    Looking at the source code to the example you downloaded, I can see why you’re having that problem, it has to do with the order of the matrix multiplication.

    Typically in OpenGL source you see matrices set up such that

    transformed vertex = projMatrix * viewMatrix * modelMatrix * input vertex

    However in the source example program that you downloaded, their shader is setup like this:

    " gl_Position = vPosition * uMVPMatrix;"

    With the position on the other side of the matrix. You can work with OpenGL in this way, but it requires that you reverse the lhs/rhs of your matrix multiplications.

    Long story short, in your case, you should change your shader to read:

    " gl_Position = uMVPMatrix * vPosition;"

    and then I believe you will get the expected behavior.

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

Sidebar

Related Questions

I've been following the beginner PlayN tutorial at http://code.google.com/p/playn/wiki/BeginnerInstallationGuide So basically I've downloaded PlayN
Beginner in Android development. My code crashes. I have made a simple Java method
the tutorial here http://www.edumobile.org/android/android-beginner-tutorials/creating-image-gallery/ teaches how to put images from resources in gallery here's
I'm a beginner android developer , I was trying to run this Linear Layout
I am a beginner in Android programming. I want to build a simple application
I am beginner of Android OpenGL I want to learn and make Live wallpaper
I am a beginner android developer and I am trying to have a button
I'm a beginner in android and at the moment, I'm working on simple app.
I am a beginner Android developer and I am trying to make a game
I am a beginner Android developer. I am trying to create an SMS application.

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.