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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:13:49+00:00 2026-05-28T05:13:49+00:00

I’ve created 3 Java classes. one that has a glsurfaceview object and this calls

  • 0

I’ve created 3 Java classes.

  1. one that has a glsurfaceview object and this calls the renderer class.
  2. this is the renderer class and this calls the cube class.
  3. this is the cube class.

If I run the app then the screen shows a rotating cube (did rotation in the rendering class) which is fine. But I want to control the direction of rotation of the cube and for that I’ve set 2 buttons. This is where I need help because I don’t know to to make the buttons control the movement of the cube. I’m new to Android so if you could leave some code for me to examine then that would be just great.

  • 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-28T05:13:50+00:00Added an answer on May 28, 2026 at 5:13 am

    Your Activity class (or your class that extends Activity) should look like this:

    public class stackoverflowTest extends Activity {
    
    GLSurfaceView glSurface;
    MyRenderer myRenderer;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.main);
    
        myRenderer = new MyRenderer(this);        
        //Create an instance of the Renderer with this Activity
    
        glSurface = (GLSurfaceView) findViewById(R.id.graphics_glsurfaceview1);
        //Set our own Renderer and hand the renderer this Activity Context
    
        glSurface.setEGLConfigChooser(true);
    
        glSurface.setRenderer(myRenderer);
        //Set the GLSurface as View to this Activity
    
    
    }
    
    /** 
    * this is the method the button click calls
    */
    public void changeRotationDirection(View v){
    
        myRenderer.changeRotationDirection();
    
    
    }
    
    }
    

    Then in your renderer:

    public class MyRenderer implements Renderer {
    
    private float rotationDirection = 1.0f;
    
    
    public MyRenderer(Context context){
        this.context = context;
    }
    
    public void setRotationDirection(){
    
        if(rotationDirection==1.0f){
            rotationDirection=-1.0f;
        } else {
            rotationDirection=1.0f;
        }
    
    }
    
    @Override
    public void onDrawFrame(GL10 gl) {
            // GL calls
    
            gl.glRotatef(angle, rotateDirection, 0.0f, 0.0f);
    
            // draw cube
            gl.glDrawArrays( etc );
    
        }
    
    }
    

    Basically, you use glRotatef to rotate the cube just before you draw it. Use -ve vales for either the angle parameter (the first) or the x,y,z amount parameters to rotate in the opposite direction. Use method calls to the Renderer to communicate with it and update the scene. Use this approach with caution as the Renderer thread and Main/UI thread (from where the button call is made) can have synchronisation issues

    To make a button call the changeRotationDirection method, simply add android:onClick="changeRotationDirection" into the XML layout (of any view. Doesn’t have to be just a button view). Any button methods declared in the XML layout have to be of the form public void [methodname](View [paramname]) and have to be in the Activity class from where the button is pressed

    For more advanced touch control, check as Erik suggested and also check out OnTouchListeners

    (Note: if you’re using openGL-ES 2.0 or above (android 2.2+) then use GLES20.glRotatef())

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.