开发者

Calling ShiVa code from within iOS

I'm still very new to ShiVa3d and fairly new to iOS.

I'd like to develop an app that runs on an iPad. I will write quite a lot of logic in objective-c that will run on the iOS and some simple lua code in ShiVa.

Here is a very simple example of what I'd like to do:

1) My app will have a single model, which will load and be viewed.

2) Inside my lua ShiVa code, as part of the MainAI, I will create a method that accepts parameters such as x,y,z let's call this method "ShiVaCameraToPostition(objX,objY,objZ)"

3) Inside my iOS objective-c code I want to call this "ShiVaCameraToPostition"开发者_如何学Python method, with parameters

Is this possible?

How would I go about doing this? What should I look for in the documentation? Are there any examples people can point to?

Many thanks in advance. Please let me know if the above is ambiguous.


Ok, success of sorts. Please don't beat me over the head over best practice, I just wanted to get this going.

So, I created a class to do my dirty work in, let's call it ShivaInterface.

ShivaInterface.h
ShivaInterface.mm /*** note the .mm ***/

The header was as follows:

#import <Foundation/Foundation.h>

@interface ShivaInterface : NSObject{

}

+(const void*)getMyParams:(NSNumber*)x andY:(NSNumber*)y;

@end

And implemented as:

#import "ShivaInterface.h"
#import "S3DXPlugin.h" //is this the correct thing to include? it worked for me

@implementation ShivaInterface

+(const void*)getMyParams:(NSNumber*)x andY:(NSNumber*)y{
    static S3DX::AIVariable args[2];
    args[0].SetNumberValue([x floatValue]);
    args[1].SetNumberValue([y floatValue]);
    return args;
}
@end

Then in my pure Obj-c method:

const void *params = [ShivaInterface getMyParams:[NSNumber numberWithFloat:100.0f] andY:[NSNumber numberWithFloat:100.0f]];
S3DClient_SendEventToCurrentUser("MainAi","onDoRotate",2,params);

That works, I realise it's not beautiful, and my lack of a deeper understanding of C/C++ probably doesn't help.

(Full thread here: http://www.stonetrip.com/developer/forum/viewtopic.php?p=29073#p29073)


You can't call a ShiVa method it would seem, you must call a handler using:

S3DClient_SendEventToCurrentUser("MainAI","onMyHandler",0);

The 3rd and 4th parameters are number of arguments and the arguments in an array (need to look into that separately).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