Set entity rotation from a dll

Blitz3D Forums/Blitz3D Programming/Set entity rotation from a dll

Lagrange(Posted 2012) [#1]
Hi,

i'm trying to move and rotate entities from a dll ( in order to do physics there and apply it directly to the objects ).

The dll recieves the entities address. I already found the list of offsets for the different properties.
Setting Entity X, Y, Z works - but the rotations don't.
I know, that you have to set the value at address + 44 to 3 to apply the changes.

Changing the value for Pitch doesn't do anything, changing Yaw scales and rotates the entity somehow - not the way i want it to.

Are the offsets wrong or is there another trick to do rotations?
And what ist the 4x4 Matrix for, you can also access?

Thank you


Yasha(Posted 2012) [#2]
The 4x4 matrix is a translation matrix. It controls rotation, position and scale. That sort of thing is described in detail here: http://www.blitzbasic.com/Community/posts.php?topic=42657

There are no stored values for pitch, yaw or roll, so I don't know what you've been setting. You have to use the matrix.

Another, probably better, option would be to use a hack to get function pointers, and simply pass a Blitz function (e.g. a little "SetPositionAndRotation" wrapper) to the DLL, that it can call with the right values.


Lagrange(Posted 2012) [#3]
ah, ok i'll think about using function pointers, as you said - thanks.

The values i was setting where:
Offset 48 ( float ) for Pitch
Offset 52 ( float ) for Yaw
Offset 56 ( float ) for Roll

because i found these in a list. Seems to be wrong information.
Im not exactly sure, but they were somehow connected with the entitys rotation.
Turning the object would make them change values ( between -1 and 1, but no sin/cos function, if i saw it right )


Yasha(Posted 2012) [#4]
Sounds like you found one of the places where the entity stores its rotation as a quaternion. Blitz translates between quaternions and Euler angles every time you use one of the rotation or angle functions.

There's quite a lot of redundancy in the entity's transformation data (cached values to make accessing it very fast and reduce the amount of recomputation). Setting certain fields "manually" runs a minor risk of breaking this system as certain things might not be updated properly, when the engine expects things to be changed only through the right access functions.

That's a second reason for suggesting the function pointer (as well as reducing the amount of hacking from several offsets to one pointer method): you'd still technically be using the "expected" methods of access for manipulating the entity, so it's highly unlikely you'd make many errors.


Tom(Posted 2012) [#5]
This stuff should have been exposed to the user many years ago.


Lagrange(Posted 2012) [#6]
I've been reading for hours now, what i learned so far is:

The best example for function pointers was this: http://www.blitzbasic.com/codearcs/codearcs.php?code=1639

I havn't tried it out yet - don't know if i could make it run - it uses a bit of assembler code in the dll, which i don't understand.
The problem is, that you can't pass arguments ( euler angles ).
So the blitz function would have to "call back" dll functions to receive the arguments.
Would be ok.

The other thing with the matrices:
The 4x4 gives the transformation from global zero to objects actual orientation, position and scaling. I have seen the standard transformation matrices to do either rotation, translation or scaling.
And i guess, that combined operations like scaling and rotating - respectively transforming an already transformed object - would have to include inverse matrices too if its done only with mat. multiplication.

Directly changing the entries in the last row (4,1) (4,2) (4,3) sets x, y, z.
What i don't understand: the x value appears also in the last column, element (3,4).

But i can't imagine how to do a rotation, because rotating the "upper left" 3x3 matrix in the usual way is probably wrong, because the values in the last column have to change somehow to.

Also i didn't even find all the elements of the matrix, some i found twice, as you said, its complicated. But is there a list of the addresses? Maybe i'll try this "magic number scan" - but that will probably take a lot of time.

Anyway, its not that important if i can get the function pointers to work. I haven't used the maths about geometry before ( don't even know what quaternions are ) but it would interest me to try it out a bit more.

I read the link you posted, but i couldn't get that much out of it.
If you know a tutorial where the 4x4 matrix, quaternions and things concerning 3d math are dealt with, that would be great, i didn't find it yet.


Edit: Or is there a possibility to call function pointers with arguments? ( without using additional dll's ).

Last edited 2012


Yasha(Posted 2012) [#7]
To use function pointers, your best bet is MikhailV's FastPointer library: http://www.fastlibs.com/index.php

It's both reliable for taking the pointer, and able to accept arguments (although it doesn't do return values - you can always work around that with a global variable or something). In my experience it doesn't like taking the pointer for builtin functions, only user-defined ones (the library relies on extremely specific assembly instructions in the backend, so e.g. the varpointers example doesn't work with locals because that generates different code: similarly the function pointers example only works with the right kind of functions).

Anyway the important bit is getting the function pointer; writing a userlib wrapper function to call a function pointer with the right arguments and return value is utterly trivial (if you need one beyond what FastPointer offers, ask and I'll show you).