• Advertisement
Sign in to follow this  

Simple jump animation using Java/OpenGLES

This topic is 1412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Do I call a (Java)recursive function for a matrix oscillation (object moving back and forth) or rather nested if loops? Currently I've attempted as such:

public void Jump(double Strength, float[] mvpMatrix){
    	long time = SystemClock.uptimeMillis() % 4000L;
    	boolean Direction=true;
    	for(int u=0; u<2;u++){
	    	if (Direction==true){
		    	for (float i=0; i<Strength;i+=0.0001f){
		    		i=0.0001f*((int) time);
		    		Matrix.translateM(mvpMatrix, 0, i, 0.0f, 0.0f);
				draw(mvpMatrix);
				if (i>Strength)Direction=false;
		    	}
	    	}
	    	if (Direction==false){
		    	for (float i=Strength; i>0;i-=0.0001f){
		    		i=Strength-(0.0001f*((int) time));
		    		Matrix.translateM(mvpMatrix, 0, i, 0.0f, 0.0f);
				draw(mvpMatrix);
				if(u==2)return;
				if(i==0)Direction=true;
		    	}
	    	}
    	}
 }

But something seems to be wrong. The object moves in one direction and that's it. This function is located in the onDrawFrame() method.

Edited by InfinityMachine

Share this post


Link to post
Share on other sites
Advertisement

You are trying to make an object move back and forth smoothly? Have you heard of interpolation functions? http://sol.gfxile.net/interpolation/

 

Yesh, I've heard of lerping. In the line of code, I just coded in that direction (I was thinking in crude JS for some reason) and got stuck. Also, I noticed that the for loop got executed onDrawFrame, where the object was drawn multiple times in one frame. This produced a neat effect - but it was hard to notice, since the square was white. (A long, white quadrilateral appeared.) Maybe this will be a good technique for motion trails in the future.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement