Moving in increments smaller than one

Problems with Canvas, OpenGL, etc...

Moving in increments smaller than one

Postby Austen520 » Tue Jun 01, 2010 9:42 pm

I'm making a breakout game where when the ball hits the paddle, the angle changes based on where it hits. I'm using the speedx = cos(angle)*velocity and speedy=sin(angle)*velocity formulas. The problem is that what gets returned is a fraction, and trying to move an object around the canvas in fractional increments doesn't work. Anything i'm missing or any tips?

Thanks and sorry for the rushed post
Austen520
Freshman
Freshman
 
Posts: 2
Joined: Tue Jun 01, 2010 9:38 pm

Top

Re: Moving in increments smaller than one

Postby Resilient » Tue Jun 01, 2010 10:00 pm

Is there a reason you don't want to use floating point? You could at least store as floating point and convert to into as needed to draw it.
Resilient
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue May 18, 2010 1:33 am

Re: Moving in increments smaller than one

Postby Austen520 » Tue Jun 01, 2010 10:30 pm

well i am storing the speeds as floating points. I can't cast them to (int) because then they would lose the information after the decimal right?
Austen520
Freshman
Freshman
 
Posts: 2
Joined: Tue Jun 01, 2010 9:38 pm

Re: Moving in increments smaller than one

Postby Resilient » Tue Jun 01, 2010 11:15 pm

Austen520 wrote:well i am storing the speeds as floating points. I can't cast them to (int) because then they would lose the information after the decimal right?


The float data will still exist in the original variable. So you could cast it as an int while adding it to the position into and still have the original speed maintained. You could also just keep track of the position as a float and cast to an into for drawing.
Resilient
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue May 18, 2010 1:33 am

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: Google [Bot] and 2 guests