Reputation: 1818
I'm trying to implement some basic UIGestureRecongnizer controls from this tutorial. I am having some trouble understanding and translating this class into Swift 3
interface Transformations : NSObject
- (id)initWithDepth:(float)z Scale:(float)s Translation:(GLKVector2)t Rotation:(GLKVector3)r;
- (void)start;
- (void)scale:(float)s;
- (void)translate:(GLKVector2)t withMultiplier:(float)m;
- (void)rotate:(GLKVector3)r withMultiplier:(float)m;
- (GLKMatrix4)getModelViewMatrix;
@end
(ps: the methods with the GLK prefix are from Apples GLKit framework)
class Transformations: NSObject {
init(Scale: Float, Translation: GLKVector2, Rotation: GLKVector3) {
func scale(s: Float) {
}
func translate(t: GLKVector2, withMultiplier: Float) {
}
func rotate(r: GLKVector3, withMultiplier: Float) {
}
}
}
So far, how is this?
Here is the .m file I am trying to translate into Swift 3.
#import "Transformations.h"
@interface Transformations ()
{
// 1
// Depth
float _depth;
}
@end
@implementation Transformations
- (id)initWithDepth:(float)z Scale:(float)s Translation:(GLKVector2)t Rotation:(GLKVector3)r
{
if(self = [super init])
{
// 2
// Depth
_depth = z;
}
return self;
}
- (void)start
{
}
- (void)scale:(float)s
{
}
- (void)translate:(GLKVector2)t withMultiplier:(float)m
{
}
- (void)rotate:(GLKVector3)r withMultiplier:(float)m
{
}
- (GLKMatrix4)getModelViewMatrix
{
// 3
GLKMatrix4 modelViewMatrix = GLKMatrix4Identity;
modelViewMatrix = GLKMatrix4Translate(modelViewMatrix, 0.0f, 0.0f, -_depth);
return modelViewMatrix;
}
@end
Upvotes: 0
Views: 110
Reputation: 4226
So you should translate the .m file. Something like this:
class Transformations: NSObject {
var _depth: Float
init(z: Float, scale s: Float, translation t: GLKVector2, rotation r: GLKVector3) {
self._depth = z
}
func start() {
}
func scale(s: Float) {
}
func translate(t: GLKVector2, withMultiplier m: Float) {
}
func rotate(r: GLKVector3, withMultiplier m: Float) {
}
func getModelViewMatrix() -> GLKMatrix4 {
var modelViewMatrix = GLKMatrix4Identity
modelViewMatrix = GLKMatrix4Translate(modelViewMatrix, 0, 0, -_depth)
return modelViewMatrix
}
}
Upvotes: 1