Dynamic Rotating Isometric Rectangles

Posted by Kenon on Sept. 9, 2008, 1:05 p.m.

Yep, that's what I'm working on right now in the mind of Kenon.

I'm looking for solutions, and I don't quite know where to look.

I'm going to start it off easy: Dynamic Rotating Rectangles.

That's simple. I think I have a script idea for it off the top of my head.

The idea comes from rotating a line. You use a rotation degree with +cos(rad)*length, blah blah blah.

ANyways, the idea I have off the top of my head works as such.

Assume the variables x for x position, y for y position, rad for radians of the angle, pi is… pi, w is the width of the rectangle, and h is the height.

For a vertex A, the first vertex would be (x+(cos(rad+pi/2)*h/2+cos(rad)*w/2),y-(sin(rad+pi/2)*h/2+sin(rad)*w/2))

Or so in theory.

Going to attempt the first vertice in a 0 degree situation where x=0 and y=0, h=8 and w=16.

(8,4). Correct on the 0 degree test.

Going to attempt the 45 degree test now. A triangle with w=16 and h=8 should in theory produce the median of (8sqrt(2),8sqrt(2))

I'll type more when I get home

Comments

Xxypher 17 years, 7 months ago

If you get this to work, I will rejoice, then demand the codes.

EXTREME EDIT:

Why don't you just make it slowly spin, by an updating variable?

Easier than going through a bunch of different tests.

s 17 years, 7 months ago

And what does dynamic mean in this case?

PY 17 years, 7 months ago

They aren't static.

I've used the word dynamic to appear smarter before too :D

Siert 17 years, 7 months ago

So what is this supposed to do?

s 17 years, 7 months ago

Draw a rotated rectangle. Since he's using a center X,Y system, he seems to of already posted the solution

Kenon 17 years, 7 months ago

In this case it means able to be changed at any moment flawlessly.

IE, it's completely generated by code and will work in all cases of all rotations.

I don't have time to test it.

The key is actually to draw an isometric rotating rectangle for something I'm working on. For that, I can just divide the y differences by 2. I didn't get the opportunity to test it. I'm going to try it again at 9:00 in 4 hours, after I get home from my college class today. After that, I'll do it.

But I'll post the remainder of the vertices. could someone test in the cases of rad= 0, pi/6, and pi/4 with some other w and h values and post the screenshots here? (at least one series where w and h are the same, where w is bigger than h, and h is bigger than w.)

draw_primitive_begin(pr_trianglestrip)

draw_vertex(x+(cos(rad+pi/2)*h/2+cos(rad)*w/2),y-(sin(rad+pi/2)*h/2+sin(rad)*w/2));

draw_vertex(x+(cos(rad-pi/2)*h/2+cos(rad)*w/2),y-(sin(rad-pi/2)*h/2+sin(rad)*w/2));

draw_vertex(x-(cos(rad-pi/2)*h/2+cos(rad)*w/2),y+(sin(rad-pi/2)*h/2+sin(rad)*w/2));

draw_vertex(x-(cos(rad+pi/2)*h/2+cos(rad)*w/2),y+(sin(rad+pi/2)*h/2+sin(rad)*w/2));

draw_primitive_end();

I'm just assuming, as I have to leave in like 2 minutes

noshenim 17 years, 7 months ago

I geussing that you're drawing a rotated rectangle, then flattening it?

but what's with 'rad+pi/2'? is rad dir*pi/180 or degtorad(dir)? ???

I assume that you want to calculate this instead of use transformations, but if you want to program this very quickly, remember that they exist =).

OBELISK 17 years, 7 months ago

If I'm reading your description correctly, I've done this.

SteveKB 17 years, 7 months ago

I done works similar to this although they were pretty slow since they used multiple layers of sprites. let me dig it out of my computer…

SteveKB 17 years, 7 months ago

here is a racing game from long ago here

here is a Mario game from long ago here

Yours seems to be using primitives instead of sprites, I've done those as well, but I've not made games with them but instead editors and I'm not distributing those.