Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Circle.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
A_jj74
Cheater
Reputation: 0

Joined: 14 Nov 2009
Posts: 41

PostPosted: Sun Mar 07, 2010 3:15 pm    Post subject: [C++] Circle. Reply with quote

How would I get the Degree of the Circle at the point where the line (x1,y1,x2,y2) intersects the circle programatically?

Heres an Image:

I know its 225 but I want to do it Programatically.
Thanks in advance.
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Sun Mar 07, 2010 3:44 pm    Post subject: Reply with quote

You drawed your circle wrong, 360 is one round + 0 degrees, it should have been:
12:00 O'clock = 0 degrees.
03:00 O'clock = 90 degrees.
06:00 O'clock = 180 degrees.
09:00 O'clock = 270 degrees.

Anyway, you can easily do this with trigonometry:
X = R * sin D
Y = R * cos D

(R = Radius, D = Degrees)

With 0 degrees being in the same place as in your draw, simply decrease 90 from degrees before you calculate the location. just use your head.
Back to top
View user's profile Send private message
A_jj74
Cheater
Reputation: 0

Joined: 14 Nov 2009
Posts: 41

PostPosted: Sun Mar 07, 2010 5:18 pm    Post subject: Reply with quote

Ooops lol!

Ok I've got that with the Trigonometry.

But what do you mean with:
Quote:
With 0 degrees being in the same place as in your draw, simply decrease 90 from degrees before you calculate the location. just use your head.



I want my Cursor to start moving from the line (CPX,CPY,X,Y)
(In the image it was x1,y1,x2,y2)
CPX is the Current X pos.
CPY is the Current Y pos.
X is the x pos of the center point of the Circle.
Y is the y pos of the center point of the Circle.

My code so far:
Code:
#include <iostream>
#include <windows.h>
#include <math.h>
using namespace std;

void Circle(int CPX, int CPY, int X, int Y, int rad)
{
    //CPX and CPY arent implemented yet
    float deg = 0;
    int dx = X;
    int dy = Y;
    float maxdeg = 6.4+deg; //+ deg to make it a full circle, if the cursor starts at a higher degree than 0
    Sleep(5);
    do
    {
        X = round(rad * cos(deg));
        Y = round(rad * sin(deg));
        SetCursorPos(X+dx, Y+dy);
        deg += 0.01;
        Sleep(2);
    }
    while (deg <= maxdeg);
}

int main()
{
    Circle(100,100,200,200,100);
return 0;
}


Thanks.
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Mon Mar 08, 2010 1:31 am    Post subject: Reply with quote

I use Atan2 to calculate this.
Code:
double angle = Atan2(x2-x1,y2-y2);
I'm a little unsure what you are asking in your second post though. Do you want the cursor to move in a circular pattern? If so, I made a function which calculates the points along a circular trajectory which you can use:
Code:

// It's worth noting that this is coded in C#, so there might be some diffrences in syntax.
public void Step(int step)
        {
            CurrentVelocity = StartVelocity + Acceleration * step;// These are doubles
            Length = 0.5 * (StartVelocity + CurrentVelocity) * step;
            _angBuff = Length / _lenToAng;// _lenToAng is the result of Circumference / (2*pi)
            CurrentPosition = Center + (_clockwise ? Vector.GetVectorByLengthAndAngle(_radius, _angBuff + (StartPosition - Center).GetAngle()) : Vector.GetVectorByLengthAndAngle(_radius, (StartPosition - Center).GetAngle()- _angBuff ));// CurrentPosition, StartPosition and Center are 2D vector objects(My own custom class). _radius is double. _clockwise is bool.
        }
public static Vector GetVectorByLengthAndAngle(double length, double angle)
        {
            length = Math.Abs(length);
            return new Vector(length * Math.Cos(angle), length * Math.Sin(angle));
        }

If there is something in the code you don't understand, don't hesitate to ask!

_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Mon Mar 08, 2010 2:27 am    Post subject: Reply with quote

Deltron Z wrote:
12:00 O'clock = π/2 radians, 90 degrees.
03:00 O'clock = 0 radians, 0 degrees.
06:00 O'clock = 3π/2 radians, 270 degrees.
09:00 O'clock = π radians, 180 degrees.


