/
PASoundListener.m
79 lines (69 loc) · 1.81 KB
/
PASoundListener.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
69
70
71
72
73
74
75
76
77
78
79
/* cocos2d for iPhone
*
* http://www.cocos2d-iphone.org
*
* Copyright (C) 2009 by Florin Dumitrescu.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
*
* You will find a copy of this license within the cocos2d for iPhone
* distribution inside the "LICENSE" file.
*
*/
#import "PASoundListener.h"
@implementation PASoundListener
- (id)init {
return [self initWithPosition:ccp(240,160)]; // middle of screen
}
- (id)initWithPosition:(CGPoint)pos {
if ((self = [super init])) {
self.position = pos;
self.orientation = 0;
}
return self;
}
- (CGPoint)position {
return position;
}
- (void)setPosition:(CGPoint)pos {
position = pos;
float x,y;
switch ( [[CCDirector sharedDirector] deviceOrientation] ) {
case CCDeviceOrientationLandscapeLeft:
x = pos.x - 240.0f;
y = 160.0f - pos.y;
break;
case CCDeviceOrientationLandscapeRight:
// XXX: set correct orientation
x = pos.x - 240.0f;
y = 160.0f - pos.y;
break;
case CCDeviceOrientationPortrait:
x = pos.x;
y = pos.y;
break;
case CCDeviceOrientationPortraitUpsideDown:
// XXX: set correct orientation
x = pos.x;
y = pos.y;
break;
}
float listenerPosAL[] = {x, y, 0.0f};
// Move our listener coordinates
alListenerfv(AL_POSITION, listenerPosAL);
}
- (float)orientation {
return orientation;
}
- (void)setOrientation:(float)o {
orientation = o;
// float ori[] = {cos(o + M_PI_2), sin(o + M_PI_2), 0., 0., 0., 1.};
float ori[] = {0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; // I want my listener to stay heads-up always, regardless of the ship's orientation
// Set our listener orientation (rotation)
alListenerfv(AL_ORIENTATION, ori);
}
- (void)dealloc {
[super dealloc];
}
@end