Initialisierungsarbeiten
// Physiksystem initialisieren (maximal 3000 Rigid Bodies):
PhysicalSimulationParameter = new CPhysicalSimulationParameter;
PhysicalSimulationParameter->Init_PhysicalSimulationParameter(
"../Physics/SimulationParameter.txt");
SimpleBodyMasspointModel = new CSimplePhysicsBodyMasspointModel;
SimpleBodyMasspointModel->Init_MasspointModel(
"../Physics/MasspointModels/Box2.txt");
OpenCLPhysicsManager = new COpenCLPhysicsManager;
OpenCLPhysicsManager->Init_CollisionGrid(100, 100, 100, 50);
long NumMassElementsMax = 45000;
long NumBondingsMax = 156000;
OpenCLPhysicsManager->Init_OpenCL_3DBodyPhysicsManager(
"../Physics/PhysicsCalculations.cl", 3000,
NumMassElementsMax, 10, NumBondingsMax, false);
SimplePhysicsBodyManager = new CSimplePhysicsBodyManager;
SimplePhysicsBodyManager->Init_SimplePhysicsBodyManager(3000,
OpenCLPhysicsManager->MassElementPool,
OpenCLPhysicsManager->BondingPool);
PhysicalTestBodies = new CPhysicalTestBodyPhysicsManager;
PhysicalTestBodies->Set_PhysicalSimulationParameter(
PhysicalSimulationParameter);
PhysicalTestBodies->Set_OpenCLPhysicsManager(OpenCLPhysicsManager);
// 2000 Rigid Bodies generieren:
PhysicalTestBodies->Init_PhysicalTestBodies(SimplePhysicsBodyManager,
SimpleBodyMasspointModel,
InstancedObjectTextureAndMeshDesc,
SimpleObjectInstanceMemoryManager, 2000);
[...]
// Terrain-Surface-Daten laden und dem Physiksystem zuweisen:
TerrainTileSet_SurfaceData = new CTerrainTileSet_SurfaceData;
TerrainTileSet_SurfaceData->Init_TileSet("../Models/TileSet1",
"MeshTestSet1.bin", true);
TerrainTileSet_SurfaceData->Init_OpenCL_DistanceToTerrainCalculation(
OpenCLPhysicsManager->OpenCLPhysicsDevice,
"../Physics/DistanceToTerrainCalculation.cl",
NumMassElementsMax, 0);
OpenCLPhysicsManager->Set_TerrainSurfaceData(TerrainTileSet_SurfaceData);
TerrainTileSet_SurfaceData->Set_GroundFrictionValues(15.0f);
TerrainTileSet_SurfaceData->
Update_OpenCLBuffer_TriangleGroundFrictionValue();
PhysicalSimulationParameter = new CPhysicalSimulationParameter;
PhysicalSimulationParameter->Init_PhysicalSimulationParameter(
"../Physics/SimulationParameter.txt");
SimpleBodyMasspointModel = new CSimplePhysicsBodyMasspointModel;
SimpleBodyMasspointModel->Init_MasspointModel(
"../Physics/MasspointModels/Box2.txt");
OpenCLPhysicsManager = new COpenCLPhysicsManager;
OpenCLPhysicsManager->Init_CollisionGrid(100, 100, 100, 50);
long NumMassElementsMax = 45000;
long NumBondingsMax = 156000;
OpenCLPhysicsManager->Init_OpenCL_3DBodyPhysicsManager(
"../Physics/PhysicsCalculations.cl", 3000,
NumMassElementsMax, 10, NumBondingsMax, false);
SimplePhysicsBodyManager = new CSimplePhysicsBodyManager;
SimplePhysicsBodyManager->Init_SimplePhysicsBodyManager(3000,
OpenCLPhysicsManager->MassElementPool,
OpenCLPhysicsManager->BondingPool);
PhysicalTestBodies = new CPhysicalTestBodyPhysicsManager;
PhysicalTestBodies->Set_PhysicalSimulationParameter(
PhysicalSimulationParameter);
PhysicalTestBodies->Set_OpenCLPhysicsManager(OpenCLPhysicsManager);
// 2000 Rigid Bodies generieren:
PhysicalTestBodies->Init_PhysicalTestBodies(SimplePhysicsBodyManager,
SimpleBodyMasspointModel,
InstancedObjectTextureAndMeshDesc,
SimpleObjectInstanceMemoryManager, 2000);
[...]
// Terrain-Surface-Daten laden und dem Physiksystem zuweisen:
TerrainTileSet_SurfaceData = new CTerrainTileSet_SurfaceData;
TerrainTileSet_SurfaceData->Init_TileSet("../Models/TileSet1",
"MeshTestSet1.bin", true);
TerrainTileSet_SurfaceData->Init_OpenCL_DistanceToTerrainCalculation(
OpenCLPhysicsManager->OpenCLPhysicsDevice,
"../Physics/DistanceToTerrainCalculation.cl",
NumMassElementsMax, 0);
OpenCLPhysicsManager->Set_TerrainSurfaceData(TerrainTileSet_SurfaceData);
TerrainTileSet_SurfaceData->Set_GroundFrictionValues(15.0f);
TerrainTileSet_SurfaceData->
Update_OpenCLBuffer_TriangleGroundFrictionValue();
Bewegungs- und Kollisionsberechnungen:
if(g_FrameTime > g_MaximalAcceptedFrameTimeUsedForPhysicalCalculations)
{
PhysicalSimulationParameter->Calculate_NumTimeSteps(
g_MaximalAcceptedFrameTimeUsedForPhysicalCalculations,
0.33f*g_MaximalAcceptedFrameTimeUsedForPhysicalCalculations);
}
else
{
PhysicalSimulationParameter->Calculate_NumTimeSteps(g_FrameTime,
0.33f*g_FrameTime);
}
PhysicalTestBodies->Consider_ActualSimulationParameter();
PhysicalTestBodies->Update_PhysicalCalculations();
PhysicalTestBodies->Update_PhysicalTestBodyCollisionsThread();
PhysicalTestBodies->Update_PhysicalTestBodyMovementThread();
{
PhysicalSimulationParameter->Calculate_NumTimeSteps(
g_MaximalAcceptedFrameTimeUsedForPhysicalCalculations,
0.33f*g_MaximalAcceptedFrameTimeUsedForPhysicalCalculations);
}
else
{
PhysicalSimulationParameter->Calculate_NumTimeSteps(g_FrameTime,
0.33f*g_FrameTime);
}
PhysicalTestBodies->Consider_ActualSimulationParameter();
PhysicalTestBodies->Update_PhysicalCalculations();
PhysicalTestBodies->Update_PhysicalTestBodyCollisionsThread();
PhysicalTestBodies->Update_PhysicalTestBodyMovementThread();
Hinweise zum Erstellen eines neuen Projekts:
- Kopieren Sie den Ordner GraphicsAndPhysicsFrameworkImports ins Projektverzeichnis
- Kopieren sie alle dll-Dateien sowie die Konfigurationsdatei ResolutionAndRendering.txt aus besagtem Ordner ins gleiche Verzeichnis, in dem sich auch die exe-Datei befindet (in unseren Programmbeispielen ist dies das Bin-Verzeichnis)
- Binden Sie die folgenden Dateien in Ihr Projekt ein: GraphicsAndPhysics_Framework_Imports.h, GraphicsAndPhysics_Framework_Imports.lib, glew32.lib, glew32s.lib, glut32.lib. Die Glew- und Glut-Bibliotheken ermöglichen die Nutzung der aktuellen OpenGL-Spezifikationen unabhängig vom Framework.
GraphicsAndPhysicsFrameworkDemo24.zip