-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameMath.m
68 lines (52 loc) · 1.55 KB
/
GameMath.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// GameMath.m
// openfireipad
//
// Created by X3N0 on 8/17/10.
// Copyright 2010 Rage Creations. All rights reserved.
//
#import "GameMath.h"
@implementation GameMath
+(CGPoint)MultiplyVel:(CGPoint)cref :(float)mfact{
cref = CGPointMake(cref.x * mfact, cref.y * mfact);
return cref;
}
+(CGPoint)GetAngle:(CGPoint) initialp :(CGPoint) secondp{
float distvar = ((initialp.x - secondp.x) * (initialp.x - secondp.x));
float distvar2 = ((initialp.y - secondp.y) * (initialp.y - secondp.y));
if (distvar + distvar2 == 0){
distvar = 1;
distvar2 = 3;
}
float veldistance = sqrt((distvar+distvar2));
distvar = ((fabsf(initialp.x-secondp.x))/veldistance);
distvar2 = ((fabsf(initialp.y-secondp.y))/veldistance);
if (secondp.x < initialp.x){
distvar = -distvar;
}
if (secondp.y < initialp.y){
distvar2 = -distvar2;
}
CGPoint fvel = CGPointMake(distvar,distvar2);
return fvel;
}
+(CGPoint)CombineVel:(CGPoint)v1 :(CGPoint)v2{
v1 = CGPointMake(v1.x+v2.x,v1.y+v2.y);
return v1;
}
+(float)GetDist:(CGPoint) initialp :(CGPoint) secondp{
float distvar = ((initialp.x - secondp.x) * (initialp.x - secondp.x));
float distvar2 = ((initialp.y - secondp.y) * (initialp.y - secondp.y));
if (distvar + distvar2 == 0){
distvar = 1;
distvar2 = 3;
}
float fdist = fabsf(sqrt((distvar+distvar2)));
return fdist;
}
+(void)rotate0: (UIImageView *)ww :(CGPoint)pt{
CGPoint tangle2 = [self GetAngle:(ww.center) :(pt)];
float ftangle = atan2( tangle2.y, tangle2.x );
ww.transform = CGAffineTransformMakeRotation(ftangle + 1.57);
}
@end