Python : mean of 2 transformation matrix


How can i make an object positionnned and oriented like it’s half way between 2 others. I don’t remember my matrix theory :frowning_face:

1 Like

Sure you could use a lerp function to get the halway point between to objects.
So like this:

def lerp(self,a, b, percent):
    return a + percent * (b-a) 

middle_location = lerp(first_object.worldPosition, second_object.worldPosition, .5) 
object_That_I_want_in_the_Middle.worldPosition = middle_location

nice, i though it was a function of an object only

cam.worldTransform = cam.worldTransform.lerp(obj2.worldTransform ,0.05 )

1 Like

yea, me too. i think its like that in godot language. built-in.

1 Like

@blenderaptor yeah it should work fine with a transfrom matrix. the only limitation would be if you were trying to divide the matrixes.

btw Thomas, are u using BGE or UPBGE for your project ? Did you receive any help for the rendering (materials, shadings, lightings, baking and all that stuff )

1 Like
  1. I was using BGE I have since migrated to UPBGE
  2. So most of the Materials were made by me. However individual assets I recieved TONS of help on from many artists around the world.
    I would say at this point the project has involved up to 40 people in one way or another.

40 people, wow your game made them that scared to refuse ? :cold_face:
you might have good connections

1 Like

Haha what? Why would people refuse to help me make the game? The people who helped wanted to help also I paid them.

Why wouldn’t people want to get paid to work on a video game?

Also I think that number may be higher. A rough estimate might be better at 90 people. Especially including my 48 patrons. It’s humbling and a bit scary to get so much support. Every dollar that goes to supporting the game goes to building the game, and I count my partons among those who are helping in a very substantial way.
Also all patrons will be credited.

1 Like

sorry, i didn’t really checked this solution as i was on another way. This doesnt answer the question beside the fact im not sure the utility to create a function for a simple weigthted sum.

Look, i want to mix the position,orientation of 2 objects (worldTransform)

obj1.worldTransform = obj1.worldTransform.lerp(obj2.worldTransform ,0.05 )

But that function just reduce by 5% the 2 matrix at each frame. I want something like this simply :

obj1.worldTransform = 0.3 * obj2.WorldTransform + 0.7 * obj3.worldTransform

maybe this

obj1.worldTransform = obj2.worldTransform.lerp(obj3.worldTransform ,0.7 )

well, it’s as simple as that. I was so used to use lerp in a 1 way that i didnt even realise it returns a matrix and was not simply a transform on the object it self. Well, nvm x)

1 Like

I’m glad this helped. I hope it helped?

mix function in glsl:

float mix(float x, float y, float a)  
vec2 mix(vec2 x, vec2 y, vec2 a)  
vec3 mix(vec3 x, vec3 y, vec3 a)  
vec4 mix(vec4 x, vec4 y, vec4 a)

The mix function returns the linear blend of x and y, i.e. the product of x and (1 - a) plus the product of y and a.

maybe it can be translated into python if helps.

I’m unsure if I have answered you question effectively, did you get it to work for you?

he wants the object to be positioned as well as ORIENTED like it’s half way between 2 others.
your code only interpolates position.

using worldTransform gives weird results, my guess it has to do with the w axis or something.

@Thomas_Murphy . It’s ok, this is the ‘dirty’ solution

obj1.worldTransform = obj2.worldTransform.lerp(obj3.worldTransform ,0.7 )

it’s not necessary to create functions when everything holds in the same line :wink:

1 Like