Results 1 to 8 of 8

Thread: Uhh, little help please? rotation and physics...

  1. #1
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Uhh, little help please? rotation and physics...

    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
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  2. #2

    Re: Uhh, little help please? rotation and physics...

    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.

    As for physics, I don't know much about it, but I've heard of a good physics engine for 2D graphics called Box2D. 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.

  3. #3
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Re: Uhh, little help please? rotation and physics...

    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.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  4. #4

    Re: Uhh, little help please? rotation and physics...

    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);
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  5. #5

    Re: Uhh, little help please? rotation and physics...

    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.

    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  6. #6
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Re: Uhh, little help please? rotation and physics...

    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.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  7. #7

    Re: Uhh, little help please? rotation and physics...

    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
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  8. #8
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Re: Uhh, little help please? rotation and physics...

    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.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •