我想在 Swift 專案中使用以下Apple 示例代碼中的 AAPLRendererUtils 和 AAPLMathUtilities 檔案。
我創建了一個橋接頭,我在其中匯入了“APPLMathUtilities.h”并且它作業得很好。但是,當我嘗試匯入“AAPLRendererUtils.h”時遇到了問題。
AAPLRendererUtils.h 是一個只有頭檔案的檔案,不遵循通常的 Objective-C @interface 和 @implementation 模式。
AAPLRendererUtils.h 還匯入了 APPLMathUtilities.h 所以也許這個依賴是一個問題?
#import "AAPLMathUtilities.h"
//----------------------------------------------------------------------------------------
struct Camera
{
vector_float3 position;
vector_float3 target;
float rotation;
float aspectRatio; // width/height
float fovVert_Half; // half of vertical field of view, in radians
float distanceNear;
float distanceFar;
matrix_float4x4 GetViewMatrix () const
{
return matrix_look_at_left_hand(position, target, (vector_float3){0,1,0});
}
matrix_float4x4 GetProjectionMatrix_LH () const
{
return matrix_perspective_left_hand (
fovVert_Half * 2.f,
aspectRatio,
distanceNear,
distanceFar);
}
};
有趣的是,如果我注釋掉代碼運行的函式宣告,但如果我保留它們,我會收到以下錯誤:
欄位“GetViewMatrix”宣告為函式
由于您不能在 C 中的結構中使用函式,我認為 Xcode 將此檔案解釋為 C 檔案是正確的嗎?
uj5u.com熱心網友回復:
這不是 C 頭檔案,而是 C 頭檔案。包含在示例檔案中的檔案都具有“.mm”擴展名,即 Objective-C 。C 確實允許結構具有方法(它基本上是一個所有成員都是公共的類,IIRC)。我知道幾年前,Swift 不太擅長處理 C 檔案。不知道有沒有變 如果您足夠勤奮,您可能可以將方法與結構分開來制作 C 檔案和頭檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/340174.html
