Posts
need math help lua: get object space coordinates
Mar 6 2018 Anchor

this is the problem i have:
i wanna attach a explo on a master object, (vehicle), and need the position from the explo (slave) from view of the master (vehicle).

Youtu.be

actually i do a simple vector difference, slave - master, but this works only, if master have a rotation of 0,0,0... by other rotations, the

``````   local pos = DifferenceVectors(slavepos:GetPos(),master:GetPos());
slave:SetPos(pos); ``````
``````function DifferenceVectors(a,b)
return {x=a.x-b.x,
y=a.y-b.y,
z=a.z-b.z
};
end``````

so, i need to get the angles from master in, but how ?
i have pos, dirvector, normalvector, angles from master and slave.
have looked now 2 days trough google and found nothing really helpfull (because i'm not a mathematician and totally not talented in that topic).

Edited by: pvcf

Apr 6 2018 Anchor

Aaand, where is this in? What engine?
It's really hard to understand your problem without knowing anything about what you are actually coding (and coding in). All I see is various name-dropping.
Is this a conversion problem? (from world space to object space - or vice versa)

--

Technical Artist @ King - an Activision Blizzard division

Apr 6 2018 Anchor

oh sorry, i was thinking the youtube video answer all possible questions (after some weeks with no response i deleted the video).

engine: cryengine, codebase: lua

> Is this a conversion problem?

i need objectspace coordinates, but i have only worldspace, normals and direction vectors and world angles.
but as far as i have seen what for a hell of math code is behind, i'm not sure if i really should dig again into it, especially it seems
the calculation must change every 90 degrees of every angle (lets say if x angle is over 90% degree it changes to y and the same with z -.-)

Edited by: pvcf

Apr 6 2018 Anchor

I've never worked with CryEngine myself but a quick google tells me that you have two functions (that are members of Entitys) for converting between global and local coordinate systems, called:
ToLocal()
ToGlobal()

Both of which takes two parameters:
slotId
point

Documentation seems to be pretty shit though. No example code anywhere - and this is the tech docs. Heck, it doesn't even tell you what data types the above parameters have, nor does it tell you the format of the return. But I guess that slotId is some kind of identifier.

The C++ docs makes more sense though. The IVehicleHelper -class has a method called GetLocalTM which will give you the transform matrix in object (local) space. And tbh, anytime you are doing rotations you want to work with matrices - not Euler angles - because they are fast and straight-forward while calculations of Euler angles are just... messy, slow and prone to causing problems.

--

Technical Artist @ King - an Activision Blizzard division

Apr 6 2018 Anchor

thank you for Investigation !
*cough* , i forgot to mention i mod cryengine1.4 from 2006, which does not have this global routines, but it have in c++ part the euler code with matrix rotation (called matrix44) and it's also used by Vehiclecode and also decalshader use this (bulletholes decals). unfortunately i don't have access to this code from lua side -.-
(beside that i'm not skilled enough to recode this function in lua, it's way too complex).

its called like this (including quarternation)

``````						Matrix44 matWorld;
matWorld.SetIdentity();
CryQuat cxquat = Quat( GetTransposed44(matWorld) );
CryQuat rxquat;``````

crymatrix.h and cryquat.h are together more than 2600 lines of math-functions, so recoding that in lua is not possible for me.
there would maybe a way to make those both functions accessible from lua but even THAT is out from my c++ knowledge -.-

however, thank you for taking part

Edited by: pvcf

Apr 7 2018 Anchor

I see.
The files ending with .h are header files, meaning they don't contain any logic themselves - only function and class declarations. The code is in .c or .cpp files.

Either way, converting a math library (even parts of it) into Lua is not only tedious but a real bad idea due to speeds. I don't know the engine but I suspect that all the Lua code is nothing but bindings to the underlying C++ code. After all, that is how you code an engine (Defold is a good example here); you have a low-level language like C++ doing all the heavy work, memory management and what not, and an optional high-level scripting language (like Lua) on top of that.

So, with this said: You don't have to rewrite the entire math-lib (or parts of it) in Lua - but you will most likely have to write your own Lua bindings to the underlying C++ functions since they are, as you say, missing in this old version of the engine. Btw is there any particular reason you are sticking to an old version of the engine?

Also, if you are serious about learning programming in general (and C++ in particular) then I would recommend the book: Accelerated C++ by Andrew Koening and Barbara E. Moo. Compared to other intro books it is very, very small (300 pages, not counting the appendices) and it doesn't overwhelm the user with tons of concepts early on in the book (in fact, pointers and memory management are at the very end of the book). If you already have basic coding skills (Lua) then it shouldn't be too much of a hurdle to get into.

--

Technical Artist @ King - an Activision Blizzard division

Apr 9 2018 Anchor

yes, the C++ part is the core code and the lua-front end is basically for finetuning,s etting up parameters and scripting entities and so on.

why i stick to this old engine:
as i have started this little mod, the newest port was CE2. inbetween they are at ~CE5 . If i would have switched every time,
the Project would be death as hell, and beside this, it is a FarCry 1 mod, and this game is based on CE1.4 which i use therefore.
maybe you wanna see how far i have threaded this old engine:
Moddb.com

Oct 4 2018 Anchor

> Is this a transformation issue?

yes, from world-space to object-space. it seems its a horrible matrix conversion, have seen the formulars from and i gave up, it's way above my math skills -.-

but thank you for looking in and responding !

Oct 6 2018 Anchor
pvcf wrote:

yes, the C++ part is the core code and the lua-front end is basically for finetuning,s etting up parameters and scripting entities and so on.

why i stick to this old engine:
as i have started this little mod, the newest port was CE2. inbetween they are at ~CE5 . If i would have switched every time,
the Project would be death as hell, and beside this, it is a FarCry 1 mod, and this game is based on CE1.4 which i use therefore.
maybe you wanna see how far i have threaded this old engine:
Moddb.com

I understand: it is a porting problem that eats up your time.
Do you have any kind of asset automation tools or have you ported things in the past manually?
It seems to me that you need a more fundamental understanding of game code, or even code in general, which is why I suggest you pickup C++ knowledge and hack the source code. Things that are tedious - like porting assets - should be automated, and if there are no tools for that you could write them yourself. Do you follow my logic here? By investing in yourself first you will save time in the long run to do your modding.

--

Technical Artist @ King - an Activision Blizzard division

Oct 6 2018 Anchor