从 iOS 内部调用 ShiVa 代码

发布于 2024-10-15 01:22:42 字数 452 浏览 1 评论 0原文

我对 ShiVa3d 还很陌生,对 iOS 也相当陌生。

我想开发一个在 iPad 上运行的应用程序。我将在 Objective-C 中编写大量将在 iOS 上运行的逻辑,并在 ShiVa 中编写一些简单的 lua 代码。

这是我想要做的一个非常简单的示例:

1)我的应用程序将有一个模型,它将加载并被查看。

2) 在我的 lua ShiVa 代码中,作为 MainAI 的一部分,我将创建一个接受 x,y,z 等参数的方法,让我们将此方法称为“ShiVaCameraToPostition(objX,objY,objZ)”

3) 在我的 iOS 目标中 - c代码我想调用这个“ShiVaCameraToPostition”方法,带参数

这可能吗?

我该怎么做呢?我应该在文档中寻找什么?人们可以举出一些例子吗?

非常感谢。如果以上内容有歧义,请告诉我。

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" 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

箜明 2024-10-22 01:22:42

好吧,算是成功了。请不要因为最佳实践而责怪我,我只是想让这件事继续下去。

所以,我创建了一个类来完成我的肮脏工作,我们称之为 ShivaInterface。

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

标题如下:

#import <Foundation/Foundation.h>

@interface ShivaInterface : NSObject{

}

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

@end

并实现为:

#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

然后在我的纯 Obj-c 方法中:

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

可行,我意识到它并不美观,而且我对 C/C++ 缺乏更深入的了解可能无济于事。

(完整线程在这里:http://www.stonetrip.com/开发者/论坛/viewtopic.php?p=29073#p29073)

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)

半岛未凉 2024-10-22 01:22:42

您似乎无法调用 ShiVa 方法,必须使用以下方式调用处理程序:

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

第三个和第四个参数是参数数量,数组中的参数(需要单独研究)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文