Jump to content

Can model be rotated by quaternion (Lua) ?


risecreature
 Share

Recommended Posts

Quaternions are used internally for rotations, and are not meant to be a front-facing user feature. They're far too complicated for the user to have to deal with.

 

The built-in functions like Entity:Turn() will allow you to rotate objects smoothly without problems with gimbal lock.

 

 

Link to comment
Share on other sites

even if i agree that they might be too complicated, i struggled with them myself a bit. However sometimes they are necessary.

Look at my script for rotating a model according to the terrain slopes. Entity:Turn will not help there. So they should be accessible.

 

I don't like if things are unaccessible just because someone thinks they are too complicated.

That just sounds like anyone else is just stupid. (really sorry for the harsh wording. don't want to be aggressive)

Link to comment
Share on other sites

Wouldn't AlignToVector() be the appropriate command for that case?

 

I don't really understand quaternions. They can't be easily visualized. I just copied the math out of a book and did a ton of testing.

 

Quats have a constructor like this: Quat(x,y,z,w). You might have to flip the w coordinate or others depending on how they are stored.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I (think rolleyes.gif ) I understand two things about Quaternions tongue.png:

- They don't suffer gimbal lock like it happen with euler angles

- It work based on an offset angle.

 

From what I understand of doing a rotation using euler angles will require 3 mathematical operations (rotateX then, RotateY then finally RotateZ), while a Quaternion rotation is done from a single pass. (directional vector (x,y,z), offset)

 

If you are using euler angle rotations and and if you are only manipulating 2 axes won't really cause gimbal lock. It's only when you are rotating using the 3 axes that it will happen. So it will mostly happen if you really need to rotate something on 3 axis (airplanes, spaceships, etc)

 

Do we have functions to convert a euler angle to a quat and the reverse?

 

Still trying to figure out how they work, it would be really usefull to move spaceships (rotating all angles) or rotating something with the mouse so it doesn't gimbal lock.

EDIT: Just seen that, thanks Josh!

The built-in functions like Entity:Turn() will allow you to rotate objects smoothly without problems with gimbal lock.
Link to comment
Share on other sites

Nope. AlignToVector didn't worked in that case because i need to take the model rotation into account and ignore the terrain vector rotation or else it works only on one side of a hill.

 

I am no expert in that. I just copied from another engine and it worked where everything else i tried failed.

Link to comment
Share on other sites

Nope. AlignToVector didn't worked in that case because i need to take the model rotation into account and ignore the terrain vector rotation or else it works only on one side of a hill.

AlignToVector has an optional value for the rotation around the vector you are aligning the entity to.

 

I (think) understand 2 things about Quaternions:

- They don't suffer gimbal lock like it happen with euler angles

- It work based on a offset angle.

 

Still trying to figure out how they work, it would really usefull to move spaceships (rotating all angles) or rotating something with the mouse so it doesn't gimbal lock. I've heard that some use transformation matrices with them to do the proper rotation.

Leadwerk is designed so that you don't need to deal with complicated math like that. TurnEntity and AlignToVector will handle gradual rotation without Gimbal Lock. Both use spherical linear interpolation to perform an error-free rotation.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

AlignToVector has an optional value for the rotation around the vector you are aligning the entity to.

 

I don't think that is exactly what is needed for an entity that should rotate according to the terrain slope and also rotate in the direction it is moving since both are different axis the entity need to align to. But maybe i am just too stupid for it.

local world = World:GetCurrent()
local pickinfo = PickInfo()
local pivotPos = self.pivot:GetPosition()
local rayStart = Vec3(pivotPos.x, pivotPos.y+1, pivotPos.z)
local rayEnd = Vec3(rayStart.x, rayStart.y-50, rayStart.z)
if (world:Pick(rayStart,rayEnd,pickinfo,0.1,true,Collision.Scene)) then
 local terrainNormal = pickinfo.normal
 local pivotRotation = self.pivot:GetRotation(true)
 self.entity:AlignToVector(terrainNormal, 1, 0.5, pivotRotation.y)
end

 

It seems no one else had an idea when i opened a forum post with that problem so i was stuck and searched for a different solution and found a more complicated one which worked for me.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...