#174789 - GeneralFOL - Tue Jul 20, 2010 12:35 am
Hi all, well ive got it so that when you tap on the screen with the stylus, the player object moves to that location, however im having trouble getting the object to slowly move there, at the moment it just apears there.
Does anyone know how i can make an object slowly move to a specific location rather than just jumping there?
Thanks.
#174791 - Azenris - Tue Jul 20, 2010 1:34 am
Are you using fixed point positioning? It will allow you to move less than 1 pixel per update, and thus allowing you to slow things down.
_________________
My Homebrew Games
#174792 - GeneralFOL - Tue Jul 20, 2010 1:44 am
Thanks for the reply, to be honest im new to c++ aswell as opengl, ive allways programmed in basic up untill recently when i began learning c++.
So im not sure if im using fixed point positioning or not, was hopeing that someone might give me some example code to learn from maybe?.
Iain
#174793 - Azenris - Tue Jul 20, 2010 2:17 am
Tonc is a good resource on fixed-point.
http://www.coranac.com/tonc/text/fixed.htm
Basically if you wanted to move something on the x-axis 1/2 a pixel each update you could
Code: |
int x = 0 << 8;
int y = (SCREEN_HEIGHT / 2) << 8;
int speed = 128;
while(1)
{
x += speed;
Obj->SetPosition(x >> 8, y >> 8);
}
|
1 is 256 because (1<<8) is 256.
I'm probably explaining it worse than you could read from tonc :p
_________________
My Homebrew Games
#174794 - relminator - Tue Jul 20, 2010 4:16 am
While adding and subtracting with fixed point is easy (as long as they have the same shift value), dividing and multiplying is a little tricky.
Multiplying and dividing tends to scale your shift values.
This may help you with some of the techniques since it's an all fixed point SAT (separating axis theorem) collision implementation.
http://rel.betterwebber.com/junk.php?id=109
Note that I am using 1.19.12 fixed point which means 1 for the sign bit, 19 for the actual value and 12 for the fixed point.
Once you get the hang of it, it's not too hard and would be second nature to you in no time.
BTW, I also code in basic(Freebasic). What basic are you using?
As for actually moving from one point to another, you can use 3 ways.
1. Use cearn's atan2() implementation and do a:
Code: |
s32 dx = cosLerp(angle);
s32 dy = sinLerp(angle); |
2. Use vector normalizing.
ie.
v = target - pos
vectornormalize(v)
now adding v to pos every frame would move pos to target.
3. Use a spline.
For an example of #1 and #3, you can see the source for this:
http://rel.betterwebber.com/junk.php?id=101
For #2, you can use the standard libnds functions for that. I also used those in my SAT demo.
_________________
http://rel.betterwebber.com
#174797 - wintermute - Tue Jul 20, 2010 10:07 am
It's not 1.19.12 fixed point, it's 20.12 signed fixed point. Bit 31 is part of the number not simply a sign bit, unlike some DSPs where there *is* a sign bit ( not sure if they even still make those, been a long time since I've seen one)
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#174798 - GeneralFOL - Tue Jul 20, 2010 11:42 am
Thanks a lot guys for all the help and info, will check out thoselinks too.
Thanks again for taking the time to help, i will post back to let you know how i get on.
Iain
#174804 - Miked0801 - Tue Jul 20, 2010 6:11 pm
Truthfully, you could probably do what you want without fixed point, though it would be a touch inaccurate (or slow if Floating point emulation). What you need is an Ease function. Google Ease for all sorts of goodness.