summary refs log tree commit diff stats
path: root/libs/cocos2d/CCCamera.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/cocos2d/CCCamera.m')
-rwxr-xr-xlibs/cocos2d/CCCamera.m131
1 files changed, 131 insertions, 0 deletions
diff --git a/libs/cocos2d/CCCamera.m b/libs/cocos2d/CCCamera.m new file mode 100755 index 0000000..1ef6655 --- /dev/null +++ b/libs/cocos2d/CCCamera.m
@@ -0,0 +1,131 @@
1/*
2 * cocos2d for iPhone: http://www.cocos2d-iphone.org
3 *
4 * Copyright (c) 2008-2010 Ricardo Quesada
5 * Copyright (c) 2011 Zynga Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26
27#import "Platforms/CCGL.h"
28#import "CCCamera.h"
29#import "ccMacros.h"
30#import "CCDrawingPrimitives.h"
31
32@implementation CCCamera
33
34@synthesize dirty = dirty_;
35
36-(id) init
37{
38 if( (self=[super init]) )
39 [self restore];
40
41 return self;
42}
43
44- (NSString*) description
45{
46 return [NSString stringWithFormat:@"<%@ = %08X | center = (%.2f,%.2f,%.2f)>", [self class], self, centerX_, centerY_, centerZ_];
47}
48
49
50- (void) dealloc
51{
52 CCLOGINFO(@"cocos2d: deallocing %@", self);
53 [super dealloc];
54}
55
56-(void) restore
57{
58 eyeX_ = eyeY_ = 0;
59 eyeZ_ = [CCCamera getZEye];
60
61 centerX_ = centerY_ = centerZ_ = 0;
62
63 upX_ = 0.0f;
64 upY_ = 1.0f;
65 upZ_ = 0.0f;
66
67 dirty_ = NO;
68}
69
70-(void) locate
71{
72 if( dirty_ )
73 gluLookAt( eyeX_, eyeY_, eyeZ_,
74 centerX_, centerY_, centerZ_,
75 upX_, upY_, upZ_
76 );
77}
78
79+(float) getZEye
80{
81 return FLT_EPSILON;
82// CGSize s = [[CCDirector sharedDirector] displaySize];
83// return ( s.height / 1.1566f );
84}
85
86-(void) setEyeX: (float)x eyeY:(float)y eyeZ:(float)z
87{
88 eyeX_ = x * CC_CONTENT_SCALE_FACTOR();
89 eyeY_ = y * CC_CONTENT_SCALE_FACTOR();
90 eyeZ_ = z * CC_CONTENT_SCALE_FACTOR();
91 dirty_ = YES;
92}
93
94-(void) setCenterX: (float)x centerY:(float)y centerZ:(float)z
95{
96 centerX_ = x * CC_CONTENT_SCALE_FACTOR();
97 centerY_ = y * CC_CONTENT_SCALE_FACTOR();
98 centerZ_ = z * CC_CONTENT_SCALE_FACTOR();
99 dirty_ = YES;
100}
101
102-(void) setUpX: (float)x upY:(float)y upZ:(float)z
103{
104 upX_ = x;
105 upY_ = y;
106 upZ_ = z;
107 dirty_ = YES;
108}
109
110-(void) eyeX: (float*)x eyeY:(float*)y eyeZ:(float*)z
111{
112 *x = eyeX_ / CC_CONTENT_SCALE_FACTOR();
113 *y = eyeY_ / CC_CONTENT_SCALE_FACTOR();
114 *z = eyeZ_ / CC_CONTENT_SCALE_FACTOR();
115}
116
117-(void) centerX: (float*)x centerY:(float*)y centerZ:(float*)z
118{
119 *x = centerX_ / CC_CONTENT_SCALE_FACTOR();
120 *y = centerY_ / CC_CONTENT_SCALE_FACTOR();
121 *z = centerZ_ / CC_CONTENT_SCALE_FACTOR();
122}
123
124-(void) upX: (float*)x upY:(float*)y upZ:(float*)z
125{
126 *x = upX_;
127 *y = upY_;
128 *z = upZ_;
129}
130
131@end