Solved

Moving Cursor, using Pythagorous - Nietod

Posted on 2000-04-10
3
210 Views
Last Modified: 2010-04-02
nietod, you previously advised me to implement 'Pythagorous's theory' to move the cursor.

I have tried to do what you said, but i am still having problems..can you help me out - or tell me where i am going wrong

here is the code


if (Dest.x > Source.x) //Move to the right
   {
//   xdir = RIGHT;
   xlength=Dest.x - Source.x;
//   xdistance=Dest.x - Source.x;
   }
else
   {
   xlength = Source.x - Dest.x; //Move to the left
//   xdistance = Source.x - Dest.x; //Move to the left
//   xdir = LEFT;
   }

if (Dest.y > Source.y) //Move Downwards
   {
   ylength=Dest.y - Source.y;
//   ydistance=Dest.y - Source.y;
//   ydir = DOWN;
   }
else
   {
   ylength = Source.y - Dest.y; //Move upwards
//   ydistance = Source.y - Dest.y;
//   ydir = UP;
   }


   xdistance=xlength;
   ydistance=ylength;

   xlength=xlength*xlength;
   ylength=ylength*ylength;

   hypot=abs(sqrt(xlength+ylength)); // work out length of the hypotenuse in pixels


   for (i=0;i<=hypot;i++) // move in pixels
   {
   xpos=abs((Source.x+(i*((float)xdistance/hypot))));
   ypos=abs((Source.y+(i*((float)ydistance/hypot))));

   SetCursorPos(xpos,ypos);
   Application->ProcessMessages();
   for (int pause = 0;pause < 1000000; pause++);;
   }


thanks

PS i have got new delay mechanism :-)

thanks
0
Comment
Question by:AntBon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:AntBon
ID: 2700683
Adjusted points from 10 to 25
0
 
LVL 22

Accepted Solution

by:
nietod earned 25 total points
ID: 2700810
POINT Dst;
POINT Src;
int DeltaX  = Dst.x - Src.x;
int DeltaY  = Dst.y - Src.y;

// this is perhaps rounded down, that is fine.
 int distance = (int) sqrt(DeltaX*DeltaX + DeltaY*DeltaY);

// you may wnat to start i at 1, not 0,  starting at 0
// makes the agorithm incude the Source point.  
for (int i = 0; i <=1 distance; ++i)
{
   int x = Src.x+ i*DeltaX/distance;
   int y =  Src.y+i*DeltaY/distance;
   // move cursor or do something with x and y.
}

That is it.  No need to worry about signs.  DeltaX and DeltaY are signed.  Although some rounding occurs (+ or - 1) for the interior points (because of integer coordinates) The final value of x and y should be exactly the destination coordinates.  (i.e there is no rounding errors in the final coordinates.
0
 

Author Comment

by:AntBon
ID: 2700882
Thanks very much, but i have just done it myself, but at least i can compare my solution with your, on the face of it they look the same, except i started my for loop at 0, but i will change now


Thanks Again
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question