setWorldRotationAnglesWithOrder [solved]

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

setWorldRotationAnglesWithOrder [solved]

Post 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.
Last edited by AdrTru on Thu Jan 01, 2015 12:37 pm, edited 1 time in total.
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: setWorldRotationAnglesWithOrder

Post 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.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: setWorldRotationAnglesWithOrder

Post 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.
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: setWorldRotationAnglesWithOrder

Post 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.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: setWorldRotationAnglesWithOrder

Post 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.
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: setWorldRotationAnglesWithOrder

Post 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....
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: setWorldRotationAnglesWithOrder

Post by minmay »

After some experimentation, I have concluded that the "mat" stands for "matrix" and I am an idiot.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: setWorldRotationAnglesWithOrder

Post 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.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: setWorldRotationAnglesWithOrder

Post 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
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: setWorldRotationAnglesWithOrder

Post 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.
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
Post Reply