risecreature Posted February 28, 2014 Share Posted February 28, 2014 I have models animation data with quaternions of rotation. How can I rotate model using this quaternion using Lua ? Quote Link to comment Share on other sites More sharing options...
beo6 Posted February 28, 2014 Share Posted February 28, 2014 Entity:SetRotation(quat) Quote Link to comment Share on other sites More sharing options...
risecreature Posted February 28, 2014 Author Share Posted February 28, 2014 How can I create quat? Quote Link to comment Share on other sites More sharing options...
james1943 Posted February 28, 2014 Share Posted February 28, 2014 go toFlowgraph Editor tutorial Quote Link to comment Share on other sites More sharing options...
beo6 Posted February 28, 2014 Share Posted February 28, 2014 Not sure what that tutorial tells about. Quaternions. But i thought you already have your quat. You can create a Quat with: local quat = Quat() Too bad that Quaternions are undocumented. Quote Link to comment Share on other sites More sharing options...
Admin Posted February 28, 2014 Share Posted February 28, 2014 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. Quote Link to comment Share on other sites More sharing options...
beo6 Posted February 28, 2014 Share Posted February 28, 2014 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) Quote Link to comment Share on other sites More sharing options...
Josh Posted February 28, 2014 Share Posted February 28, 2014 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. Quote 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 More sharing options...
Christian Clavet Posted March 1, 2014 Share Posted March 1, 2014 I (think ) I understand two things about Quaternions : - 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. Quote Link to comment Share on other sites More sharing options...
beo6 Posted March 1, 2014 Share Posted March 1, 2014 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted March 1, 2014 Share Posted March 1, 2014 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. Quote 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 More sharing options...
beo6 Posted March 1, 2014 Share Posted March 1, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.