|
smaller numbers? Displaying 1-19 of 19 total.
1
locke
|
Hi all.
I finally wrangled up a PC and am now back on the set. Seems like YEARS since I've been here. I've been lurking with my Mac, trying to score a PC. And I finally got one.
Let the games begin!
Again.
Err... to my question: I'm building a shooter of sorts (just to get back into the swing of things), and have an issue where I need to move an object by a very small amount around the screen. For example, space shooter... you want to move a ... err... say a planet ... across the background. It would move very slowly, right? 'Cause it's a long ways away, and it huge.
Anyway, my problem is, if I just use a timer to make it move slowly (skipping draws) it obviously moves slowly, but with very stuttered movement.
I'm using vectors to move the planet, and I can't get vector lengths to be small enough to move it in very small increments, only large chunks.
I'd like to be able to simply manipulate my vector lengths... that would be easiest, but alas, no floats to divide them by.
I suspect someone will tell me to scale the whole thing up by a couple of places, I haven't wrapped my brain around exactly how that would work. Also, I understand the concept behind %, I'm just not sure how I could get it to apply to my problem. I can 'simulate' a float, but I still can't make incremental changes.
I'm wandering all over the place here, aren't I? The nice thing is that it's all coming back to me pretty quickly.
Lovin the new engine. I'll start working on some server apps as soon as I can get that danged planet to glide rather than stumble across space. ;)
Thanks.
-lok
Posted on 2004-10-01 19:46:01
|
resident
|
Well, the smallest distance you can move is a single pixel. Drop the vectors and do it the simple way - just increase it a whole pixel every now and again. Make it a regular interval and it should move reasonably smoothly. As you say, it might stutter a bit, but in a shooter, the odds are good your player isn't going to be paying attention to the background.
Oh, and while I think of it - welcome back Locke!
Posted on 2004-10-01 19:50:19 (last edited on 2004-10-01 19:51:33)
|
locke
|
Heh. Thanks.
It's an interesting idea. The vectors are because I'm moving my ship around 360 degrees (like the old Star Control). It has to be able to move around freely, or not at all, given the player's movement.
Hmm... For some reason, this is making my mind spark. I shall ponder your words some more.
-l
edit: My sig is huge.
Posted on 2004-10-01 19:59:51 (last edited on 2004-10-01 20:00:48)
|
locke
|
Ah HA!
Fixed Point numbers!
You tricky people you... now if only I knew what the hell that all meant.
//reading the manual (nice work on this, McG)//
-lok
Edit: OK... I read it. I'm still not sure how to apply it to my problem, though, because you still end up with a whole number, even it if represents a fraction.
Can someone show me an example of how I would use FP numbers to do the following:
I need to move a circle across the screen, given a vector angle, and a vector length. Can I use FP numbers to represent the vector length? Like, for example, a vector length of 2 ends up being a couple of pixels if you do a straight draw from it (with a timer to slow it down). How could I use FP numbers to make it 1/10th of 2?
Am I making sense? Let's assume I have different layers, and the ship is one layer. I need to move the 'planet layer' much slower, so I want to take a fraction (let's say 1/100th) of the 'player's speed' (vector length), and move the planet at that fractional rate.
Man I ramble a lot.
-l
Posted on 2004-10-01 20:02:57 (last edited on 2004-10-01 20:11:27)
|
vecna
|
1) You can learn the magical voodoo of fixed-point math
2) You can instead of making an integer 'pixelmoves per ticks' counter you can make your integer instead 'ticks per pixel move'
3) You can wait till the next major build which will have floats.
Couldn't really say for sure at this point how far away #3 is tho.
Posted on 2004-10-01 21:15:57
|
Omni
|
Er...how about this? Here's a circle drawer. Assume 100 units = 1 pixel. So I can move something by 50 (0.5 pixel) or 33 (0.33 pixel) or 100 (1 pixel). Right.
int circlex_100, circley_100
for every tick on timer...
circlex_100 + 5
circley_100 + 5
//To convert to pixel units, use the conversion 100 units = 1 pixel
//Think of it as chemistry conversions, or simple ratios.
Draw a Circle(circlex_100 / 100, circley_100 / 100,
3 radius, 3 radius, cWhite)
The above pseudocode would draw a Circle that would move by 5 units (0.05 pixels) every tick.
Simple conversion math to help you see what's happening:
Since there are 100 ticks per second...
100 ticks per sec * (5 units / 1 tick) = 500 units per sec
And 100 units in a pixel...
500 units per sec * (1 pixel / 100 units) = 5 pixels per sec
Thus, the Circle is incrementing in the Y and X axis at 5 pixels per second.
You could make the scale even smaller.
every tick...
Circlex_1000 + 5
Circley_1000 + 5
DrawCircle( circlex_1000 / 1000, circley_1000 / 1000)
In the above example there are 1000 units in 1 pixel.
Thus,
100 ticks / 1 second * 5 units / 1 second * 1 pixel / 1000 units = The circle will move at 0.5 pixels per second.
Now, of course you can't blit to pixel 4.5, 6.5, but the position of the circle will accumulate at that rate.
Make any sense?
[Zip Edit: Nope. Your < pre > breaks less now. I need a bigger monitor.]
Posted on 2004-10-01 21:19:51 (last edited on 2004-10-01 22:49:02)
|
locke
|
Makes a lot of sense, and that's precisely the kind of logical response I'd expect here. :)
Thanks.
-l
EDIT: AHHH... but wait. I'm using vectors here so that I can move the planet relative to the ship's direction (360 degree freedom).
How can I apply this method to a vector length?
Posted on 2004-10-01 22:47:42 (last edited on 2004-10-01 22:57:21)
|
locke
|
1) You can learn the magical voodoo of fixed-point math
2) You can instead of making an integer 'pixelmoves per ticks' counter you can make your integer instead 'ticks per pixel move'
3) You can wait till the next major build which will have floats.
Couldn't really say for sure at this point how far away #3 is tho.
I am definitely interested in learning the dark art of fixed point math. /me goes and does some research.
...
#2 might take less time.
...
...and #3... well, that certainly won't hurt. But I'm in that groove, ye know? I'm just rolling through a lot of functionality very quickly. It's all very self-inspiring. But floats would be really nice.
Hey... thanks for the net code, btw. My mind bends and warps with thoughts about downloaded updates, stat tracking, and database access. Yum.
-l
Posted on 2004-10-01 22:54:39
|
mcgrue
|
Omni, You're now my personal god for introducing me to that naming convention.
Posted on 2004-10-01 23:04:18
|
Zip
|
Fixed point is easy. You just need to remember what you store at greater precision, and what you don't, 'cos you don't have the type protection of floats. It's good practice though, 'cos if you're used to this kinda aproach you're less likely to get the conversion rounding errors people tend to stumble into.
Zip
Posted on 2004-10-01 23:08:28
|
locke
|
Woot!
It worked.
Thanks, Omni.
Now I'm going to try to switch it over to Fixed-Point. Learning is gud.
-l
Posted on 2004-10-02 00:08:49
|
Technetium
|
This is probably a really stupid question, but have you considered just using map tiles and putting the distant objects in a background layer that has a different parallax? I had a single-stage shooter in V2 that had 3 levels of stars and that was how I did it. Then you just increment the winx variable periodically.
Of course, there are many more options with going all sprite.
Posted on 2004-10-02 00:28:55
|
Omni
|
Er, what's up with the pre tags? And...er...what exact naming convention are we talking about? I tacked _100 onto the variables, and if anybody's interested I first saw that in Zara's 4Four source, so, his credit, not mine.
Also, you could do the same thing with angles and vectors, yes.
int angle_100, velocity_x100, velocity_y100, vector_length100 = 50 //vector length can be anything.
//Here, 50 units = 0.5 pixel.
for each tick...
if they turn
angle_100 + 100 //100 units = 1 degree
if they move
//The '>> 16' brings the result from 16.16 fixed point back to our 1/100 conversion.
velocity_x100 = vector_length100 * Cos(angle_100 / 100) >> 16
velocity_y100 = vector_length100 * Sin(angle_100 / 100) >> 16
circlex_100 += velocity_x100 //Increments the circle x, y position by the
//vector x, y magnitude [ie, the velocity x, y]
circley_100 += velocity_y100
CircleDraw( circlex_100 / 100, circley_100 / 100)
This is significantly more complicated, because you're not just multiplying by the conversion, you're also multiplying by the Sin and Cos. Does this make sense as well?
Edit: Also, if you don't know a ton of trig or aren't comfortable with it, check
Sin and Cos: The Programmer's Pals!
Posted on 2004-10-02 01:00:24 (last edited on 2004-10-03 21:43:38)
|
locke
|
Yeah, that's basically how I ended up doing it (with vectors). Works like a champ. I'm even thinking of faking some layers like this... a star layer, a local planet layer, and an immediate (just 'below' the player) layer.
The idea of doing it with a map had crossed my mind, but since the details are so simple (a couple of planets, maybe a nebula-like thing hovering way off in the distance), I figured I'd just do it with coordinates. I'll replace the filled circle with a graphic, etc. Though the thought of having some animation is appealing...
I shall ponder this further.
That site, btw... particularly that piece on sin and cos is excellent.
-l
Posted on 2004-10-02 13:09:34
|
aen
|
Aww, everybody forgot my little fixed-point primer! Take a look at this, locke:
http://www.verge-rpg.com/~aen/code/fixed-point/fixed-point-r3.txt
Hopefully that'll help get your brain more warmed up to the concept.
Posted on 2004-10-09 23:56:40
|
zaril
|
Posted on 2004-10-10 00:17:27
|
aen
|
Oh yeah! Documentation. Imagine that. <-- hasn't RTFM
Posted on 2004-10-10 19:04:43
|
locke
|
Quote: Originally posted by zaril
aen/locke: http://www.verge-rpg.com/docs/view.php?libid=1§ion=85
Uhm, yeah... I read that. I tried it out based on what I learned, and it still wasn't working. So I used the forums.
That's typically how it works for me, though it may not look like it.
Heck, I've even used the fabled 'Search the Forums' functionality, which works pretty well, btw. Would be nice if it kept stuff by thread, though.
-l
Posted on 2004-10-12 22:05:25
|
Feyr
|
Yeah, organizing search results by thread would be great. I don't -think- I missed the information I was looking for last time I used it (map file format), but I had to go over the results three times to make sure because most of them were from a six-month-old thread saying that the map file format is secret.
Posted on 2004-10-13 01:10:10
|
Displaying 1-19 of 19 total.
1
|
|