-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.m
More file actions
55 lines (34 loc) · 1.39 KB
/
Sprite.m
File metadata and controls
55 lines (34 loc) · 1.39 KB
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
//
// Sprite.m
// IntroOpenGL
//
// Created by boyapati ravi kumar on 30/06/15.
// Copyright (c) 2015 Custom Furniish. All rights reserved.
//
#import "Sprite.h"
@interface Sprite()
@property (nonatomic, weak) GLKBaseEffect *baseEffect;
@end
@implementation Sprite
- (id)initWithEffect:(GLKBaseEffect *)baseEffect {
if( (self = [super init])) {
self.baseEffect = baseEffect;
}
return self;
}
- (void) render {
self.baseEffect.texture2d0.name = self.textureInfo.name;
self.baseEffect.texture2d0.target = self.textureInfo.target;
GLKMatrix4 modelViewMatrix = GLKMatrix4Translate(GLKMatrix4Identity, self.position.x, self.position.y, 0);
GLKMatrix4 modelViewMatrixTranslate = GLKMatrix4Translate(modelViewMatrix, SQUARE_SIZE /2 , SQUARE_SIZE / 2, 0);
GLKMatrix4 modelViewMatrixRotation = GLKMatrix4Rotate(modelViewMatrixTranslate, GLKMathDegreesToRadians(self.rotation), 0.f, 0.f, 1.f);
GLKMatrix4 modelViewMatrixReTranslate = GLKMatrix4Translate(modelViewMatrixRotation, - SQUARE_SIZE /2 , - SQUARE_SIZE / 2, 0);
self.baseEffect.transform.modelviewMatrix = modelViewMatrixReTranslate;
[self.baseEffect prepareToDraw];
glDrawArrays(GL_TRIANGLES, 0, 6);
}
- (void) update {
self.position = GLKVector2Add(self.position , self.velocity);
self.rotation += self.rotationVelocity;
}
@end