cocoaTouch/otherSrc/CGPointUtils.c
author nemo
Mon, 22 Mar 2010 11:52:16 +0000
changeset 3043 3acdb4dac6eb
parent 2725 89908847b155
child 3385 361bd29293f4
permissions -rw-r--r--
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     1
/*
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     2
 *  CGPointUtils.c
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     3
 *  PinchMe
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     4
 *
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     5
 *  Created by Jeff LaMarche on 8/2/08.
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     6
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     7
 *
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     8
 */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     9
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    10
#include "CGPointUtils.h"
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    11
#include <math.h>
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    12
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    13
#define degreesToRadian(x) (M_PI * x / 180.0)
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    14
#define radiansToDegrees(x) (180.0 * x / M_PI)
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    15
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    16
CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    17
	CGFloat deltaX = second.x - first.x;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    18
	CGFloat deltaY = second.y - first.y;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    19
	return sqrt(deltaX*deltaX + deltaY*deltaY );
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2678
diff changeset
    20
}
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    21
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    22
CGFloat angleBetweenPoints(CGPoint first, CGPoint second) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    23
	CGFloat height = second.y - first.y;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    24
	CGFloat width = first.x - second.x;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    25
	CGFloat rads = atan(height/width);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    26
	return radiansToDegrees(rads);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    27
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    28
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    29
CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    30
	CGFloat a = line1End.x - line1Start.x;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    31
	CGFloat b = line1End.y - line1Start.y;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    32
	CGFloat c = line2End.x - line2Start.x;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    33
	CGFloat d = line2End.y - line2Start.y;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    34
	CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    35
	return radiansToDegrees(rads);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    36
}