[Objective-C] Categories 의 활용
Objective-C & OpenGL ES 2009. 7. 28. 23:33 |
#import <Foundation/Foundation.h>
#import "Texture2D.h"
@interface Texture2D (SpriteAnimation)
- (void) drawAtPointTest:(CGPoint)point;
@end
#import "Texture2DEx.h"
@implementation Texture2D (SpriteAnimation)
- (void) drawAtPointTest:(CGPoint)point
{
_maxS = 63.0 / 256.0; // test
GLfloat coordinates[] = { 0, _maxT,
_maxS, _maxT,
0, 0,
_maxS, 0 };
GLfloat width = (GLfloat)_width * _maxS,
height = (GLfloat)_height * _maxT;
width = 63.0; // test
GLfloat vertices[] = { -width / 2 + point.x, -height / 2 + point.y, 0.0,
width / 2 + point.x, -height / 2 + point.y, 0.0,
-width / 2 + point.x, height / 2 + point.y, 0.0,
width / 2 + point.x, height / 2 + point.y, 0.0 };
glBindTexture(GL_TEXTURE_2D, _name);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
@end