Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Quaternions

in Questions Posts: 1,865

@dave1707 - @Simeon - in the dim and distant past a Codea explorer (@ignatz) wrote a demo with well documented code for the use of quaternions. I can’t run it as an error is thrown up regarding a reserved word setfenv which is recognised by the system but I can’t find documented anywhere. In addition I think it has been shelved or modified as it is the source of the error. @loopspace introduced the feature to @ignatz. So could someone point me to details on this functionality or - a way round it.

Apparently setfenv enabled the ability to run several demos, essentially separate projects, in a single multiple tab project. I think similar code is used in some of the example projects for Codea/Craft.

Comments

  • dave1707dave1707 Mod
    Posts: 8,671

    @Bri_G What demo are you trying to run. Have you tried a forum search on setfenv.

  • JohnJohn Admin Mod
    Posts: 639

    @Bri_G setfenv is no longer available in Lua 5.2 as far as I know. You can recreate it, if you search it on google there are a bunch of recommended solutions: https://leafo.net/guides/setfenv-in-lua52-and-above.html

  • Posts: 1,865

    @dave1707 - I'm still trying to find the demo on @ignatz 's website for which I have the code - there are several on his website but so far can't match against the code I have. Unfortunately there are problems with several of his demos - still digging.

    @John - thanks for the prompt reply and link - very interesting link. Am digging further as just adding the two functions, in your reference, to the existing code still throws up errors. I'm assuming placement of the code and possible format are important. If I manage to progress this I'll post the working code for future reference. Thanks again.

  • Posts: 498

    As there is now the quat built-in, I'm not sure that the old quaternion code is all that useful any more.

    I have my explanation of quaternions at https://loopspace.mathforge.org/HowDidIDoThat/Codea/Quaternions/, and my library code is part of my vecExt library which is available at https://github.com/loopspace/Codea-Library-Maths/blob/master/VecExt.lua.

    What are you trying to achieve? I may be able to help.

  • edited November 25 Posts: 1,865
    @LoopSpace - thanks for the links. When you say that quat is built in do you mean quaternions are now covered within Codea? I have a couple of problems which are related to rotating models, one is smooth 360rotation the other is model distortion on rotation.
    I thought the Craft system for rotation suffered from this so was trying to extract the quaternion code from @Ignatz 's flying tutorial - but, so far, haven't found the detail from his website. II'll read through your explanation and code - thanks again.
  • Posts: 1,865

    @LoopSpace - just a quick, very impressed with the library - certainly needs a mathematician to appreciate it. Sadly - I’m not.But installed the vecExt library and attempted to run your example program for Quaternions but failed. I pasted the library code into a tab. Do you need the full library present to use the vecExt library?

  • Posts: 498

    @Bri_G You might need a little history lesson here ...

    I originally wrote a library called Quaternion for implementing quaternions. The underlying object here was a table. Then Codea included a vec4 userdata and also I learnt about metatables and how to extend userdata. This led to me to re-implement my quaternion code using vec4s as the underlying object. Finally, Codea introduced the quat userdata to be a genuine quaternion object. It doesn't have the full functionality that I would want so I redesigned my code to add that to it.

    The post on Quaternions hosted at mathforge was written in the first phase of this. So the "example program" at the end is horribly out of date. Don't try it. I should update it, but honestly my todo list is so long that it is visible from the moon ... Rather, use that post to understand what quaternions can give you.

    The VecExt code on github is my latest code (well, I might have a few bug fixes on my iPad, but broadly speaking it is). It should work as a tab in a project (I use toadkick's cmodule for side-ways importing of code so that I can load individual tabs from projects programatically rather than via dependencies but I tried to design it so that it will also work without that). I do have plenty of examples of using the modern code, I'll dig one out for you later.

    I remember well discussing quaternions with Ignatz and the flying demo was the one that we used to go back and forth. It therefore suffers a bit since it was updated a bit ad hoc, with bits of it being rewritten at different times as the discussion progressed. So although it has much in it that demonstrates quaternions, I wouldn't recommend it as a template to follow.

Sign In or Register to comment.