Guevara-chan / Raylib-Forever

:.raylib headers for Nim anytime.:
https://guevara-chan.github.io/Raylib-Forever/main.html
75 stars 4 forks source link

Need a little help porting an example... #7

Open Skaruts opened 4 years ago

Skaruts commented 4 years ago

I was trying to port the first person maze example, and came across this:

Model model = LoadModelFromMesh(mesh);
//(...)
model.materials[0].maps[MAP_DIFFUSE].texture = texture;             // Set map diffuse texture

And I'm not being able to translate that second line there, because it involves C array pointers, and I don't quite know how to work with those in Nim. Someone suggested that I use UncheckedArrays, and I used that successfully with Image data in another example, but here I'm not managing to. I tried this but didn't work:

var mats = cast[ptr UncheckedArray[Material]](model.materials)
var maps = cast[ptr UncheckedArray[MaterialMap]](mats[0])         # <--- line 42
maps[MAP_DIFFUSE].texture = texture                  
... first_person_maze.nim(42, 15) Error: expression cannot be cast to ptr UncheckedArray[MaterialMap]
Skaruts commented 4 years ago

Well I atually figured it out shortly after posting this... This works.

let maps = cast[ptr UncheckedArray[MaterialMap]](mats[0].maps)  # <-- I had neglected '.maps'

Although I'm still having trouble getting anything to render -- I just get blank screen when I run it -- which may be related to what I'm doing there. When I press escape to quit I get a storage access error:

... first_person_maze.nim(123)
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

and line 123 is

UnloadModel(model)

But model isn't nil...

Guevara-chan commented 4 years ago

I'm trying to convert this sample myself. Something seems to be wrong with collisions.

Skaruts commented 4 years ago

Thanks. There are problems with collisions in the original too, though.

Guevara-chan commented 4 years ago

Well, what I found so far is that problem lies with mesh generation - it only creates disjointed triangles with mangled plane on 0,0,0. Not so sure why, investigating.