- Joined
- Feb 2, 2012
- Messages
- 1,666
- Reaction score
- 100
- Points
- 78
Hi all,
I need to rotate paylaods mesh in MS2015 and I found around the following function which was originally written by Face:
This works perfectly with inline client, but not with d3d9 and since I want MS2015 to be of course compatible also with d3d9 I need to using devmeshhandles instead of meshhandles. But if I change the first argument of this function to devmeshhandle and I pass a correct devmesh to it I get a CTD...
from a bit of testing I found out that there is something wrong with oapiMeshGroupCount (since it seems not to support devmeshes) and from that line on everything seems not to work anymore.
Any help would be greatly appreciated
---------- Post added at 14:58 ---------- Previous post was at 09:38 ----------
Maybe since there is no need to have absolute references for payload rotation I can simply animate the payload mesh and turn it. The user will just have to know the order with which rotations are applied and will deal with that.
I need to rotate paylaods mesh in MS2015 and I found around the following function which was originally written by Face:
Code:
// Rotates a vector around an arbitrary axis (angle should be in Radians)
VECTOR3 chippersat::RotateVector(const VECTOR3& input, double angle, const VECTOR3& rotationaxis)
{
// To rotate a vector in 3D space we'll need to build a matrix, these are the variables treqired to do so.
MATRIX3 rMatrix;
double c = cos(angle);
double s = sin(angle);
double t = 1.0 - c;
double x = rotationaxis.x;
double y = rotationaxis.y;
double z = rotationaxis.z;
// Build rotation matrix
rMatrix.m11 = (t * x * x + c);
rMatrix.m12 = (t * x * y - s * z);
rMatrix.m13 = (t * x * z + s * y);
rMatrix.m21 = (t * x * y + s * z);
rMatrix.m22 = (t * y * y + c);
rMatrix.m23 = (t * y * z - s * x);
rMatrix.m31 = (t * x * z - s * y);
rMatrix.m32 = (t * y * z + s * x);
rMatrix.m33 = (t * z * z + c);
// Perform Rotation
VECTOR3 output = mul(rMatrix, input); // multiply the input vector by our rotation matrix to get our output vector
return output; // Return rotated vector
}
// Rotates an entire mesh around an arbitrary axis Orginally written by Face as part of the "Ascension Ultra" addon.
void RotateMesh(MESHHANDLE mesh, float angle, VECTOR3 rotationaxis, VECTOR3 ref)
{
// Build rotation matrix
double c = cos(angle);
double s = sin(angle);
double t = 1.0 - c;
double x = rotationaxis.x;
double y = rotationaxis.y;
double z = rotationaxis.z;
MATRIX3 rMatrix;
rMatrix.m11 = (t * x * x + c);
rMatrix.m12 = (t * x * y - s * z);
rMatrix.m13 = (t * x * z + s * y);
rMatrix.m21 = (t * x * y + s * z);
rMatrix.m22 = (t * y * y + c);
rMatrix.m23 = (t * y * z - s * x);
rMatrix.m31 = (t * x * z - s * y);
rMatrix.m32 = (t * y * z + s * x);
rMatrix.m33 = (t * z * z + c);
// Perform Rotation
int k = oapiMeshGroupCount(mesh); // Get number of meshgroups in mesh and sake it as "k"
for (int i=0; i<k; i++) // Go through each mesh group in turn
{
MESHGROUP *m = oapiMeshGroup(mesh, i); // Get group data and store it in "m".
DWORD l=m->nVtx; // Get number of vertices if "m" in and store it as "l".
for(DWORD j=0; j<l; j++) // For each vertex...
{
VECTOR3 p = _V( m->Vtx[j].x, m->Vtx[j].y, m->Vtx[j].z); // Store the original position of the vertex in p.
VECTOR3 n = _V( m->Vtx[j].nx, m->Vtx[j].ny, m->Vtx[j].nz); // Store the original normal of the vertex in n.
p = mul( rMatrix, (p-ref)) + ref; // Shift p by ref, multiply it by rMatrix, and then shift the result back.
n = mul( rMatrix, (n-ref)) + ref; // Do the same to n.
// Write new value of p into the live structure.
m->Vtx[j].x=p.x;
m->Vtx[j].y=p.y;
m->Vtx[j].z=p.z;
// Write new value of n into the live structure.
m->Vtx[j].nx=n.x;
m->Vtx[j].ny=n.y;
m->Vtx[j].nz=n.z;
} // End vertext operations
} // End meshgroup operations
} // End void
This works perfectly with inline client, but not with d3d9 and since I want MS2015 to be of course compatible also with d3d9 I need to using devmeshhandles instead of meshhandles. But if I change the first argument of this function to devmeshhandle and I pass a correct devmesh to it I get a CTD...
from a bit of testing I found out that there is something wrong with oapiMeshGroupCount (since it seems not to support devmeshes) and from that line on everything seems not to work anymore.
Any help would be greatly appreciated
---------- Post added at 14:58 ---------- Previous post was at 09:38 ----------
Maybe since there is no need to have absolute references for payload rotation I can simply animate the payload mesh and turn it. The user will just have to know the order with which rotations are applied and will deal with that.