Orbiting Sprites (Revisited)

First I have to thank everybody who has given input to this thread.
I went from hopelessly confused, to only mildly confused.

From all your input, and some digging on Google, I’ve come up with something that sorta-kinda works.

First of all I have defined the origin of my ellipse to be:

center_x = screen->w / 2;
center_y = screen->h / 2;

Then I set the radius in each direction to be:

x_rad = screen->w / 2;
y_rad = screen->h / 2;

Obviously this should allow me to put things around the circumference of an ellipse that has a diameter the hight and width of my screen…

Then I simply calculate where on that circumference an object will be placed by doing some simple trig like so:

obj->x = (cos(180 * M_PI / 180) * x_rad) + center_x;
obj->y = (sin(180 * M_PI / 180) * y_rad) + center_y;

Now, if I am not mistaken this should give the point that if this were graphed
in cartesian coordinated would rest at (x_rad,origin), right?

Now having just said that did I answer my own question? Since a video display is not in cartesian coordinates, do I have to do some sort of translation to my x,y values to get the actual point to plot?

Currently, under the given example, the sprite draws toward the left edge of the screen.

-Chris

Ok. Sorry to reply to my own e-mail.
But it turns out that I was doing everything right, and the samples I was basing my code off of were wrong.

I had my sin and cos reversed, and a few other things.

So things are looking good now.

Thanks again.

</off-topice thread>

-Chris> ----- Original Message -----

From: Chris Heller
Sent: Wed 9/24/2003 9:37 PM
To: sdl at libsdl.org
Cc:
Subject: [SDL] Orbiting Sprites (Revisited)
First I have to thank everybody who has given input to this thread.
I went from hopelessly confused, to only mildly confused.

From all your input, and some digging on Google, I’ve come up with something that sorta-kinda works.

First of all I have defined the origin of my ellipse to be:

center_x = screen->w / 2;
center_y = screen->h / 2;

Then I set the radius in each direction to be:

x_rad = screen->w / 2;
y_rad = screen->h / 2;

Obviously this should allow me to put things around the circumference of an ellipse that has a diameter the hight and width of my screen…

Then I simply calculate where on that circumference an object will be placed by doing some simple trig like so:

obj->x = (cos(180 * M_PI / 180) * x_rad) + center_x;
obj->y = (sin(180 * M_PI / 180) * y_rad) + center_y;

Now, if I am not mistaken this should give the point that if this were graphed
in cartesian coordinated would rest at (x_rad,origin), right?

Now having just said that did I answer my own question? Since a video display is not in cartesian coordinates, do I have to do some sort of translation to my x,y values to get the actual point to plot?

Currently, under the given example, the sprite draws toward the left edge of the screen.

-Chris


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/ms-tnef
Size: 3519 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030924/e03edf13/attachment.bin

using the siny_rad and cosx_rad, the object orbits around the origin… by adding half the screen’s width and height to the x and y coordinates respectively, you make the object orbit the center of the screen (screen origin is the top left corner)… so if you want your sprite to orbit an arbitrary point of
the screen, you should add its screen coordinates to the x and y values computed by siny_rad and cosz_rad.
Another thing…if you want to simulate 3d… that is, the object is suposed to have the effect of goint inside and outside of the screen when the rotation angle is 90 and -90 degrees, then you should also slow down rotation speed as the sin of the rotation angle increases in absolute value…
something like speed = base_speed - |sin(ang)| * speed_attenuance (speed_attenuance MUST be < base_speed or the object will stay still once it reaches |sin(ang)| = 1)

well, hope this helps…

KOn Wed, 24 Sep 2003 21:37:10 -0400 “Chris Heller” wrote:

First I have to thank everybody who has given input to this thread.
I went from hopelessly confused, to only mildly confused.

From all your input, and some digging on Google, I’ve come up with something that sorta-kinda works.

First of all I have defined the origin of my ellipse to be:

center_x = screen->w / 2;
center_y = screen->h / 2;

Then I set the radius in each direction to be:

x_rad = screen->w / 2;
y_rad = screen->h / 2;

Obviously this should allow me to put things around the circumference of an ellipse that has a diameter the hight and width of my screen…

Then I simply calculate where on that circumference an object will be placed by doing some simple trig like so:

obj->x = (cos(180 * M_PI / 180) * x_rad) + center_x;
obj->y = (sin(180 * M_PI / 180) * y_rad) + center_y;

Now, if I am not mistaken this should give the point that if this were graphed
in cartesian coordinated would rest at (x_rad,origin), right?

Now having just said that did I answer my own question? Since a video display is not in cartesian coordinates, do I have to do some sort of translation to my x,y values to get the actual point to plot?

Currently, under the given example, the sprite draws toward the left edge of the screen.

-Chris


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl