• Register
Forum Thread
  Posts  
need math help lua: get object space coordinates (Forums : Coding & Scripting : need math help lua: get object space coordinates) Post Reply
Thread Options
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
resulted position fade away.

   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).

please help :)

Edited by: pvcf

Nightshade
Nightshade Unemployed 3D artist
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)

--

   - My portfolio
“There he goes. One of God's own prototypes. Some kind of high powered mutant never even considered for mass production. Too weird to live, and too rare to die.” Hunter S. Thompson

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

Nightshade
Nightshade Unemployed 3D artist
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.

Edited by: Nightshade

--

   - My portfolio
“There he goes. One of God's own prototypes. Some kind of high powered mutant never even considered for mass production. Too weird to live, and too rare to die.” Hunter S. Thompson

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();
						matWorld=Matrix44::CreateRotationZYX(-gf_DEGTORAD*m_vEyeAngles)*matWorld; //NOTE: angles in radians and negated 
						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

Nightshade
Nightshade Unemployed 3D artist
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.

Edited by: Nightshade

--

   - My portfolio
“There he goes. One of God's own prototypes. Some kind of high powered mutant never even considered for mass production. Too weird to live, and too rare to die.” Hunter S. Thompson

Apr 9 2018 Anchor

thank you very much for your advise and the Book recommendation!
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 !

Nightshade
Nightshade Unemployed 3D artist
Oct 6 2018 Anchor
pvcf wrote:

thank you very much for your advise and the Book recommendation!
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.

Edited by: Nightshade

--

   - My portfolio
“There he goes. One of God's own prototypes. Some kind of high powered mutant never even considered for mass production. Too weird to live, and too rare to die.” Hunter S. Thompson

Oct 6 2018 Anchor

@Nighshade

thank you for still taking part :)

you have right, i really need to learn c++ so i can dive deeper in. Actually i loose my 10 year relationship, my Job and my Home. so after i hopefully can get my pieces from my life together and start from new, i will try to find the time learning some Basics.
Porting Stuff is actually not needed, because i stick to this old engine, atleast i have a running game. Have worked in the Gamebizz for various Companies long time and took part on more than 60 Released Games, and everytime as the devstuff decided to port to the new version of their engine, things became crazy :D i learned some things at that time, so, my private MOD will be not ported to a new engine version beside my own additions :D


Edited by: pvcf

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.