File: PhysicsWorldNewton.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (577 lines) | stat: -rw-r--r-- 18,972 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * Copyright (C) 2006-2010 - Frictional Games
 *
 * This file is part of HPL1 Engine.
 */

#include "hpl1/engine/impl/PhysicsWorldNewton.h"

#include "hpl1/engine/impl/CharacterBodyNewton.h"
#include "hpl1/engine/impl/CollideShapeNewton.h"
#include "hpl1/engine/impl/PhysicsBodyNewton.h"
#include "hpl1/engine/impl/PhysicsMaterialNewton.h"

#include "hpl1/engine/impl/PhysicsJointBallNewton.h"
#include "hpl1/engine/impl/PhysicsJointHingeNewton.h"
#include "hpl1/engine/impl/PhysicsJointScrewNewton.h"
#include "hpl1/engine/impl/PhysicsJointSliderNewton.h"

#include "hpl1/engine/impl/PhysicsControllerNewton.h"

#include "hpl1/engine/math/MathTypes.h"
#include "hpl1/engine/math/Vector3.h"
#include "hpl1/engine/physics/CollideShape.h"
#include "hpl1/engine/scene/PortalContainer.h"
#include "hpl1/engine/scene/World3D.h"

#include "hpl1/engine/graphics/LowLevelGraphics.h"
#include "hpl1/engine/graphics/VertexBuffer.h"
#include "hpl1/engine/math/Math.h"
#include "hpl1/engine/system/low_level_system.h"

