I have this code which I'd imagine would work, so I don't really need help on that yet -- I need help getting the compiler to accept it.
So, lets see, I'm using the newest Xcode, and am trying to compile this as a Console Tool. Most of the errors I'm getting when I try to build this have to do with the headers CGEvent and CGEventTypes not being found (but theres one about not being able to use a... function as a function
), as you'll see if you try to build it. I'd also like a better alternative to my homebrew SleepMS function, if you could find one. (I saw some like nanosleep, but couldn't find out what a timespec struct looked like.)
If someone could help me find out where those two header files are and maybe supply the information needed to use nanosleep or a similar function, and point out whatever else I've almost irreversibly screwed up, I will be a happy forum user
	
	
	
		
	
		
			
		
		
	
				
			So, lets see, I'm using the newest Xcode, and am trying to compile this as a Console Tool. Most of the errors I'm getting when I try to build this have to do with the headers CGEvent and CGEventTypes not being found (but theres one about not being able to use a... function as a function
If someone could help me find out where those two header files are and maybe supply the information needed to use nanosleep or a similar function, and point out whatever else I've almost irreversibly screwed up, I will be a happy forum user
		Code:
	
	#include <iostream>
#include <time.h>
#include <math.h>
#include "ApplicationServices/CoreGraphics/CGEvent.h"
#include "ApplicationServices/CoreGraphics/CGEventTypes.h"
int	    Distance(int x1, int y1, int x2, int y2);
CGPoint PointOnCubicBezier(const CGPoint *cp, float t);
CGPoint Spline(CGPoint* Result, int sx, int sy, int ex, int ey, CGPoint CtrlP1, CGPoint CtrlP2);
void    BezierMouse(int x1, int y1, int x2, int y2, CGPoint p1, CGPoint p2);
int main (int argc, char * const argv[]) {
	CGPoint tmp1 = {500, 500}, tmp2 = {750, 150};
	BezierMouse(100, 100, 1000, 1000, tmp1, tmp2);
    return 0;
}
int	Distance(int x1, int y1, int x2, int y2) {
	return sqrt(pow((x2 - x1), 2)) + sqrt(pow((y2-y1), 2));
}
CGPoint PointOnCubicBezier(const CGPoint *cp, float t) {
	
	float zx, zy, bx, by, cx, cy, tSquared, tCubed, Curve;
	int I;
	CGPoint RBuffer;
	
	Curve = 3.0;
	cx = Curve * (cp[1].x - cp[0].x);
	bx = Curve * (cp[2].x - cp[1].x) - cx;
	ax = cp[3].x - cp[0].x - cx - bx;
 
	cy = Curve * (cp[1].y - cp[0].y);
	by = Curve * (cp[2].y - cp[1].y) - cy;
	ay = cp[3].y - cp[0].y - cy - by;
 
	tSquared = t * t;
	tCubed	 = t * t * t;
	
	RBuffer.x = round((ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x);
	RBuffer.y = round((ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y);
	
	return RBuffer;
}
int Spline(CGPoint* Result, int sx, int sy, int ex, int ey, CGPoint CtrlP1, CGPoint CtrlP2) {
	float theta, theta_inc;
	int Dist = 0, I = 0;
	CGPoint CtrlPoints[] = {{sx, sy}, CtrlP1, CtrlP2, {ex, ey}};
	
	Dist = Distance(sx, sy, ex, ey);
	theta_inc = 1.0 / Dist;
	theta = 0.0;
	
	do {
		theta_inc = min(1.0 - theta, theta_inc);
		theta	  = theta + theta_inc;
		Result[I] = PointOnCubicBezier(CtrlPoints, theta);
		I++;
	} while(theta >= 1.0);
	
	Result[I] = CtrlPoints[3];
	return I;
}
void BezierMouse(int x1, int y1, int x2, int y2, CGPoint p1, CGPoint p2) {
	CGPoint *Pt;
	int I, J = 0;
	timespec WaitT;
	
	WaitT.tv_sec  = 0;
	WaitT.tv_nsec = 8000000;
	
	I = Spline(Pt, x1, y1, x2, y2, p1, p2);
	
	for(; J <= I; J++) {
		CGEventCreateMouseEvent(NULL,
		                        kCGEventMouseMoved,
		                        Pt[J],
								NULL);
		nanosleep(&WaitT, NULL);
	}
}