FTFY, YW.
Back to top
View user's profile Send private message
A_jj74
Cheater
Reputation: 0

Joined: 14 Nov 2009
Posts: 41

PostPosted: Mon Mar 08, 2010 2:46 am    Post subject: Reply with quote

Odecey thanks for your reply but C# doesn't help me a lot =/.

Basically I need to set the "Starting Degree" (where the mouse should start to move from) to that, I don't know how to explain it.


PS: It should move the Cursor "along" the Imaginary Circle (the Circle with the Black Perimeter), just wrote this, not that you think it should move the Cursor around the Black Circle with a +Distance.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Mon Mar 08, 2010 4:04 am    Post subject: Reply with quote

Most I could be bothered to write. You might want to use a vector math library to make it cleaner.

Code:
// MoveMouseInCircle.cpp : Defines the entry point for the console application.
//

#include <Windows.h>
#include <cmath>
#include <utility>

using namespace std;

struct Point {
   double X;
   double Y;

   Point()
      : X(0), Y(0) {}

   Point(double x, double y)
      : X(x), Y(y) {}
};

class GenerateCircleCoOrds {
   double const radius_;
   double currentAngle_;

public:
   GenerateCircleCoOrds(double x, double y)
      : radius_(::sqrt(::pow(x, 2) + ::pow(y, 2))),
        currentAngle_(::atan2(x, y)) {}

   Point Step(double dPhi) {
      currentAngle_ += dPhi;
      return Point(radius_ * ::cos(currentAngle_), radius_ * ::sin(currentAngle_));
   }
};

int main()
{
   GenerateCircleCoOrds circle(-200, -200);
   RECT rect;
   if(::GetWindowRect(::GetDesktopWindow(), &rect)) {
      for(int x = 0; x < 200; ++x) {
         Point point = circle.Step(6.28/100);
         ::SetCursorPos(rect.right/2 + point.X, rect.bottom/2 - point.Y);
         ::Sleep(15);
      }
   }
   return 0;
}
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Mon Mar 08, 2010 5:00 am    Post subject: Reply with quote

Tvirusx1 wrote:
Ooops lol!

Ok I've got that with the Trigonometry.

But what do you mean with:
Quote:
With 0 degrees being in the same place as in your draw, simply decrease 90 from degrees before you calculate the location. just use your head.


