Moderators: Sascha Willems, walaber
Function ApplyMatrixToVec3(M : TMatrix4; V : TVec3) : TVec3;
begin
Result[0] := ( V[0] * M[0,0] + V[1] * M[1,0] + V[2] * M[2,0] + M[3,0]);
Result[1] := ( V[0] * M[0,1] + V[1] * M[1,1] + V[2] * M[2,1] + M[3,1]);
Result[2] := ( V[0] * M[0,2] + V[1] * M[1,2] + V[2] * M[2,2] + M[3,2]);
end;
static void DebugSubmitGeometryCollision (void* userData, int vertexCount, const dFloat* faceVertec, int id)
{
dVector p0 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
for (int i = 0; (i < vertexCount) && (debugPointsCount < MAX_DEBUG_CONTACTS); i ++) {
dVector p1 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
debugDisplayList[debugLineCount][0] = p0;
debugDisplayList[debugLineCount][1] = p1;
debugLineCount ++;
p0 = p1;
}
}
static void DebugShowBodyCollision (const NewtonBody* body, void* userData)
{
dMatrix matrix;
NewtonBodyGetMatrix(body, &matrix[0][0]);
NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, NULL);
}
void DebugRenderWorldCollision (const NewtonWorld* world)
{
dVector aabbP0 (-1000.0f, -500.0f, -1000.0f);
dVector aabbP1 (1000.0f, 500.0f, 1000.0f);
debugLineCount = 0;
NewtonWorldForEachBodyInAABBDo (world, &aabbP0[0], &aabbP1[0], DebugShowBodyCollision, NULL);
}
...
DebugRenderWorldCollision (world)
// Render the array of line list usng d3d
Stucuk wrote:
- Code: Select all
Function ApplyMatrixToVec3(M : TMatrix4; V : TVec3) : TVec3;
begin
Result[0] := ( V[0] * M[0,0] + V[1] * M[1,0] + V[2] * M[2,0] + M[3,0]);
Result[1] := ( V[0] * M[0,1] + V[1] * M[1,1] + V[2] * M[2,1] + M[3,1]);
Result[2] := ( V[0] * M[0,2] + V[1] * M[1,2] + V[2] * M[2,2] + M[3,2]);
end;
void SetTransformCallback (const NewtonBody* body, const float* matrix, int threadIndex){
Model* ent;
Matrix mx = matrix;
ent = (Model*)NewtonBodyGetUserData(body);
ent->vecPos.x = matrix[12];
ent->vecPos.y = matrix[13];
ent->vecPos.z = matrix[14];
Vector3 newRot(
ent->vecRot.x*mx._11 + ent->vecRot.y*mx._21 + ent->vecRot.z*mx._31 + mx._41,
ent->vecRot.x*mx._12 + ent->vecRot.y*mx._22 + ent->vecRot.z*mx._32 + mx._42,
ent->vecRot.x*mx._13 + ent->vecRot.y*mx._23 + ent->vecRot.z*mx._33 + mx._43);
ent->vecRot = newRot;
}
Ripiz wrote:I did it wrong, either these maths are wrong, because object is rotating like crazy.
Users browsing this forum: No registered users and 1 guest