I need the quaternion of a triangle in the trimesh. When there's a
collision, I can use the index and the trimesh along with the get
triangle function to get the vertices of the triangle like so:
dVector3 v0, v1, v2;
dGeomTriMeshGetTriangle( trimeshGeom, triangleIndex, &v0, &v1, &v2 );
I'm actually not concerned with the imaginary 'w' component of the
quaternion so I'm only after the x, y and z. I thought I could get
these by getting the normal of the triangle:
D3DXVECTOR3 dxV1 ( v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2] );
D3DXVECTOR3 dxV2 ( v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2] );
D3DXVec3Cross( &triNormal, &dxV1, &dxV2 );
and then using that cross product of that and the inverse normal to
get the x, y and z components I desire, but it seems I'm very wrong.
This is the first time I ever hear of triangles inherently having quaternions, so I don't know what you're talking about, however, I guess that you could take the triangle normal, normalize one of the sides of the triangle to get a perpendicular normal, get the cross product of those to get a second "axis" and finally the cross product of the second axis and the normal to get the third axis, stuff them in a 3x3 matrix (I have no idea of the order though) and extract a quaternion from that.
colmsl...@gmail.com wrote: > I need the quaternion of a triangle in the trimesh. When there's a > collision, I can use the index and the trimesh along with the get > triangle function to get the vertices of the triangle like so: > dVector3 v0, v1, v2; > dGeomTriMeshGetTriangle( trimeshGeom, triangleIndex, &v0, &v1, &v2 );
> I'm actually not concerned with the imaginary 'w' component of the > quaternion so I'm only after the x, y and z. I thought I could get > these by getting the normal of the triangle: > D3DXVECTOR3 dxV1 ( v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2] ); > D3DXVECTOR3 dxV2 ( v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2] ); > D3DXVec3Cross( &triNormal, &dxV1, &dxV2 );
> and then using that cross product of that and the inverse normal to > get the x, y and z components I desire, but it seems I'm very wrong.
Rodrigo Hernandez wrote: > This is the first time I ever hear of triangles inherently having > quaternions, so I don't know what you're talking about, however, I guess > that you could take the triangle normal, normalize one of the sides of > the triangle to get a perpendicular normal, get the cross product of > those to get a second "axis" and finally the cross product of the second > axis and the normal to get the third axis, stuff them in a 3x3 matrix (I > have no idea of the order though) and extract a quaternion from that.
>> I need the quaternion of a triangle in the trimesh. When there's a >> collision, I can use the index and the trimesh along with the get >> triangle function to get the vertices of the triangle like so: >> dVector3 v0, v1, v2; >> dGeomTriMeshGetTriangle( trimeshGeom, triangleIndex, &v0, &v1, &v2 );
>> I'm actually not concerned with the imaginary 'w' component of the >> quaternion so I'm only after the x, y and z. I thought I could get >> these by getting the normal of the triangle: >> D3DXVECTOR3 dxV1 ( v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2] ); >> D3DXVECTOR3 dxV2 ( v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2] ); >> D3DXVec3Cross( &triNormal, &dxV1, &dxV2 );
>> and then using that cross product of that and the inverse normal to >> get the x, y and z components I desire, but it seems I'm very wrong.
colmsl...@gmail.com wrote: > I need the quaternion of a triangle in the trimesh. When there's > and then using that cross product of that and the inverse normal to > get the x, y and z components I desire, but it seems I'm very wrong.
That's not a well-defined concept. You have to define what it is you want better. A triangle does not, inherently, have a "rotation," any more than it has a "translation." Those concepts can only be defined in reference to some other state.
Also, normals don't have inverses, as they are vectors, not transforms.
Perhaps what you want is a rotation that takes the normal from the state the triangle has in an untransformed mesh, and rotates the triangle to match the new normal? The problem is that there is an infinity of such rotations, because the triangle can be rotated any degree around the normal. Perhaps what you want is the shortest circular rotation that will make the identity normal align with the current triangle normal? Or do you want the rotation that will make all vertices of the original triangle align with the current triangle? In all these cases, the assumed reference is an "untransformed" triangle, but if your triangle mesh is static (doesn't move), then the rotation will always be identity.
So, if you can define what it is you want, then perhaps someone can help you come up with how to get that. Or perhaps it falls out directly from the definition.
> I need the quaternion of a triangle in the trimesh. [...] > Is there an easier way of doing this?
To put what Rodrigo and John said in simpler terms:
What you said does not make much sense to us. Why don't you tell us what you are trying to accomplish, so we can try to guide you to the "easier"/correct solution?
Are you by any chance trying to convert between local/world coordinates? The dGeomTriMeshGetTriangle() function returns the triangle in world coordinates. To get local coordinates, just access the trimesh data you provided to ODE instead of doing the inverse rotation+translation transform.
-- Daniel K. O. "The only way to succeed is to build success yourself"
i )) )[1]),
fabs(dBodyGetQuaternion( dGeomGetBody( dSpaceGetGeom( _turbineSpace,
i )) )[2]),
fabs(dBodyGetQuaternion( dGeomGetBody( dSpaceGetGeom( _turbineSpace,
i )) )[3]) );
and this was working perfectly but now I've changed my setup so I no
longer have contact details (I was testing on a box but now I'm
testing on a trimesh). Any ideas?
I think the confusion is that the orientation you are looking for seems not to be unique and can rotate around the normal of the triangle. Similarly, in step 2 in the image, it seems like the ray could go to any direction that is parallel to the plane of the triangle.
I'm just speculating, maybe you want the initial ray to have the smallest possible angle with the bouncing ray that is constrained to be in the plane of the triangle (and any direction would be fine if the ray was exactly parallel to the normal). In this case you can find the direction of the second ray by just projecting the initial ray to the plane of the triangle. A simple way to do that is to first project the ray on the normal and subtract that from the ray.
Hope that helps.
-Gazi
On 28/03/2008, colmsl...@gmail.com <colmsl...@gmail.com> wrote:
where trinormal is the triangle normal and ray is the ray's direction (destination-origin if you have it in segment notation). output will contain the normalized direction of the projected ray.
You may notice this is very similar to what I described before, getting the orthonormal basis for the triangle.