Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Simple jump animation using Java/OpenGLES


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 InfinityMachine   Members   -  Reputation: 182

Like
0Likes
Like

Posted 11 March 2014 - 05:38 PM

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, 11 March 2014 - 05:54 PM.

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


Sponsor:

#2 DevLiquidKnight   Members   -  Reputation: 834

Like
0Likes
Like

Posted 11 March 2014 - 06:41 PM

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


Edited by DevLiquidKnight, 11 March 2014 - 06:41 PM.


#3 InfinityMachine   Members   -  Reputation: 182

Like
0Likes
Like

Posted 13 March 2014 - 01:27 PM

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!


Edited by InfinityMachine, 13 March 2014 - 01:27 PM.

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


#4 InfinityMachine   Members   -  Reputation: 182

Like
0Likes
Like

Posted 14 March 2014 - 03:53 PM

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.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS