Using GLKMath from GLKit in Swift
So I'm using a book called iOS Games by tutorials from Ray Wenderlich and trying to utilize some of the objective-C code found there to make the accelerometer control of a character in my game work. Instead of Objective-C though, I want to use Swift. I ran into an issue when trying to create a var of type GLKVector3, which represents a 3D vector. When I type in:
var raw:GLKVector3 = GLKVector3Make(irrelevant stuff)
I get the following error:
use of module GLKVector3 as type.
I have an import at the top of my swift file for GLKit:
import GLKit
Any ideas how I can get the functionality from the GLKMath files to use in my program?
ios swift frameworks glkit
add a comment |
So I'm using a book called iOS Games by tutorials from Ray Wenderlich and trying to utilize some of the objective-C code found there to make the accelerometer control of a character in my game work. Instead of Objective-C though, I want to use Swift. I ran into an issue when trying to create a var of type GLKVector3, which represents a 3D vector. When I type in:
var raw:GLKVector3 = GLKVector3Make(irrelevant stuff)
I get the following error:
use of module GLKVector3 as type.
I have an import at the top of my swift file for GLKit:
import GLKit
Any ideas how I can get the functionality from the GLKMath files to use in my program?
ios swift frameworks glkit
add a comment |
So I'm using a book called iOS Games by tutorials from Ray Wenderlich and trying to utilize some of the objective-C code found there to make the accelerometer control of a character in my game work. Instead of Objective-C though, I want to use Swift. I ran into an issue when trying to create a var of type GLKVector3, which represents a 3D vector. When I type in:
var raw:GLKVector3 = GLKVector3Make(irrelevant stuff)
I get the following error:
use of module GLKVector3 as type.
I have an import at the top of my swift file for GLKit:
import GLKit
Any ideas how I can get the functionality from the GLKMath files to use in my program?
ios swift frameworks glkit
So I'm using a book called iOS Games by tutorials from Ray Wenderlich and trying to utilize some of the objective-C code found there to make the accelerometer control of a character in my game work. Instead of Objective-C though, I want to use Swift. I ran into an issue when trying to create a var of type GLKVector3, which represents a 3D vector. When I type in:
var raw:GLKVector3 = GLKVector3Make(irrelevant stuff)
I get the following error:
use of module GLKVector3 as type.
I have an import at the top of my swift file for GLKit:
import GLKit
Any ideas how I can get the functionality from the GLKMath files to use in my program?
ios swift frameworks glkit
ios swift frameworks glkit
edited Nov 26 '18 at 7:28
Shruti Thombre
8311823
8311823
asked Jul 8 '14 at 1:43
DShaarDShaar
8026
8026
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Swift has added union support in version 1.2. The fields in imported unions are read-only, even if declared with var
, but can be passed to and from C functions as necessary.
The release notes for Swift 1.2 imply that the fields may not be accessible at all, but they are still readable for at least the GLKit
types:
Swift can now partially import C aggregates containing unions, bitfields, SIMD vector types, and other C language features that are not natively supported in Swift. The unsupported fields will not be accessible from Swift, but C and Objective-C APIs that have arguments and return values of these types can be used in Swift. This includes the Foundation
NSDecimal
type and theGLKit GLKVector
andGLKMatrix
types, among others.
1
Does this mean that I can't use GLKVector3 at all?
– DShaar
Jul 8 '14 at 3:00
3
So far as I can tell, not in Swift as it is today. They may implement unions in a coming version, but I haven't seen anything about that. File a bug report!
– Nate Cook
Jul 10 '14 at 2:50
For a possible workaround (create a C function) see: stackoverflow.com/questions/8262004/… Provided that the receiver (framework, objc library) already implements a union.
– LearnCocos2D
Jan 27 '15 at 16:50
@LearnCocos2D have you tried that? The problem is that Swift isn't bridging theGLKVector3
type, so the compiler won't recognize or allow any instances.
– Nate Cook
Jan 27 '15 at 19:08
1
you can wrap it in a objc interface that exposes glk structs as custom struct that swift can work with. Of course this stops being useful if you have to directly interface with an api that makes use of glkit structs, especially subclasses that override methods with glk struct params are not possible in swift.
– LearnCocos2D
Jan 27 '15 at 20:59
add a comment |
With the release of beta version of Xcode 6.3/Swift 1.2 yesterday (Feb 8, 2015) it is now possible to use GLKit from Swift.
1
Any idea how to pass GLKMatrices as uniforms though? I'm trying to convert it to an UnsafePointer<Float>, without success. Would love some pointers, as it were!
– Gusutafu
Mar 14 '15 at 22:06
1
@Gusutafuvar viewProj = GLKMatrix4Multiply(...) var pData = uniformBuffer.contents() pData.advancedBy(sizeof(GLKMatrix4) * inflightBufferIndex) let address = withUnsafePointer(&viewProj) { UnsafeMutablePointer<Float>($0) } memcpy(pData, address, sizeof(GLKMatrix4))
– aoakenfo
Apr 20 '15 at 19:03
add a comment |
Here check my repo: https://github.com/noxytrux/SwiftGeom i actually build a whole lib for that, so you are no more forced to use GLKit or wait for Apple to implement it in swift.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24622475%2fusing-glkmath-from-glkit-in-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Swift has added union support in version 1.2. The fields in imported unions are read-only, even if declared with var
, but can be passed to and from C functions as necessary.
The release notes for Swift 1.2 imply that the fields may not be accessible at all, but they are still readable for at least the GLKit
types:
Swift can now partially import C aggregates containing unions, bitfields, SIMD vector types, and other C language features that are not natively supported in Swift. The unsupported fields will not be accessible from Swift, but C and Objective-C APIs that have arguments and return values of these types can be used in Swift. This includes the Foundation
NSDecimal
type and theGLKit GLKVector
andGLKMatrix
types, among others.
1
Does this mean that I can't use GLKVector3 at all?
– DShaar
Jul 8 '14 at 3:00
3
So far as I can tell, not in Swift as it is today. They may implement unions in a coming version, but I haven't seen anything about that. File a bug report!
– Nate Cook
Jul 10 '14 at 2:50
For a possible workaround (create a C function) see: stackoverflow.com/questions/8262004/… Provided that the receiver (framework, objc library) already implements a union.
– LearnCocos2D
Jan 27 '15 at 16:50
@LearnCocos2D have you tried that? The problem is that Swift isn't bridging theGLKVector3
type, so the compiler won't recognize or allow any instances.
– Nate Cook
Jan 27 '15 at 19:08
1
you can wrap it in a objc interface that exposes glk structs as custom struct that swift can work with. Of course this stops being useful if you have to directly interface with an api that makes use of glkit structs, especially subclasses that override methods with glk struct params are not possible in swift.
– LearnCocos2D
Jan 27 '15 at 20:59
add a comment |
Swift has added union support in version 1.2. The fields in imported unions are read-only, even if declared with var
, but can be passed to and from C functions as necessary.
The release notes for Swift 1.2 imply that the fields may not be accessible at all, but they are still readable for at least the GLKit
types:
Swift can now partially import C aggregates containing unions, bitfields, SIMD vector types, and other C language features that are not natively supported in Swift. The unsupported fields will not be accessible from Swift, but C and Objective-C APIs that have arguments and return values of these types can be used in Swift. This includes the Foundation
NSDecimal
type and theGLKit GLKVector
andGLKMatrix
types, among others.
1
Does this mean that I can't use GLKVector3 at all?
– DShaar
Jul 8 '14 at 3:00
3
So far as I can tell, not in Swift as it is today. They may implement unions in a coming version, but I haven't seen anything about that. File a bug report!
– Nate Cook
Jul 10 '14 at 2:50
For a possible workaround (create a C function) see: stackoverflow.com/questions/8262004/… Provided that the receiver (framework, objc library) already implements a union.
– LearnCocos2D
Jan 27 '15 at 16:50
@LearnCocos2D have you tried that? The problem is that Swift isn't bridging theGLKVector3
type, so the compiler won't recognize or allow any instances.
– Nate Cook
Jan 27 '15 at 19:08
1
you can wrap it in a objc interface that exposes glk structs as custom struct that swift can work with. Of course this stops being useful if you have to directly interface with an api that makes use of glkit structs, especially subclasses that override methods with glk struct params are not possible in swift.
– LearnCocos2D
Jan 27 '15 at 20:59
add a comment |
Swift has added union support in version 1.2. The fields in imported unions are read-only, even if declared with var
, but can be passed to and from C functions as necessary.
The release notes for Swift 1.2 imply that the fields may not be accessible at all, but they are still readable for at least the GLKit
types:
Swift can now partially import C aggregates containing unions, bitfields, SIMD vector types, and other C language features that are not natively supported in Swift. The unsupported fields will not be accessible from Swift, but C and Objective-C APIs that have arguments and return values of these types can be used in Swift. This includes the Foundation
NSDecimal
type and theGLKit GLKVector
andGLKMatrix
types, among others.
Swift has added union support in version 1.2. The fields in imported unions are read-only, even if declared with var
, but can be passed to and from C functions as necessary.
The release notes for Swift 1.2 imply that the fields may not be accessible at all, but they are still readable for at least the GLKit
types:
Swift can now partially import C aggregates containing unions, bitfields, SIMD vector types, and other C language features that are not natively supported in Swift. The unsupported fields will not be accessible from Swift, but C and Objective-C APIs that have arguments and return values of these types can be used in Swift. This includes the Foundation
NSDecimal
type and theGLKit GLKVector
andGLKMatrix
types, among others.
edited Feb 11 '15 at 5:16
answered Jul 8 '14 at 2:37
Nate CookNate Cook
76.2k26184163
76.2k26184163
1
Does this mean that I can't use GLKVector3 at all?
– DShaar
Jul 8 '14 at 3:00
3
So far as I can tell, not in Swift as it is today. They may implement unions in a coming version, but I haven't seen anything about that. File a bug report!
– Nate Cook
Jul 10 '14 at 2:50
For a possible workaround (create a C function) see: stackoverflow.com/questions/8262004/… Provided that the receiver (framework, objc library) already implements a union.
– LearnCocos2D
Jan 27 '15 at 16:50
@LearnCocos2D have you tried that? The problem is that Swift isn't bridging theGLKVector3
type, so the compiler won't recognize or allow any instances.
– Nate Cook
Jan 27 '15 at 19:08
1
you can wrap it in a objc interface that exposes glk structs as custom struct that swift can work with. Of course this stops being useful if you have to directly interface with an api that makes use of glkit structs, especially subclasses that override methods with glk struct params are not possible in swift.
– LearnCocos2D
Jan 27 '15 at 20:59
add a comment |
1
Does this mean that I can't use GLKVector3 at all?
– DShaar
Jul 8 '14 at 3:00
3
So far as I can tell, not in Swift as it is today. They may implement unions in a coming version, but I haven't seen anything about that. File a bug report!
– Nate Cook
Jul 10 '14 at 2:50
For a possible workaround (create a C function) see: stackoverflow.com/questions/8262004/… Provided that the receiver (framework, objc library) already implements a union.
– LearnCocos2D
Jan 27 '15 at 16:50
@LearnCocos2D have you tried that? The problem is that Swift isn't bridging theGLKVector3
type, so the compiler won't recognize or allow any instances.
– Nate Cook
Jan 27 '15 at 19:08
1
you can wrap it in a objc interface that exposes glk structs as custom struct that swift can work with. Of course this stops being useful if you have to directly interface with an api that makes use of glkit structs, especially subclasses that override methods with glk struct params are not possible in swift.
– LearnCocos2D
Jan 27 '15 at 20:59
1
1
Does this mean that I can't use GLKVector3 at all?
– DShaar
Jul 8 '14 at 3:00
Does this mean that I can't use GLKVector3 at all?
– DShaar
Jul 8 '14 at 3:00
3
3
So far as I can tell, not in Swift as it is today. They may implement unions in a coming version, but I haven't seen anything about that. File a bug report!
– Nate Cook
Jul 10 '14 at 2:50
So far as I can tell, not in Swift as it is today. They may implement unions in a coming version, but I haven't seen anything about that. File a bug report!
– Nate Cook
Jul 10 '14 at 2:50
For a possible workaround (create a C function) see: stackoverflow.com/questions/8262004/… Provided that the receiver (framework, objc library) already implements a union.
– LearnCocos2D
Jan 27 '15 at 16:50
For a possible workaround (create a C function) see: stackoverflow.com/questions/8262004/… Provided that the receiver (framework, objc library) already implements a union.
– LearnCocos2D
Jan 27 '15 at 16:50
@LearnCocos2D have you tried that? The problem is that Swift isn't bridging the
GLKVector3
type, so the compiler won't recognize or allow any instances.– Nate Cook
Jan 27 '15 at 19:08
@LearnCocos2D have you tried that? The problem is that Swift isn't bridging the
GLKVector3
type, so the compiler won't recognize or allow any instances.– Nate Cook
Jan 27 '15 at 19:08
1
1
you can wrap it in a objc interface that exposes glk structs as custom struct that swift can work with. Of course this stops being useful if you have to directly interface with an api that makes use of glkit structs, especially subclasses that override methods with glk struct params are not possible in swift.
– LearnCocos2D
Jan 27 '15 at 20:59
you can wrap it in a objc interface that exposes glk structs as custom struct that swift can work with. Of course this stops being useful if you have to directly interface with an api that makes use of glkit structs, especially subclasses that override methods with glk struct params are not possible in swift.
– LearnCocos2D
Jan 27 '15 at 20:59
add a comment |
With the release of beta version of Xcode 6.3/Swift 1.2 yesterday (Feb 8, 2015) it is now possible to use GLKit from Swift.
1
Any idea how to pass GLKMatrices as uniforms though? I'm trying to convert it to an UnsafePointer<Float>, without success. Would love some pointers, as it were!
– Gusutafu
Mar 14 '15 at 22:06
1
@Gusutafuvar viewProj = GLKMatrix4Multiply(...) var pData = uniformBuffer.contents() pData.advancedBy(sizeof(GLKMatrix4) * inflightBufferIndex) let address = withUnsafePointer(&viewProj) { UnsafeMutablePointer<Float>($0) } memcpy(pData, address, sizeof(GLKMatrix4))
– aoakenfo
Apr 20 '15 at 19:03
add a comment |
With the release of beta version of Xcode 6.3/Swift 1.2 yesterday (Feb 8, 2015) it is now possible to use GLKit from Swift.
1
Any idea how to pass GLKMatrices as uniforms though? I'm trying to convert it to an UnsafePointer<Float>, without success. Would love some pointers, as it were!
– Gusutafu
Mar 14 '15 at 22:06
1
@Gusutafuvar viewProj = GLKMatrix4Multiply(...) var pData = uniformBuffer.contents() pData.advancedBy(sizeof(GLKMatrix4) * inflightBufferIndex) let address = withUnsafePointer(&viewProj) { UnsafeMutablePointer<Float>($0) } memcpy(pData, address, sizeof(GLKMatrix4))
– aoakenfo
Apr 20 '15 at 19:03
add a comment |
With the release of beta version of Xcode 6.3/Swift 1.2 yesterday (Feb 8, 2015) it is now possible to use GLKit from Swift.
With the release of beta version of Xcode 6.3/Swift 1.2 yesterday (Feb 8, 2015) it is now possible to use GLKit from Swift.
answered Feb 10 '15 at 3:02
Johan KoolJohan Kool
13.1k65677
13.1k65677
1
Any idea how to pass GLKMatrices as uniforms though? I'm trying to convert it to an UnsafePointer<Float>, without success. Would love some pointers, as it were!
– Gusutafu
Mar 14 '15 at 22:06
1
@Gusutafuvar viewProj = GLKMatrix4Multiply(...) var pData = uniformBuffer.contents() pData.advancedBy(sizeof(GLKMatrix4) * inflightBufferIndex) let address = withUnsafePointer(&viewProj) { UnsafeMutablePointer<Float>($0) } memcpy(pData, address, sizeof(GLKMatrix4))
– aoakenfo
Apr 20 '15 at 19:03
add a comment |
1
Any idea how to pass GLKMatrices as uniforms though? I'm trying to convert it to an UnsafePointer<Float>, without success. Would love some pointers, as it were!
– Gusutafu
Mar 14 '15 at 22:06
1
@Gusutafuvar viewProj = GLKMatrix4Multiply(...) var pData = uniformBuffer.contents() pData.advancedBy(sizeof(GLKMatrix4) * inflightBufferIndex) let address = withUnsafePointer(&viewProj) { UnsafeMutablePointer<Float>($0) } memcpy(pData, address, sizeof(GLKMatrix4))
– aoakenfo
Apr 20 '15 at 19:03
1
1
Any idea how to pass GLKMatrices as uniforms though? I'm trying to convert it to an UnsafePointer<Float>, without success. Would love some pointers, as it were!
– Gusutafu
Mar 14 '15 at 22:06
Any idea how to pass GLKMatrices as uniforms though? I'm trying to convert it to an UnsafePointer<Float>, without success. Would love some pointers, as it were!
– Gusutafu
Mar 14 '15 at 22:06
1
1
@Gusutafu
var viewProj = GLKMatrix4Multiply(...) var pData = uniformBuffer.contents() pData.advancedBy(sizeof(GLKMatrix4) * inflightBufferIndex) let address = withUnsafePointer(&viewProj) { UnsafeMutablePointer<Float>($0) } memcpy(pData, address, sizeof(GLKMatrix4))
– aoakenfo
Apr 20 '15 at 19:03
@Gusutafu
var viewProj = GLKMatrix4Multiply(...) var pData = uniformBuffer.contents() pData.advancedBy(sizeof(GLKMatrix4) * inflightBufferIndex) let address = withUnsafePointer(&viewProj) { UnsafeMutablePointer<Float>($0) } memcpy(pData, address, sizeof(GLKMatrix4))
– aoakenfo
Apr 20 '15 at 19:03
add a comment |
Here check my repo: https://github.com/noxytrux/SwiftGeom i actually build a whole lib for that, so you are no more forced to use GLKit or wait for Apple to implement it in swift.
add a comment |
Here check my repo: https://github.com/noxytrux/SwiftGeom i actually build a whole lib for that, so you are no more forced to use GLKit or wait for Apple to implement it in swift.
add a comment |
Here check my repo: https://github.com/noxytrux/SwiftGeom i actually build a whole lib for that, so you are no more forced to use GLKit or wait for Apple to implement it in swift.
Here check my repo: https://github.com/noxytrux/SwiftGeom i actually build a whole lib for that, so you are no more forced to use GLKit or wait for Apple to implement it in swift.
answered Oct 28 '14 at 19:35
Marcin MałyszMarcin Małysz
623811
623811
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24622475%2fusing-glkmath-from-glkit-in-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown