本文整理汇总了C++中dgMatrix类的典型用法代码示例。如果您正苦于以下问题:C++ dgMatrix类的具体用法?C++ dgMatrix怎么用?C++ dgMatrix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了dgMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: origin
void dgCollisionScene::CalcAABB (const dgMatrix& matrix, dgVector& p0, dgVector& p1) const
{
dgVector origin (matrix.TransformVector(m_boxOrigin));
dgVector size (m_boxSize.m_x * dgAbsf(matrix[0][0]) + m_boxSize.m_y * dgAbsf(matrix[1][0]) + m_boxSize.m_z * dgAbsf(matrix[2][0]) + DG_MAX_COLLISION_PADDING,
m_boxSize.m_x * dgAbsf(matrix[0][1]) + m_boxSize.m_y * dgAbsf(matrix[1][1]) + m_boxSize.m_z * dgAbsf(matrix[2][1]) + DG_MAX_COLLISION_PADDING,
m_boxSize.m_x * dgAbsf(matrix[0][2]) + m_boxSize.m_y * dgAbsf(matrix[1][2]) + m_boxSize.m_z * dgAbsf(matrix[2][2]) + DG_MAX_COLLISION_PADDING,
dgFloat32 (0.0f));
p0 = origin - size;
p1 = origin + size;
#ifdef DG_DEBUG_AABB
dgInt32 i;
dgVector q0;
dgVector q1;
dgMatrix trans (matrix.Transpose());
for (i = 0; i < 3; i ++) {
q0[i] = matrix.m_posit[i] + matrix.RotateVector (BoxSupportMapping(trans[i].Scale (-1.0f)))[i];
q1[i] = matrix.m_posit[i] + matrix.RotateVector (BoxSupportMapping(trans[i]))[i];
}
dgVector err0 (p0 - q0);
dgVector err1 (p1 - q1);
dgFloat32 err;
err = GetMax (size.m_x, size.m_y, size.m_z) * 0.5f;
_ASSERTE ((err0 % err0) < err);
_ASSERTE ((err1 % err1) < err);
#endif
}
示例2: OOBBTest
bool dgCollisionConvexHull::OOBBTest (const dgMatrix& matrix, const dgCollisionConvex* const shape, void* const cacheOrder) const
{
bool ret;
_ASSERTE (cacheOrder);
ret = dgCollisionConvex::OOBBTest (matrix, shape, cacheOrder);
if (ret) {
const dgConvexSimplexEdge* const* faceArray = m_faceArray;
dgCollisionBoundPlaneCache* const cache = (dgCollisionBoundPlaneCache*)cacheOrder;
for (dgInt32 i = 0; i < dgInt32 (sizeof (cache->m_planes) / sizeof (dgPlane)); i ++) {
dgFloat32 dist;
const dgPlane& plane = cache->m_planes[i];
if ((plane % plane) > dgFloat32 (0.0f)) {
dgVector dir (matrix.UnrotateVector(plane.Scale (-1.0f)));
dir.m_w = dgFloat32 (0.0f);
dgVector p (matrix.TransformVector (shape->SupportVertex(dir)));
dist = plane.Evalue (p);
if (dist > dgFloat32 (0.1f)){
return false;
}
}
}
for (dgInt32 i = 0; i < m_boundPlanesCount; i ++) {
dgInt32 i0;
dgInt32 i1;
dgInt32 i2;
dgFloat32 dist;
const dgConvexSimplexEdge* const face = faceArray[i];
i0 = face->m_prev->m_vertex;
i1 = face->m_vertex;
i2 = face->m_next->m_vertex;
const dgVector& p0 = m_vertex[i0];
dgVector normal ((m_vertex[i1] - p0) * (m_vertex[i2] - p0));
normal = normal.Scale (dgFloat32 (1.0f) / dgSqrt (normal % normal));
dgVector dir (matrix.UnrotateVector(normal.Scale (-1.0f)));
dir.m_w = dgFloat32 (0.0f);
dgVector p (matrix.TransformVector (shape->SupportVertex(dir)));
//_ASSERTE ((normal % (m_boxOrigin - p0)) < 0.0f);
dist = normal % (p - p0);
if (dist > dgFloat32 (0.1f)){
for (dgInt32 j = 0; j < (dgInt32 (sizeof (cache->m_planes) / sizeof (dgPlane)) - 1); j ++) {
cache->m_planes[j + 1] = cache->m_planes[j];
}
cache->m_planes[1] = dgPlane (normal, - (normal % p0));
return false;
}
}
}
return ret;
}
示例3: BoundingBox
// Compute axis aligned box
static void BoundingBox (const dgMatrix &Mat, const hacd::HaF32 vertex[], hacd::HaI32 vertexCount, hacd::HaI32 stride, dgVector &min, dgVector &max)
{
hacd::HaF32 xmin = hacd::HaF32 (1.0e10f);
hacd::HaF32 ymin = hacd::HaF32 (1.0e10f);
hacd::HaF32 zmin = hacd::HaF32 (1.0e10f);
hacd::HaF32 xmax = hacd::HaF32 (-1.0e10f);
hacd::HaF32 ymax = hacd::HaF32 (-1.0e10f);
hacd::HaF32 zmax = hacd::HaF32 (-1.0e10f);
const hacd::HaF32* ptr = vertex;
for (hacd::HaI32 i = 0 ; i < vertexCount; i ++ ) {
dgVector tmp (ptr[0], ptr[1], ptr[2], hacd::HaF32 (0.0f));
ptr += stride;
tmp = Mat.UnrotateVector (tmp);
if (tmp.m_x < xmin) xmin = tmp.m_x;
if (tmp.m_y < ymin) ymin = tmp.m_y;
if (tmp.m_z < zmin) zmin = tmp.m_z;
if (tmp.m_x > xmax) xmax = tmp.m_x;
if (tmp.m_y > ymax) ymax = tmp.m_y;
if (tmp.m_z > zmax) zmax = tmp.m_z;
}
min = dgVector (xmin, ymin, zmin, hacd::HaF32 (0.0f));
max = dgVector (xmax, ymax, zmax, hacd::HaF32 (0.0f));
}
示例4: ConvexCast
dgInt32 dgBroadPhaseDefault::ConvexCast(dgCollisionInstance* const shape, const dgMatrix& matrix, const dgVector& target, dgFloat32& timeToImpact, OnRayPrecastAction prefilter, void* const userData, dgConvexCastReturnInfo* const info, dgInt32 maxContacts, dgInt32 threadIndex) const
{
dgInt32 totalCount = 0;
if (m_rootNode) {
dgVector boxP0;
dgVector boxP1;
dgAssert(matrix.TestOrthogonal());
shape->CalcAABB(matrix, boxP0, boxP1);
dgFloat32 distance[DG_BROADPHASE_MAX_STACK_DEPTH];
const dgBroadPhaseNode* stackPool[DG_BROADPHASE_MAX_STACK_DEPTH];
dgVector velocA((target - matrix.m_posit) & dgVector::m_triplexMask);
dgVector velocB(dgFloat32(0.0f));
dgFastRayTest ray(dgVector(dgFloat32(0.0f)), velocA);
dgVector minBox(m_rootNode->m_minBox - boxP1);
dgVector maxBox(m_rootNode->m_maxBox - boxP0);
stackPool[0] = m_rootNode;
distance[0] = ray.BoxIntersect(minBox, maxBox);
totalCount = dgBroadPhase::ConvexCast(stackPool, distance, 1, velocA, velocB, ray, shape, matrix, target, timeToImpact, prefilter, userData, info, maxContacts, threadIndex);
}
return totalCount;
}
示例5: CalcAABB
void dgCollisionDeformableMesh::CalcAABB (const dgMatrix& matrix, dgVector& p0, dgVector& p1) const
{
dgVector origin (matrix.TransformVector(m_boxOrigin));
dgVector size (matrix.m_front.Abs().Scale4(m_boxSize.m_x) + matrix.m_up.Abs().Scale4(m_boxSize.m_y) + matrix.m_right.Abs().Scale4(m_boxSize.m_z));
p0 = (origin - size) & dgVector::m_triplexMask;
p1 = (origin + size) & dgVector::m_triplexMask;
}
示例6: dgAssert
void dgCollisionDeformableSolidMesh::SetMatrix(const dgMatrix& matrix)
{
dgAssert (m_myBody);
//dgMatrix globalMatrix (GetBody()->GetCollision()->GetLocalMatrix() * matrix);
for (dgInt32 i = 0; i < m_particles.m_count; i ++) {
m_particles.m_posit[i] = m_shapePosit[i];
m_posit[i] = matrix.TransformVector(m_shapePosit[i]) & dgVector::m_triplexMask;
}
}
示例7: dgFloat32
void dgCollisionChamferCylinder::DebugCollision (const dgMatrix& matrix, dgCollision::OnDebugCollisionMeshCallback callback, void* const userData) const
{
//dgCollisionConvex::DebugCollision (matrix, callback, userData);
//return;
dgInt32 slices = 12;
dgInt32 brakes = 24;
dgFloat32 sliceAngle = dgFloat32 (0.0f);
dgFloat32 sliceStep = dgPI / slices;
dgFloat32 breakStep = dgPI2 / brakes;
dgTriplex pool[24 * (12 + 1)];
dgMatrix rot (dgPitchMatrix (breakStep));
dgInt32 index = 0;
for (dgInt32 j = 0; j <= slices; j ++) {
dgVector p0 (-m_height * dgCos(sliceAngle), dgFloat32 (0.0f), m_radius + m_height * dgSin(sliceAngle), dgFloat32 (0.0f));
sliceAngle += sliceStep;
for (dgInt32 i = 0; i < brakes; i ++) {
pool[index].m_x = p0.m_x;
pool[index].m_y = p0.m_y;
pool[index].m_z = p0.m_z;
index ++;
p0 = rot.UnrotateVector (p0);
}
}
//dgMatrix matrix (GetLocalMatrix() * matrixPtr);
matrix.TransformTriplex (&pool[0].m_x, sizeof (dgTriplex), &pool[0].m_x, sizeof (dgTriplex), 24 * (12 + 1));
dgTriplex face[32];
index = 0;
for (dgInt32 j = 0; j < slices; j ++) {
dgInt32 index0 = index + brakes - 1;
for (dgInt32 i = 0; i < brakes; i ++) {
face[0] = pool[index];
face[1] = pool[index0];
face[2] = pool[index0 + brakes];
face[3] = pool[index + brakes];
index0 = index;
index ++;
callback (userData, 4, &face[0].m_x, 0);
}
}
for (dgInt32 i = 0; i < brakes; i ++) {
face[i] = pool[i];
}
callback (userData, 24, &face[0].m_x, 0);
for (dgInt32 i = 0; i < brakes; i ++) {
face[i] = pool[brakes * (slices + 1) - i - 1];
}
callback (userData, 24, &face[0].m_x, 0);
}
示例8:
dgMatrix::dgMatrix (const dgMatrix& transformMatrix, const dgVector& scale, const dgMatrix& stretchAxis)
{
dgMatrix scaledAxis;
scaledAxis[0] = stretchAxis[0].Scale4 (scale[0]);
scaledAxis[1] = stretchAxis[1].Scale4 (scale[1]);
scaledAxis[2] = stretchAxis[2].Scale4 (scale[2]);
scaledAxis[3] = stretchAxis[3];
*this = stretchAxis.Transpose() * scaledAxis * transformMatrix;
}
示例9: dgSqrt
dgQuaternion::dgQuaternion (const dgMatrix& matrix)
{
enum QUAT_INDEX
{
X_INDEX=0,
Y_INDEX=1,
Z_INDEX=2
};
static QUAT_INDEX QIndex [] = {Y_INDEX, Z_INDEX, X_INDEX};
dgFloat32 trace = matrix[0][0] + matrix[1][1] + matrix[2][2];
if (trace > dgFloat32(0.0f)) {
trace = dgSqrt (trace + dgFloat32(1.0f));
m_q0 = dgFloat32 (0.5f) * trace;
trace = dgFloat32 (0.5f) / trace;
m_q1 = (matrix[1][2] - matrix[2][1]) * trace;
m_q2 = (matrix[2][0] - matrix[0][2]) * trace;
m_q3 = (matrix[0][1] - matrix[1][0]) * trace;
} else {
QUAT_INDEX i = X_INDEX;
if (matrix[Y_INDEX][Y_INDEX] > matrix[X_INDEX][X_INDEX]) {
i = Y_INDEX;
}
if (matrix[Z_INDEX][Z_INDEX] > matrix[i][i]) {
i = Z_INDEX;
}
QUAT_INDEX j = QIndex [i];
QUAT_INDEX k = QIndex [j];
trace = dgFloat32(1.0f) + matrix[i][i] - matrix[j][j] - matrix[k][k];
trace = dgSqrt (trace);
dgFloat32* const ptr = &m_q1;
ptr[i] = dgFloat32 (0.5f) * trace;
trace = dgFloat32 (0.5f) / trace;
m_q0 = (matrix[j][k] - matrix[k][j]) * trace;
ptr[j] = (matrix[i][j] + matrix[j][i]) * trace;
ptr[k] = (matrix[i][k] + matrix[k][i]) * trace;
}
#ifdef _DEBUG
dgMatrix tmp (*this, matrix.m_posit);
dgMatrix unitMatrix (tmp * matrix.Inverse());
for (dgInt32 i = 0; i < 4; i ++) {
dgFloat32 err = dgAbsf (unitMatrix[i][i] - dgFloat32(1.0f));
dgAssert (err < dgFloat32 (1.0e-2f));
}
dgFloat32 err = dgAbsf (DotProduct(*this) - dgFloat32(1.0f));
dgAssert (err < dgFloat32(dgEPSILON * 100.0f));
#endif
}
示例10: DebugCollision
void dgCollisionDeformableMesh::DebugCollision (const dgMatrix& matrix, dgCollision::OnDebugCollisionMeshCallback callback, void* const userData) const
{
const dgVector* const particlePosit = m_particles.m_posit;
for (dgInt32 i = 0; i < m_trianglesCount; i ++ ) {
dgTriplex points[3];
for (dgInt32 j = 0; j < 3; j ++) {
dgInt32 index = m_indexList[i * 3 + j];
dgVector p (matrix.TransformVector(particlePosit[index]));
points[j].m_x = p.m_x;
points[j].m_y = p.m_y;
points[j].m_z = p.m_z;
}
callback (userData, 3, &points[0].m_x, 0);
}
}
示例11: BoundingBox
static void BoundingBox (
const dgMatrix &matrix,
const dgFloat32 vertex[],
dgInt32 stride,
const dgInt32 index[],
dgInt32 indexCount,
dgVector &min,
dgVector &max)
{
dgInt32 i;
dgInt32 j;
const dgFloat32 *ptr;
dgFloat32 xmin;
dgFloat32 xmax;
dgFloat32 ymin;
dgFloat32 ymax;
dgFloat32 zmin;
dgFloat32 zmax;
xmin = dgFloat32 (1.0e10f);
ymin = dgFloat32 (1.0e10f);
zmin = dgFloat32 (1.0e10f);
xmax = dgFloat32 (-1.0e10f);
ymax = dgFloat32 (-1.0e10f);
zmax = dgFloat32 (-1.0e10f);
ptr = vertex;
for (j = 0 ; j < indexCount; j ++ ) {
i = index[j] * stride;
dgVector tmp (ptr[i + 0], ptr[i + 1], ptr[i + 2], dgFloat32 (0.0f));
tmp = matrix.UnrotateVector (tmp);
if (tmp.m_x < xmin) xmin = tmp.m_x;
if (tmp.m_y < ymin) ymin = tmp.m_y;
if (tmp.m_z < zmin) zmin = tmp.m_z;
if (tmp.m_x > xmax) xmax = tmp.m_x;
if (tmp.m_y > ymax) ymax = tmp.m_y;
if (tmp.m_z > zmax) zmax = tmp.m_z;
}
min = dgVector (xmin, ymin, zmin, dgFloat32 (0.0f));
max = dgVector (xmax, ymax, zmax, dgFloat32 (0.0f));
}
示例12: DebugCollision
void dgCollisionTaperedCylinder::DebugCollision (const dgMatrix& matrix, dgCollision::OnDebugCollisionMeshCallback callback, void* const userData) const
{
dgTriplex pool[24 * 2];
dgFloat32 angle = dgFloat32 (0.0f);
for (dgInt32 i = 0; i < 24; i ++) {
dgFloat32 z = dgSin (angle);
dgFloat32 y = dgCos (angle);
pool[i].m_x = - m_height;
pool[i].m_y = y * m_radio1;
pool[i].m_z = z * m_radio1;
pool[i + 24].m_x = m_height;
pool[i + 24].m_y = y * m_radio0;
pool[i + 24].m_z = z * m_radio0;
angle += dgPI2 / dgFloat32 (24.0f);
}
matrix.TransformTriplex (&pool[0].m_x, sizeof (dgTriplex), &pool[0].m_x, sizeof (dgTriplex), 24 * 2);
dgTriplex face[24];
dgInt32 j = 24 - 1;
for (dgInt32 i = 0; i < 24; i ++) {
face[0] = pool[j];
face[1] = pool[i];
face[2] = pool[i + 24];
face[3] = pool[j + 24];
j = i;
callback (userData, 4, &face[0].m_x, 0);
}
for (dgInt32 i = 0; i < 24; i ++) {
face[i] = pool[24 - 1 - i];
}
callback (userData, 24, &face[0].m_x, 0);
for (dgInt32 i = 0; i < 24; i ++) {
face[i] = pool[i + 24];
}
callback (userData, 24, &face[0].m_x, 0);
}
示例13: dgAssert
dgVector dgBilateralConstraint::CalculateGlobalMatrixAndAngle (dgMatrix& globalMatrix0, dgMatrix& globalMatrix1) const
{
dgAssert (m_body0);
dgAssert (m_body1);
const dgMatrix& body0Matrix = m_body0->GetMatrix();
const dgMatrix& body1Matrix = m_body1->GetMatrix();
globalMatrix0 = m_localMatrix0 * body0Matrix;
globalMatrix1 = m_localMatrix1 * body1Matrix;
dgMatrix relMatrix (globalMatrix1 * globalMatrix0.Inverse());
dgAssert (dgAbsf (dgFloat32 (1.0f) - (relMatrix.m_front % relMatrix.m_front)) < 1.0e-5f);
dgAssert (dgAbsf (dgFloat32 (1.0f) - (relMatrix.m_up % relMatrix.m_up)) < 1.0e-5f);
dgAssert (dgAbsf (dgFloat32 (1.0f) - (relMatrix.m_right % relMatrix.m_right)) < 1.0e-5f);
dgVector euler0;
dgVector euler1;
relMatrix.CalcPitchYawRoll (euler0, euler1);
return euler0;
}
示例14: DebugCollision
void dgCollisionCone::DebugCollision (const dgMatrix& matrix, dgCollision::OnDebugCollisionMeshCallback callback, void* const userData) const
{
//dgCollisionConvex::DebugCollision (matrix, callback, userData);
//return;
#define NUMBER_OF_DEBUG_SEGMENTS 40
dgTriplex pool[NUMBER_OF_DEBUG_SEGMENTS + 1];
dgTriplex face[NUMBER_OF_DEBUG_SEGMENTS];
dgFloat32 angle = dgFloat32 (0.0f);
for (dgInt32 i = 0; i < NUMBER_OF_DEBUG_SEGMENTS; i ++) {
dgFloat32 z = dgSin (angle) * m_radius;
dgFloat32 y = dgCos (angle) * m_radius;
pool[i].m_x = -m_height;
pool[i].m_y = y;
pool[i].m_z = z;
angle += dgPI2 / dgFloat32 (NUMBER_OF_DEBUG_SEGMENTS);
}
pool[NUMBER_OF_DEBUG_SEGMENTS].m_x = m_height;
pool[NUMBER_OF_DEBUG_SEGMENTS].m_y = dgFloat32 (0.0f);
pool[NUMBER_OF_DEBUG_SEGMENTS].m_z = dgFloat32 (0.0f);
matrix.TransformTriplex (&pool[0].m_x, sizeof (dgTriplex), &pool[0].m_x, sizeof (dgTriplex), NUMBER_OF_DEBUG_SEGMENTS + 1);
dgInt32 j = NUMBER_OF_DEBUG_SEGMENTS - 1;
for (dgInt32 i = 0; i < NUMBER_OF_DEBUG_SEGMENTS; i ++) {
face[0] = pool[j];
face[1] = pool[i];
face[2] = pool[NUMBER_OF_DEBUG_SEGMENTS];
j = i;
callback (userData, 3, &face[0].m_x, 0);
}
for (dgInt32 i = 0; i < NUMBER_OF_DEBUG_SEGMENTS; i ++) {
face[i] = pool[NUMBER_OF_DEBUG_SEGMENTS - 1 - i];
}
callback (userData, NUMBER_OF_DEBUG_SEGMENTS, &face[0].m_x, 0);
}
示例15: DebugCollision
void dgCollisionConvexHull::DebugCollision (const dgMatrix& matrix, dgCollision::OnDebugCollisionMeshCallback callback, void* const userData) const
{
// dgTriplex tmp[1024 * 4];
// matrix.TransformTriplex (&tmp[0].m_x, sizeof (dgTriplex), &m_vertex[0].m_x, sizeof (dgVector), m_vertexCount);
dgTriplex vertex[256];
for (dgInt32 i = 0; i < m_faceCount; i ++) {
dgConvexSimplexEdge* const face = m_faceArray[i];
dgConvexSimplexEdge* ptr = face;
dgInt32 count = 0;
do {
//vertex[count] = tmp[ptr->m_vertex];
vertex[count].m_x = m_vertex[ptr->m_vertex].m_x;
vertex[count].m_y = m_vertex[ptr->m_vertex].m_y;
vertex[count].m_z = m_vertex[ptr->m_vertex].m_z;
count ++;
dgAssert (count < sizeof (vertex)/ sizeof (vertex[0]));
ptr = ptr->m_next;
} while (ptr != face);
matrix.TransformTriplex (&vertex[0].m_x, sizeof (dgTriplex), &vertex[0].m_x, sizeof (dgTriplex), count);
callback (userData, count, &vertex[0].m_x, 0);
}
}