ThreadBoard ArchivesSite FeaturesActiveworlds SupportHistoric Archives |
Finding the distance between two avatars (Sdk)
Finding the distance between two avatars // SdkprogrammerAug 17, 2001, 12:50am
Hello,
I was if someone can help me by telling my the C++ code for the AW SDK to find the distance between two avatars. I know it has to to with algebra and I think I get the math on how to do it, but I need an example. Thanks, Programmer john viperAug 17, 2001, 1:41am
Its really fairly straightforward. You need to set up a handler for the
AW_EVENT_AVATAR_ADD: aw_event_set(AW_EVENT_AVATAR_ADD, avatar_add); Every time someone appears, this method gets called. It will also be called if you call aw_state_change (I think) for every avatar that happens to be in the general viscinity of your bot. Inside of avatar_add(), you can have it add each avatar to some kind of list (perhaps a ListView in the GUI): void avatar_add() { // get AW_AVATAR_X and AW_AVATAR_Y and AW_AVATAR_Z and add it to a list } From some kind of list you can select two avatars and compare them with something like this: // xa and za are the X and Z positions of one avatar // ya and yb are the X and Z positions of another avatar int avatarDistance(int xa, int xb, int za, int zb) { int distance; int xdist; int zdist; xdist = xa - xb; zdist = za - zb; if(xdist < 0) xdist -= (xdist * 2); //We cant sqrt negatives if(zdist < 0) zdist -= (zdist * 2); //"" "" "" "" distance = sqrt(xdist^2 + zdist^2); //Good 'ol Pythagoras :-) return distance; } Of course, this code only supports avatars on the ground. We haven't gotten to the part in Geometry where we can find 3-dimentional stuff, but I am sure someone around here can help you with that :-) Hope this helps. -JV [View Quote] > Hello, > > I was if someone can help me by telling my the C++ code for the AW > SDK to find the distance between two avatars. I know it has to to with > algebra and I think I get the math on how to do it, but I need an > example. > > Thanks, > > Programmer > > -- John Viper (#296714) jviper at jtsoft.net http://www.jtsoft.net "Life on Earth may be expensive, but it does include a free trip around the sun..." -anonymous |