samb90
samb90

Reputation: 1073

Converting a Java constructor with custom parameters into Objective-C code

I am in the process of converting an OpenGL java application into Objective-C. Here is a copy of the constructor from my java constructor from a file called AmbientMovement:

public class AmbientMovement {

private final float         FPS;

private final Frame[]               FRAMES;
private final int           NUMBER_FRAMES;
private final float         CYCLE;
private final Random            RANDOM;
private int             indexAmbient;
private float               timeAmbient;
private float               timeCurrent;

public AmbientMovement(Frame[] frames, float fps) {

    this.FPS              = fps;

    this.FRAMES           = frames;
    this.NUMBER_FRAMES    = frames.length;

    Frame lastframe       = frames[this.NUMBER_FRAMES - 1];
    this.CYCLE            = lastframe.getTime() + lastframe.getDuration();
    this.RANDOM           = new Random();

    this.resetClock();
}

This is my attempt to write the code using Objective-c for iOS 6 and X-Code 4.5:

AmbientMovement.h

    #import "VA-Frame.h"
    #import "VA-TRSet.h"
    #import "VA-Morph.h"
    #import "VA-Quaternion.h" 
    #import "math.h"

    @interface VA_AmbientMovement : NSObject{

    /* Private members */
    @private {
        @property float const*  FPS;
        @property int const*    NUMBER_FRAMES;
        @property float const*  CYCLE;
        @property int           indexAmbient;
        @property float         timeAmbient;
        @property float         timeCurrent;
    }

}

AmbientMovement.m

#import "VA_AmbientMovement.h"

@implementation VA_AmbientMovement

/* Initialise the AmbientMovement constructor */
-(id)initAmbientMovement:(Frame[])frames AndFPS :(float)fps{
    self=[super init];
    if(self){
        FPS                 = 0;
        NUMBER_FRAMES       = 0;
        CYCLE               = 0;
        indexAmbient        = 0;
        timeAmbient         = 0;
        timeCurrent         = 0;

        Frame* frame = [[Frame alloc]      initAmbientManager:frames AndFPS:fps];
        TRSet* trset = [[TRSet alloc]      initAmbientManager:frames AndFPS:fps];
        Morph* morph = [[Morph alloc]      initAmbientManager:frames AndFPS:fps];
        Quaternion* quat   = [[Quaternion alloc]    initAmbientManager:frames AndFPS:fps];
    }
    return self;
};

-(id)init{
    return [self initAmbientMovement:0 AndFPS: 0];
};

One of the major things I am confused with, is how to pass a parameter of type class. In java this is done through "Frame[] frames". Can I do this in objective-c using the following line "(Frame[])aframes" or am I making a mistake?

Many Thanks

Upvotes: 0

Views: 263

Answers (1)

Eric Petroelje
Eric Petroelje

Reputation: 60518

What you have there will work fine - but generally when passing arrays around in objective-c you would want to use either an NSArray or an NSMutableArray rather than the c-style arrays.

Upvotes: 4

Related Questions