Say that you're making an analog clock, and you want 0 degrees to point to 3 O'clock (as in your draw), simply increase the degrees by 90, then it'll point to 3 O'clock (90 degrees) when the input (or any value used to calculate the right time's degrees) should point to 12:00 O'clock. it's useful when, for example, you have a character in a 3D world and you want side view of it, or add 180 degrees for viewing it from the back.

Tvirusx1 wrote:
I want my Cursor to start moving from the line (CPX,CPY,X,Y)
(In the image it was x1,y1,x2,y2)
CPX is the Current X pos.
CPY is the Current Y pos.
X is the x pos of the center point of the Circle.
Y is the y pos of the center point of the Circle.

My code so far:
Code:
#include <iostream>
#include <windows.h>
#include <math.h>
using namespace std;
...
...
        X = round(rad * cos([b]deg[/b]));
        Y = round(rad * sin([b]deg[/b]));
...
...

sin and cos functions from Math.h takes Radians, you passed the parameter as degrees. simply convert by dividing by 180 (half a rotation in degrees) and multipy by PI. (half a rotation in radians, 3.14...)

I'd do it like this: (spiral Razz )
Code:
   int Width = GetSystemMetrics(SM_CXSCREEN);
   int Height = GetSystemMetrics(SM_CYSCREEN);
   int X, Y, Degrees = 0;
   double Radius = 1;

   while (Radius < min(Width, Height))
   {
      X = (int)(Radius * sin((double)(Degrees % 360) / 180.0 * 3.14));
      Y = (int)(Radius * cos((double)(Degrees % 360) / 180.0 * 3.14));
      SetCursorPos(X + Width / 2, Y + Height / 2);

      Degrees++;
      Radius += 0.5;

      Sleep(5);
   }
Back to top
View user's profile Send private message
A_jj74
Cheater
Reputation: 0

Joined: 14 Nov 2009
Posts: 41

PostPosted: Mon Mar 08, 2010 6:56 am    Post subject: Reply with quote

Quote:
Say that you're making an analog clock, and you want 0 degrees to point to 3 O'clock (as in your draw), simply increase the degrees by 90, then it'll point to 3 O'clock (90 degrees) when the input (or any value used to calculate the right time's degrees) should point to 12:00 O'clock. it's useful when, for example, you have a character in a 3D world and you want side view of it, or add 180 degrees for viewing it from the back.


It wasn't me who decided that 0 should be at 3 O'Clock lol.
C++ calculates 0 Degrees/Radians at 3 O'Clock.

What I was trying to do was to set the "0" to the direction of My X and Y pos (CPX,CPY).

I think this code should do, it's not too accurate though.
Code:
#include <iostream>
#include <windows.h>
#include <math.h>
using namespace std;

float PI = 3.14159265358979323846264338327950288;

float DegreesToRadians(float Degrees)
{
      float Radians;
      Radians = Degrees * (PI/180);
      return Radians;
}

float RadiansToDegrees(float Radians)
{
      float Degrees;
      Degrees = Radians * (180/PI);
      return Degrees;
}

void Circle(int CPX, int CPY, int X, int Y, int Radius)
{
    float Degrees = 0;
    if((CPX<X)&&(CPY==Y))
        Degrees = 180;
    if((CPX<X)&&(CPY<Y))
        Degrees = 225;
    if((CPX<X)&&(CPY>Y))
        Degrees = 135;
    if((CPX==X)&&(CPY>Y))
        Degrees = 90;
    if((CPX>X)&&(CPY>Y))
        Degrees = 45;
    if((CPX>X)&&(CPY==Y))
        Degrees = 0;
    if((CPX==X)&&(CPY>Y))
        Degrees = 270;
    if((CPX>X)&&(CPY<Y))
        Degrees = 315;
    float Radians = DegreesToRadians(Degrees);
    int dx = X;
    int dy = Y;
    float MaxDegrees = 360+Degrees; //+ deg to make it a full circle, if the cursor starts at a higher degree than 0
    Sleep(5);
    do
    {
        X = round(Radius * cos(Radians));
        Y = round(Radius * sin(Radians));
        SetCursorPos(X+dx, Y+dy);
        Radians += 0.01;
        Degrees = RadiansToDegrees(Radians);
        Sleep(2);
    }
    while (Degrees <= MaxDegrees);
}

int main()
{
    cout << "Upper left" << endl;
    Circle(100,100,200,200,100);//upper left
    cout << "Bottom right" << endl;
    Circle(300,300,200,200,100);//bottom right
    cout << "Bottom left" << endl;
    Circle(100,300,200,200,100);//Bottom left
    cout << "Upper right" << endl;
    Circle(300,100,200,200,100);
    cin.get();
return 0;
}


If theres a way I could improve it please let me know Very Happy.
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Mon Mar 08, 2010 7:27 am    Post subject: Reply with quote

I don't understand what you were trying to do in this piece of code...
Try using the code I've posted before and see what happens. Wink
Back to top
View user's profile Send private message
A_jj74
Cheater
Reputation: 0

Joined: 14 Nov 2009
Posts: 41

PostPosted: Mon Mar 08, 2010 11:52 am    Post subject: Reply with quote

Deltron Z wrote:
I don't understand what you were trying to do in this piece of code...
Try using the code I've posted before and see what happens. Wink


I have tried it, it moves in a Spiral, but thats not what I need =/.
(Although it will be useful for me in the future)
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Mon Mar 08, 2010 12:07 pm    Post subject: Reply with quote

So simply use a constant radius. use your head. Confused
Back to top
View user's profile Send private message
A_jj74
Cheater
Reputation: 0

Joined: 14 Nov 2009
Posts: 41

PostPosted: Mon Mar 08, 2010 8:07 pm    Post subject: Reply with quote

Deltron Z wrote:
So simply use a constant radius. use your head. Confused


I have posted a working code at Post #9.
But it needs to be improved =/.

@Your Spiral code, I know I would have to use a Constant Radius.


I somewhat got it.

Close Thread?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites