• Create Account

### #ActualPointer2APointer

Posted 22 September 2012 - 02:09 PM

x = x*cos(angle) - y*sin(angle);
----------------------------------------
y = x*sin(angle) + y*cos(angle);

It's pretty hard for a lot of people because it involves Algebra, and we all know that many people prefer to only touch Algebra with a ten foot long stick.

I'll try and explain the situation as best as I can using C++ and SDL as an example, but the problem is the same in any library/language:

First, you might want to try and center the X and Y coordinates of the focus block(the block that's currently falling and you're moving):

int Xcenter;
int Ycenter;


Next, you can try and implement a median (the distance from the center of the focus block to its sides ) like this:

Xcenter -= MEDIAN * 2;
Xcenter += MEDIAN * 2;
Ycenter += MEDIAN * 2;


Then, you can use a coordinate variable (e.g. int x, int y, int x1, int y1, etc.) to call a function (accessor) to return the center of the square, and position it at its origin:

x1 = Xcenter;
y1 = Ycenter;


Then, perform the rotation like follows:

x2 = - y1;
y2 = x1;


Make the necessary adjustments to your control, engine, etc. to change the image in memory of the rotation angle by the 90 degrees or -90 degrees as necessary, and you can get your original location like:

x2 = Xcenter;
y2 = Ycenter;


Of course, there's a bit more to it than just that. You can't expect to rotate an L-block without pre-checking to see if there's a collision at the position, and without not knowing the positions in any sense, or else you'd expect a creepy little bug.

But you said rotation was your problem. The solution I enlisted shows you how to fix a median from a centered image, and then rotate negative or positive, and move around the center of the origin.

Of course, again, someone not being so sufficient in math would probably gain very little from this.

But it's basically a rotation of four 90 degree angles. Whatever you ultimately can put together is up to each person.

If it works, it works. Those are the basic steps. Cleaning up messy code, working on memory use, and fixing small bugs can done progessively through the production, but testing a well-working program always should be satisfactory.

### #1Pointer2APointer

Posted 21 September 2012 - 03:19 PM

x = x*cos(angle) - y*sin(angle);
----------------------------------------
y = x*sin(angle) + y*cos(angle);

It's pretty hard for a lot of people because it involves Algebra, and we all know that many people prefer to only touch Algebra with a ten foot long stick.

I'll try and explain the situation as best as I can using C++ and SDL as an example, but the problem is the same in any library/language:

First, you might want to try and center the X and Y coordinates of the focus block(the block that's currently falling and you're moving):

int Xcenter;
int Ycenter;


Next, you can try and implement a median (the distance from the center of the focus block to its sides ) like this:

Xcenter -= MEDIAN * 2;
Xcenter += MEDIAN * 2;
Ycenter += MEDIAN * 2;


Then, you can use a coordinate variable (e.g. int x, int y, int x1, int y1, etc.) to call a function (accessor) to return the center of the square, and position it at its origin:

x1 = Xcenter;
y1 = Ycenter;


Then, perform the rotation like follows:

x2 = - y1;
y2 = x1;


Make the necessary adjustments to your control, engine, etc. to change the image in memory of the rotation angle by the 90 degrees or -90 degrees as necessary, and you can get your original location like:

x2 = Xcenter;
y2 = Ycenter;


Of course, there's a bit more to it than just that. You can't expect to rotate an L-block without pre-checking to see if there's a collision at the position, and without not knowing the positions in any sense, or else you'd expect a creepy little bug.

But you said rotation was your problem. The solution I enlisted shows you how to fix a median from a centered image, and then rotate negative or positive, and move around the center of the origin.

Of course, again, someone not being so sufficient in math would probably gain very little from this.

This is why I decided to include pictures:

PARTNERS