Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075919 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:33:06 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)SAT rotated rectangle problem
Pages: 1 [2]
Print
Author Topic: SAT rotated rectangle problem  (Read 1332 times)
CharsAce
Level 0
***


View Profile
« Reply #20 on: July 06, 2012, 06:46:58 PM »

oops, what an idiot I am! I forgot to add a line:

Code:
int quarter_revs = 0;
loop {
  float angle = float(quarter_revs)*(pi/2)
  drawbox(angle)
  quarter_revs++
}

The quarter revs specifies how many quarter turns you want to perform, it should increment each frame (I'm taking your video as a guide).
So, as you know pi/2 radians is the same as 90 degrees. But since we cant represent pi faithfully, the first snippet of code is accumulating the error. The second snippet is better because you are only using pi once to calculate the angle. It is used in a direct calculation, not in an iterative manner.

If you prefer to work in degrees, it would look like this (since at some point you have to convert to radians anyway):

Code:
float angle_degrees = 0.0;
loop {
  float angle_radians = angle_degrees*(pi/180)
  drawbox(angle_radians)
  angle_degrees += 90.0
}

Hope thats clearer. Sorry about the mistake.

Ok, Thanks. Will test this out.
Logged
Netsu
Level 10
*****


proficient at just chillin'


View Profile WWW
« Reply #21 on: July 07, 2012, 12:11:34 AM »

This would need another set of points though right? Because it doesn't make sense to rotate the points every time I draw them to screen.

Well, you don't NEED the second set of points, but the simulation would probably be faster if you had two sets of points. One is the starting unmodified set, those are never translated (it makes most sense for them to be relative to the centre of the shape). The second set is computed from the first one using the shape offset and angle once per logical frame. Then it is used for computing collisions and for rendering until it is computed again in the next logical frame (again using the first set, offset and angle).
Logged

CharsAce
Level 0
***


View Profile
« Reply #22 on: July 09, 2012, 07:12:24 AM »

Thanks for all the help guys. Did the things you all suggested.
Logged
CharsAce
Level 0
***


View Profile
« Reply #23 on: September 30, 2012, 11:32:44 AM »

Since making this thread I changed my rotated rectangle class. I'm using the version Gottschalk outlined. In the new class I have the center point and two half lengths for the x and y axis. I store the rotation in a float and  2x2 matrix that I use for rotation calculations.

Thanks for all the help though fellas.
Logged
Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic