PDA

View Full Version : Uhh, little help please? rotation and physics...



code_glitch
14-04-2010, 04:16 AM
OK, I know that the name usually scares people off, and I know there are tutorials out there that explain how to do this with SDL. BUT, those are aimed at the fully abled and usually not self-taught improvising in a bad way programmer that programs as a hobby...

Neither are they aimed at people who are learning GCSE math (although doing well). Every bit I have seen has some type of matrix or vertex or other illogical thing on how to rotate an image ??? and wikipedia (or rather phd-pedia) doesnt shed any light on the matter.

So I was wondering if any of you guys could kinda explain what units I need and how to do it please? Im so stuck and i was thinking of making a game (depends on how far I get i might submit into competition thing for fun) but it relies on rotating images big time... Also, how to plot a trajectory on a screen with X velocity, Y velocity, and power and gravity values in an arc is a big thing too.

Anyways, sorry for the real long post, if you're in a hurry I will say READ PARAGRAPH 3 FOR BASELINE OF PROBLEM, if not, my writing style is annoying, and my hopes lie on the able-minded here. Oh, and btw: Its on this General forum/thread because I didn't want to make one post for the rotate and the other for the trajectory question which i can only clutch at straws with...

thanx a bunch in advance (damn, i really need to help more, being confused is frustrating).
code_glitch

Brainer
14-04-2010, 05:23 AM
If you need a unit for matrix math, I'd suggest using the one that comes with GLScene. Go to www.glscene.org, create your local copy of their repository and locate the file there. Alternatively, you can grab the file here (http://glscene.cvs.sourceforge.net/viewvc/*checkout*/glscene/Source/Base/VectorGeometry.pas?revision=1.63).

As for physics, I don't know much about it, but I've heard of a good physics engine for 2D graphics called Box2D (http://www.google.pl/url?sa=t&source=web&ct=res&cd=1&ved=0CAYQFjAA&url=http%3A%2F%2Fwww.box2d.org%2F&ei=NVHFS_KCHNGVOJay6ZEP&usg=AFQjCNGHb4oI6qtD1xbLjMM-wTHhCZ4JRw&sig2=T71p_Dyj6_7UFZcyXXkf8w). IIRC, there's a wrapper for Pascal somewhere, too (probably even here, but you'd need to look for it).

I hope this helps a little. :)

code_glitch
14-04-2010, 12:20 PM
hmm, now these are very helpful indeed, but I am developing a 2d game, so a 3d glscene doesnt do me much good, or am i missing something? I heard of sdl_gfx and gthat it can do rotation but am clueless on it so if anyone could enlighten me on it I'd much appreciate it.

JSoftware
14-04-2010, 12:45 PM
Just include the sdl_gfx unit. It comes with freepascal, don't know about delphi.

It has the rotozoomSurface function which probably does what you want. It's defined like this:
function rotozoomSurface( src : PSDL_Surface; angle : double; zoom : double; smooth : integer ) : PSDL_Surface;
so it'll return a newly instantiated surface that's rotated about the center.

So, if I remember correctly,
dest := rotozoomSurface(src, angle, 1, 1);
//do something with dest
SDL_FreeSurface(dest);

Stoney
14-04-2010, 01:03 PM
When working with SDL_gfx you need to be as careful as when working SDL_DisplayFormat or SDL_DisplayFormatAlpha, so source surface and dest surface must not be the same and use SDL_FreeSurface() when you don't the surface any more or else your application will leak memory.

Also, SDLUtils.pas provides a rotation function out-of-the-box, but is not as reliable as SDL_gfx.

code_glitch
14-04-2010, 01:14 PM
thanks a lot guys. I would assume that the 1,1 on the rotate surface command is the point around which to rotate. just to clarify, is that on the source or destination surface? and the angle works in degrees i hope (1 - 360) not radians...

many thanks guys.

JSoftware
14-04-2010, 01:34 PM
It works in degrees. But the 3rd parameter(as you can read in the definition and documentation) is the zoom factor, and 4th is whether is should do filtering on the output image or not

code_glitch
14-04-2010, 01:41 PM
ok, so the zoom factor works like on a camera? 2x zoom is 2x height and 2x width?
and the filter or not is like boolean? 0 = off 1 = on?

sorry about all the questions, I am still new to graphics and that (been working in a shell for past 3 years ie. since i started) so all this rotate, opengl and sdl is still quite new to me. and finding working documentation that is up to date for SDL written in pascal is still quite rare apart form what is hosted here on pgd. ;D