简体   繁体   中英

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

您所拥有的将可以正常工作-但通常在Objective-C中传递数组时,您可能希望使用NSArrayNSMutableArray而不是c样式的数组。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM