Working on a camera object, using the glm vector/matrix library. The compiler says Front is an undeclared identifier, I can't figure out why:
type Camera* = ref object
Position*,Front*,Up*,Right*,WorldUp*:Vec3f
Yaw*,Pitch*,MovementSpeed*,MouseSensitivity*,Zoom*:float32
method UpdateCameraVectors(this: Camera) {.base.} =
Front.x = cos(radians(Yaw)) * cos(radians(Pitch))
Front.y = sin(radians(Pitch))
Front.z = sin(radians(Yaw)) * cos(radians(Pitch))
Front = normalize(Front);
I believe Nim assumes that identifiers starting with a capital letter are types.
Use this:
type Camera* = ref object
position*,front*,up*,right*,worldUp*:Vec3f
yaw*,pitch*,movementSpeed*,mouseSensitivity*,zoom*:float32
I believe Nim assumes that identifiers starting with a capital letter are types. Use this:
type Camera* = ref object
position*,front*,up*,right*,worldUp*:Vec3f
yaw*,pitch*,movementSpeed*,mouseSensitivity*,zoom*:float32
Fortunatly Nim isn't Go, you may name your identifiers as you want.
I think your problem is that even in methods, by default, you explicitly have to add the this, like so:
method UpdateCameraVectors(this: Camera) {.base.} =
this.Front.x = cos(radians(this.Yaw)) * cos(radians(this.Pitch))
this.Front.y = sin(radians(this.Pitch))
this.Front.z = sin(radians(this.Yaw)) * cos(radians(this.Pitch))
this.Front = normalize(this.Front);
If you add the following:
{.this: this.}
at the top of your file, it should work without explicitly stating the this(see here: https://nim-lang.org/docs/manual.html#overloading-resolution-automatic-self-insertions)ahh, I see.
Do people tend to bother with methods then much in nim? Or just leverage the universal call syntax on normal procs? If one was publishing a library, what would people expect? Or what are the pros/cons?
Here's one nice use of methods vs procs in Nim that I've seen recently:
Do people tend to bother with methods then much in nim?
IMO, no. It was a bold experiment, but I think multimethods haven't been well received in Nim. If you look at "Nim In Action", they don't even rate a place in the index.
I do think there's a place for some kind of OO in Nim (by which I mean, dynamic dispatch and open recursion) and I was hoping this would be through the VTable types described in the manual, but I'm less sanguine about its prospects for existence with each git pull. There are tools for doing OO in Nim without methods now, so if you really need to have this consider those.