cocoaTouch/otherSrc/CGPointUtils.c
author koda
Thu, 07 Jan 2010 05:23:23 +0000
changeset 2678 334016e8d895
child 2725 89908847b155
permissions -rw-r--r--
injection of custom code in SDL for iPhone in order to implement our frontend initial support for (real) multitouch events
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 );
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    20
};
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
	//degs = degrees(atan((top - bottom)/(right - left)))
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
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    30
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
    31
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    32
	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
    33
	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
    34
	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
    35
	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
    36
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    37
	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
    38
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    39
	return radiansToDegrees(rads);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    40
}