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 / Rotating images by less than 90 degrees

Author
Message
Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 18th Jul 2009 01:14 Edited at: 18th Jul 2009 02:30
Hidy ho! A long while ago i posted this thread aspiring to program a sort of powder game with accurate gravity. Thanks to all of the wonderful replies, i understood the gravity portion. Unfortunately, my plans were cut short by a growing interest in robotics.

I have since returned to programming, and with a warm up pseudo-particle sim (
<-- The code for anyone interested) completed, i am going to return to my previous ambition.

Now before i can start, i have one problem. As particles coalesces into larger chunks, the program will have to identify the particles that are joined. To do this i was thinking of have a section of the program check to see if two particles need to be joined, and if so, create an array of the relative locations of the particles in the chunk. Something like : Chunk_array(chunk_id,x,y).

If these "chunks" are to have any spin, i need to be able to rotate all the particles a cirtain amount without distorting the look. I, not being the best programmer in the world, have no clue how to do this. Help ?

Everything is more than the sum of its parts.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Jul 2009 01:44
http://forum.thegamecreators.com/?m=forum_view&t=140077&b=6

You can check that out, or you can use plain objects instead of images.

TheComet


Make the path of your enemies easier with Waypoint Pro!
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th Jul 2009 01:55
I could try and whip up a rotate image function, but im working right now so it'll have to wait

im not gona guarantee it will work since im still just envisioning it but most of the people on this board will tell you I can come up with some pretty bizarre and impressive functions

Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 18th Jul 2009 02:21
@ Comet

Thanks loads for the link, but it sounds like it will be a bit slow if i try calling it bunches of times in realtime. Also, i probably should have chosen a different title, because if i could keep it in the array life would be much better. Not sure what you mean by plain objects though, could you explain?

Everything is more than the sum of its parts.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th Jul 2009 02:38
i havent read your first post thoroughly but im guessing hes saying make a 3d plain object and texture it with the image, then you can free rotate the plain

Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 18th Jul 2009 03:15
Ok! i get the plain object thingey. Im wondering tho if thers a mathematical way of doing it though? or maybe im just being too picky

Everything is more than the sum of its parts.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th Jul 2009 03:31
yeah i know theres a math way, gimme the rest of the day and ill whip you up a function to do that

Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 18th Jul 2009 05:02
Thank you so much Smart guy!!! if i don't post again till tomorrow evening don't let your feelings be hurt,i have business early in the morning till late afternoon.

Everything is more than the sum of its parts.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th Jul 2009 05:23
no problem, honestly im not gona guarantee ill get it finished 2nite, but I will try

That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th Jul 2009 06:31
ok i have a plan on rotating it, but i wont be able to do it til 2moro afternoon, however im not sure how well it will work, we'll have to see

TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Jul 2009 11:21
It's quite easy. Make the plain object exactly the size of the image. Let's say the sprite positions are 35,342 (sx=35,sy=342). To convert that to the 3D positions, do this:



Note this only works in a 640*480 display mode. You will have to multiply the positions by a certain amount for bigger or smaller displays.

TheComet


Make the path of your enemies easier with Waypoint Pro!
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Jul 2009 19:17
A little diddy:

Rotate Images

Enjoy your day.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th Jul 2009 22:51
i just skimmed through the first post of that thread latch and it sounds like youre essentially doing exactly what I had planned:

make a memblock fom the image

loop through all te image pixels and for each:
{
find the angle form the center of the image to that pixel

calculate the new angle based on the old

put a dot on an offscreen bitmap in the new position
}

find the furthest pixels left,up,right, and down from the center that have a colored pixel in them

get the image based on those pixels

Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 18th Jul 2009 23:52
@ comet

Thanks for your help but using a plain object wouldn't integrate very easily with the rest of my program. Unfortunately i am guilty of ill naming this thread: rotating the data in an array would work best.

Having said that i think i can adapt what Smart guy explained to my program. The one thing i don't know how to do is get the angle from the center of the picture/array/whatever i end up using.

Everything is more than the sum of its parts.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 19th Jul 2009 00:05
well from the image to get the angle I find it best to use the function:

atanfull(xdiff,ydiff)

which returns the angle between 2 points, you input the DIFFERENCE between their xs and ys coords and it outputs an angle

inputting 0 ,anything>0 will return an angle of 0 and inputting anything>0 ,0 (in that order) wil return 90

play around with the function to test it out

anyway to get your angle you need you need the image width and height (imgw and imgh) using either of these methods:

make a sprite of the image then use sprite width() and height()

or use make memblock from image memblocknum,imagenum along with get memblock dword(memnum,0) for the width and get memblock dword(memnum,4) for the height

once you have that data then fill in this formula to find the angle of te center and the point at px,py

angle=atanfull(px-(.5*imgw),py-(.5*imgh))

Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 19th Jul 2009 00:46
Thanks Smartguy that should help loads!!!!

Everything is more than the sum of its parts.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 19th Jul 2009 01:32
no prob

Login to post a reply

Server time is: 2024-05-20 12:02:34
Your offset time is: 2024-05-20 12:02:34