namespace hpl {

//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------

cPhysicsWorldNewton::cPhysicsWorldNewton()
	: iPhysicsWorld() {
	mpNewtonWorld = NewtonCreate();

	if (mpNewtonWorld == NULL) {
		Warning("Couldn't create newton world!\n");
	}

	/////////////////////////////////
	// Set default values to properties
	mvWorldSizeMin = cVector3f(0, 0, 0);
	mvWorldSizeMax = cVector3f(0, 0, 0);

	mvGravity = cVector3f(0, -9.81f, 0);
	mfMaxTimeStep = 1.0f / 60.0f;

	/////////////////////////////////
	// Create default material.
	int lDefaultMatId = 0; // NewtonMaterialGetDefaultGroupID(mpNewtonWorld);
	cPhysicsMaterialNewton *pMaterial = hplNew(cPhysicsMaterialNewton, ("Default", this, lDefaultMatId));
	tPhysicsMaterialMap::value_type Val("Default", pMaterial);
	m_mapMaterials.insert(Val);
	pMaterial->UpdateMaterials();

	mpTempDepths = hplNewArray(float, 500);
	mpTempNormals = hplNewArray(float, 500 * 3);
	mpTempPoints = hplNewArray(float, 500 * 3);
}

//-----------------------------------------------------------------------

cPhysicsWorldNewton::~cPhysicsWorldNewton() {
	DestroyAll();
	NewtonDestroy(mpNewtonWorld);

	hplDeleteArray(mpTempDepths);
	hplDeleteArray(mpTempNormals);
	hplDeleteArray(mpTempPoints);
}

//-----------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------

void cPhysicsWorldNewton::Simulate(float afTimeStep) {
	// cPhysicsBodyNewton::SetUseCallback(false);
	// static lUpdate =0;

	// if(lUpdate % 30==0)
	{
		while (afTimeStep > mfMaxTimeStep) {
			NewtonUpdate(mpNewtonWorld, mfMaxTimeStep);
			afTimeStep -= mfMaxTimeStep;
		}
		NewtonUpdate(mpNewtonWorld, afTimeStep);
	}
	// lUpdate++;
	// cPhysicsBodyNewton::SetUseCallback(true);

	tPhysicsBodyListIt it = mlstBodies.begin();
	for (; it != mlstBodies.end(); ++it) {
		cPhysicsBodyNewton *pBody = static_cast<cPhysicsBodyNewton *>(*it);
		pBody->ClearForces();
	}
}

//-----------------------------------------------------------------------

void cPhysicsWorldNewton::SetMaxTimeStep(float afTimeStep) {
	mfMaxTimeStep = afTimeStep;
}

float cPhysicsWorldNewton::GetMaxTimeStep() {
	return mfMaxTimeStep;
}

//-----------------------------------------------------------------------

void cPhysicsWorldNewton::SetWorldSize(const cVector3f &avMin, const cVector3f &avMax) {
	mvWorldSizeMin = avMin;
	mvWorldSizeMax = avMax;
	VEC3_CONST_ARRAY(min, avMin);
	VEC3_CONST_ARRAY(max, avMax);
	NewtonSetWorldSize(mpNewtonWorld, min, max);
}

cVector3f cPhysicsWorldNewton::GetWorldSizeMin() {
	return mvWorldSizeMin;
}

cVector3f cPhysicsWorldNewton::GetWorldSizeMax() {
	return mvWorldSizeMax;
}

//-----------------------------------------------------------------------

void cPhysicsWorldNewton::SetGravity(const cVector3f &avGravity) {
	mvGravity = avGravity;
}

//-----------------------------------------------------------------------

cVector3f cPhysicsWorldNewton::GetGravity() {
	return mvGravity;
}

//-----------------------------------------------------------------------

void cPhysicsWorldNewton::SetAccuracyLevel(ePhysicsAccuracy aAccuracy) {
	mAccuracy = aAccuracy;

	switch (mAccuracy) {
	case ePhysicsAccuracy_Low:
		NewtonSetSolverModel(mpNewtonWorld, 8);
		NewtonSetFrictionModel(mpNewtonWorld, 1);
		Log("SETTING LOW!\n");
		break;
	case ePhysicsAccuracy_Medium:
		NewtonSetSolverModel(mpNewtonWorld, 1);
		NewtonSetFrictionModel(mpNewtonWorld, 1);
		break;
	case ePhysicsAccuracy_High:
		NewtonSetSolverModel(mpNewtonWorld, 0);
		NewtonSetFrictionModel(mpNewtonWorld, 0);
		break;
	default:
		break;
	}
}

//-----------------------------------------------------------------------

ePhysicsAccuracy cPhysicsWorldNewton::GetAccuracyLevel() {
	return mAccuracy;
}

//-----------------------------------------------------------------------

iCollideShape *cPhysicsWorldNewton::CreateNullShape() {
	iCollideShape *pShape = hplNew(cCollideShapeNewton, (eCollideShapeType_Null, 0, NULL,
														 mpNewtonWorld, this));
	mlstShapes.push_back(pShape);

	return pShape;
}

//-----------------------------------------------------------------------

iCollideShape *cPhysicsWorldNewton::CreateBoxShape(const cVector3f &avSize, cMatrixf *apOffsetMtx) {
	iCollideShape *pShape = hplNew(cCollideShapeNewton, (eCollideShapeType_Box, avSize, apOffsetMtx,
														 mpNewtonWorld, this));
	mlstShapes.push_back(pShape);

	return pShape;
}

//-----------------------------------------------------------------------

iCollideShape *cPhysicsWorldNewton::CreateSphereShape(const cVector3f &avRadii, cMatrixf *apOffsetMtx) {
	iCollideShape *pShape = hplNew(cCollideShapeNewton, (eCollideShapeType_Sphere, avRadii, apOffsetMtx,
														 mpNewtonWorld, this));
	mlstShapes.push_back(pShape);

	return pShape;
}

//-----------------------------------------------------------------------

iCollideShape *cPhysicsWorldNewton::CreateCylinderShape(float afRadius, float afHeight, cMatrixf *apOffsetMtx) {
	iCollideShape *pShape = hplNew(cCollideShapeNewton, (eCollideShapeType_Cylinder,
														 cVector3f(afRadius, afHeight, afRadius),
														 apOffsetMtx,
														 mpNewtonWorld, this));
	mlstShapes.push_back(pShape);

	return pShape;
}

//-----------------------------------------------------------------------

iCollideShape *cPhysicsWorldNewton::CreateCapsuleShape(float afRadius, float afHeight, cMatrixf *apOffsetMtx) {
	iCollideShape *pShape = hplNew(cCollideShapeNewton, (eCollideShapeType_Capsule,
														 cVector3f(afRadius, afHeight, afRadius),
														 apOffsetMtx,
														 mpNewtonWorld, this));
	mlstShapes.push_back(pShape);

	return pShape;
}

//-----------------------------------------------------------------------

iCollideShape *cPhysicsWorldNewton::CreateMeshShape(iVertexBuffer *apVtxBuffer) {
	cCollideShapeNewton *pShape = hplNew(cCollideShapeNewton, (eCollideShapeType_Mesh,
															   0, NULL, mpNewtonWorld, this));

	pShape->CreateFromVertices(apVtxBuffer->GetIndices(), apVtxBuffer->GetIndexNum(),
							   apVtxBuffer->GetArray(eVertexFlag_Position),
							   kvVertexElements[cMath::Log2ToInt(eVertexFlag_Position)],
							   apVtxBuffer->GetVertexNum());
	mlstShapes.push_back(pShape);

	return pShape;
}

//-----------------------------------------------------------------------

iCollideShape *cPhysicsWorldNewton::CreateCompundShape(tCollideShapeVec &avShapes) {
	cCollideShapeNewton *pShape = hplNew(cCollideShapeNewton, (eCollideShapeType_Compound,
															   0, NULL, mpNewtonWorld, this));
	pShape->CreateFromShapeVec(avShapes);
	mlstShapes.push_back(pShape);

	return pShape;
}

//-----------------------------------------------------------------------

iPhysicsJointBall *cPhysicsWorldNewton::CreateJointBall(const tString &asName,
														const cVector3f &avPivotPoint,
														iPhysicsBody *apParentBody, iPhysicsBody *apChildBody) {
	iPhysicsJointBall *pJoint = hplNew(cPhysicsJointBallNewton, (asName, apParentBody, apChildBody, this,
																 avPivotPoint));
	mlstJoints.push_back(pJoint);
	return pJoint;
}

iPhysicsJointHinge *cPhysicsWorldNewton::CreateJointHinge(const tString &asName,
														  const cVector3f &avPivotPoint, const cVector3f &avPinDir,
														  iPhysicsBody *apParentBody, iPhysicsBody *apChildBody) {
	iPhysicsJointHinge *pJoint = hplNew(cPhysicsJointHingeNewton, (asName, apParentBody, apChildBody, this,
																   avPivotPoint, avPinDir));
	mlstJoints.push_back(pJoint);
	return pJoint;
}

iPhysicsJointSlider *cPhysicsWorldNewton::CreateJointSlider(const tString &asName,
															const cVector3f &avPivotPoint, const cVector3f &avPinDir,
															iPhysicsBody *apParentBody, iPhysicsBody *apChildBody) {
	iPhysicsJointSlider *pJoint = hplNew(cPhysicsJointSliderNewton, (asName, apParentBody, apChildBody, this,
																	 avPivotPoint, avPinDir));
	mlstJoints.push_back(pJoint);
	return pJoint;
}

iPhysicsJointScrew *cPhysicsWorldNewton::CreateJointScrew(const tString &asName,
														  const cVector3f &avPivotPoint, const cVector3f &avPinDir,
														  iPhysicsBody *apParentBody, iPhysicsBody *apChildBody) {
	iPhysicsJointScrew *pJoint = hplNew(cPhysicsJointScrewNewton, (asName, apParentBody, apChildBody, this,
																   avPivotPoint, avPinDir));
	mlstJoints.push_back(pJoint);
	return pJoint;
}

//-----------------------------------------------------------------------

iPhysicsBody *cPhysicsWorldNewton::CreateBody(const tString &asName, iCollideShape *apShape) {
	cPhysicsBodyNewton *pBody = hplNew(cPhysicsBodyNewton, (asName, this, apShape));

	mlstBodies.push_back(pBody);

	if (mpWorld3D)
		mpWorld3D->GetPortalContainer()->AddEntity(pBody);

	return pBody;
}

//-----------------------------------------------------------------------

iCharacterBody *cPhysicsWorldNewton::CreateCharacterBody(const tString &asName, const cVector3f &avSize) {
	cCharacterBodyNewton *pChar = hplNew(cCharacterBodyNewton, (asName, this, avSize));

	mlstCharBodies.push_back(pChar);

	return pChar;
}

//-----------------------------------------------------------------------

iPhysicsMaterial *cPhysicsWorldNewton::CreateMaterial(const tString &asName) {
	cPhysicsMaterialNewton *pMaterial = hplNew(cPhysicsMaterialNewton, (asName, this));

	tPhysicsMaterialMap::value_type Val(asName, pMaterial);
	m_mapMaterials.insert(Val);

	pMaterial->UpdateMaterials();

	return pMaterial;
}

//-----------------------------------------------------------------------

iPhysicsController *cPhysicsWorldNewton::CreateController(const tString &asName) {
	iPhysicsController *pController = hplNew(cPhysicsControllerNewton, (asName, this));

	mlstControllers.push_back(pController);

	return pController;
}

//-----------------------------------------------------------------------

static bool gbRayCalcDist;
static bool gbRayCalcNormal;
static bool gbRayCalcPoint;
static iPhysicsRayCallback *gpRayCallback;
static cVector3f gvRayOrigin;
static cVector3f gvRayEnd;
static cVector3f gvRayDelta;
static float gfRayLength;

static cPhysicsRayParams gRayParams;

//////////////////////////////////////

static unsigned RayCastPrefilterFunc(const NewtonBody *apNewtonBody, const NewtonCollision *collision, void *userData) {
	cPhysicsBodyNewton *pRigidBody = (cPhysicsBodyNewton *)NewtonBodyGetUserData(apNewtonBody);
	if (pRigidBody->IsActive() == false)
		return 0;

	bool bRet = gpRayCallback->BeforeIntersect(pRigidBody);

	if (bRet)
		return 1;
	else
		return 0;
}

static float RayCastFilterFunc(const NewtonBody *apNewtonBody, const float *apNormalVec,
							   int alCollisionID, void *apUserData, float afIntersetParam) {
	cPhysicsBodyNewton *pRigidBody = (cPhysicsBodyNewton *)NewtonBodyGetUserData(apNewtonBody);
	if (pRigidBody->IsActive() == false)
		return 1;

	gRayParams.mfT = afIntersetParam;

	// Calculate stuff needed.
	if (gbRayCalcDist) {
		gRayParams.mfDist = gfRayLength * afIntersetParam;
	}
	if (gbRayCalcNormal) {
		gRayParams.mvNormal.FromVec(apNormalVec);
	}
	if (gbRayCalcPoint) {
		gRayParams.mvPoint = gvRayOrigin + gvRayDelta * afIntersetParam;
	}

	// Call the call back
	bool bRet = gpRayCallback->OnIntersect(pRigidBody, &gRayParams);

	// return correct value.
	if (bRet)
		return 1; // afIntersetParam;
	else
		return 0;
}

//////////////////////////////////////

void cPhysicsWorldNewton::CastRay(iPhysicsRayCallback *apCallback,
								  const cVector3f &avOrigin, const cVector3f &avEnd,
								  bool abCalcDist, bool abCalcNormal, bool abCalcPoint,
								  bool abUsePrefilter) {
	gbRayCalcPoint = abCalcPoint;
	gbRayCalcNormal = abCalcNormal;
	gbRayCalcDist = abCalcDist;

	gvRayOrigin = avOrigin;
	gvRayEnd = avEnd;

	gvRayDelta = avEnd - avOrigin;
	gfRayLength = gvRayDelta.Length();

	gpRayCallback = apCallback;
	VEC3_CONST_ARRAY(origin, avOrigin);
	VEC3_CONST_ARRAY(end, avEnd);

	if (abUsePrefilter)
		NewtonWorldRayCast(mpNewtonWorld, origin, end, RayCastFilterFunc, NULL, RayCastPrefilterFunc);
	else
		NewtonWorldRayCast(mpNewtonWorld, origin, end, RayCastFilterFunc, NULL, NULL);
}

//-----------------------------------------------------------------------

// Fix found in HPL2 (https://github.com/FrictionalGames/AmnesiaTheDarkDescent)
static void correctNormal(cVector3f &normal, const cVector3f &collidePoint, const cVector3f &shapeCenter) {
	cVector3f vCenterToCollidePoint = collidePoint - shapeCenter;
	// A check if the normal points in the wrong direction.
	if (cMath::Vector3Dot(vCenterToCollidePoint, normal) > 0)
		normal = normal * -1;
}

bool cPhysicsWorldNewton::CheckShapeCollision(iCollideShape *apShapeA, const cMatrixf &a_mtxA,
											  iCollideShape *apShapeB, const cMatrixf &a_mtxB,
											  cCollideData &aCollideData, int alMaxPoints,
											  bool correctNormalDirection) {
	cCollideShapeNewton *pNewtonShapeA = static_cast<cCollideShapeNewton *>(apShapeA);
	cCollideShapeNewton *pNewtonShapeB = static_cast<cCollideShapeNewton *>(apShapeB);

	cMatrixf mtxTransposeA = a_mtxA.GetTranspose();
	cMatrixf mtxTransposeB = a_mtxB.GetTranspose();

	//////////////////////////////
	// Check compound collision
	if (pNewtonShapeA->GetType() == eCollideShapeType_Compound ||
		pNewtonShapeB->GetType() == eCollideShapeType_Compound) {
		int lACount = pNewtonShapeA->GetSubShapeNum();
		int lBCount = pNewtonShapeB->GetSubShapeNum();

		bool bCollision = false;
		aCollideData.mlNumOfPoints = 0;
		int lCollideDataStart = 0;

		for (int a = 0; a < lACount; a++) {
			for (int b = 0; b < lBCount; b++) {
				cCollideShapeNewton *pSubShapeA = static_cast<cCollideShapeNewton *>(pNewtonShapeA->GetSubShape(a));
				cCollideShapeNewton *pSubShapeB = static_cast<cCollideShapeNewton *>(pNewtonShapeB->GetSubShape(b));

				int lNum = NewtonCollisionCollide(mpNewtonWorld, alMaxPoints,
												  pSubShapeA->GetNewtonCollision(), &(mtxTransposeA.m[0][0]),
												  pSubShapeB->GetNewtonCollision(), &(mtxTransposeB.m[0][0]),
												  mpTempPoints, mpTempNormals, mpTempDepths, 0);
				if (lNum < 1)
					continue;
				if (lNum > alMaxPoints)
					lNum = alMaxPoints;

				bCollision = true;

				// Log("Collided %d vs %d. Num: %d\n",a,b,lNum);

				// Negate for each iteration.
				alMaxPoints -= lNum;

				for (int i = 0; i < lNum; i++) {
					cCollidePoint &CollPoint = aCollideData.mvContactPoints[lCollideDataStart + i];
					CollPoint.mfDepth = mpTempDepths[i];

					int lVertex = i * 3;

					CollPoint.mvNormal.x = mpTempNormals[lVertex + 0];
					CollPoint.mvNormal.y = mpTempNormals[lVertex + 1];
					CollPoint.mvNormal.z = mpTempNormals[lVertex + 2];

					CollPoint.mvPoint.x = mpTempPoints[lVertex + 0];
					CollPoint.mvPoint.y = mpTempPoints[lVertex + 1];
					CollPoint.mvPoint.z = mpTempPoints[lVertex + 2];

					if (correctNormalDirection && apShapeA->GetType() != eCollideShapeType_Mesh)
						correctNormal(CollPoint.mvNormal, CollPoint.mvPoint, a_mtxA.GetTranslation());
				}

				lCollideDataStart += lNum;
				aCollideData.mlNumOfPoints += lNum;

				if (alMaxPoints <= 0)
					break;
			}
			if (alMaxPoints <= 0)
				break;
		}

		return bCollision;
	}
	//////////////////////////////
	// Check NON compound collision
	else {
		int lNum = NewtonCollisionCollide(mpNewtonWorld, alMaxPoints,
										  pNewtonShapeA->GetNewtonCollision(), &(mtxTransposeA.m[0][0]),
										  pNewtonShapeB->GetNewtonCollision(), &(mtxTransposeB.m[0][0]),
										  mpTempPoints, mpTempNormals, mpTempDepths, 0);

		if (lNum < 1)
			return false;
		if (lNum > alMaxPoints)
			lNum = alMaxPoints;

		for (int i = 0; i < lNum; i++) {
			cCollidePoint &CollPoint = aCollideData.mvContactPoints[i];
			CollPoint.mfDepth = mpTempDepths[i];

			int lVertex = i * 3;

			CollPoint.mvNormal.x = mpTempNormals[lVertex + 0];
			CollPoint.mvNormal.y = mpTempNormals[lVertex + 1];
			CollPoint.mvNormal.z = mpTempNormals[lVertex + 2];

			CollPoint.mvPoint.x = mpTempPoints[lVertex + 0];
			CollPoint.mvPoint.y = mpTempPoints[lVertex + 1];
			CollPoint.mvPoint.z = mpTempPoints[lVertex + 2];

			if (correctNormalDirection && apShapeA->GetType() != eCollideShapeType_Mesh)
				correctNormal(CollPoint.mvNormal, CollPoint.mvPoint, a_mtxA.GetTranslation());
		}

		aCollideData.mlNumOfPoints = lNum;
	}
	return true;
}

//-----------------------------------------------------------------------

void cPhysicsWorldNewton::RenderDebugGeometry(iLowLevelGraphics *apLowLevel, const cColor &aColor) {
	tPhysicsBodyListIt it = mlstBodies.begin();
	for (; it != mlstBodies.end(); ++it) {
		iPhysicsBody *pBody = *it;
		pBody->RenderDebugGeometry(apLowLevel, aColor);
	}
}

//-----------------------------------------------------------------------
} // namespace hpl