Still trying to get it working.
This commit is contained in:
@@ -1,4 +1,23 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include <Common/Base/keycode.cxx>
|
||||
// We’re not using anything product specific yet. We undef these so we don’t get the usual
|
||||
// product initialization for the products.
|
||||
#undef HK_FEATURE_PRODUCT_AI
|
||||
//#undef HK_FEATURE_PRODUCT_ANIMATION
|
||||
#undef HK_FEATURE_PRODUCT_CLOTH
|
||||
#undef HK_FEATURE_PRODUCT_DESTRUCTION_2012
|
||||
#undef HK_FEATURE_PRODUCT_DESTRUCTION
|
||||
#undef HK_FEATURE_PRODUCT_BEHAVIOR
|
||||
#undef HK_FEATURE_PRODUCT_PHYSICS_2012
|
||||
//#undef HK_FEATURE_PRODUCT_PHYSICS
|
||||
// Also we’re not using any serialization/versioning so we don’t need any of these.
|
||||
#define HK_EXCLUDE_FEATURE_SerializeDeprecatedPre700
|
||||
#define HK_EXCLUDE_FEATURE_RegisterVersionPatches
|
||||
#define HK_EXCLUDE_FEATURE_RegisterReflectedClasses
|
||||
#define HK_EXCLUDE_FEATURE_MemoryTracker
|
||||
// This include generates an initialization function based on the products
|
||||
// and the excluded features.
|
||||
#include <Common/Base/Config/hkProductFeatures.cxx>
|
||||
#include "PhysicsSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
@@ -7,11 +26,43 @@
|
||||
Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world)
|
||||
{
|
||||
|
||||
hkMemorySystem::FrameInfo finfo(500 * 1024); // Allocate 500KB of Physics solver buffer
|
||||
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
||||
hkBaseSystem::init(memoryRouter, HavokErrorReport);
|
||||
|
||||
{
|
||||
hkpWorldCinfo worldInfo;
|
||||
worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
|
||||
worldInfo.m_gravity = hkVector4(0.0f, -9.8f, 0.0f);
|
||||
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far
|
||||
|
||||
// You must specify the size of the broad phase - objects should not be simulated outside this region
|
||||
worldInfo.setBroadPhaseWorldSize(1000.0f);
|
||||
m_PhysicsWorld = new hkpWorld(worldInfo);
|
||||
}
|
||||
// Register all collision agents, even though only box - box will be used in this particular example.
|
||||
// It's important to register collision agents before adding any entities to the world.
|
||||
hkpAgentRegisterUtil::registerAllAgents(m_PhysicsWorld->getCollisionDispatcher());
|
||||
|
||||
//
|
||||
// Initialize the visual debugger so we can connect remotely to the simulation
|
||||
// The context must exist beyond the use of the VDB instance, and you can make
|
||||
// whatever contexts you like for your own viewer types.
|
||||
//
|
||||
hkpPhysicsContext* context = new hkpPhysicsContext;
|
||||
hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers
|
||||
context->addWorld(m_PhysicsWorld); // add the physics world so the viewers can see it
|
||||
SetupVisualDebugger(context);
|
||||
|
||||
SetupPhysics(m_PhysicsWorld);
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::Update(double dt)
|
||||
{
|
||||
m_PhysicsWorld->stepDeltaTime(dt);
|
||||
|
||||
// Step the visual debugger
|
||||
StepVisualDebugger();
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
@@ -39,3 +90,81 @@ void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID pare
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::SetupVisualDebugger(hkpPhysicsContext* worlds)
|
||||
{
|
||||
// Setup the visual debugger
|
||||
hkArray<hkProcessContext*> contexts;
|
||||
contexts.pushBack(worlds);
|
||||
|
||||
m_VisualDebugger = new hkVisualDebugger(contexts);
|
||||
m_VisualDebugger->serve();
|
||||
|
||||
// Allocate memory for internal profiling information
|
||||
// You can discard this if you do not want Havok profiling information
|
||||
hkMonitorStream& stream = hkMonitorStream::getInstance();
|
||||
stream.resize(500 * 1024); // 500K for timer info
|
||||
stream.reset();
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::StepVisualDebugger()
|
||||
{
|
||||
// Step the debugger
|
||||
m_VisualDebugger->step();
|
||||
|
||||
// Reset internal profiling info for next frame
|
||||
hkMonitorStream::getInstance().reset();
|
||||
}
|
||||
|
||||
void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
|
||||
{
|
||||
LOG_ERROR("%s", msg);
|
||||
}
|
||||
|
||||
|
||||
void Systems::PhysicsSystem::SetupPhysics(hkpWorld* physicsWorld)
|
||||
{
|
||||
// Create the floor as a fixed box
|
||||
{
|
||||
hkpRigidBodyCinfo boxInfo;
|
||||
hkVector4 boxSize(5.0f, 0.5f, 5.0f);
|
||||
hkpBoxShape* boxShape = new hkpBoxShape(boxSize);
|
||||
boxInfo.m_shape = boxShape;
|
||||
boxInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
||||
boxInfo.m_position.set(0.0f, 0.0f, 0.0f);
|
||||
boxInfo.m_restitution = 0.9f;
|
||||
|
||||
hkpRigidBody* floor = new hkpRigidBody(boxInfo);
|
||||
boxShape->removeReference();
|
||||
|
||||
physicsWorld->addEntity(floor);
|
||||
floor->removeReference();
|
||||
}
|
||||
|
||||
// Create a moving sphere
|
||||
{
|
||||
hkReal sphereRadius = 0.5f;
|
||||
hkpConvexShape* sphereShape = new hkpSphereShape(sphereRadius);
|
||||
|
||||
hkpRigidBodyCinfo sphereInfo;
|
||||
sphereInfo.m_shape = sphereShape;
|
||||
sphereInfo.m_position.set(0.0f, 5.0f, 0.0f);
|
||||
sphereInfo.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA;
|
||||
|
||||
// Compute mass properties
|
||||
hkReal sphereMass = 10.0f;
|
||||
hkMassProperties sphereMassProperties;
|
||||
hkpInertiaTensorComputer::computeSphereVolumeMassProperties(sphereRadius, sphereMass, sphereMassProperties);
|
||||
sphereInfo.m_inertiaTensor = sphereMassProperties.m_inertiaTensor;
|
||||
sphereInfo.m_centerOfMass = sphereMassProperties.m_centerOfMass;
|
||||
sphereInfo.m_mass = sphereMassProperties.m_mass;
|
||||
|
||||
// Create sphere RigidBody
|
||||
hkpRigidBody* sphereRigidBody = new hkpRigidBody(sphereInfo);
|
||||
sphereShape->removeReference();
|
||||
|
||||
physicsWorld->addEntity(sphereRigidBody);
|
||||
g_ball = sphereRigidBody;
|
||||
sphereRigidBody->removeReference();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,41 @@
|
||||
#ifndef PhysicsSystem_h__
|
||||
#define PhysicsSystem_h__
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
|
||||
#include <unordered_set>
|
||||
// Math and base include
|
||||
|
||||
#include <Common/Base/hkBase.h>
|
||||
#include <Common/Base/Memory/System/Util/hkMemoryInitUtil.h>
|
||||
#include <Common/Base/System/Error/hkDefaultError.h>
|
||||
#include <Common/Base/Monitor/hkMonitorStream.h>
|
||||
#include <Common/Base/Config/hkConfigVersion.h>
|
||||
#include <Common/Base/Memory/System/hkMemorySystem.h>
|
||||
#include <Common/Base/Memory/Allocator/Malloc/hkMallocAllocator.h>
|
||||
#include <Common/Base/Container/String/hkStringBuf.h>
|
||||
|
||||
// Dynamics includes
|
||||
#include <Physics2012/Collide/hkpCollide.h>
|
||||
#include <Physics2012/Collide/Agent/ConvexAgent/SphereBox/hkpSphereBoxAgent.h>
|
||||
#include <Physics2012/Collide/Shape/Convex/Box/hkpBoxShape.h>
|
||||
#include <Physics2012/Collide/Shape/Convex/Sphere/hkpSphereShape.h>
|
||||
#include <Physics2012/Collide/Dispatch/hkpAgentRegisterUtil.h>
|
||||
|
||||
|
||||
|
||||
#include <Physics2012/Dynamics/World/hkpWorld.h>
|
||||
#include <Physics2012/Dynamics/Entity/hkpRigidBody.h>
|
||||
#include <Physics2012/Utilities/Dynamics/Inertia/hkpInertiaTensorComputer.h>
|
||||
|
||||
// Visual Debugger includes
|
||||
#include <Common/Visualize/hkVisualDebugger.h>
|
||||
#include <Physics2012/Utilities/VisualDebugger/hkpPhysicsContext.h>
|
||||
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -17,11 +48,25 @@ public:
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
hkpWorld* m_PhysicsWorld;
|
||||
|
||||
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
||||
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
||||
|
||||
hkVisualDebugger* m_VisualDebugger;
|
||||
void SetupVisualDebugger(hkpPhysicsContext* worlds);
|
||||
void StepVisualDebugger();
|
||||
static void HK_CALL HavokErrorReport(const char* msg, void*);
|
||||
|
||||
void SetupPhysics(hkpWorld* physicsWorld);
|
||||
|
||||
hkpRigidBody* g_ball;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PhysicsSystem_h__
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
@@ -39,14 +39,14 @@
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IncludePath>$(BOOST_ROOT);$(SolutionDir)\..\src;$(SolutionDir)\..\libs;$(SolutionDir)\..\libs\glew-1.10.0\include;$(SolutionDir)\..\libs\glfw-3.0.4\include;$(SolutionDir)\..\libs\glm-0.9.5.3;$(SolutionDir)\..\libs\openal-soft-1.15.1\include;$(SolutionDir)\..\libs\bullet-2.82-r2704\src;$(SolutionDir)\..\libs\SOIL\src;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(BOOST_ROOT)\lib32-msvc-11.0;$(SolutionDir)\..\libs\glew-1.10.0\lib\Debug\Win32;$(SolutionDir)\..\libs\glfw-3.0.4\lib\Debug;$(SolutionDir)\..\libs\openal-soft-1.15.1\lib\Win32\Debug;$(SolutionDir)\..\libs\bullet-2.82-r2704\lib\Debug;$(SolutionDir)\..\libs\SOIL\lib\Debug;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(HAVOK_ROOT)\Source;$(BOOST_ROOT);$(SolutionDir)\..\src;$(SolutionDir)\..\libs;$(SolutionDir)\..\libs\glew-1.10.0\include;$(SolutionDir)\..\libs\glfw-3.0.4\include;$(SolutionDir)\..\libs\glm-0.9.5.3;$(SolutionDir)\..\libs\openal-soft-1.15.1\include;$(SolutionDir)\..\libs\bullet-2.82-r2704\src;$(SolutionDir)\..\libs\SOIL\src;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(HAVOK_ROOT)\Lib\win32_vs2012_win7\debug;$(BOOST_ROOT)\lib32-msvc-11.0;$(SolutionDir)\..\libs\glew-1.10.0\lib\Debug\Win32;$(SolutionDir)\..\libs\glfw-3.0.4\lib\Debug;$(SolutionDir)\..\libs\openal-soft-1.15.1\lib\Win32\Debug;$(SolutionDir)\..\libs\bullet-2.82-r2704\lib\Debug;$(SolutionDir)\..\libs\SOIL\lib\Debug;$(LibraryPath)</LibraryPath>
|
||||
<OutDir>$(SolutionDir)\..\bin\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\..\obj\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>$(BOOST_ROOT);$(SolutionDir)\..\src;$(SolutionDir)\..\libs;$(SolutionDir)\..\libs\glew-1.10.0\include;$(SolutionDir)\..\libs\glfw-3.0.4\include;$(SolutionDir)\..\libs\glm-0.9.5.3;$(SolutionDir)\..\libs\openal-soft-1.15.1\include;$(SolutionDir)\..\libs\bullet-2.82-r2704\src;$(SolutionDir)\..\libs\SOIL\src;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(BOOST_ROOT)\lib32-msvc-11.0;$(SolutionDir)\..\libs\glfw-3.0.4\lib\Release;$(SolutionDir)\..\libs\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\..\libs\openal-soft-1.15.1\lib\Win32\Release;$(SolutionDir)\..\libs\bullet-2.82-r2704\lib\Release;$(SolutionDir)\..\libs\SOIL\lib\Release;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(HAVOK_ROOT)\Source;$(BOOST_ROOT);$(SolutionDir)\..\src;$(SolutionDir)\..\libs;$(SolutionDir)\..\libs\glew-1.10.0\include;$(SolutionDir)\..\libs\glfw-3.0.4\include;$(SolutionDir)\..\libs\glm-0.9.5.3;$(SolutionDir)\..\libs\openal-soft-1.15.1\include;$(SolutionDir)\..\libs\bullet-2.82-r2704\src;$(SolutionDir)\..\libs\SOIL\src;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(HAVOK_ROOT)\Lib\win32_vs2012_win7\release_dll;$(BOOST_ROOT)\lib32-msvc-11.0;$(SolutionDir)\..\libs\glfw-3.0.4\lib\Release;$(SolutionDir)\..\libs\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\..\libs\openal-soft-1.15.1\lib\Win32\Release;$(SolutionDir)\..\libs\bullet-2.82-r2704\lib\Release;$(SolutionDir)\..\libs\SOIL\lib\Release;$(LibraryPath)</LibraryPath>
|
||||
<OutDir>$(SolutionDir)\..\bin\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\..\obj\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
@@ -55,14 +55,16 @@
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>DEBUG;_CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_WINDOWS;WIN32;_WIN32;_DEBUG;HK_DEBUG;HK_DEBUG_SLOW;_XT_STATICLINK;_CONSOLE;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;HK_CONFIG_SIMD=1;DEBUG;_CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>PrecompiledHeader.h</PrecompiledHeaderFile>
|
||||
<BrowseInformation>true</BrowseInformation>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32d.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32d.lib;glfw3.lib;hkBase.lib;hkVisualize.lib;hkInternal.lib;hkSerialize.lib;hkGeometryUtilities.lib;hkcdInternal.lib;hkcdCollide.lib;hkpCollide.lib;hkpConstraint.lib;hkpConstraintSolver.lib;hkpDynamics.lib;hkpInternal.lib;hkpUtilities.lib;hkpVehicle.lib;hkSceneData.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions> /ignore:4221</AdditionalOptions>
|
||||
</Link>
|
||||
<CustomBuildStep />
|
||||
<Bscmake>
|
||||
@@ -84,7 +86,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32.lib;glfw3.lib;hkBase.lib;hkVisualize.lib;hkInternal.lib;hkSerialize.lib;hkGeometryUtilities.lib;hkcdInternal.lib;hkcdCollide.lib;hkpCollide.lib;hkpConstraint.lib;hkpConstraintSolver.lib;hkpDynamics.lib;hkpInternal.lib;hkpUtilities.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<CustomBuildStep />
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
Reference in New Issue
Block a user