Page 1 of 2

setWorldRotationAnglesWithOrder [solved]

Posted: Wed Dec 17, 2014 5:38 pm
by AdrTru
Hi,

Do someone known how correct call this function?
GameObject:setWorldRotationAnglesWithOrder(x, y, z, order)

I mean format for order (string).

Thank you for reply.

Re: setWorldRotationAnglesWithOrder

Posted: Wed Dec 17, 2014 9:42 pm
by JohnWordsworth
It's a complete guess, but logically, I would expect something like...

entity.go:setWorldRotationAnglesWithOrder(45, 0, 90, "zxy")

When rotating something by using 3 Euler angles, the order that the 3 separate rotations are applied matters, so the string must represent that ordering somehow. It is possible its "ypr" instead I guess (yaw, pitch, roll) but my gut is telling me just a combination of "xyz" is what you are after.

Re: setWorldRotationAnglesWithOrder

Posted: Wed Dec 17, 2014 11:43 pm
by AdrTru
Thank you for describtion,
but this function dont work like my imagination :)

I have objects, this are free rotated. My problem is get new rotation of these objects by facing of main object.
That means I need relative rotate object by world axes.
My knowledge of mathematic for this transformation is unfortunately too low.

Re: setWorldRotationAnglesWithOrder

Posted: Thu Dec 18, 2014 2:20 am
by minmay
Has anyone figured out a way to make the "mat" type needed by setWorldRotation()? I'm not sure what exactly the meaning of it is (looks like four quaternions, but that's 3 more than I would expect...) but it might be easier than using Euler angles in some cases.

Re: setWorldRotationAnglesWithOrder

Posted: Sat Dec 20, 2014 9:55 pm
by AdrTru
Hi,

I wos study rotation systems.
I thing that "ypr" will be good for managing rotation by facing. But isnt worked yet.

BTW: I wish you great XMas.

Re: setWorldRotationAnglesWithOrder

Posted: Sat Dec 20, 2014 10:00 pm
by MrChoke
I too am trying out WorldRotations and see this new type called "mat". No idea what it is. I guess it is experimentation time to figure it out....

Re: setWorldRotationAnglesWithOrder

Posted: Mon Dec 22, 2014 8:41 am
by minmay
After some experimentation, I have concluded that the "mat" stands for "matrix" and I am an idiot.

Re: setWorldRotationAnglesWithOrder

Posted: Tue Dec 23, 2014 1:00 am
by JohnWordsworth
I don't know if we have the facility to create our own matrix objects (I've tried the obvious calls, such as mat(), mat44(), mat4() to no avail).

HOWEVER, I have figured out one useful thing with regards to using matrices for setWorldRotation().

Code: Select all

local m = entity.go:getWorldRotation();
print(m);
m.x = vec(1,0,0,0)
entity.go:setWorldRotation(m)
This allows you to get the matrix object from the object, change the values (the matrix information looks to be stored where x, y, z, w are each a vector of length 4 - ie. it's a 4x4 matrix).

Haven't really had much chance to play with this otherwise, but that's the foundation of it.

Re: setWorldRotationAnglesWithOrder

Posted: Tue Dec 23, 2014 11:03 am
by AdrTru
Thank you JohnWordsword,

but unfortunetaly entity.go:getWorldRotation() make error : "attempt to call method 'getWorldRotation' (a nil value) X"

EDIT: my mistake - I miss update to 2.1.17 - in this update its function working

Re: setWorldRotationAnglesWithOrder

Posted: Thu Jan 01, 2015 12:35 pm
by AdrTru
I solved this rotation problem by creating socket component in base object - insert item into it - get word parameters of this item - destroy socket component.
This algorythm work in version 2.1.17.

Code: Select all

------------------------------------------------------------------------------------------------
-- Transform position and rotation for item 
-- entity - GameObject suitable for arrange item on it
-- pos - position offset for inserted item
-- rot - rotation of this item in Angles

function transformSocket(entity,pos,rot)

	-------- Create socket component in entity ----------------
	entity:createComponent("Socket","false_socket")
	local sock = entity.false_socket	
	sock:setRotationAngles(rot[1],rot[2],rot[3])
	sock:setOffset(vec(pos[1],pos[2],pos[3]))
	
	-------- Create some item in new socket ----------------
	local false_item = spawn("herder_cap")
	sock:addItem(false_item.item)
	
	-------- Get information of word position and rotation of socketed item ----------------
	local rotx = false_item:getWorldRotation();
	local posx = false_item:getWorldPosition();
	
	-------- Destroy item and socket component ----------------
	false_item:destroy()
	entity:removeComponent("false_socket")
	
	-------- Return word position and word rotation for correct item ----------------
	return posx,rotx
end
Now I am ready for make MultiAlcoveManager for LOG2.