well I assume that:
you have the total distance (if not that you can calculate it)
the average velocity
and points (in an array) that should be connected with a straight line to make the whole route.
the current time.
Printable View
well I assume that:
you have the total distance (if not that you can calculate it)
the average velocity
and points (in an array) that should be connected with a straight line to make the whole route.
the current time.
am I right with that?? and... is it enough to display the bus at the point that is closest to where the bus is at or does it need to be the exact position of the bus?
fkheng,
A misanthrope is someone who dislikes people in general, doesn't trust anyone etc
With regard to your problem, the easiest way of doing it is to set a list of co-ordinates that the bus follows on its route.
The more co-ordinates you specify the more accurate your program will be.
The first co-ordinate will be the start, the last will be the end and all the ones in between will be the route.
Then, you put all these co-ordinates in an array.
In order to calculate where the bus is, you calculate the % of the way through the bus is based on the journey time. For example, if the bus set off 30 mins ago and the journey takes 1 hour then you know it's 50% of the way through the journey.
Now this is where the array of co-ordinates come in. You select the co-ordinate that's 50% (or whatever) of the way through the array and that will tell you where the bus should be.
Then you simply draw the bus's representative picture (a blob, or even a drawing of a bus, whatever) at the co-ordinates you pulled from the array.
For ease of coding, routes could be given exactly 100 co-ordinates (one for each % of the journey) . It makes your job easier, but if you want more or less (to make the program more or less accurate) then you can do this but it will require extra coding.
By doing it this way, it also provides you with an easy way of changing the bus route (by simply changing the list of co-ordinates) or to support multiple buses.
Make sense?
Cool, in the time it took me write all that ,Misanthrop posted. Twice!
And the quote isn't from the bible (although the bible is very quotable), it's from T.S. Eliot's - 'The Waste Land'.
hey arbiter well I was working on some code but I did not post it yet...
well what you said with the % works fine if the distance between each point is the same if not you need to calculate it first (I would do that with phythagoras and than just find an equation for the line and move it along...)
Alternatively the array could hold the distance between itself and the next point. Then you'd need to know the total length of the route and the distance between each points. He's not made any mention of knowing that so I gave the best solution I could think of at the time.
If he wants to know exactly where the bus is, he's going to have to fit a GPS to it....
you are right. I hope he is going for your advice (implying that the points have a fixed distance) because otherwise that could mean some wierd coding... I tried to put it into some pseudo code and I think it would need like 6 or 8 variables just for that little task...
sorry for the late reply, yeap, actually Arbiter is going along the same line as i am, and the formula sounds fine with me, i also thought about something like that.
I am assuming that the distance between each coordinate is the same.
I am also storing each coordinate of the route into an array.
The challenge now is from the point I position the bus on the screen, I'll have to make the bus move from that point onwards till it reaches its destination accross time.
Another hassle would be that though using a route, there maybe many trips. The route works fine, but on my map, I have routes which branch out.
The problem just gets bigger. Was just wondering if you ppl could offer some ideas. I hope I this is clear. I'd be glad to clarify as many time as possible if what I have said is 'blurry'.
Well, I think to make it easier for Misanthrop and myself, you might want to post your map and any code you have at the moment.
If we can see where you're up to, we can provide pointers for you.
true well the fragment of code that I was working on kind of would do the job... it's not done though and I got to work for school...
so I could post it after doing a little morfe to it... but it would be no real code just vb like code you could get the idea from...
but didn't you say every point the bus should ever be at is stored in the array? in that case you could just go like
(you could put some code to slow it down in between, so it wont just fly through though....)Code:sub movebus(start as long)
for i= start to end
bus.x = array(i).x
bus.y = array(i).y
next
You'd probably use a timer event to check the time every user defined interval and then calculate which image to draw.
It'd be more accurate than looping through the array with a delay.
hey thanx ppl, i really appreciate all the help...
yeap, i do have all the coordinates i need for the route, stored in various arrays...
ok, i'll post the map, and see if you ppl understand it, it might be confusing...
for now, its disfunctional, can't work properly...not sure wat i'm doing...
misanthrope's idea is good, just that i can't use a loop to make the bus move, becoz i onli require the bus to move to the next coordinate according to thee next given time... that is why i was wondering if there was a way to find out the interval between 2 coordinates...
arbiter, the timer event, hm...........yeah, but i'm really talking about possibly long times, coujld be measured in hours, but still, the timer is the easiest way rite? so wat do u think?
attached below is the map...
here's the frx file...
I'll try and look at these this evening or tomorrow for you.
And for the timer event, I didn't mean set the timer gap to the gap between updates, I meant have the timer check the time every second/10 secs/minute and compare to the start time.
e.g. Every second, the timer gets the time from the system using the now() function.
It compares that the start time of the bus and calculates as follows.
time running = Now - start time
journey complete percent = (total time of journey / 100) * time running
Then you get the co-ordinate which corresponds with the percentage complete and draw the bus.
Easy... :)
ok, but how do i know or calculate which coordinate lies at which position or percentage?
er.........wat is the purpose of the offset?
and have u taken a look at my code?
The offset is to select the co-ordinate from the percentage if you have anything other than 100 co-ordinates.
Do you understand the theory that I've posted?
I've not had chance to look at your code yet, I've been busy with other projects.
You should have everything you need in the posts above to code the solution to your problem.