Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / How Do I Rotate A Square?

Author
Message
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Sep 2007 19:49 Edited at: 26th Sep 2007 19:59
I'm stuck on this
Here's what I have so far, just trying with a single line for now but it's all wrong. It looks more like a dangling thread than a rotating line

[EDIT] I noticed a typo which made it look much different. I've added in the other lines and is look like it's rotating along x and y axis! Cool but not what I wanted


Thanks in advance

In programming, nothing exists
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 26th Sep 2007 19:56 Edited at: 26th Sep 2007 19:57
smartass

Unless you're actually stuck and then sorry..haha.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Sep 2007 04:32
i am actually stuck
I want it to rotate in 2D

In programming, nothing exists
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 27th Sep 2007 05:10
Sorry then obese, I'm not sure what to tell ya there. Is this for that game you made 3d with 2d commands because that was really f****in cool haha.

aluseus GOD
18
Years of Service
User Offline
Joined: 19th Mar 2007
Location: I\'m here. Now I\'m there. I keep moving
Posted: 27th Sep 2007 06:14
If this is 2d, its easy, I've done a gajillion times, I'll post the code in a bit.

Your signature has been deleted by a moderator because this joke is getting old.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Sep 2007 10:25
@Obese87

There's a couple of things in your code that may be giving you problems. The formula you are using looks like a cartesian to polar coordinate conversion and it's basic form around is:

radius = sqrt(x^2+y^2)
x = radius*cos(angle)+midx
y = radius*sin(angle)+midy

This bit in your for next loop
*vect(sv,x)

is basically the place for the radius. But your value will not be a consistant radius because you are using the values of the x point which can be 100 or -100 meaning there will be points moving in opposite directions.

The other thing is the angle a#. Each point will not only move the angle a# but they will move with an offset to a# because of each points original starting position.

(100,100) from (320,240) and (-100,100) will have different offset angles which they start from (remember tangent is a slope which we can derive an angle from):

offset1 = atanfull(100-240,100-320) ~ -147
offset2 = atanfull(100-240,-100-320) ~ -162

So as you change a#, you should add the offset to it as a constant. If you want to use polar coordinates, hopefully this helps.

Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Sep 2007 19:08 Edited at: 27th Sep 2007 19:14
@Latch
Thanks, I still don't really understand it though
what does "~" mean?
are you saying that the offset should be a single value and a direction (angle)?

@Zombie
I've been wanting to do this for a while, it'll mean I can make a 2D game where you can rotate the characters

check this out


crazier


In programming, nothing exists
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Sep 2007 02:30 Edited at: 28th Sep 2007 02:38
Quote: "Thanks, I still don't really understand it though
what does "~" mean?"

I use it to mean approximately. The final angle in the rotation calculation for each point should be that point's angular offset + the angle all of the points are being rotated to.

aluseus GOD might have a different method or be able to explain the 2d rotation better so I'll hold off on posting a code example for this.

But
Quote: "it'll mean I can make a 2D game where you can rotate the characters"

If you want to handle the rotation in real time like it's done in 3d, why not just use 3d? (I know it's the fun of figuring it out and conquring the task) But if you don't mind fixed rotations, you can just use rotated images that you capture from 3d. This example rotates a 3d cube with a couple of arms around the y axis. I captured images for a full 360 degrees. But for a sprite in a 2d game, it would probably suffice just to capture 8 images at 45 degree increments:



The idea is you could save all of these images to files, or (depending on how many) you could make a sprite sheet or a tile of a single bitmap of all of the images and save that. Then you could recall the images and just cycle through them according to your character's controls. And you could of course, reuse the images over and over for whatever game you wanted. Also, if you wanted a larger and smaller version of the same character, scaling in 3d before capturing the image is usually clearer than scaling a sprite (can become blocky). So if you have any modeling skills or can get hold of some good 3d models, your 2d game could look very good.

Enjoy your day.
aluseus GOD
18
Years of Service
User Offline
Joined: 19th Mar 2007
Location: I\'m here. Now I\'m there. I keep moving
Posted: 28th Sep 2007 03:51 Edited at: 28th Sep 2007 04:05
Guess what, I can explain. But if I explain, you'll have to explain what atanfull does, It's a crucial part for my code to work, but I need to know what it does.

And its easier if you know what trigonometry is so tell me if you understand sin, cos, and tan and then I will explain.

Edit:
I UNDERSTAND ATANFULL NOW! (I was trying to do what it could do all along.

Redit:


Your signature has been deleted by a moderator because this joke is getting old.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Sep 2007 19:54
cheers AG, that's what I wanted
I had to change it around a bit for it to work in DBC

You can't use -COS in DBC; what difference does it make?

In programming, nothing exists
aluseus GOD
18
Years of Service
User Offline
Joined: 19th Mar 2007
Location: I\'m here. Now I\'m there. I keep moving
Posted: 28th Sep 2007 23:52 Edited at: 29th Sep 2007 02:59
Nothing, it just starts angle 0 somewhere else, but it shouldn't make a difference,

I actually owe you some thanks. Why?
You showed me arrays that are like array(f,m).

Your signature has been deleted by a moderator because this joke is getting old.

Login to post a reply

Server time is: 2025-05-31 20:30:19
Your offset time is: 2025-05-31 20:30:19