Skip to main content
GameDev.net gamedev.net
🔒 Locked

Simple jump animation using Java/OpenGLES

Started by InfinityMachine Mar 11, 2014 at 11:38 PM 2 replies 4.1k views
Original Post
InfinityMachine
InfinityMachine

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.

Find yourself. If you can't, keep looking.
InfinityMachine
InfinityMachine

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

Your level of ownage ranks higher it seems. Perfect documentation reference. Thanks!

Find yourself. If you can't, keep looking.
InfinityMachine
InfinityMachine

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.

Find yourself. If you can't, keep looking.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.