|
-
Mar 29th, 2002, 01:05 PM
#1
Thread Starter
Hyperactive Member
Help!~
I'm not sure if i'm posting this thread in the correct VB Section.
What i have to produce on a program is this:
I have to use a map, which has the routes between states on it. Whatever it is, I have to make a dot, or any other object, move along those routes. The thing is, how do I do this in VB?
-
Mar 29th, 2002, 01:46 PM
#2
Hyperactive Member
easy enough.
1.For starters you need a picture of a map, save it as a bmp and use this as your background pic.
2. Hard code the dimentions of the pic using scalemode pixels and scalewidth and scaleheight.
3.Code an Array of index's for x and y values that correspond to the different states and/or cities.
4.Code it so that on mousedown or mousemove the x,y values are compared to the vals in the array and produce a shape,pic,or pixel color at that position.
5.Remove(visible=false) or move (move method) or biltblt the shape,pic,or pixelcolor when not over anymore.
pset(x,y) will get you a dot
circle (x,y),r will do a circle
not gonna touch blitting here
a simple method might be using formName(or picname).cls before each shape or whatever is moved. Be prepared for a lot of flickering if your not gonna dive deep into bltblit or Memory DC's though. If you go the blt and DC route come back when you understand those for more help.
-
Mar 29th, 2002, 09:58 PM
#3
Thread Starter
Hyperactive Member
i don't get step number2! thanx for that guide by the way...
-
Apr 1st, 2002, 08:28 AM
#4
Frenzied Member
you have a certain width for your map.
instead of doing the calculations yourself how many pixels represent what on your pic you just set the scalemode to user and the scalewidth to you width. let's say you got a map in your task that is supposed to be 200 meters than you just put in 200 into scalewidth, do the same for the hight and follow the guidelines posted by joey
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 1st, 2002, 09:30 AM
#5
Hyperactive Member
Well intrpreted /\/\issinthrop! This should get you there fkheng.
-
Apr 1st, 2002, 01:14 PM
#6
Frenzied Member
MY NAME IS MISANTHROP
why can't anyone spell my name right???
you even bothered to write /\/\ instead of M.
Misanthrop(e).
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 2nd, 2002, 05:35 AM
#7
Fanatic Member
I spelled it right the first time *proud* 
Anyways. The ScaleWidth thing is a nice way to do it, just make sure you don't set the ScaleWidth to represent for example kilometers when you need to set the dots per meter (we don't use miles here ), as that would make it difficult to position them...
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 2nd, 2002, 08:25 AM
#8
Frenzied Member
true
and if the program is to draw those dots and stuff more regularly you better figure out your own scale thing and use the API (setPixel) because it is way faster!
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 4th, 2002, 01:02 PM
#9
Thread Starter
Hyperactive Member
there are so many dots on the form, how do i determine the coordinate of each dot?
-
Apr 4th, 2002, 01:04 PM
#10
Frenzied Member
I thought you would draw them yourself... whenever you draw one you pass the coordiantes...
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 4th, 2002, 01:14 PM
#11
Thread Starter
Hyperactive Member
teh lines are already on the graphic itself, the thing is now, how do i proceed from there?
-
Apr 4th, 2002, 01:32 PM
#12
Frenzied Member
so you need to find lines in a picture file?
that is gonna be a little more challenging...
is the picture clean? are the lines in a different color than anything else?
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 5th, 2002, 01:15 AM
#13
Thread Starter
Hyperactive Member
yeap, the color is different from the other elements on the picture...
-
Apr 5th, 2002, 02:20 AM
#14
Thread Starter
Hyperactive Member
so wat if the color is differnet, how can it be achieved?
also, er........how do I find out the X, Y coordinates on a form at design-time? there are many small dots on the form....how do i make the coordinates out?
how do i make a picture appear at a specified coordinatE?
-
Apr 5th, 2002, 10:36 AM
#15
Frenzied Member
well since the color is different all you have to do is go through every pixel and look if it's the color you are looking for, otherwise you would have needed to recognize shapes what would have been much harder.
what do you mean by the X,Y coordinates on a form?
and if you load the picture into a picturebox than you can just set the left and top properties. If you blt the picture onto a dc you have to give the coordinates anywayws...
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 6th, 2002, 11:47 PM
#16
Lively Member
I have two destination in the map. Lets say from destination A to destination B takes 6 hours.
How do i set that the particular circle is in the middle of the two destination after 3 hours ???
I thought of using timer, but timer only can set it in terms of seconds for the interval but not hours.
How can i solved this problem ???
-
Apr 7th, 2002, 06:37 AM
#17
Frenzied Member
you want the program to actually take 6 hours for a task that would take 6hours in reality? If so you will probably run into some trouble, because noramally I would tell you to use GetTickcount, but that gets resetted after a day or two (other people here will give you more info on that) and timers are just sucky.
But if you really would want to you could measure any time using a timer (even though timers remain inaccurate) by just setting it's interval to a minute and than count how many times the event occured... after 60 times it would be one hour and so on...
what I think would be way better would be to make a 'in program time' which runs faster than the real time so you can speed things up! (and make programming easier or at least cleaner)
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 7th, 2002, 07:10 AM
#18
Member
I think that's an example winsonlee is giving us.
Goes like this:
You need to know how far along the journey you are. Therefore:
Code:
k = timetotal / timenow
i = (x1 - x2) / k
j = (y1 - y2) / k
if j < 0 then j = -j
if i < 0 then i = -i
makecircle(i, j)
Sorry about the psuedo-code.
That gets the totaltime, and divides it by the time now (in your case, equalling 2, because 6/3 = 2/1 = 2)
Then, it gets the point in the middle of the line (assuming the line is from x1, y1 to x2, y2), and stores the points at i, j.
The little if statements make sure i and j are not negative (x1-x2 sometimes does that)
Then it makes a circle and i, j.
if you want to do that after 3 horus, just use the timer (1000 = 1 second, so 60000 = I minute, so 3600000 = 1 hour, so 10800000 = 3 hours), or use GetTickCount, and put in 10800000.
If you don't know how to use GetTickCount, sorry, I have to go now. 
Good luck.
Last edited by SapphireGreen; Apr 7th, 2002 at 07:13 AM.
On Error Give Up
Mind over matter. Then if it doesn't matter, you lose your mind.
-
Apr 7th, 2002, 08:48 AM
#19
Frenzied Member
that should work theoretically, while I am not sure if you can put numbers that high into the timer control!
that is why I propsed to have it count minutes....
for gettickcount just open the API viewer copy the declaration and paste it into you project than you can use it like that:
lngTime = gettickcount 'LngTime now has the value of how many milliseconds the system is up...
now you could calculate how much time has passed since you assigne the ticks to lngTime by
(gettickcount-lgntime)/1000 'would give you the seconds that have passed for example....
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 9th, 2002, 03:11 PM
#20
Thread Starter
Hyperactive Member
is there any code which allows me then to find out the difference between 2 given times?
i plan to find the difference between 2 times and then take the difference and assign it to timer1.interval. Shouldn't this be possible?
-
Apr 9th, 2002, 03:13 PM
#21
Thread Starter
Hyperactive Member
i am actually at a stage now, where i have followed joey's step 3 which was mentioned earlier in this thread (I did not follow the other steps, but used that idea).
SO now if i can fin dthe difference in time, then the next challenge would be "How do I spread the coordinates for the picture to move upon over timer1.interval?"
-
Apr 9th, 2002, 03:20 PM
#22
Frenzied Member
well basically I am sure that you can get the difference between two times. in which format do you get them?
I am not exactly sure what you want to do now.
what are those two time representing?
basically if you move from one point to another you should get the slope m and the offset c and than you can just go there in a loop
y=m*x+c
so you increase x depend to the time and you will get from the first point to the second one.
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 9th, 2002, 03:26 PM
#23
Thread Starter
Hyperactive Member
oh no no, i do not intend to use formulas here...
one is a time which i have stored in a database, and another is captured real-time from the system...
what i need to know is that if there is any code or method available which already does the subtraction between 2 given times?
I have assigned the coordinates along a curved line to an array, therefore I have the coordinates for a given route.
So if i want to move a picture from a source to its destination, how do I do that over a given time? Moreover, how do I spread it out evenly accross the amount of coordinates i have?
-
Apr 9th, 2002, 03:33 PM
#24
Frenzied Member
well if you have all the coordiantes where you want the picture to be at at a certain time you can just have a static var increase by one every time the timer event occurs and than move the pic like:
pic.x = coordinates(theIncreasingVar).x
pic.y = coordinates(theIncreasingVar).y
did that make any sense?
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 9th, 2002, 03:42 PM
#25
Thread Starter
Hyperactive Member
nope, it did not, not in my case
you're assuming that the line i'm using is a straight line
i can't increment the value of the variable by one each time as i'm using a curve line, which can bend anywhere....
any other way?
-
Apr 10th, 2002, 06:43 AM
#26
Frenzied Member
well that would still work.
It gets better the more points you have but unless you don't have a y coordinate per pixel it is best to connect those you have by lines even if it makes a curve
you could try that pretty fast on a sine wave and see that it gives you quite good appearance.
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 10th, 2002, 07:54 AM
#27
Thread Starter
Hyperactive Member
ok, but wat if i do have an x and a y coordinate per pixel?
i have stored all the coordinates of the curve and saved them into an array...
how can i manipulate them now?
-
Apr 10th, 2002, 08:51 AM
#28
Frenzied Member
what do you want to manipulate?
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 10th, 2002, 10:03 AM
#29
Thread Starter
Hyperactive Member
manipulate the coordinates, so that i know how to move a picture (which is actually a dot), over them with respect to time...
-
Apr 10th, 2002, 10:33 AM
#30
Frenzied Member
hm sorry I still don't get you right.
do you have all the coordiantes where the point should be sometimes or where it should be all over it's way there?
well maybe someone else knows what you want to do now. I really don't understand...
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 10th, 2002, 12:44 PM
#31
Thread Starter
Hyperactive Member
I haev the coordinates. Among al tehse coordinates, some are assigned to special arrays, which signify that each represents a state.
What I am doing is loading the source and destination from a database, for any given record, matching the source and destination with the appropriate coordinates, and then make the bus moev along those coordinates from source to destination accross a given time....
get it?
-
Apr 10th, 2002, 12:59 PM
#32
Frenzied Member
so you know the time the whole trip takes and now you want to know where the bus has to be in between?
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 10th, 2002, 01:04 PM
#33
Thread Starter
Hyperactive Member
yeap
i know the trip duration, now i want to know, wat if the user opens the form in the middle of the trip duration, i'll haev to calculate the position of the bus at that time, and determine which coordinate it has to start from...
and from there onwards, it has to move according to the remaining trip duration till it reaches its destination...
-
Apr 10th, 2002, 01:57 PM
#34
Frenzied Member
hm as of right now I can't tell you of any great way....
basically you need the avarage velocity.. to get that you need the distance... you could get the distance by doing a for loop and adding up the distance from point i and i+1... than you can get the average velocity... than you could put marks in some array how far every point is... than you could calculate how far you are at the time the user opens the form... than you first go to the point it needs to be
from there on you need to get the way from this point to the next one as a function which would be easy... well I guess you know what I mean and you could have just come up with it yourself...
I really can't think of any more elegant way right now...
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 10th, 2002, 04:32 PM
#35
Thread Starter
Hyperactive Member
er........is there any way you could elaborate on wat u just said?
-
Apr 10th, 2002, 04:35 PM
#36
Frenzied Member
haha tomorrow ok? it's 11:30 pm and I have to get up early...
good luck working that out...
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 10th, 2002, 05:30 PM
#37
PowerPoster
Good grief DM!
I've just read this through and it seems to have got somewhat complicated along the way.
Just to confirm fkheng...
You have a map.
You know the start point of this bus and the end point.
You know the route in between.
You know how long it takes to make the trip.
You know the start time.
What you want to do is draw is how far the bus is along the route, based on the current time?
If you confirm/correct the above then you'll be pleased to know what I think you're trying to do is childishly simple... 
On the other hand, if the above is completely wrong - I'll get my coat...
Gentile or Jew,
O you who turn the wheel and look to windward,
Consider Phlebas, who was once handsome and tall as you...
-
Apr 11th, 2002, 12:25 AM
#38
Frenzied Member
hi well when my alarm woke me up this morning I suddenly had an easier Idea... gonna post it here right after school...
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 11th, 2002, 07:07 AM
#39
Thread Starter
Hyperactive Member
/\/\isanThr0p, would lvoe to have u share that idea with us....
by the way, just curious, what does ur username stand for?
arbiter, u r absolutely right, that's wat i would like to do...
well, if that's easy, i'd like to tkae it a step further...
after finding out the current position of the bus at that current time, i would like the bus to move on till it reaches its destination...
any ideas?
-
Apr 11th, 2002, 07:11 AM
#40
Thread Starter
Hyperactive Member
hey arbiter, is that signature of urs a verse from the bible?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|