如何创建存储为由 2 个点(头、尾)组成的矢量的圆柱骨骼? [英] How to create a cylinderical bone stored as a vector made of 2 points (Head, Tail)?

查看:27
本文介绍了如何创建存储为由 2 个点(头、尾)组成的矢量的圆柱骨骼?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要的,有人在网上某处写过,但我以前从未使用过四元数,所以不知道如何实现它.我相信这只是一个简单的等式问题,但如何在 c/c++ 代码中实现?

 这里:您可以使用存储为由 2 个点(头、尾)组成的向量的骨骼.既然你在旋转它,头部将是支点,尾部将旋转绕任意轴.那是四元数的工作."

我有圆柱网格所有顶点的绝对位置,现在如果我在顶端和底端创建两个向量/点 V1(x, y, z) 和 V2(x, y, z),那么我将仅通过变换 V2(顶端)点即可变换网格顶点,但 V1(底端)不应改变其位置.

我可以在 OpenGL 中使用 glutSolidCylinder,它非常简单,但在这里我想用网格顶点来实现,所以每个顶点都应该在顶部或底部向量/点发生任何变化后更新.

谢谢.

解决方案

  1. 我改用 1 个变换矩阵 + 骨骼长度

    您如何知道仅从 2 个点绕哪个轴旋转?所以让

  2. 关节旋转

    现在您可以为每个骨骼添加一个或两个旋转角度.我使用 1 个自由度旋转,因此我将围绕绿色轴旋转.旋转矩阵的简单乘法,不需要四元数.

    在任何使用骨骼之前记住新矩阵(旋转)或角度并创建旋转矩阵,但始终记住原始矩阵以避免累积舍入误差

[注释]

有关更多信息,请使用谷歌直接或正向运动学问题.此外,CCD 和反向运动学 可能会有所帮助,OpenGL 中有大量机械臂示例,因此请搜索...您可以将任何运动学转换为一组单轴线性和角执行器

对于游戏和演示,您可以使用 BVH 文件为您的网格设置动画,请参阅:

This is what I want, somebody wrote somewhere on net but i never use quaternion before, so have no idea how to implement it. I am sure it would be just a matter of one simple equation but how to implement in c/c++ code?

    Here:
    "You could use a bone stored as a vector made of 2 points (Head,Tail).
 Since you are rotating it, Head will be the fulcrum and Tail will rotate
 around an arbitrary axis. That's a quaternion's job."

I have absolute positions of all vertices of a cylindrical mesh, now if I create two vectors/points V1(x, y, z) and V2(x, y, z) at top and bottom ends, then I will be able to transform the mesh vertices by just transforming the V2(top end) point, but V1(bottom end) should not change its position.

I can do in OpenGL with glutSolidCylinder, its pretty simple, but here I want to implement with mesh vertices, so each vertex should be updated after any change in top or bottom vectors/points.

Thanks.

解决方案

  1. I use 1 transform matrix + bone length instead

    How would you know around what axis to rotate from 2 points only? So make transform matrix representing bone origin. One axis is the bone axis (red) other one is the rotation axis of the joint (green) and the last is perpendicular to each (blue). Also the bone size (length) is needed (orange)

  2. Now the mesh is a tree of bones

    root sub-mesh is the starting point and the top layer bones are connected to it via joints. Second layer bones are connected to the first layer bones, and so on ... So you have to add index of previous bone/sub-mesh to which is current bone connected and can add also list of connected lower layer bones to speed up processing

  3. Drawing / computing

    this task is really just forward kinematics so translate/rotate root bone to desired object position. Take it matrix and store it to some temp. Draw/handle root sub-mesh/bone.

    Now for loop through all directly connected sub-meshes/bones to it and take its matrix and compute the multiplication of temp and it. Order depends on matrix style (row/column wise) this gets you actual matrix for sub-mesh/bone.

    So handle this as root sub-mesh/bone before moving to next bone translate this matrix along blue axis by bone length and recursively handle all next bones ...

    see old OpenGL API implementation: Rotating a multipart object

  4. Rotation of joints

    now you can add one or two angles of rotation per each bone. I use 1 degree of freedom rotations so I would rotate just around green axis. Simple multiplication by rotation matrix no quaternions needed.

    Either remember new matrix (rotated) or the angle and create rotated matrix before any use of bone but always remember the original matrix to avoid cumulative rounding errors

[notes]

For more info google direct or forward kinematics problem. Also CCD and Inverse Kinematics may help there are tons of robotic arm examples in OpenGL so search ... You can transform any kinematics to set of single axis linear and angular actuators

For games and demos you can use BVH files to animate your meshes see:

这篇关于如何创建存储为由 2 个点(头、尾)组成的矢量的圆柱骨骼?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