mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-10 14:14:33 +00:00
* Adjustment: Update Bullet version to 3.24.
This commit is contained in:
parent
35de012ee7
commit
4a3f31df2a
6148 changed files with 2112532 additions and 56873 deletions
471
Engine/lib/bullet/examples/ExampleBrowser/CMakeLists.txt
Normal file
471
Engine/lib/bullet/examples/ExampleBrowser/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,471 @@
|
|||
|
||||
INCLUDE_DIRECTORIES(
|
||||
.
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs
|
||||
)
|
||||
|
||||
FILE(GLOB GwenGUISupport_SRCS "GwenGUISupport/*" )
|
||||
FILE(GLOB GwenGUISupport_HDRS "GwenGUISupport/*" )
|
||||
|
||||
|
||||
IF (WIN32)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad
|
||||
)
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
ELSE(WIN32)
|
||||
IF(APPLE)
|
||||
find_library(COCOA NAMES Cocoa)
|
||||
ELSE(APPLE)
|
||||
ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1")
|
||||
ADD_DEFINITIONS("-DGLEW_STATIC")
|
||||
ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1")
|
||||
INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad )
|
||||
ENDIF(APPLE)
|
||||
ENDIF(WIN32)
|
||||
|
||||
|
||||
ADD_LIBRARY(BulletExampleBrowserLib
|
||||
OpenGLExampleBrowser.cpp
|
||||
OpenGLGuiHelper.cpp
|
||||
GL_ShapeDrawer.cpp
|
||||
CollisionShape2TriangleMesh.cpp
|
||||
CollisionShape2TriangleMesh.h
|
||||
../Utils/b3Clock.cpp
|
||||
../Utils/b3Clock.h
|
||||
../Utils/ChromeTraceUtil.cpp
|
||||
../Utils/ChromeTraceUtil.h
|
||||
../Utils/b3ResourcePath.cpp
|
||||
../Utils/b3ResourcePath.h
|
||||
../Utils/b3ERPCFMHelper.hpp
|
||||
../Utils/b3ReferenceFrameHelper.hpp
|
||||
${GwenGUISupport_SRCS}
|
||||
${GwenGUISupport_HDRS}
|
||||
|
||||
)
|
||||
|
||||
SET_TARGET_PROPERTIES(BulletExampleBrowserLib PROPERTIES VERSION ${BULLET_VERSION})
|
||||
SET_TARGET_PROPERTIES(BulletExampleBrowserLib PROPERTIES SOVERSION ${BULLET_VERSION})
|
||||
IF (BUILD_SHARED_LIBS)
|
||||
IF (WIN32)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils
|
||||
BulletInverseDynamics LinearMath OpenGLWindow gwen BussIK
|
||||
${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
ELSE(WIN32)
|
||||
IF(APPLE)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils
|
||||
BulletInverseDynamics LinearMath OpenGLWindow gwen BussIK
|
||||
${COCOA} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
ELSE(APPLE)
|
||||
FIND_PACKAGE(Threads)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils
|
||||
BulletInverseDynamics LinearMath OpenGLWindow gwen BussIK
|
||||
${CMAKE_THREAD_LIBS_INIT} ${DL}
|
||||
)
|
||||
ENDIF(APPLE)
|
||||
ENDIF(WIN32)
|
||||
ENDIF(BUILD_SHARED_LIBS)
|
||||
|
||||
INSTALL(TARGETS BulletExampleBrowserLib
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib${LIB_SUFFIX}
|
||||
ARCHIVE DESTINATION lib${LIB_SUFFIX})
|
||||
|
||||
####################
|
||||
#
|
||||
# Bullet Example Browser main app
|
||||
#
|
||||
####################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
.
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/examples/SharedMemory
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs
|
||||
)
|
||||
|
||||
|
||||
LINK_LIBRARIES(
|
||||
BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen BussIK
|
||||
)
|
||||
|
||||
|
||||
add_definitions(-DINCLUDE_CLOTH_DEMOS)
|
||||
|
||||
IF (WIN32)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad
|
||||
)
|
||||
LINK_LIBRARIES(
|
||||
${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
ELSE(WIN32)
|
||||
IF(APPLE)
|
||||
find_library(COCOA NAMES Cocoa)
|
||||
MESSAGE(${COCOA})
|
||||
link_libraries(${COCOA} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
|
||||
INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad )
|
||||
ELSE(APPLE)
|
||||
ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1")
|
||||
ADD_DEFINITIONS("-DGLEW_STATIC")
|
||||
ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1")
|
||||
INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad )
|
||||
FIND_PACKAGE(Threads)
|
||||
LINK_LIBRARIES( ${CMAKE_THREAD_LIBS_INIT} ${DL} )
|
||||
ENDIF(APPLE)
|
||||
ENDIF(WIN32)
|
||||
|
||||
|
||||
SET(ExtendedTutorialsSources
|
||||
../ExtendedTutorials/Chain.cpp
|
||||
../ExtendedTutorials/Chain.h
|
||||
../ExtendedTutorials/Bridge.cpp
|
||||
../ExtendedTutorials/Bridge.h
|
||||
../ExtendedTutorials/RigidBodyFromObj.cpp
|
||||
../ExtendedTutorials/RigidBodyFromObj.h
|
||||
../ExtendedTutorials/SimpleBox.cpp
|
||||
../ExtendedTutorials/SimpleBox.h
|
||||
../ExtendedTutorials/MultipleBoxes.cpp
|
||||
../ExtendedTutorials/MultipleBoxes.h
|
||||
../ExtendedTutorials/CompoundBoxes.cpp
|
||||
../ExtendedTutorials/CompoundBoxes.h
|
||||
../ExtendedTutorials/SimpleCloth.cpp
|
||||
../ExtendedTutorials/SimpleCloth.h
|
||||
../ExtendedTutorials/SimpleJoint.cpp
|
||||
../ExtendedTutorials/SimpleJoint.h
|
||||
../ExtendedTutorials/NewtonsCradle.cpp
|
||||
../ExtendedTutorials/NewtonsCradle.h
|
||||
../ExtendedTutorials/InclinedPlane.cpp
|
||||
../ExtendedTutorials/InclinedPlane.h
|
||||
../ExtendedTutorials/MultiPendulum.cpp
|
||||
../ExtendedTutorials/MultiPendulum.h
|
||||
)
|
||||
|
||||
SET(BulletExampleBrowser_SRCS
|
||||
../BulletRobotics/FixJointBoxes.cpp
|
||||
|
||||
../BulletRobotics/BoxStack.cpp
|
||||
../BulletRobotics/JointLimit.cpp
|
||||
# ../BulletRobotics/GraspBox.cpp
|
||||
|
||||
../TinyRenderer/geometry.cpp
|
||||
../TinyRenderer/model.cpp
|
||||
../TinyRenderer/tgaimage.cpp
|
||||
../TinyRenderer/our_gl.cpp
|
||||
../TinyRenderer/TinyRenderer.cpp
|
||||
../SharedMemory/plugins/collisionFilterPlugin/collisionFilterPlugin.cpp
|
||||
../SharedMemory/plugins/collisionFilterPlugin/collisionFilterPlugin.h
|
||||
../SharedMemory/plugins/pdControlPlugin/pdControlPlugin.cpp
|
||||
../SharedMemory/plugins/pdControlPlugin/pdControlPlugin.h
|
||||
../SharedMemory/plugins/tinyRendererPlugin/tinyRendererPlugin.cpp
|
||||
../SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp
|
||||
../SharedMemory/IKTrajectoryHelper.cpp
|
||||
../SharedMemory/IKTrajectoryHelper.h
|
||||
../SharedMemory/PhysicsServer.cpp
|
||||
../SharedMemory/PhysicsClientSharedMemory.cpp
|
||||
../SharedMemory/PhysicsClientSharedMemory_C_API.cpp
|
||||
../SharedMemory/PhysicsClient.cpp
|
||||
../SharedMemory/PhysicsClientC_API.cpp
|
||||
../SharedMemory/GraphicsServerExample.cpp
|
||||
../SharedMemory/GraphicsClientExample.cpp
|
||||
../SharedMemory/RemoteGUIHelper.cpp
|
||||
../SharedMemory/GraphicsServerExample.h
|
||||
../SharedMemory/GraphicsClientExample.h
|
||||
../SharedMemory/RemoteGUIHelper.h
|
||||
../SharedMemory/GraphicsSharedMemoryCommands.h
|
||||
../SharedMemory/GraphicsSharedMemoryPublic.h
|
||||
../SharedMemory/PhysicsServerExample.cpp
|
||||
../SharedMemory/PhysicsServerExampleBullet2.cpp
|
||||
../SharedMemory/PhysicsClientExample.cpp
|
||||
../SharedMemory/PosixSharedMemory.cpp
|
||||
../SharedMemory/Win32SharedMemory.cpp
|
||||
../SharedMemory/InProcessMemory.cpp
|
||||
../SharedMemory/PhysicsServerSharedMemory.cpp
|
||||
../SharedMemory/PhysicsDirect.cpp
|
||||
../SharedMemory/PhysicsDirect.h
|
||||
../SharedMemory/PhysicsDirectC_API.cpp
|
||||
../SharedMemory/PhysicsDirectC_API.h
|
||||
../SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp
|
||||
../SharedMemory/PhysicsLoopBack.cpp
|
||||
../SharedMemory/PhysicsLoopBack.h
|
||||
../SharedMemory/PhysicsLoopBackC_API.cpp
|
||||
../SharedMemory/PhysicsLoopBackC_API.h
|
||||
../SharedMemory/PhysicsServerCommandProcessor.cpp
|
||||
../SharedMemory/PhysicsServerCommandProcessor.h
|
||||
../SharedMemory/SharedMemoryCommands.h
|
||||
../SharedMemory/SharedMemoryPublic.h
|
||||
../SharedMemory/b3PluginManager.cpp
|
||||
../SharedMemory/b3RobotSimulatorClientAPI_NoGUI.cpp
|
||||
../SharedMemory/b3RobotSimulatorClientAPI_NoGUI.h
|
||||
../SharedMemory/b3RobotSimulatorClientAPI_NoDirect.cpp
|
||||
../SharedMemory/b3RobotSimulatorClientAPI_NoDirect.h
|
||||
../RobotSimulator/b3RobotSimulatorClientAPI.cpp
|
||||
../RobotSimulator/b3RobotSimulatorClientAPI.h
|
||||
../BasicDemo/BasicExample.cpp
|
||||
../BasicDemo/BasicExample.h
|
||||
../InverseDynamics/InverseDynamicsExample.cpp
|
||||
../InverseDynamics/InverseDynamicsExample.h
|
||||
../InverseKinematics/InverseKinematicsExample.cpp
|
||||
../InverseKinematics/InverseKinematicsExample.h
|
||||
../ForkLift/ForkLiftDemo.cpp
|
||||
../ForkLift/ForkLiftDemo.h
|
||||
../MultiThreadedDemo/MultiThreadedDemo.cpp
|
||||
../MultiThreadedDemo/MultiThreadedDemo.h
|
||||
../MultiThreadedDemo/CommonRigidBodyMTBase.cpp
|
||||
../MultiThreadedDemo/CommonRigidBodyMTBase.h
|
||||
../Heightfield/HeightfieldExample.cpp
|
||||
../Heightfield/HeightfieldExample.h
|
||||
../Tutorial/Tutorial.cpp
|
||||
../Tutorial/Tutorial.h
|
||||
../Tutorial/Dof6ConstraintTutorial.cpp
|
||||
../Tutorial/Dof6ConstraintTutorial.h
|
||||
../Evolution/NN3DWalkers.cpp
|
||||
../Evolution/NN3DWalkers.h
|
||||
../Evolution/NN3DWalkersTimeWarpBase.h
|
||||
../ExtendedTutorials/NewtonsRopeCradle.cpp
|
||||
../ExtendedTutorials/NewtonsRopeCradle.h
|
||||
../Collision/CollisionSdkC_Api.cpp
|
||||
../Collision/CollisionSdkC_Api.h
|
||||
../Collision/CollisionTutorialBullet2.cpp
|
||||
../Collision/CollisionTutorialBullet2.h
|
||||
../Collision/Internal/Bullet2CollisionSdk.cpp
|
||||
../Collision/Internal/Bullet2CollisionSdk.h
|
||||
../Collision/Internal/CollisionSdkInterface.h
|
||||
../Collision/Internal/RealTimeBullet3CollisionSdk.cpp
|
||||
../Collision/Internal/RealTimeBullet3CollisionSdk.h
|
||||
../GyroscopicDemo/GyroscopicSetup.cpp
|
||||
../GyroscopicDemo/GyroscopicSetup.h
|
||||
../Planar2D/Planar2D.cpp
|
||||
../Planar2D/Planar2D.h
|
||||
../RollingFrictionDemo/RollingFrictionDemo.cpp
|
||||
../RollingFrictionDemo/RollingFrictionDemo.h
|
||||
../FractureDemo/FractureDemo.cpp
|
||||
../FractureDemo/btFractureBody.cpp
|
||||
../FractureDemo/btFractureDynamicsWorld.cpp
|
||||
../FractureDemo/FractureDemo.h
|
||||
../FractureDemo/btFractureBody.h
|
||||
../FractureDemo/btFractureDynamicsWorld.h
|
||||
../DynamicControlDemo/MotorDemo.cpp
|
||||
../DynamicControlDemo/MotorDemo.h
|
||||
../MultiThreading/MultiThreadingExample.cpp
|
||||
../MultiThreading/b3PosixThreadSupport.cpp
|
||||
../MultiThreading/b3Win32ThreadSupport.cpp
|
||||
../MultiThreading/b3ThreadSupportInterface.cpp
|
||||
../RenderingExamples/TinyRendererSetup.cpp
|
||||
../RenderingExamples/TimeSeriesCanvas.cpp
|
||||
../RenderingExamples/TimeSeriesCanvas.h
|
||||
../RenderingExamples/TimeSeriesFontData.cpp
|
||||
../RenderingExamples/TimeSeriesFontData.h
|
||||
../RenderingExamples/DynamicTexturedCubeDemo.cpp
|
||||
../RenderingExamples/DynamicTexturedCubeDemo.h
|
||||
../RenderingExamples/TinyVRGui.cpp
|
||||
../RenderingExamples/TinyVRGui.h
|
||||
|
||||
../RoboticsLearning/GripperGraspExample.cpp
|
||||
../RoboticsLearning/GripperGraspExample.h
|
||||
../RoboticsLearning/R2D2GraspExample.cpp
|
||||
../RoboticsLearning/R2D2GraspExample.h
|
||||
../RoboticsLearning/KukaGraspExample.cpp
|
||||
../RoboticsLearning/KukaGraspExample.h
|
||||
../RenderingExamples/CoordinateSystemDemo.cpp
|
||||
../RenderingExamples/CoordinateSystemDemo.h
|
||||
../RenderingExamples/RaytracerSetup.cpp
|
||||
../RenderingExamples/RaytracerSetup.h
|
||||
../RenderingExamples/RenderInstancingDemo.cpp
|
||||
../RenderingExamples/RenderInstancingDemo.h
|
||||
../RenderingExamples/TimeSeriesExample.cpp
|
||||
../Benchmarks/BenchmarkDemo.cpp
|
||||
../Benchmarks/BenchmarkDemo.h
|
||||
../Benchmarks/landscapeData.h
|
||||
../Benchmarks/TaruData
|
||||
../Raycast/RaytestDemo.cpp
|
||||
../Importers/ImportBsp/BspConverter.h
|
||||
../Importers/ImportBullet/SerializeSetup.cpp
|
||||
../Importers/ImportBullet/SerializeSetup.h
|
||||
../Importers/ImportMeshUtility/b3ImportMeshUtility.cpp
|
||||
../Importers/ImportMeshUtility/b3ImportMeshUtility.h
|
||||
../../Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp
|
||||
../../Extras/Serialize/BulletWorldImporter/btMultiBodyWorldImporter.cpp
|
||||
../../Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp
|
||||
../../Extras/Serialize/BulletFileLoader/bChunk.cpp
|
||||
../../Extras/Serialize/BulletFileLoader/bFile.cpp
|
||||
../../Extras/Serialize/BulletFileLoader/bDNA.cpp
|
||||
../../Extras/Serialize/BulletFileLoader/btBulletFile.cpp
|
||||
|
||||
../Importers/ImportBsp/BspLoader.h
|
||||
../Importers/ImportBsp/ImportBspExample.h
|
||||
../Importers/ImportColladaDemo/btMatrix4x4.h
|
||||
../Importers/ImportColladaDemo/ColladaGraphicsInstance.h
|
||||
../Importers/ImportColladaDemo/ImportColladaSetup.h
|
||||
../Importers/ImportColladaDemo/LoadMeshFromCollada.h
|
||||
../Importers/ImportObjDemo/ImportObjExample.h
|
||||
../Importers/ImportObjDemo/LoadMeshFromObj.h
|
||||
../Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.h
|
||||
../Importers/ImportSTLDemo/ImportSTLSetup.h
|
||||
../Importers/ImportSTLDemo/LoadMeshFromSTL.h
|
||||
../Importers/ImportURDFDemo/ConvertRigidBodies2MultiBody.h
|
||||
../Importers/ImportURDFDemo/ImportURDFSetup.h
|
||||
../Importers/ImportURDFDemo/URDF2Bullet.h
|
||||
../Importers/ImportURDFDemo/urdf_samples.h
|
||||
../Importers/ImportURDFDemo/urdf_samples.h
|
||||
../Importers/ImportMJCFDemo/BulletMJCFImporter.cpp
|
||||
../Importers/ImportMJCFDemo/BulletMJCFImporter.h
|
||||
../Importers/ImportMJCFDemo/ImportMJCFSetup.cpp
|
||||
../Importers/ImportMJCFDemo/ImportMJCFSetup.h
|
||||
../Importers/ImportBsp/BspConverter.cpp
|
||||
../Importers/ImportBsp/BspLoader.cpp
|
||||
../Importers/ImportBsp/ImportBspExample.cpp
|
||||
../Importers/ImportColladaDemo/ImportColladaSetup.cpp
|
||||
../Importers/ImportColladaDemo/LoadMeshFromCollada.cpp
|
||||
../Importers/ImportObjDemo/ImportObjExample.cpp
|
||||
../Importers/ImportObjDemo/LoadMeshFromObj.cpp
|
||||
../Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp
|
||||
../Importers/ImportSTLDemo/ImportSTLSetup.cpp
|
||||
../Importers/ImportSDFDemo/ImportSDFSetup.cpp
|
||||
../Importers/ImportURDFDemo/ImportURDFSetup.cpp
|
||||
../Importers/ImportURDFDemo/URDF2Bullet.cpp
|
||||
../Importers/ImportURDFDemo/MyMultiBodyCreator.cpp
|
||||
../Importers/ImportURDFDemo/MyMultiBodyCreator.h
|
||||
../Importers/ImportURDFDemo/UrdfParser.cpp
|
||||
../Utils/RobotLoggingUtil.cpp
|
||||
../Utils/RobotLoggingUtil.h
|
||||
../Importers/ImportURDFDemo/urdfStringSplit.cpp
|
||||
../Importers/ImportURDFDemo/urdfStringSplit.h
|
||||
../Importers/ImportURDFDemo/BulletUrdfImporter.cpp
|
||||
../Importers/ImportURDFDemo/BulletUrdfImporter.h
|
||||
../VoronoiFracture/VoronoiFractureDemo.cpp
|
||||
../VoronoiFracture/VoronoiFractureDemo.h
|
||||
../VoronoiFracture/btConvexConvexMprAlgorithm.cpp
|
||||
../VoronoiFracture/btConvexConvexMprAlgorithm.h
|
||||
../Vehicles/Hinge2Vehicle.cpp
|
||||
../Vehicles/Hinge2Vehicle.h
|
||||
../MultiBody/Pendulum.cpp
|
||||
../MultiBody/MultiBodySoftContact.cpp
|
||||
../MultiBody/TestJointTorqueSetup.cpp
|
||||
../MultiBody/TestJointTorqueSetup.h
|
||||
../MultiBody/InvertedPendulumPDControl.cpp
|
||||
../MultiBody/InvertedPendulumPDControl.h
|
||||
../MultiBody/MultiBodyConstraintFeedback.cpp
|
||||
../MultiBody/KinematicMultiBodyExample.cpp
|
||||
../SoftDemo/SoftDemo.cpp
|
||||
../SoftDemo/SoftDemo.h
|
||||
../DeformableDemo/DeformableContact.cpp
|
||||
../DeformableDemo/DeformableContact.h
|
||||
../DeformableDemo/GraspDeformable.cpp
|
||||
../DeformableDemo/GraspDeformable.h
|
||||
../DeformableDemo/Pinch.cpp
|
||||
../DeformableDemo/Pinch.h
|
||||
../DeformableDemo/DeformableSelfCollision.cpp
|
||||
../DeformableDemo/DeformableSelfCollision.h
|
||||
../DeformableDemo/PinchFriction.cpp
|
||||
../DeformableDemo/PinchFriction.h
|
||||
../DeformableDemo/ClothFriction.cpp
|
||||
../DeformableDemo/ClothFriction.h
|
||||
../DeformableDemo/DeformableMultibody.cpp
|
||||
../DeformableDemo/DeformableMultibody.h
|
||||
../DeformableDemo/DeformableRigid.cpp
|
||||
../DeformableDemo/DeformableRigid.h
|
||||
../DeformableDemo/SplitImpulse.cpp
|
||||
../DeformableDemo/SplitImpulse.h
|
||||
../DeformableDemo/VolumetricDeformable.cpp
|
||||
../DeformableDemo/VolumetricDeformable.h
|
||||
../DeformableDemo/Collide.cpp
|
||||
../DeformableDemo/Collide.h
|
||||
../DeformableDemo/LargeDeformation.cpp
|
||||
../DeformableDemo/LoadDeformed.h
|
||||
../DeformableDemo/LoadDeformed.cpp
|
||||
../DeformableDemo/LargeDeformation.h
|
||||
../DeformableDemo/DeformableClothAnchor.cpp
|
||||
../DeformableDemo/DeformableClothAnchor.h
|
||||
../DeformableDemo/MultibodyClothAnchor.cpp
|
||||
../DeformableDemo/MultibodyClothAnchor.h
|
||||
../MultiBody/MultiDofDemo.cpp
|
||||
../MultiBody/MultiDofDemo.h
|
||||
../RigidBody/RigidBodySoftContact.cpp
|
||||
../RigidBody/KinematicRigidBodyExample.cpp
|
||||
../ReducedDeformableDemo/ConservationTest.cpp
|
||||
../ReducedDeformableDemo/ConservationTest.h
|
||||
../ReducedDeformableDemo/Springboard.cpp
|
||||
../ReducedDeformableDemo/Springboard.h
|
||||
../ReducedDeformableDemo/ModeVisualizer.cpp
|
||||
../ReducedDeformableDemo/ModeVisualizer.h
|
||||
../ReducedDeformableDemo/FreeFall.cpp
|
||||
../ReducedDeformableDemo/FreeFall.h
|
||||
../ReducedDeformableDemo/FrictionSlope.cpp
|
||||
../ReducedDeformableDemo/FrictionSlope.h
|
||||
../ReducedDeformableDemo/ReducedCollide.cpp
|
||||
../ReducedDeformableDemo/ReducedCollide.h
|
||||
../ReducedDeformableDemo/ReducedGrasp.cpp
|
||||
../ReducedDeformableDemo/ReducedGrasp.h
|
||||
../ReducedDeformableDemo/ReducedBenchmark.cpp
|
||||
../ReducedDeformableDemo/ReducedBenchmark.h
|
||||
../ReducedDeformableDemo/ReducedMotorGrasp.cpp
|
||||
../ReducedDeformableDemo/ReducedMotorGrasp.h
|
||||
../Constraints/TestHingeTorque.cpp
|
||||
../Constraints/TestHingeTorque.h
|
||||
../Constraints/ConstraintDemo.cpp
|
||||
../Constraints/ConstraintDemo.h
|
||||
../Constraints/Dof6Spring2Setup.cpp
|
||||
../Constraints/Dof6Spring2Setup.h
|
||||
../Constraints/ConstraintPhysicsSetup.cpp
|
||||
../Constraints/ConstraintPhysicsSetup.h
|
||||
|
||||
|
||||
../ThirdPartyLibs/stb_image/stb_image.cpp
|
||||
../ThirdPartyLibs/stb_image/stb_image.h
|
||||
../ThirdPartyLibs/stb_image/stb_image_write.cpp
|
||||
../ThirdPartyLibs/Wavefront/tiny_obj_loader.cpp
|
||||
|
||||
../ThirdPartyLibs/tinyxml2/tinyxml2.cpp
|
||||
InProcessExampleBrowser.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
|
||||
|
||||
|
||||
ADD_EXECUTABLE(App_ExampleBrowser
|
||||
main.cpp
|
||||
ExampleEntries.cpp
|
||||
ExampleEntries.h
|
||||
${ExtendedTutorialsSources}
|
||||
${BulletExampleBrowser_SRCS}
|
||||
)
|
||||
|
||||
FILE( MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/data" )
|
||||
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET App_ExampleBrowser
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory ${BULLET_PHYSICS_SOURCE_DIR}/data ${PROJECT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
IF (BULLET2_USE_TBB_MULTITHREADING AND WIN32)
|
||||
# add a post build command to copy some dlls to the executable directory
|
||||
set(TBB_VC_VER "vc12")
|
||||
set(TBB_VC_ARCH "ia32")
|
||||
# assume 32-bit build in VC12 for now
|
||||
# checks can be added here at a later time
|
||||
ADD_CUSTOM_COMMAND(TARGET App_ExampleBrowser POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${BULLET2_TBB_INCLUDE_DIR}/../bin/${TBB_VC_ARCH}/${TBB_VC_VER}/tbb.dll"
|
||||
$<TARGET_FILE_DIR:App_ExampleBrowser>)
|
||||
ADD_CUSTOM_COMMAND(TARGET App_ExampleBrowser POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${BULLET2_TBB_INCLUDE_DIR}/../bin/${TBB_VC_ARCH}/${TBB_VC_VER}/tbbmalloc.dll"
|
||||
$<TARGET_FILE_DIR:App_ExampleBrowser>)
|
||||
ENDIF (BULLET2_USE_TBB_MULTITHREADING AND WIN32)
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(App_ExampleBrowser PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(App_ExampleBrowser PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(App_ExampleBrowser PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
|
||||
|
|
@ -0,0 +1,230 @@
|
|||
|
||||
#include "CollisionShape2TriangleMesh.h"
|
||||
|
||||
#include "btBulletCollisionCommon.h"
|
||||
#include "BulletCollision/CollisionShapes/btShapeHull.h" //to create a tesselation of a generic btConvexShape
|
||||
#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
|
||||
|
||||
void CollisionShape2TriangleMesh(btCollisionShape* collisionShape, const btTransform& parentTransform, btAlignedObjectArray<btVector3>& vertexPositions, btAlignedObjectArray<btVector3>& vertexNormals, btAlignedObjectArray<int>& indicesOut)
|
||||
|
||||
{
|
||||
//todo: support all collision shape types
|
||||
switch (collisionShape->getShapeType())
|
||||
{
|
||||
case SOFTBODY_SHAPE_PROXYTYPE:
|
||||
{
|
||||
//skip the soft body collision shape for now
|
||||
break;
|
||||
}
|
||||
case STATIC_PLANE_PROXYTYPE:
|
||||
{
|
||||
//draw a box, oriented along the plane normal
|
||||
const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(collisionShape);
|
||||
btScalar planeConst = staticPlaneShape->getPlaneConstant();
|
||||
const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
|
||||
btVector3 planeOrigin = planeNormal * planeConst;
|
||||
btVector3 vec0, vec1;
|
||||
btPlaneSpace1(planeNormal, vec0, vec1);
|
||||
btScalar vecLen = 100.f;
|
||||
btVector3 verts[4];
|
||||
|
||||
verts[0] = planeOrigin + vec0 * vecLen + vec1 * vecLen;
|
||||
verts[1] = planeOrigin - vec0 * vecLen + vec1 * vecLen;
|
||||
verts[2] = planeOrigin - vec0 * vecLen - vec1 * vecLen;
|
||||
verts[3] = planeOrigin + vec0 * vecLen - vec1 * vecLen;
|
||||
|
||||
int startIndex = vertexPositions.size();
|
||||
indicesOut.push_back(startIndex + 0);
|
||||
indicesOut.push_back(startIndex + 1);
|
||||
indicesOut.push_back(startIndex + 2);
|
||||
indicesOut.push_back(startIndex + 0);
|
||||
indicesOut.push_back(startIndex + 2);
|
||||
indicesOut.push_back(startIndex + 3);
|
||||
|
||||
btVector3 triNormal = parentTransform.getBasis() * planeNormal;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
btVector3 vtxPos;
|
||||
btVector3 pos = parentTransform * verts[i];
|
||||
vertexPositions.push_back(pos);
|
||||
vertexNormals.push_back(triNormal);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TRIANGLE_MESH_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)collisionShape;
|
||||
btVector3 trimeshScaling = trimesh->getLocalScaling();
|
||||
btStridingMeshInterface* meshInterface = trimesh->getMeshInterface();
|
||||
btAlignedObjectArray<btVector3> vertices;
|
||||
btAlignedObjectArray<int> indices;
|
||||
|
||||
for (int partId = 0; partId < meshInterface->getNumSubParts(); partId++)
|
||||
{
|
||||
const unsigned char* vertexbase = 0;
|
||||
int numverts = 0;
|
||||
PHY_ScalarType type = PHY_INTEGER;
|
||||
int stride = 0;
|
||||
const unsigned char* indexbase = 0;
|
||||
int indexstride = 0;
|
||||
int numfaces = 0;
|
||||
PHY_ScalarType indicestype = PHY_INTEGER;
|
||||
//PHY_ScalarType indexType=0;
|
||||
|
||||
btVector3 triangleVerts[3];
|
||||
meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase, numverts, type, stride, &indexbase, indexstride, numfaces, indicestype, partId);
|
||||
btVector3 aabbMin, aabbMax;
|
||||
|
||||
for (int triangleIndex = 0; triangleIndex < numfaces; triangleIndex++)
|
||||
{
|
||||
unsigned int* gfxbase = (unsigned int*)(indexbase + triangleIndex * indexstride);
|
||||
|
||||
for (int j = 2; j >= 0; j--)
|
||||
{
|
||||
int graphicsindex;
|
||||
switch (indicestype) {
|
||||
case PHY_INTEGER: graphicsindex = gfxbase[j]; break;
|
||||
case PHY_SHORT: graphicsindex = ((unsigned short*)gfxbase)[j]; break;
|
||||
case PHY_UCHAR: graphicsindex = ((unsigned char*)gfxbase)[j]; break;
|
||||
default: btAssert(0);
|
||||
}
|
||||
if (type == PHY_FLOAT)
|
||||
{
|
||||
float* graphicsbase = (float*)(vertexbase + graphicsindex * stride);
|
||||
triangleVerts[j] = btVector3(
|
||||
graphicsbase[0] * trimeshScaling.getX(),
|
||||
graphicsbase[1] * trimeshScaling.getY(),
|
||||
graphicsbase[2] * trimeshScaling.getZ());
|
||||
}
|
||||
else
|
||||
{
|
||||
double* graphicsbase = (double*)(vertexbase + graphicsindex * stride);
|
||||
triangleVerts[j] = btVector3(btScalar(graphicsbase[0] * trimeshScaling.getX()),
|
||||
btScalar(graphicsbase[1] * trimeshScaling.getY()),
|
||||
btScalar(graphicsbase[2] * trimeshScaling.getZ()));
|
||||
}
|
||||
}
|
||||
indices.push_back(vertices.size());
|
||||
vertices.push_back(triangleVerts[0]);
|
||||
indices.push_back(vertices.size());
|
||||
vertices.push_back(triangleVerts[1]);
|
||||
indices.push_back(vertices.size());
|
||||
vertices.push_back(triangleVerts[2]);
|
||||
|
||||
btVector3 triNormal = (triangleVerts[1] - triangleVerts[0]).cross(triangleVerts[2] - triangleVerts[0]);
|
||||
btScalar dot = triNormal.dot(triNormal);
|
||||
|
||||
//cull degenerate triangles
|
||||
if (dot >= SIMD_EPSILON * SIMD_EPSILON)
|
||||
{
|
||||
triNormal /= btSqrt(dot);
|
||||
for (int v = 0; v < 3; v++)
|
||||
{
|
||||
btVector3 pos = parentTransform * triangleVerts[v];
|
||||
indicesOut.push_back(vertexPositions.size());
|
||||
vertexPositions.push_back(pos);
|
||||
vertexNormals.push_back(triNormal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (collisionShape->isConvex())
|
||||
{
|
||||
btConvexShape* convex = (btConvexShape*)collisionShape;
|
||||
{
|
||||
const btConvexPolyhedron* pol = 0;
|
||||
if (convex->isPolyhedral())
|
||||
{
|
||||
btPolyhedralConvexShape* poly = (btPolyhedralConvexShape*)convex;
|
||||
pol = poly->getConvexPolyhedron();
|
||||
}
|
||||
|
||||
if (pol)
|
||||
{
|
||||
int baseIndex = vertexPositions.size();
|
||||
for (int v = 0; v < pol->m_vertices.size(); v++)
|
||||
{
|
||||
vertexPositions.push_back(pol->m_vertices[v]);
|
||||
btVector3 norm = pol->m_vertices[v];
|
||||
norm.safeNormalize();
|
||||
vertexNormals.push_back(norm);
|
||||
}
|
||||
for (int f = 0; f < pol->m_faces.size(); f++)
|
||||
{
|
||||
for (int ii = 2; ii < pol->m_faces[f].m_indices.size(); ii++)
|
||||
{
|
||||
indicesOut.push_back(baseIndex+pol->m_faces[f].m_indices[0]);
|
||||
indicesOut.push_back(baseIndex + pol->m_faces[f].m_indices[ii - 1]);
|
||||
indicesOut.push_back(baseIndex + pol->m_faces[f].m_indices[ii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
btShapeHull* hull = new btShapeHull(convex);
|
||||
hull->buildHull(0.0, 1);
|
||||
|
||||
{
|
||||
//int strideInBytes = 9*sizeof(float);
|
||||
//int numVertices = hull->numVertices();
|
||||
//int numIndices =hull->numIndices();
|
||||
|
||||
for (int t = 0; t < hull->numTriangles(); t++)
|
||||
{
|
||||
btVector3 triNormal;
|
||||
|
||||
int index0 = hull->getIndexPointer()[t * 3 + 0];
|
||||
int index1 = hull->getIndexPointer()[t * 3 + 1];
|
||||
int index2 = hull->getIndexPointer()[t * 3 + 2];
|
||||
btVector3 pos0 = parentTransform * hull->getVertexPointer()[index0];
|
||||
btVector3 pos1 = parentTransform * hull->getVertexPointer()[index1];
|
||||
btVector3 pos2 = parentTransform * hull->getVertexPointer()[index2];
|
||||
triNormal = (pos1 - pos0).cross(pos2 - pos0);
|
||||
triNormal.safeNormalize();
|
||||
|
||||
for (int v = 0; v < 3; v++)
|
||||
{
|
||||
int index = hull->getIndexPointer()[t * 3 + v];
|
||||
btVector3 pos = parentTransform * hull->getVertexPointer()[index];
|
||||
indicesOut.push_back(vertexPositions.size());
|
||||
vertexPositions.push_back(pos);
|
||||
vertexNormals.push_back(triNormal);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete hull;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (collisionShape->isCompound())
|
||||
{
|
||||
btCompoundShape* compound = (btCompoundShape*)collisionShape;
|
||||
for (int i = 0; i < compound->getNumChildShapes(); i++)
|
||||
{
|
||||
btTransform childWorldTrans = parentTransform * compound->getChildTransform(i);
|
||||
CollisionShape2TriangleMesh(compound->getChildShape(i), childWorldTrans, vertexPositions, vertexNormals, indicesOut);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (collisionShape->getShapeType() == SDF_SHAPE_PROXYTYPE)
|
||||
{
|
||||
//not yet
|
||||
}
|
||||
else
|
||||
{
|
||||
btAssert(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef COLLISION_SHAPE_2_GRAPHICS_H
|
||||
#define COLLISION_SHAPE_2_GRAPHICS_H
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "LinearMath/btTransform.h"
|
||||
class btCollisionShape;
|
||||
|
||||
void CollisionShape2TriangleMesh(btCollisionShape* collisionShape, const btTransform& parentTransform, btAlignedObjectArray<btVector3>& vertexPositions, btAlignedObjectArray<btVector3>& vertexNormals, btAlignedObjectArray<int>& indicesOut);
|
||||
|
||||
#endif //COLLISION_SHAPE_2_GRAPHICS_H
|
||||
45
Engine/lib/bullet/examples/ExampleBrowser/EmptyBrowser.h
Normal file
45
Engine/lib/bullet/examples/ExampleBrowser/EmptyBrowser.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef EMPTY_BROWSER
|
||||
#define EMPTY_BROWSER
|
||||
|
||||
#include "ExampleBrowserInterface.h"
|
||||
#include "EmptyExample.h"
|
||||
|
||||
class EmptyBrowser : public ExampleBrowserInterface
|
||||
{
|
||||
public:
|
||||
EmptyExample m_emptyExample;
|
||||
|
||||
virtual CommonExampleInterface* getCurrentExample()
|
||||
{
|
||||
return &m_emptyExample;
|
||||
}
|
||||
|
||||
EmptyBrowser(class ExampleEntries* examples)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool init(int /*argc*/, char* argv[])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void update(float deltaTime)
|
||||
{
|
||||
m_emptyExample.stepSimulation(deltaTime);
|
||||
}
|
||||
|
||||
virtual void updateGraphics()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool requestedExit()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void setSharedMemoryInterface(class SharedMemoryInterface* sharedMem)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EMPTY_BROWSER
|
||||
27
Engine/lib/bullet/examples/ExampleBrowser/EmptyExample.h
Normal file
27
Engine/lib/bullet/examples/ExampleBrowser/EmptyExample.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef EMPTY_EXAMPLE_H
|
||||
#define EMPTY_EXAMPLE_H
|
||||
|
||||
#include "../CommonInterfaces/CommonExampleInterface.h"
|
||||
|
||||
class EmptyExample : public CommonExampleInterface
|
||||
{
|
||||
public:
|
||||
EmptyExample() {}
|
||||
virtual ~EmptyExample() {}
|
||||
|
||||
static CommonExampleInterface* CreateFunc(struct CommonExampleOptions& /* unusedOptions*/)
|
||||
{
|
||||
return new EmptyExample;
|
||||
}
|
||||
|
||||
virtual void initPhysics() {}
|
||||
virtual void exitPhysics() {}
|
||||
virtual void stepSimulation(float deltaTime) {}
|
||||
virtual void renderScene() {}
|
||||
virtual void physicsDebugDraw(int debugFlags) {}
|
||||
virtual bool mouseMoveCallback(float x, float y) { return false; }
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y) { return false; }
|
||||
virtual bool keyboardCallback(int key, int state) { return false; }
|
||||
};
|
||||
|
||||
#endif //EMPTY_EXAMPLE_H
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef EXAMPLE_BROWSER_GUI_H
|
||||
#define EXAMPLE_BROWSER_GUI_H
|
||||
|
||||
#include "../CommonInterfaces/CommonExampleInterface.h"
|
||||
|
||||
class ExampleBrowserInterface
|
||||
{
|
||||
public:
|
||||
virtual ~ExampleBrowserInterface() {}
|
||||
|
||||
virtual CommonExampleInterface* getCurrentExample() = 0;
|
||||
|
||||
virtual bool init(int argc, char* argv[]) = 0;
|
||||
|
||||
virtual void update(float deltaTime) = 0;
|
||||
|
||||
virtual void updateGraphics() = 0;
|
||||
|
||||
virtual bool requestedExit() = 0;
|
||||
|
||||
virtual void setSharedMemoryInterface(class SharedMemoryInterface* sharedMem) = 0;
|
||||
};
|
||||
|
||||
#endif //EXAMPLE_BROWSER_GUI_H
|
||||
499
Engine/lib/bullet/examples/ExampleBrowser/ExampleEntries.cpp
Normal file
499
Engine/lib/bullet/examples/ExampleBrowser/ExampleEntries.cpp
Normal file
|
|
@ -0,0 +1,499 @@
|
|||
#include "ExampleEntries.h"
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "EmptyExample.h"
|
||||
#include "../Heightfield/HeightfieldExample.h"
|
||||
#include "../RenderingExamples/RenderInstancingDemo.h"
|
||||
#include "../RenderingExamples/CoordinateSystemDemo.h"
|
||||
#include "../RenderingExamples/RaytracerSetup.h"
|
||||
#include "../RenderingExamples/TinyRendererSetup.h"
|
||||
#include "../RenderingExamples/DynamicTexturedCubeDemo.h"
|
||||
#include "../SharedMemory/GraphicsServerExample.h"
|
||||
#include "../SharedMemory/GraphicsClientExample.h"
|
||||
|
||||
#include "../ForkLift/ForkLiftDemo.h"
|
||||
#include "../MultiThreadedDemo/MultiThreadedDemo.h"
|
||||
#include "../BasicDemo/BasicExample.h"
|
||||
#include "../Planar2D/Planar2D.h"
|
||||
#include "../Benchmarks/BenchmarkDemo.h"
|
||||
#include "../Importers/ImportObjDemo/ImportObjExample.h"
|
||||
#include "../Importers/ImportBsp/ImportBspExample.h"
|
||||
#include "../Importers/ImportColladaDemo/ImportColladaSetup.h"
|
||||
#include "../Importers/ImportSTLDemo/ImportSTLSetup.h"
|
||||
#include "../Importers/ImportURDFDemo/ImportURDFSetup.h"
|
||||
#include "../Importers/ImportSDFDemo/ImportSDFSetup.h"
|
||||
#include "../Importers/ImportMJCFDemo/ImportMJCFSetup.h"
|
||||
#include "../Collision/CollisionTutorialBullet2.h"
|
||||
#include "../GyroscopicDemo/GyroscopicSetup.h"
|
||||
#include "../Constraints/Dof6Spring2Setup.h"
|
||||
#include "../Constraints/ConstraintPhysicsSetup.h"
|
||||
#include "../MultiBody/TestJointTorqueSetup.h"
|
||||
#include "../MultiBody/Pendulum.h"
|
||||
#include "../MultiBody/MultiBodySoftContact.h"
|
||||
#include "../MultiBody/MultiBodyConstraintFeedback.h"
|
||||
#include "../MultiBody/MultiDofDemo.h"
|
||||
#include "../MultiBody/InvertedPendulumPDControl.h"
|
||||
#include "../MultiBody/KinematicMultiBodyExample.h"
|
||||
|
||||
#include "../RigidBody/RigidBodySoftContact.h"
|
||||
#include "../RigidBody/KinematicRigidBodyExample.h"
|
||||
#include "../VoronoiFracture/VoronoiFractureDemo.h"
|
||||
#include "../SoftDemo/SoftDemo.h"
|
||||
#include "../Constraints/ConstraintDemo.h"
|
||||
#include "../Vehicles/Hinge2Vehicle.h"
|
||||
#include "../Importers/ImportBullet/SerializeSetup.h"
|
||||
#include "../Raycast/RaytestDemo.h"
|
||||
#include "../FractureDemo/FractureDemo.h"
|
||||
#include "../DynamicControlDemo/MotorDemo.h"
|
||||
#include "../RollingFrictionDemo/RollingFrictionDemo.h"
|
||||
#include "../DeformableDemo/DeformableRigid.h"
|
||||
#include "../DeformableDemo/SplitImpulse.h"
|
||||
#include "../DeformableDemo/ClothFriction.h"
|
||||
#include "../DeformableDemo/Pinch.h"
|
||||
#include "../DeformableDemo/DeformableSelfCollision.h"
|
||||
#include "../DeformableDemo/PinchFriction.h"
|
||||
#include "../DeformableDemo/DeformableMultibody.h"
|
||||
#include "../DeformableDemo/VolumetricDeformable.h"
|
||||
#include "../DeformableDemo/LargeDeformation.h"
|
||||
#include "../DeformableDemo/LoadDeformed.h"
|
||||
#include "../DeformableDemo/Collide.h"
|
||||
#include "../DeformableDemo/GraspDeformable.h"
|
||||
#include "../DeformableDemo/DeformableContact.h"
|
||||
#include "../DeformableDemo/DeformableClothAnchor.h"
|
||||
#include "../DeformableDemo/MultibodyClothAnchor.h"
|
||||
#include "../SharedMemory/PhysicsServerExampleBullet2.h"
|
||||
#include "../SharedMemory/PhysicsServerExample.h"
|
||||
#include "../SharedMemory/PhysicsClientExample.h"
|
||||
#include "../Constraints/TestHingeTorque.h"
|
||||
#include "../RenderingExamples/TimeSeriesExample.h"
|
||||
#include "../Tutorial/Tutorial.h"
|
||||
#include "../Tutorial/Dof6ConstraintTutorial.h"
|
||||
#include "../MultiThreading/MultiThreadingExample.h"
|
||||
#include "../InverseDynamics/InverseDynamicsExample.h"
|
||||
#include "../RoboticsLearning/R2D2GraspExample.h"
|
||||
#include "../RoboticsLearning/KukaGraspExample.h"
|
||||
#include "../RoboticsLearning/GripperGraspExample.h"
|
||||
#include "../ReducedDeformableDemo/ConservationTest.h"
|
||||
#include "../ReducedDeformableDemo/ModeVisualizer.h"
|
||||
#include "../ReducedDeformableDemo/Springboard.h"
|
||||
#include "../ReducedDeformableDemo/FreeFall.h"
|
||||
#include "../ReducedDeformableDemo/FrictionSlope.h"
|
||||
#include "../ReducedDeformableDemo/ReducedCollide.h"
|
||||
#include "../ReducedDeformableDemo/ReducedGrasp.h"
|
||||
#include "../ReducedDeformableDemo/ReducedMotorGrasp.h"
|
||||
#include "../ReducedDeformableDemo/ReducedBenchmark.h"
|
||||
#include "../InverseKinematics/InverseKinematicsExample.h"
|
||||
|
||||
#ifdef B3_ENABLE_TINY_AUDIO
|
||||
#include "../TinyAudio/TinyAudioExample.h"
|
||||
#endif //B3_ENABLE_TINY_AUDIO
|
||||
|
||||
#ifdef ENABLE_LUA
|
||||
#include "../LuaDemo/LuaPhysicsSetup.h"
|
||||
#endif
|
||||
|
||||
#ifdef B3_USE_CLEW
|
||||
#ifndef NO_OPENGL3
|
||||
#include "../OpenCL/broadphase/PairBench.h"
|
||||
#include "../OpenCL/rigidbody/GpuConvexScene.h"
|
||||
#endif
|
||||
#endif //B3_USE_CLEW
|
||||
|
||||
//Extended Tutorial Includes Added by Mobeen and Benelot
|
||||
#include "../ExtendedTutorials/SimpleBox.h"
|
||||
#include "../ExtendedTutorials/MultipleBoxes.h"
|
||||
#include "../ExtendedTutorials/CompoundBoxes.h"
|
||||
#include "../ExtendedTutorials/SimpleJoint.h"
|
||||
#include "../ExtendedTutorials/SimpleCloth.h"
|
||||
#include "../ExtendedTutorials/Chain.h"
|
||||
#include "../ExtendedTutorials/Bridge.h"
|
||||
#include "../ExtendedTutorials/RigidBodyFromObj.h"
|
||||
#include "../ExtendedTutorials/InclinedPlane.h"
|
||||
#include "../ExtendedTutorials/NewtonsCradle.h"
|
||||
#include "../ExtendedTutorials/NewtonsRopeCradle.h"
|
||||
#include "../ExtendedTutorials/MultiPendulum.h"
|
||||
#include "../Evolution/NN3DWalkers.h"
|
||||
|
||||
struct ExampleEntry
|
||||
{
|
||||
int m_menuLevel;
|
||||
const char* m_name;
|
||||
const char* m_description;
|
||||
CommonExampleInterface::CreateFunc* m_createFunc;
|
||||
int m_option;
|
||||
|
||||
ExampleEntry(int menuLevel, const char* name)
|
||||
: m_menuLevel(menuLevel), m_name(name), m_description(0), m_createFunc(0), m_option(0)
|
||||
{
|
||||
}
|
||||
|
||||
ExampleEntry(int menuLevel, const char* name, const char* description, CommonExampleInterface::CreateFunc* createFunc, int option = 0)
|
||||
: m_menuLevel(menuLevel), m_name(name), m_description(description), m_createFunc(createFunc), m_option(option)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static ExampleEntry gDefaultExamples[] =
|
||||
{
|
||||
ExampleEntry(0, "API"),
|
||||
|
||||
ExampleEntry(1, "Basic Example", "Create some rigid bodies using box collision shapes. This is a good example to familiarize with the basic initialization of Bullet. The Basic Example can also be compiled without graphical user interface, as a console application. Press W for wireframe, A to show AABBs, I to suspend/restart physics simulation. Press D to toggle auto-deactivation of the simulation. ", BasicExampleCreateFunc),
|
||||
|
||||
ExampleEntry(1, "Rolling Friction", "Damping is often not good enough to keep rounded objects from rolling down a sloped surface. Instead, you can set the rolling friction of a rigid body. Generally it is best to leave the rolling friction to zero, to avoid artifacts.", RollingFrictionCreateFunc),
|
||||
|
||||
ExampleEntry(1, "Constraints", "Show the use of the various constraints in Bullet. Press the L key to visualize the constraint limits. Press the C key to visualize the constraint frames.",
|
||||
AllConstraintCreateFunc),
|
||||
|
||||
ExampleEntry(1, "Motorized Hinge", "Use of a btHingeConstraint. You can adjust the first slider to change the target velocity, and the second slider to adjust the maximum impulse applied to reach the target velocity. Note that the hinge angle can reach beyond -360 and 360 degrees.", ConstraintCreateFunc),
|
||||
ExampleEntry(1, "TestHingeTorque", "Apply a torque in the hinge axis. This example uses a btHingeConstraint and btRigidBody. The setup is similar to the multi body example TestJointTorque.",
|
||||
TestHingeTorqueCreateFunc),
|
||||
// ExampleEntry(0,"What's new in 2.83"),
|
||||
|
||||
ExampleEntry(1, "6DofSpring2", "Show the use of the btGeneric6DofSpring2Constraint. This is a replacement of the btGeneric6DofSpringConstraint, it has various improvements. This includes improved spring implementation and better control over the restitution (bounce) when the constraint hits its limits.",
|
||||
Dof6Spring2CreateFunc),
|
||||
|
||||
ExampleEntry(1, "Motor Demo", "Dynamic control the target velocity of a motor of a btHingeConstraint. This demo makes use of the 'internal tick callback'. You can press W for wireframe, C and L to visualize constraint frame and limits.", MotorControlCreateFunc),
|
||||
|
||||
ExampleEntry(1, "Gyroscopic", "Show the Dzhanibekov effect using various settings of the gyroscopic term. You can select the gyroscopic term computation using btRigidBody::setFlags, with arguments BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT (using explicit integration, which adds energy and can lead to explosions), BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_WORLD, BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY. If you don't set any of these flags, there is no gyroscopic term used.", GyroscopicCreateFunc),
|
||||
|
||||
ExampleEntry(1, "Soft Contact", "Using the error correction parameter (ERP) and constraint force mixing (CFM) values for contacts to simulate compliant contact.", RigidBodySoftContactCreateFunc),
|
||||
ExampleEntry(1, "Kinematic Body", "Let the user set the transform, the physics engine computes the velocity for one-way contact and friction interaction.", KinematicRigidBodyExampleCreateFunc),
|
||||
|
||||
ExampleEntry(0, "MultiBody"),
|
||||
ExampleEntry(1, "MultiDof", "Create a basic btMultiBody with 3-DOF spherical joints (mobilizers). The demo uses a fixed base or a floating base at restart.", MultiDofCreateFunc),
|
||||
ExampleEntry(1, "TestJointTorque", "Apply a torque to a btMultiBody with 1-DOF joints (mobilizers). This setup is similar to API/TestHingeTorque.", TestJointTorqueCreateFunc),
|
||||
ExampleEntry(1, "TestPendulum", "Simulate a pendulum using btMultiBody with a constant joint torque applied. The same code is also used as a unit test comparing Bullet with the numerical solution of second-order non-linear differential equation stored in pendulum_gold.h", TestPendulumCreateFunc),
|
||||
|
||||
ExampleEntry(1, "Constraint Feedback", "The example shows how to receive joint reaction forces in a btMultiBody. Also the applied impulse is available for a btMultiBodyJointMotor", MultiBodyConstraintFeedbackCreateFunc),
|
||||
ExampleEntry(1, "Inverted Pendulum PD", "Keep an inverted pendulum up using open loop PD control", InvertedPendulumPDControlCreateFunc),
|
||||
ExampleEntry(1, "MultiBody Soft Contact", "Using the error correction parameter (ERP) and constraint force mixing (CFM) values for contacts to simulate compliant contact.", MultiBodySoftContactCreateFunc, 0),
|
||||
ExampleEntry(1, "Kinematic MultiBody", "Let the user set the transform, the physics engine computes the velocity for one-way contact and friction interaction.", KinematicMultiBodyExampleCreateFunc),
|
||||
|
||||
ExampleEntry(0, "Physics Client-Server"),
|
||||
ExampleEntry(1, "Physics Server", "Create a physics server that communicates with a physics client over shared memory. You can connect to the server using pybullet, a PhysicsClient or a UDP/TCP Bridge.",
|
||||
PhysicsServerCreateFuncBullet2),
|
||||
ExampleEntry(1, "Physics Client (Shared Mem)", "Create a physics client that can communicate with a physics server over shared memory.", PhysicsClientCreateFunc),
|
||||
|
||||
ExampleEntry(1, "Physics Server (Logging)", "Create a physics server that communicates with a physics client over shared memory. It will log all commands to a file.",
|
||||
PhysicsServerCreateFuncBullet2, PHYSICS_SERVER_ENABLE_COMMAND_LOGGING),
|
||||
ExampleEntry(1, "Physics Server (Replay Log)", "Create a physics server that replay a command log from disk.",
|
||||
PhysicsServerCreateFuncBullet2, PHYSICS_SERVER_REPLAY_FROM_COMMAND_LOG),
|
||||
ExampleEntry(1, "Graphics Server", "Create a graphics server.",GraphicsServerCreateFuncBullet),
|
||||
ExampleEntry(1, "Graphics Client", "Create a graphics client.", GraphicsClientCreateFunc),
|
||||
|
||||
//
|
||||
// ExampleEntry(1, "Physics Client (Direct)", "Create a physics client that can communicate with a physics server directly in-process.", PhysicsClientCreateFunc,eCLIENTEXAMPLE_DIRECT),
|
||||
|
||||
|
||||
ExampleEntry(0, "Inverse Dynamics"),
|
||||
ExampleEntry(1, "Inverse Dynamics URDF", "Create a btMultiBody from URDF. Create an inverse MultiBodyTree model from that. Use either decoupled PD control or computed torque control using the inverse model to track joint position targets", InverseDynamicsExampleCreateFunc, BT_ID_LOAD_URDF),
|
||||
ExampleEntry(1, "Inverse Dynamics Prog", "Create a btMultiBody programatically. Create an inverse MultiBodyTree model from that. Use either decoupled PD control or computed torque control using the inverse model to track joint position targets", InverseDynamicsExampleCreateFunc, BT_ID_PROGRAMMATICALLY),
|
||||
|
||||
ExampleEntry(0, "Inverse Kinematics"),
|
||||
ExampleEntry(1, "SDLS", "Selectively Damped Least Squares by Sam Buss. Example configures the IK tree of a Kuka IIWA", InverseKinematicsExampleCreateFunc, IK_SDLS),
|
||||
ExampleEntry(1, "DLS", "Damped Least Squares by Sam Buss. Example configures the IK tree of a Kuka IIWA", InverseKinematicsExampleCreateFunc, IK_DLS),
|
||||
ExampleEntry(1, "DLS-SVD", "Damped Least Squares with Singular Value Decomposition by Sam Buss. Example configures the IK tree of a Kuka IIWA", InverseKinematicsExampleCreateFunc, IK_DLS_SVD),
|
||||
|
||||
ExampleEntry(1, "Jacobi Transpose", "Jacobi Transpose by Sam Buss. Example configures the IK tree of a Kuka IIWA", InverseKinematicsExampleCreateFunc, IK_JACOB_TRANS),
|
||||
ExampleEntry(1, "Jacobi Pseudo Inv", "Jacobi Pseudo Inverse Method by Sam Buss. Example configures the IK tree of a Kuka IIWA", InverseKinematicsExampleCreateFunc, IK_PURE_PSEUDO),
|
||||
|
||||
ExampleEntry(0, "Tutorial"),
|
||||
ExampleEntry(1, "Constant Velocity", "Free moving rigid body, without external or constraint forces", TutorialCreateFunc, TUT_VELOCITY),
|
||||
ExampleEntry(1, "Gravity Acceleration", "Motion of a free falling rigid body under constant gravitational acceleration", TutorialCreateFunc, TUT_ACCELERATION),
|
||||
ExampleEntry(1, "Contact Computation", "Discrete Collision Detection for sphere-sphere", TutorialCreateFunc, TUT_COLLISION),
|
||||
ExampleEntry(1, "Solve Contact Constraint", "Compute and apply the impulses needed to satisfy non-penetrating contact constraints", TutorialCreateFunc, TUT_SOLVE_CONTACT_CONSTRAINT),
|
||||
ExampleEntry(1, "Spring constraint", "A rigid body with a spring constraint attached", Dof6ConstraintTutorialCreateFunc, 0),
|
||||
|
||||
ExampleEntry(0, "Collision"),
|
||||
ExampleEntry(1, "Spheres & Plane C-API (Bullet2)", "Collision C-API using Bullet 2.x backend", CollisionTutorialBullet2CreateFunc, TUT_SPHERE_PLANE_BULLET2),
|
||||
//ExampleEntry(1, "Spheres & Plane C-API (Bullet3)", "Collision C-API using Bullet 3.x backend", CollisionTutorialBullet2CreateFunc,TUT_SPHERE_PLANE_RTB3),
|
||||
|
||||
ExampleEntry(0, "Deformabe Body"),
|
||||
ExampleEntry(1, "Deformable Self Collision", "Deformable Self Collision", DeformableSelfCollisionCreateFunc),
|
||||
ExampleEntry(1, "Deformable-Deformable Contact", "Deformable contact", DeformableContactCreateFunc),
|
||||
ExampleEntry(1, "Cloth Friction", "Cloth friction contact", ClothFrictionCreateFunc),
|
||||
ExampleEntry(1, "Deformable-Deformable Friction Contact", "Deformable friction contact", PinchFrictionCreateFunc),
|
||||
ExampleEntry(1, "Deformable-RigidBody Contact", "Deformable test", DeformableRigidCreateFunc),
|
||||
ExampleEntry(1, "Split Impulse Contact", "Split impulse test", SplitImpulseCreateFunc),
|
||||
ExampleEntry(1, "Grasp Deformable Cube", "Grasping test", PinchCreateFunc),
|
||||
ExampleEntry(1, "Grasp Deformable with Motor", "Grasping test", GraspDeformableCreateFunc),
|
||||
ExampleEntry(1, "Volumetric Deformable Objects", "Volumetric Deformable test", VolumetricDeformableCreateFunc),
|
||||
ExampleEntry(1, "Extreme Deformation", "Recovery from extreme deformation", LargeDeformationCreateFunc),
|
||||
ExampleEntry(1, "Load Deformed", "Reconstruct a deformed object", LoadDeformedCreateFunc),
|
||||
ExampleEntry(1, "Colliding Test", "Volumetric deformable collide with rigid box", CollideCreateFunc),
|
||||
ExampleEntry(1, "Rigid Cloth Anchor", "Deformable Rigid body Anchor test", DeformableClothAnchorCreateFunc),
|
||||
ExampleEntry(1, "Multibody Cloth Anchor", "Deformable Multibody Anchor test", MultibodyClothAnchorCreateFunc),
|
||||
ExampleEntry(1, "Deformable-MultiBody Contact", "MultiBody and Deformable contact", DeformableMultibodyCreateFunc),
|
||||
// ExampleEntry(1, "MultiBody Baseline", "MultiBody Baseline", MultiBodyBaselineCreateFunc),
|
||||
|
||||
ExampleEntry(0, "Reduced Deformabe Body"),
|
||||
ExampleEntry(1, "Mode Visualizer", "Visualizer the modes for reduced deformable objects", ReducedModeVisualizerCreateFunc),
|
||||
ExampleEntry(1, "Reduced Conservation Test", "Momentum conservation test for the reduced deformable objects", ReducedConservationTestCreateFunc),
|
||||
ExampleEntry(1, "Reduced Springboard", "Moving rigid object colliding with a fixed reduced deformable objects", ReducedSpringboardCreateFunc),
|
||||
ExampleEntry(1, "Reduced Free Fall", "Free fall ground contact test for the reduced deformable model", ReducedFreeFallCreateFunc),
|
||||
ExampleEntry(1, "Reduced Collision Test", "Collision between a reduced block and the a rigid block", ReducedCollideCreateFunc),
|
||||
ExampleEntry(1, "Reduced Grasp", "Grasp a reduced deformable block", ReducedGraspCreateFunc),
|
||||
ExampleEntry(1, "Reduced Motor Grasp", "Grasp a reduced deformable block with motor", ReducedMotorGraspCreateFunc),
|
||||
ExampleEntry(1, "Reduced Friction Slope", "Grasp a reduced deformable block", FrictionSlopeCreateFunc),
|
||||
ExampleEntry(1, "Reduced Benchmark", "Reduced deformable performance benchmark example", ReducedBenchmarkCreateFunc),
|
||||
// ExampleEntry(1, "Simple Reduced Deformable Test", "Simple dynamics test for the reduced deformable objects", ReducedBasicTestCreateFunc),
|
||||
|
||||
#ifdef INCLUDE_CLOTH_DEMOS
|
||||
ExampleEntry(0, "Soft Body"),
|
||||
ExampleEntry(1, "Cloth", "Simulate a patch of cloth.", SoftDemoCreateFunc, 0),
|
||||
|
||||
ExampleEntry(1, "Pressure", "Simulate 3d soft body using a pressure constraint.", SoftDemoCreateFunc, 1),
|
||||
ExampleEntry(1, "Volume", "Simulate 3d soft body using a volume constraint.", SoftDemoCreateFunc, 2),
|
||||
ExampleEntry(1, "Ropes", "Simulate ropes", SoftDemoCreateFunc, 3),
|
||||
ExampleEntry(1, "Rope Attach", "Simulate a rigid body connected to a rope.", SoftDemoCreateFunc, 4),
|
||||
ExampleEntry(1, "Cloth Attach", "A rigid body attached to a cloth.", SoftDemoCreateFunc, 5),
|
||||
ExampleEntry(1, "Sticks", "Show simulation of ropes fixed to the ground.", SoftDemoCreateFunc, 6),
|
||||
ExampleEntry(1, "Capsule Collision", "Collision detection between a capsule shape and cloth.", SoftDemoCreateFunc, 7),
|
||||
|
||||
ExampleEntry(1, "Collide", "Soft body collision", SoftDemoCreateFunc, 8),
|
||||
ExampleEntry(1, "Collide 2", "Soft body collision", SoftDemoCreateFunc, 9),
|
||||
ExampleEntry(1, "Collide 3", "Soft body collision", SoftDemoCreateFunc, 10),
|
||||
ExampleEntry(1, "Impact", "Soft body impact", SoftDemoCreateFunc, 11),
|
||||
ExampleEntry(1, "Aero", "Rudimentary aero dynamics simulation", SoftDemoCreateFunc, 12),
|
||||
ExampleEntry(1, "Aero 2", "Rudimentary aero dynamics simulation", SoftDemoCreateFunc, 13),
|
||||
ExampleEntry(1, "Friction", "Simulate soft body friction with friction coefficients ranging from 0 to 1.", SoftDemoCreateFunc, 14),
|
||||
ExampleEntry(1, "Torus", "Simulate a soft body torus.", SoftDemoCreateFunc, 15),
|
||||
ExampleEntry(1, "Torus (Shape Match)", "Simulate a soft body torus using shape matching.", SoftDemoCreateFunc, 16),
|
||||
ExampleEntry(1, "Bunny", "Simulate the Stanford bunny as deformable object.", SoftDemoCreateFunc, 17),
|
||||
ExampleEntry(1, "Bunny (Shape Match)", "Simulate the Stanford bunny as deformable object including shape matching.", SoftDemoCreateFunc, 18),
|
||||
ExampleEntry(1, "Cutting", "Allow cutting of the soft body, by clicking on the cloth", SoftDemoCreateFunc, 19),
|
||||
ExampleEntry(1, "Cluster Deform", "Soft body collision detection using convex collision clusters.", SoftDemoCreateFunc, 20),
|
||||
ExampleEntry(1, "Cluster Collide1", "Collision detection between soft bodies using convex collision clusters.", SoftDemoCreateFunc, 21),
|
||||
ExampleEntry(1, "Cluster Collide2", "Collision detection between soft bodies using convex collision clusters.", SoftDemoCreateFunc, 22),
|
||||
ExampleEntry(1, "Cluster Socket", "Soft bodies connected by a point to point (ball-socket) constraints. This requires collision clusters, in order to define a frame of reference for the constraint.", SoftDemoCreateFunc, 23),
|
||||
ExampleEntry(1, "Cluster Hinge", "Soft bodies connected by a hinge constraints. This requires collision clusters, in order to define a frame of reference for the constraint.", SoftDemoCreateFunc, 24),
|
||||
ExampleEntry(1, "Cluster Combine", "Simulate soft bodies using collision clusters.", SoftDemoCreateFunc, 25),
|
||||
ExampleEntry(1, "Cluster Car", "Simulate the Stanford bunny by multiple soft bodies connected by constraints.", SoftDemoCreateFunc, 26),
|
||||
ExampleEntry(1, "Cluster Robot", "A rigid body base connected by soft body wheels, connected by constraints.", SoftDemoCreateFunc, 27),
|
||||
ExampleEntry(1, "Cluster Stack Soft", "Stacking of soft bodies.", SoftDemoCreateFunc, 28),
|
||||
ExampleEntry(1, "Cluster Stack Mixed", "Stacking of soft bodies and rigid bodies.", SoftDemoCreateFunc, 29),
|
||||
ExampleEntry(1, "Tetra Cube", "Simulate a volumetric soft body cube defined by tetrahedra.", SoftDemoCreateFunc, 30),
|
||||
ExampleEntry(1, "Tetra Bunny", "Simulate a volumetric soft body Stanford bunny defined by tetrahedra.", SoftDemoCreateFunc, 31),
|
||||
|
||||
#endif //INCLUDE_CLOTH_DEMOS
|
||||
|
||||
///we disable the benchmarks in debug mode, they are way too slow and benchmarking in debug mode is not recommended
|
||||
//#ifndef _DEBUG
|
||||
ExampleEntry(0, "Benchmarks"),
|
||||
ExampleEntry(1, "3000 boxes", "Benchmark a stack of 3000 boxes. It will stress the collision detection, a specialized box-box implementation based on the separating axis test, and the constraint solver. ", BenchmarkCreateFunc, 1),
|
||||
ExampleEntry(1, "1000 stack", "Benchmark a stack of 3000 boxes. It will stress the collision detection, a specialized box-box implementation based on the separating axis test, and the constraint solver. ",
|
||||
BenchmarkCreateFunc, 2),
|
||||
ExampleEntry(1, "Ragdolls", "Benchmark the performance of the ragdoll constraints, btHingeConstraint and btConeTwistConstraint, in addition to capsule collision detection.", BenchmarkCreateFunc, 3),
|
||||
ExampleEntry(1, "Convex stack", "Benchmark the performance and stability of rigid bodies using btConvexHullShape.", BenchmarkCreateFunc, 4),
|
||||
ExampleEntry(1, "Prim vs Mesh", "Benchmark the performance and stability of rigid bodies using primitive collision shapes (btSphereShape, btBoxShape), resting on a triangle mesh, btBvhTriangleMeshShape.", BenchmarkCreateFunc, 5),
|
||||
ExampleEntry(1, "Convex vs Mesh", "Benchmark the performance and stability of rigid bodies using convex hull collision shapes (btConvexHullShape), resting on a triangle mesh, btBvhTriangleMeshShape.", BenchmarkCreateFunc, 6),
|
||||
ExampleEntry(1, "Raycast", "Benchmark the performance of the btCollisionWorld::rayTest. Note that currently the rays are not rendered.", BenchmarkCreateFunc, 7),
|
||||
ExampleEntry(1, "Convex Pack", "Benchmark the performance of the convex hull primitive.", BenchmarkCreateFunc, 8),
|
||||
ExampleEntry(1, "Heightfield", "Raycast against a btHeightfieldTerrainShape", HeightfieldExampleCreateFunc),
|
||||
//#endif
|
||||
|
||||
ExampleEntry(0, "Importers"),
|
||||
ExampleEntry(1, "Import .bullet", "Load a binary .bullet file. The serialization mechanism can deal with versioning, differences in endianess, 32 and 64bit, double/single precision. It is easy to save a .bullet file, see the examples/Importers/ImportBullet/SerializeDemo.cpp for a code example how to export a .bullet file.", SerializeBulletCreateFunc),
|
||||
ExampleEntry(1, "Wavefront Obj", "Import a Wavefront .obj file", ImportObjCreateFunc, 0),
|
||||
ExampleEntry(1, "Obj2RigidBody (Show Obj)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body. We can use the original .obj mesh data to visualize the rigid body. In 'debug' wireframe mode (press 'w' to toggle) we still see the convex hull data.", ET_RigidBodyFromObjCreateFunc),
|
||||
ExampleEntry(1, "Obj2RigidBody (Show Hull)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body", ET_RigidBodyFromObjCreateFunc, ObjUseConvexHullForRendering),
|
||||
ExampleEntry(1, "Obj2RigidBody Optimize", "Load a triangle mesh from Wavefront .obj, remove the vertices that are not on the convex hull", ET_RigidBodyFromObjCreateFunc, OptimizeConvexObj),
|
||||
|
||||
ExampleEntry(1, "Quake BSP", "Import a Quake .bsp file", ImportBspCreateFunc, 0),
|
||||
ExampleEntry(1, "COLLADA dae", "Import the geometric mesh data from a COLLADA file. This is used as part of the URDF importer. This loader can also be used to import collision geometry in general. ",
|
||||
ImportColladaCreateFunc, 0),
|
||||
ExampleEntry(1, "STL", "Import the geometric mesh data from a STL file. This is used as part of the URDF importer. This loader can also be used to import collision geometry in general. ", ImportSTLCreateFunc, 0),
|
||||
ExampleEntry(1, "URDF (RigidBody)", "Import a URDF file, and create rigid bodies (btRigidBody) connected by constraints.", ImportURDFCreateFunc, 0),
|
||||
ExampleEntry(1, "URDF (MultiBody)", "Import a URDF file and create a single multibody (btMultiBody) with tree hierarchy of links (mobilizers).",
|
||||
ImportURDFCreateFunc, 1),
|
||||
ExampleEntry(1, "MJCF (MultiBody)", "Import a MJCF xml file, create multiple multibodies etc", ImportMJCFCreateFunc),
|
||||
|
||||
ExampleEntry(1, "SDF (MultiBody)", "Import an SDF file, create multiple multibodies etc", ImportSDFCreateFunc),
|
||||
|
||||
ExampleEntry(0, "Vehicles"),
|
||||
ExampleEntry(1, "Hinge2 Vehicle", "A rigid body chassis with 4 rigid body wheels attached by a btHinge2Constraint", Hinge2VehicleCreateFunc),
|
||||
ExampleEntry(1, "ForkLift",
|
||||
"Simulate a fork lift vehicle with a working fork lift that can be moved using the cursor keys. The wheels collision is simplified using ray tests."
|
||||
"There are currently some issues with the wheel rendering, the wheels rotate when picking up the object."
|
||||
"The demo implementation allows to choose various MLCP constraint solvers.",
|
||||
ForkLiftCreateFunc),
|
||||
|
||||
ExampleEntry(0, "Raycast"),
|
||||
ExampleEntry(1, "Raytest", "Cast rays using the btCollisionWorld::rayTest method. The example shows how to receive the hit position and normal along the ray against the first object. Also it shows how to receive all the hits along a ray.", RaytestCreateFunc),
|
||||
ExampleEntry(1, "Raytracer", "Implement an extremely simple ray tracer using the ray trace functionality in btCollisionWorld.",
|
||||
RayTracerCreateFunc),
|
||||
|
||||
ExampleEntry(0, "Experiments"),
|
||||
|
||||
ExampleEntry(1, "Robot Control", "Create a physics client and server to create and control robots.",
|
||||
PhysicsClientCreateFunc, eCLIENTEXAMPLE_SERVER),
|
||||
|
||||
ExampleEntry(1, "R2D2 Grasp", "Load the R2D2 robot from URDF file and control it to grasp objects", R2D2GraspExampleCreateFunc, eROBOTIC_LEARN_GRASP),
|
||||
ExampleEntry(1, "Kuka IK", "Control a Kuka IIWA robot to follow a target using IK. This IK is not setup properly yet.", KukaGraspExampleCreateFunc, 0),
|
||||
ExampleEntry(1, "URDF Compliant Contact", "Work-in-progress, experiment/improve compliant rigid contact using parameters from URDF file (contact_cfm, contact_erp, lateral_friction, rolling_friction)", R2D2GraspExampleCreateFunc, eROBOTIC_LEARN_COMPLIANT_CONTACT),
|
||||
ExampleEntry(1, "Rolling friction", "Experiment on multibody rolling friction", R2D2GraspExampleCreateFunc, eROBOTIC_LEARN_ROLLING_FRICTION),
|
||||
ExampleEntry(1, "Gripper Grasp", "Grasp experiment with a gripper to improve contact model", GripperGraspExampleCreateFunc, eGRIPPER_GRASP),
|
||||
ExampleEntry(1, "Two Point Grasp", "Grasp experiment with two point contact to test rolling friction", GripperGraspExampleCreateFunc, eTWO_POINT_GRASP),
|
||||
ExampleEntry(1, "Grasp Deformable Cloth", "Grasp experiment with deformable cloth", GripperGraspExampleCreateFunc, eGRASP_DEFORMABLE_CLOTH),
|
||||
ExampleEntry(1, "One Motor Gripper Grasp", "Grasp experiment with a gripper with one motor to test slider constraint for closed loop structure", GripperGraspExampleCreateFunc, eONE_MOTOR_GRASP),
|
||||
#ifndef SKIP_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD
|
||||
ExampleEntry(1, "Grasp Soft Body", "Grasp soft body experiment", GripperGraspExampleCreateFunc, eGRASP_SOFT_BODY),
|
||||
ExampleEntry(1, "Softbody Multibody Coupling", "Two way coupling between soft body and multibody experiment", GripperGraspExampleCreateFunc, eSOFTBODY_MULTIBODY_COUPLING),
|
||||
#endif //SKIP_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD
|
||||
|
||||
#ifdef ENABLE_LUA
|
||||
ExampleEntry(1, "Lua Script", "Create the dynamics world, collision shapes and rigid bodies using Lua scripting",
|
||||
LuaDemoCreateFunc),
|
||||
#endif
|
||||
ExampleEntry(1, "MultiThreading (submitJob)", "Simple example of executing jobs across multiple threads.",
|
||||
MultiThreadingExampleCreateFunc, SINGLE_SIM_THREAD),
|
||||
|
||||
ExampleEntry(1, "Voronoi Fracture", "Automatically create a compound rigid body using voronoi tesselation. Individual parts are modeled as rigid bodies using a btConvexHullShape.",
|
||||
VoronoiFractureCreateFunc),
|
||||
|
||||
ExampleEntry(1, "Fracture demo", "Create a basic custom implementation to model fracturing objects, based on a btCompoundShape. It explicitly propagates the collision impulses and breaks the rigid body into multiple rigid bodies. Press F to toggle fracture and glue mode.", FractureDemoCreateFunc),
|
||||
|
||||
ExampleEntry(1, "Planar 2D", "Show the use of 2D collision shapes and rigid body simulation. The collision shape is wrapped into a btConvex2dShape. The rigid bodies are restricted in a plane using the 'setAngularFactor' and 'setLinearFactor' API call.", Planar2DCreateFunc),
|
||||
#if BT_THREADSAFE
|
||||
// only enable MultiThreaded demo if a task scheduler is available
|
||||
ExampleEntry(1, "Multithreaded Demo",
|
||||
"Stacks of boxes that do not sleep. Good for testing performance with large numbers of bodies and contacts. Sliders can be used to change the number of stacks (restart needed after each change).",
|
||||
MultiThreadedDemoCreateFunc),
|
||||
#endif
|
||||
|
||||
ExampleEntry(0, "Rendering"),
|
||||
ExampleEntry(1, "Instanced Rendering", "Simple example of fast instanced rendering, only active when using OpenGL3+.", RenderInstancingCreateFunc),
|
||||
ExampleEntry(1, "CoordinateSystemDemo", "Show the axis and positive rotation direction around the axis.", CoordinateSystemCreateFunc),
|
||||
ExampleEntry(1, "Time Series", "Render some value(s) in a 2D graph window, shifting to the left", TimeSeriesCreateFunc),
|
||||
ExampleEntry(1, "TinyRenderer", "Very small software renderer.", TinyRendererCreateFunc),
|
||||
ExampleEntry(1, "Dynamic Texture", "Dynamic updated textured applied to a cube.", DynamicTexturedCubeDemoCreateFunc),
|
||||
|
||||
#ifdef B3_ENABLE_TINY_AUDIO
|
||||
ExampleEntry(0, "Audio"),
|
||||
ExampleEntry(1, "Simple Audio", "Play some sound", TinyAudioExampleCreateFunc),
|
||||
#endif
|
||||
|
||||
//Extended Tutorials Added by Mobeen
|
||||
ExampleEntry(0, "Extended Tutorials"),
|
||||
ExampleEntry(1, "Simple Box", "Simplest possible demo creating a single box rigid body that falls under gravity", ET_SimpleBoxCreateFunc),
|
||||
ExampleEntry(1, "Multiple Boxes", "Add multiple box rigid bodies that fall under gravity", ET_MultipleBoxesCreateFunc),
|
||||
ExampleEntry(1, "Compound Boxes", "Add multiple boxes to a single CompoundShape to form a simple rigid L-beam, that falls under gravity", ET_CompoundBoxesCreateFunc),
|
||||
ExampleEntry(1, "Simple Joint", "Create a single distance constraint between two box rigid bodies", ET_SimpleJointCreateFunc),
|
||||
ExampleEntry(1, "Simple Cloth", "Create a simple piece of cloth", ET_SimpleClothCreateFunc),
|
||||
ExampleEntry(1, "Simple Chain", "Create a simple chain using a pair of point2point/distance constraints. You may click and drag any box to see the chain respond.", ET_ChainCreateFunc),
|
||||
ExampleEntry(1, "Simple Bridge", "Create a simple bridge using a pair of point2point/distance constraints. You may click and drag any plank to see the bridge respond.", ET_BridgeCreateFunc),
|
||||
ExampleEntry(1, "Inclined Plane", "Create an inclined plane to show restitution and different types of friction. Use the sliders to vary restitution and friction and press space to reset the scene.", ET_InclinedPlaneCreateFunc),
|
||||
ExampleEntry(1, "Newton's Cradle", "Create a Newton's Cradle using a pair of point2point/slider constraints. Press 1/2 to lengthen/shorten the pendula, press 3 to displace pendula. Use the sliders to select the number (reset simulation), length and restitution of pendula, the number of displaced pendula and apply the displacement force.", ET_NewtonsCradleCreateFunc),
|
||||
ExampleEntry(1, "Newton's Rope Cradle", "Create a Newton's Cradle using ropes. Press 3 to displace pendula. Use the sliders to select the number (reset simulation), length and restitution of pendula and the number of displaced pendula and apply the displacement force.", ET_NewtonsRopeCradleCreateFunc),
|
||||
ExampleEntry(1, "Multi-Pendulum", "Create a Multi-Pendulum using point2point/slider constraints. Press 1/2 to lengthen/shorten the pendula, press 3 to displace pendula. Use the sliders to select the number (reset simulation), length and restitution of pendula, the number of displaced pendula and apply the displacement force.", ET_MultiPendulumCreateFunc),
|
||||
|
||||
ExampleEntry(9, "Evolution"),
|
||||
ExampleEntry(1, "Neural Network 3D Walkers", "A simple example of using evolution to make a creature walk.", ET_NN3DWalkersCreateFunc),
|
||||
|
||||
//todo: create a category/tutorial about advanced topics, such as optimizations, using different collision detection algorithm, different constraint solvers etc.
|
||||
//ExampleEntry(0,"Advanced"),
|
||||
//ExampleEntry(1,"Obj2RigidBody Add Features", "Load a triangle mesh from Wavefront .obj and create polyhedral features to perform the separating axis test (instead of GJK/MPR). It is best to combine optimization and polyhedral feature generation.", ET_RigidBodyFromObjCreateFunc,OptimizeConvexObj+ComputePolyhedralFeatures),
|
||||
|
||||
};
|
||||
|
||||
#ifdef B3_USE_CLEW
|
||||
#ifndef NO_OPENGL3
|
||||
static ExampleEntry gOpenCLExamples[] =
|
||||
{
|
||||
ExampleEntry(0, "OpenCL (experimental)"),
|
||||
ExampleEntry(1, "Box-Box", "Full OpenCL implementation of the entire physics and collision detection pipeline, showing box-box rigid body",
|
||||
OpenCLBoxBoxCreateFunc),
|
||||
ExampleEntry(1, "Pair Bench", "Benchmark of overlapping pair search using OpenCL.", PairBenchOpenCLCreateFunc),
|
||||
|
||||
};
|
||||
#endif
|
||||
#endif //
|
||||
static btAlignedObjectArray<ExampleEntry> gAdditionalRegisteredExamples;
|
||||
|
||||
struct ExampleEntriesInternalData
|
||||
{
|
||||
btAlignedObjectArray<ExampleEntry> m_allExamples;
|
||||
};
|
||||
|
||||
ExampleEntriesAll::ExampleEntriesAll()
|
||||
{
|
||||
m_data = new ExampleEntriesInternalData;
|
||||
}
|
||||
|
||||
ExampleEntriesAll::~ExampleEntriesAll()
|
||||
{
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
void ExampleEntriesAll::initOpenCLExampleEntries()
|
||||
{
|
||||
#ifdef B3_USE_CLEW
|
||||
#ifndef NO_OPENGL3
|
||||
int numDefaultEntries = sizeof(gOpenCLExamples) / sizeof(ExampleEntry);
|
||||
for (int i = 0; i < numDefaultEntries; i++)
|
||||
{
|
||||
m_data->m_allExamples.push_back(gOpenCLExamples[i]);
|
||||
}
|
||||
#endif
|
||||
#endif //B3_USE_CLEW
|
||||
}
|
||||
|
||||
void ExampleEntriesAll::initExampleEntries()
|
||||
{
|
||||
m_data->m_allExamples.clear();
|
||||
|
||||
for (int i = 0; i < gAdditionalRegisteredExamples.size(); i++)
|
||||
{
|
||||
m_data->m_allExamples.push_back(gAdditionalRegisteredExamples[i]);
|
||||
}
|
||||
|
||||
int numDefaultEntries = sizeof(gDefaultExamples) / sizeof(ExampleEntry);
|
||||
for (int i = 0; i < numDefaultEntries; i++)
|
||||
{
|
||||
m_data->m_allExamples.push_back(gDefaultExamples[i]);
|
||||
}
|
||||
|
||||
if (m_data->m_allExamples.size() == 0)
|
||||
{
|
||||
{
|
||||
ExampleEntry e(0, "Empty");
|
||||
m_data->m_allExamples.push_back(e);
|
||||
}
|
||||
|
||||
{
|
||||
ExampleEntry e(1, "Empty", "Empty Description", EmptyExample::CreateFunc);
|
||||
m_data->m_allExamples.push_back(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExampleEntriesAll::registerExampleEntry(int menuLevel, const char* name, const char* description, CommonExampleInterface::CreateFunc* createFunc, int option)
|
||||
{
|
||||
ExampleEntry e(menuLevel, name, description, createFunc, option);
|
||||
gAdditionalRegisteredExamples.push_back(e);
|
||||
}
|
||||
|
||||
int ExampleEntriesAll::getNumRegisteredExamples()
|
||||
{
|
||||
return m_data->m_allExamples.size();
|
||||
}
|
||||
|
||||
CommonExampleInterface::CreateFunc* ExampleEntriesAll::getExampleCreateFunc(int index)
|
||||
{
|
||||
return m_data->m_allExamples[index].m_createFunc;
|
||||
}
|
||||
|
||||
int ExampleEntriesAll::getExampleOption(int index)
|
||||
{
|
||||
return m_data->m_allExamples[index].m_option;
|
||||
}
|
||||
|
||||
const char* ExampleEntriesAll::getExampleName(int index)
|
||||
{
|
||||
return m_data->m_allExamples[index].m_name;
|
||||
}
|
||||
|
||||
const char* ExampleEntriesAll::getExampleDescription(int index)
|
||||
{
|
||||
return m_data->m_allExamples[index].m_description;
|
||||
}
|
||||
32
Engine/lib/bullet/examples/ExampleBrowser/ExampleEntries.h
Normal file
32
Engine/lib/bullet/examples/ExampleBrowser/ExampleEntries.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
#ifndef EXAMPLE_ENTRIES_H
|
||||
#define EXAMPLE_ENTRIES_H
|
||||
|
||||
#include "../CommonInterfaces/CommonExampleInterface.h"
|
||||
|
||||
class ExampleEntriesAll : public ExampleEntries
|
||||
{
|
||||
struct ExampleEntriesInternalData* m_data;
|
||||
|
||||
public:
|
||||
ExampleEntriesAll();
|
||||
virtual ~ExampleEntriesAll();
|
||||
|
||||
static void registerExampleEntry(int menuLevel, const char* name, const char* description, CommonExampleInterface::CreateFunc* createFunc, int option = 0);
|
||||
|
||||
virtual void initExampleEntries();
|
||||
|
||||
virtual void initOpenCLExampleEntries();
|
||||
|
||||
virtual int getNumRegisteredExamples();
|
||||
|
||||
virtual CommonExampleInterface::CreateFunc* getExampleCreateFunc(int index);
|
||||
|
||||
virtual const char* getExampleName(int index);
|
||||
|
||||
virtual const char* getExampleDescription(int index);
|
||||
|
||||
virtual int getExampleOption(int index);
|
||||
};
|
||||
|
||||
#endif //EXAMPLE_ENTRIES_H
|
||||
911
Engine/lib/bullet/examples/ExampleBrowser/GL_ShapeDrawer.cpp
Normal file
911
Engine/lib/bullet/examples/ExampleBrowser/GL_ShapeDrawer.cpp
Normal file
|
|
@ -0,0 +1,911 @@
|
|||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32 //needed for glut.h
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "../OpenGLWindow/OpenGL2Include.h"
|
||||
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btSphereShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btConeShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCylinderShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btUniformScalingShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
|
||||
#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "LinearMath/btDefaultMotionState.h"
|
||||
|
||||
///
|
||||
#include "BulletCollision/CollisionShapes/btShapeHull.h"
|
||||
|
||||
#include "LinearMath/btTransformUtil.h"
|
||||
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
//for debugmodes
|
||||
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#if defined(BT_USE_DOUBLE_PRECISION)
|
||||
#define btglLoadMatrix glLoadMatrixd
|
||||
#define btglMultMatrix glMultMatrixd
|
||||
#define btglColor3 glColor3d
|
||||
#define btglVertex3 glVertex3d
|
||||
#else
|
||||
#define btglLoadMatrix glLoadMatrixf
|
||||
#define btglMultMatrix glMultMatrixf
|
||||
#define btglColor3 glColor3f
|
||||
#define btglVertex3 glVertex3d
|
||||
#endif
|
||||
|
||||
void GL_ShapeDrawer::drawCoordSystem()
|
||||
{
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1, 0, 0);
|
||||
glVertex3d(0, 0, 0);
|
||||
glVertex3d(1, 0, 0);
|
||||
glColor3f(0, 1, 0);
|
||||
glVertex3d(0, 0, 0);
|
||||
glVertex3d(0, 1, 0);
|
||||
glColor3f(0, 0, 1);
|
||||
glVertex3d(0, 0, 0);
|
||||
glVertex3d(0, 0, 1);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
class GlDrawcallback : public btTriangleCallback
|
||||
{
|
||||
public:
|
||||
bool m_wireframe;
|
||||
|
||||
GlDrawcallback()
|
||||
: m_wireframe(false)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
|
||||
{
|
||||
(void)triangleIndex;
|
||||
(void)partId;
|
||||
|
||||
if (m_wireframe)
|
||||
{
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1, 0, 0);
|
||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||
glColor3f(0, 1, 0);
|
||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||
glColor3f(0, 0, 1);
|
||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
glBegin(GL_TRIANGLES);
|
||||
//glColor3f(1, 1, 1);
|
||||
|
||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||
|
||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class TriangleGlDrawcallback : public btInternalTriangleIndexCallback
|
||||
{
|
||||
public:
|
||||
virtual void internalProcessTriangleIndex(btVector3* triangle, int partId, int triangleIndex)
|
||||
{
|
||||
(void)triangleIndex;
|
||||
(void)partId;
|
||||
|
||||
glBegin(GL_TRIANGLES); //LINES);
|
||||
glColor3f(1, 0, 0);
|
||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||
glColor3f(0, 1, 0);
|
||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||
glColor3f(0, 0, 1);
|
||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||
glEnd();
|
||||
}
|
||||
};
|
||||
|
||||
void GL_ShapeDrawer::drawSphere(btScalar radius, int lats, int longs)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i <= lats; i++)
|
||||
{
|
||||
btScalar lat0 = SIMD_PI * (-btScalar(0.5) + (btScalar)(i - 1) / lats);
|
||||
btScalar z0 = radius * std::sin(lat0);
|
||||
btScalar zr0 = radius * std::cos(lat0);
|
||||
|
||||
btScalar lat1 = SIMD_PI * (-btScalar(0.5) + (btScalar)i / lats);
|
||||
btScalar z1 = radius * std::sin(lat1);
|
||||
btScalar zr1 = radius * std::cos(lat1);
|
||||
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (j = 0; j <= longs; j++)
|
||||
{
|
||||
btScalar lng = 2 * SIMD_PI * (btScalar)(j - 1) / longs;
|
||||
btScalar x = std::cos(lng);
|
||||
btScalar y = std::sin(lng);
|
||||
glNormal3f(x * zr1, y * zr1, z1);
|
||||
glVertex3f(x * zr1, y * zr1, z1);
|
||||
glNormal3f(x * zr0, y * zr0, z0);
|
||||
glVertex3f(x * zr0, y * zr0, z0);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
GL_ShapeDrawer::ShapeCache* GL_ShapeDrawer::cache(btConvexShape* shape)
|
||||
{
|
||||
ShapeCache* sc = (ShapeCache*)shape->getUserPointer();
|
||||
if (!sc)
|
||||
{
|
||||
sc = new (btAlignedAlloc(sizeof(ShapeCache), 16)) ShapeCache(shape);
|
||||
sc->m_shapehull.buildHull(shape->getMargin());
|
||||
m_shapecaches.push_back(sc);
|
||||
shape->setUserPointer(sc);
|
||||
/* Build edges */
|
||||
const int ni = sc->m_shapehull.numIndices();
|
||||
const int nv = sc->m_shapehull.numVertices();
|
||||
const unsigned int* pi = sc->m_shapehull.getIndexPointer();
|
||||
const btVector3* pv = sc->m_shapehull.getVertexPointer();
|
||||
btAlignedObjectArray<ShapeCache::Edge*> edges;
|
||||
sc->m_edges.reserve(ni);
|
||||
edges.resize(nv * nv, 0);
|
||||
for (int i = 0; i < ni; i += 3)
|
||||
{
|
||||
const unsigned int* ti = pi + i;
|
||||
const btVector3 nrm = btCross(pv[ti[1]] - pv[ti[0]], pv[ti[2]] - pv[ti[0]]).normalized();
|
||||
for (int j = 2, k = 0; k < 3; j = k++)
|
||||
{
|
||||
const unsigned int a = ti[j];
|
||||
const unsigned int b = ti[k];
|
||||
ShapeCache::Edge*& e = edges[btMin(a, b) * nv + btMax(a, b)];
|
||||
if (!e)
|
||||
{
|
||||
sc->m_edges.push_back(ShapeCache::Edge());
|
||||
e = &sc->m_edges[sc->m_edges.size() - 1];
|
||||
e->n[0] = nrm;
|
||||
e->n[1] = -nrm;
|
||||
e->v[0] = a;
|
||||
e->v[1] = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->n[1] = nrm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (sc);
|
||||
}
|
||||
|
||||
void renderSquareA(float x, float y, float z)
|
||||
{
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex3f(x, y, z);
|
||||
glVertex3f(x + 10.f, y, z);
|
||||
glVertex3f(x + 10.f, y + 10.f, z);
|
||||
glVertex3f(x, y + 10.f, z);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
inline void glDrawVector(const btVector3& v) { glVertex3d(v[0], v[1], v[2]); }
|
||||
|
||||
void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color, int debugMode, const btVector3& worldBoundsMin, const btVector3& worldBoundsMax)
|
||||
{
|
||||
if (shape->getShapeType() == CUSTOM_CONVEX_SHAPE_TYPE)
|
||||
{
|
||||
btVector3 org(m[12], m[13], m[14]);
|
||||
btVector3 dx(m[0], m[1], m[2]);
|
||||
btVector3 dy(m[4], m[5], m[6]);
|
||||
// btVector3 dz(m[8], m[9], m[10]);
|
||||
const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
|
||||
btVector3 halfExtent = boxShape->getHalfExtentsWithMargin();
|
||||
dx *= halfExtent[0];
|
||||
dy *= halfExtent[1];
|
||||
// dz *= halfExtent[2];
|
||||
glColor3f(1, 1, 1);
|
||||
glDisable(GL_LIGHTING);
|
||||
glLineWidth(2);
|
||||
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glDrawVector(org - dx - dy);
|
||||
glDrawVector(org - dx + dy);
|
||||
glDrawVector(org + dx + dy);
|
||||
glDrawVector(org + dx - dy);
|
||||
glEnd();
|
||||
return;
|
||||
}
|
||||
else if ((shape->getShapeType() == BOX_SHAPE_PROXYTYPE) && (debugMode & btIDebugDraw::DBG_FastWireframe))
|
||||
{
|
||||
btVector3 org(m[12], m[13], m[14]);
|
||||
btVector3 dx(m[0], m[1], m[2]);
|
||||
btVector3 dy(m[4], m[5], m[6]);
|
||||
btVector3 dz(m[8], m[9], m[10]);
|
||||
const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
|
||||
btVector3 halfExtent = boxShape->getHalfExtentsWithMargin();
|
||||
dx *= halfExtent[0];
|
||||
dy *= halfExtent[1];
|
||||
dz *= halfExtent[2];
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glDrawVector(org - dx - dy - dz);
|
||||
glDrawVector(org + dx - dy - dz);
|
||||
glDrawVector(org + dx + dy - dz);
|
||||
glDrawVector(org - dx + dy - dz);
|
||||
glDrawVector(org - dx + dy + dz);
|
||||
glDrawVector(org + dx + dy + dz);
|
||||
glDrawVector(org + dx - dy + dz);
|
||||
glDrawVector(org - dx - dy + dz);
|
||||
glEnd();
|
||||
glBegin(GL_LINES);
|
||||
glDrawVector(org + dx - dy - dz);
|
||||
glDrawVector(org + dx - dy + dz);
|
||||
glDrawVector(org + dx + dy - dz);
|
||||
glDrawVector(org + dx + dy + dz);
|
||||
glDrawVector(org - dx - dy - dz);
|
||||
glDrawVector(org - dx + dy - dz);
|
||||
glDrawVector(org - dx - dy + dz);
|
||||
glDrawVector(org - dx + dy + dz);
|
||||
glEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
btglMultMatrix(m);
|
||||
|
||||
if (shape->getShapeType() == UNIFORM_SCALING_SHAPE_PROXYTYPE)
|
||||
{
|
||||
const btUniformScalingShape* scalingShape = static_cast<const btUniformScalingShape*>(shape);
|
||||
const btConvexShape* convexShape = scalingShape->getChildShape();
|
||||
float scalingFactor = (float)scalingShape->getUniformScalingFactor();
|
||||
{
|
||||
btScalar tmpScaling[4][4] = {{scalingFactor, 0, 0, 0},
|
||||
{0, scalingFactor, 0, 0},
|
||||
{0, 0, scalingFactor, 0},
|
||||
{0, 0, 0, 1}};
|
||||
|
||||
drawOpenGL((btScalar*)tmpScaling, convexShape, color, debugMode, worldBoundsMin, worldBoundsMax);
|
||||
}
|
||||
glPopMatrix();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
|
||||
{
|
||||
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
|
||||
for (int i = compoundShape->getNumChildShapes() - 1; i >= 0; i--)
|
||||
{
|
||||
btTransform childTrans = compoundShape->getChildTransform(i);
|
||||
const btCollisionShape* colShape = compoundShape->getChildShape(i);
|
||||
ATTRIBUTE_ALIGNED16(btScalar)
|
||||
childMat[16];
|
||||
childTrans.getOpenGLMatrix(childMat);
|
||||
drawOpenGL(childMat, colShape, color, debugMode, worldBoundsMin, worldBoundsMax);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_textureenabled && (!m_textureinitialized))
|
||||
{
|
||||
GLubyte* image = new GLubyte[256 * 256 * 4];
|
||||
for (int y = 0; y < 256; ++y)
|
||||
{
|
||||
const int t = y >> 4;
|
||||
GLubyte* pi = image + y * 256 * 3;
|
||||
for (int x = 0; x < 256; ++x)
|
||||
{
|
||||
const int s = x >> 4;
|
||||
const GLubyte b = 180;
|
||||
GLubyte c = b + ((s + (t & 1)) & 1) * (255 - b);
|
||||
pi[0] = pi[1] = pi[2] = pi[3] = c;
|
||||
pi += 3;
|
||||
}
|
||||
}
|
||||
|
||||
glGenTextures(1, (GLuint*)&m_texturehandle);
|
||||
glBindTexture(GL_TEXTURE_2D, m_texturehandle);
|
||||
|
||||
glGenTextures(1, (GLuint*)&m_texturehandle);
|
||||
glBindTexture(GL_TEXTURE_2D, m_texturehandle);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
||||
//glGenerateMipmap(GL_TEXTURE_2D);
|
||||
delete[] image;
|
||||
}
|
||||
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glLoadIdentity();
|
||||
glScalef(0.025f, 0.025f, 0.025f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
static const GLfloat planex[] = {1, 0, 0, 0};
|
||||
// static const GLfloat planey[]={0,1,0,0};
|
||||
static const GLfloat planez[] = {0, 0, 1, 0};
|
||||
glTexGenfv(GL_S, GL_OBJECT_PLANE, planex);
|
||||
glTexGenfv(GL_T, GL_OBJECT_PLANE, planez);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
m_textureinitialized = true;
|
||||
|
||||
//drawCoordSystem();
|
||||
|
||||
//glPushMatrix();
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
if (m_textureenabled)
|
||||
{
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, m_texturehandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glColor3f(color.x(), color.y(), color.z());
|
||||
|
||||
//bool useWireframeFallback = true;
|
||||
|
||||
if (!(debugMode & btIDebugDraw::DBG_DrawWireframe))
|
||||
{
|
||||
///you can comment out any of the specific cases, and use the default
|
||||
|
||||
///the benefit of 'default' is that it approximates the actual collision shape including collision margin
|
||||
//int shapetype=m_textureenabled?MAX_BROADPHASE_COLLISION_TYPES:shape->getShapeType();
|
||||
int shapetype = shape->getShapeType();
|
||||
switch (shapetype)
|
||||
{
|
||||
case SPHERE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
|
||||
float radius = sphereShape->getMargin(); //radius doesn't include the margin, so draw with margin
|
||||
drawSphere(radius, 10, 10);
|
||||
//useWireframeFallback = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case BOX_SHAPE_PROXYTYPE:
|
||||
{
|
||||
const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
|
||||
btVector3 halfExtent = boxShape->getHalfExtentsWithMargin();
|
||||
|
||||
static int indices[36] = {
|
||||
0, 1, 2,
|
||||
3, 2, 1,
|
||||
4, 0, 6,
|
||||
6, 0, 2,
|
||||
5, 1, 4,
|
||||
4, 1, 0,
|
||||
7, 3, 1,
|
||||
7, 1, 5,
|
||||
5, 4, 7,
|
||||
7, 4, 6,
|
||||
7, 2, 3,
|
||||
7, 6, 2};
|
||||
|
||||
btVector3 vertices[8] = {
|
||||
btVector3(halfExtent[0], halfExtent[1], halfExtent[2]),
|
||||
btVector3(-halfExtent[0], halfExtent[1], halfExtent[2]),
|
||||
btVector3(halfExtent[0], -halfExtent[1], halfExtent[2]),
|
||||
btVector3(-halfExtent[0], -halfExtent[1], halfExtent[2]),
|
||||
btVector3(halfExtent[0], halfExtent[1], -halfExtent[2]),
|
||||
btVector3(-halfExtent[0], halfExtent[1], -halfExtent[2]),
|
||||
btVector3(halfExtent[0], -halfExtent[1], -halfExtent[2]),
|
||||
btVector3(-halfExtent[0], -halfExtent[1], -halfExtent[2])};
|
||||
#if 1
|
||||
glBegin(GL_TRIANGLES);
|
||||
int si = 36;
|
||||
for (int i = 0; i < si; i += 3)
|
||||
{
|
||||
const btVector3& v1 = vertices[indices[i]];
|
||||
;
|
||||
const btVector3& v2 = vertices[indices[i + 1]];
|
||||
const btVector3& v3 = vertices[indices[i + 2]];
|
||||
btVector3 normal = (v3 - v1).cross(v2 - v1);
|
||||
normal.normalize();
|
||||
glNormal3f(normal.getX(), normal.getY(), normal.getZ());
|
||||
glVertex3f(v1.x(), v1.y(), v1.z());
|
||||
glVertex3f(v2.x(), v2.y(), v2.z());
|
||||
glVertex3f(v3.x(), v3.y(), v3.z());
|
||||
}
|
||||
glEnd();
|
||||
#endif
|
||||
|
||||
//useWireframeFallback = false;
|
||||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
case CONE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
|
||||
int upIndex = coneShape->getConeUpIndex();
|
||||
float radius = coneShape->getRadius();//+coneShape->getMargin();
|
||||
float height = coneShape->getHeight();//+coneShape->getMargin();
|
||||
switch (upIndex)
|
||||
{
|
||||
case 0:
|
||||
glRotatef(90.0, 0.0, 1.0, 0.0);
|
||||
break;
|
||||
case 1:
|
||||
glRotatef(-90.0, 1.0, 0.0, 0.0);
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
glTranslatef(0.0, 0.0, -0.5*height);
|
||||
glutSolidCone(radius,height,10,10);
|
||||
//useWireframeFallback = false;
|
||||
break;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
case STATIC_PLANE_PROXYTYPE:
|
||||
{
|
||||
const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);
|
||||
btScalar planeConst = staticPlaneShape->getPlaneConstant();
|
||||
const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
|
||||
btVector3 planeOrigin = planeNormal * planeConst;
|
||||
btVector3 vec0, vec1;
|
||||
btPlaneSpace1(planeNormal, vec0, vec1);
|
||||
btScalar vecLen = 100.f;
|
||||
btVector3 pt0 = planeOrigin + vec0 * vecLen;
|
||||
btVector3 pt1 = planeOrigin - vec0 * vecLen;
|
||||
btVector3 pt2 = planeOrigin + vec1 * vecLen;
|
||||
btVector3 pt3 = planeOrigin - vec1 * vecLen;
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(pt0.getX(), pt0.getY(), pt0.getZ());
|
||||
glVertex3f(pt1.getX(), pt1.getY(), pt1.getZ());
|
||||
glVertex3f(pt2.getX(), pt2.getY(), pt2.getZ());
|
||||
glVertex3f(pt3.getX(), pt3.getY(), pt3.getZ());
|
||||
glEnd();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case MULTI_SPHERE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape);
|
||||
|
||||
btTransform childTransform;
|
||||
childTransform.setIdentity();
|
||||
|
||||
for (int i = multiSphereShape->getSphereCount() - 1; i >= 0; i--)
|
||||
{
|
||||
btSphereShape sc(multiSphereShape->getSphereRadius(i));
|
||||
childTransform.setOrigin(multiSphereShape->getSpherePosition(i));
|
||||
ATTRIBUTE_ALIGNED16(btScalar)
|
||||
childMat[16];
|
||||
childTransform.getOpenGLMatrix(childMat);
|
||||
drawOpenGL(childMat, &sc, color, debugMode, worldBoundsMin, worldBoundsMax);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if (shape->isConvex())
|
||||
{
|
||||
const btConvexPolyhedron* poly = shape->isPolyhedral() ? ((btPolyhedralConvexShape*)shape)->getConvexPolyhedron() : 0;
|
||||
if (poly)
|
||||
{
|
||||
int i;
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (i = 0; i < poly->m_faces.size(); i++)
|
||||
{
|
||||
btVector3 centroid(0, 0, 0);
|
||||
int numVerts = poly->m_faces[i].m_indices.size();
|
||||
if (numVerts > 2)
|
||||
{
|
||||
btVector3 v1 = poly->m_vertices[poly->m_faces[i].m_indices[0]];
|
||||
for (int v = 0; v < poly->m_faces[i].m_indices.size() - 2; v++)
|
||||
{
|
||||
btVector3 v2 = poly->m_vertices[poly->m_faces[i].m_indices[v + 1]];
|
||||
btVector3 v3 = poly->m_vertices[poly->m_faces[i].m_indices[v + 2]];
|
||||
btVector3 normal = (v3 - v1).cross(v2 - v1);
|
||||
normal.normalize();
|
||||
glNormal3f(normal.getX(), normal.getY(), normal.getZ());
|
||||
glVertex3f(v1.x(), v1.y(), v1.z());
|
||||
glVertex3f(v2.x(), v2.y(), v2.z());
|
||||
glVertex3f(v3.x(), v3.y(), v3.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShapeCache* sc = cache((btConvexShape*)shape);
|
||||
//glutSolidCube(1.0);
|
||||
btShapeHull* hull = &sc->m_shapehull /*(btShapeHull*)shape->getUserPointer()*/;
|
||||
|
||||
if (hull->numTriangles() > 0)
|
||||
{
|
||||
int index = 0;
|
||||
const unsigned int* idx = hull->getIndexPointer();
|
||||
const btVector3* vtx = hull->getVertexPointer();
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
for (int i = 0; i < hull->numTriangles(); i++)
|
||||
{
|
||||
int i1 = index++;
|
||||
int i2 = index++;
|
||||
int i3 = index++;
|
||||
btAssert(i1 < hull->numIndices() &&
|
||||
i2 < hull->numIndices() &&
|
||||
i3 < hull->numIndices());
|
||||
|
||||
int index1 = idx[i1];
|
||||
int index2 = idx[i2];
|
||||
int index3 = idx[i3];
|
||||
btAssert(index1 < hull->numVertices() &&
|
||||
index2 < hull->numVertices() &&
|
||||
index3 < hull->numVertices());
|
||||
|
||||
btVector3 v1 = vtx[index1];
|
||||
btVector3 v2 = vtx[index2];
|
||||
btVector3 v3 = vtx[index3];
|
||||
btVector3 normal = (v3 - v1).cross(v2 - v1);
|
||||
normal.normalize();
|
||||
glNormal3f(normal.getX(), normal.getY(), normal.getZ());
|
||||
glVertex3f(v1.x(), v1.y(), v1.z());
|
||||
glVertex3f(v2.x(), v2.y(), v2.z());
|
||||
glVertex3f(v3.x(), v3.y(), v3.z());
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glNormal3f(0, 1, 0);
|
||||
|
||||
/// for polyhedral shapes
|
||||
if (debugMode == btIDebugDraw::DBG_DrawFeaturesText && (shape->isPolyhedral()))
|
||||
{
|
||||
btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*)shape;
|
||||
|
||||
{
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
int i;
|
||||
for (i = 0; i < polyshape->getNumVertices(); i++)
|
||||
{
|
||||
btVector3 vtx;
|
||||
polyshape->getVertex(i, vtx);
|
||||
char buf[12];
|
||||
sprintf(buf, " %d", i);
|
||||
//btDrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
}
|
||||
|
||||
for (i = 0; i < polyshape->getNumPlanes(); i++)
|
||||
{
|
||||
btVector3 normal;
|
||||
btVector3 vtx;
|
||||
polyshape->getPlane(normal, vtx, i);
|
||||
//btScalar d = vtx.dot(normal);
|
||||
|
||||
//char buf[12];
|
||||
//sprintf(buf," plane %d",i);
|
||||
//btDrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
//
|
||||
void GL_ShapeDrawer::drawShadow(btScalar* m, const btVector3& extrusion, const btCollisionShape* shape, const btVector3& worldBoundsMin, const btVector3& worldBoundsMax)
|
||||
{
|
||||
glPushMatrix();
|
||||
btglMultMatrix(m);
|
||||
if (shape->getShapeType() == UNIFORM_SCALING_SHAPE_PROXYTYPE)
|
||||
{
|
||||
const btUniformScalingShape* scalingShape = static_cast<const btUniformScalingShape*>(shape);
|
||||
const btConvexShape* convexShape = scalingShape->getChildShape();
|
||||
float scalingFactor = (float)scalingShape->getUniformScalingFactor();
|
||||
btScalar tmpScaling[4][4] = {{scalingFactor, 0, 0, 0},
|
||||
{0, scalingFactor, 0, 0},
|
||||
{0, 0, scalingFactor, 0},
|
||||
{0, 0, 0, 1}};
|
||||
drawShadow((btScalar*)tmpScaling, extrusion, convexShape, worldBoundsMin, worldBoundsMax);
|
||||
glPopMatrix();
|
||||
return;
|
||||
}
|
||||
else if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
|
||||
{
|
||||
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
|
||||
for (int i = compoundShape->getNumChildShapes() - 1; i >= 0; i--)
|
||||
{
|
||||
btTransform childTrans = compoundShape->getChildTransform(i);
|
||||
const btCollisionShape* colShape = compoundShape->getChildShape(i);
|
||||
ATTRIBUTE_ALIGNED16(btScalar)
|
||||
childMat[16];
|
||||
childTrans.getOpenGLMatrix(childMat);
|
||||
drawShadow(childMat, extrusion * childTrans.getBasis(), colShape, worldBoundsMin, worldBoundsMax);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// bool useWireframeFallback = true;
|
||||
if (shape->isConvex())
|
||||
{
|
||||
ShapeCache* sc = cache((btConvexShape*)shape);
|
||||
btShapeHull* hull = &sc->m_shapehull;
|
||||
glBegin(GL_QUADS);
|
||||
for (int i = 0; i < sc->m_edges.size(); ++i)
|
||||
{
|
||||
const btScalar d = btDot(sc->m_edges[i].n[0], extrusion);
|
||||
if ((d * btDot(sc->m_edges[i].n[1], extrusion)) < 0)
|
||||
{
|
||||
const int q = d < 0 ? 1 : 0;
|
||||
const btVector3& a = hull->getVertexPointer()[sc->m_edges[i].v[q]];
|
||||
const btVector3& b = hull->getVertexPointer()[sc->m_edges[i].v[1 - q]];
|
||||
glVertex3f(a[0], a[1], a[2]);
|
||||
glVertex3f(b[0], b[1], b[2]);
|
||||
glVertex3f(b[0] + extrusion[0], b[1] + extrusion[1], b[2] + extrusion[2]);
|
||||
glVertex3f(a[0] + extrusion[0], a[1] + extrusion[1], a[2] + extrusion[2]);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
if (shape->isConcave()) //>getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
|
||||
// if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
|
||||
{
|
||||
btConcaveShape* concaveMesh = (btConcaveShape*)shape;
|
||||
|
||||
GlDrawcallback drawCallback;
|
||||
drawCallback.m_wireframe = false;
|
||||
|
||||
concaveMesh->processAllTriangles(&drawCallback, worldBoundsMin, worldBoundsMax);
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
//
|
||||
GL_ShapeDrawer::GL_ShapeDrawer()
|
||||
{
|
||||
m_texturehandle = 0;
|
||||
m_textureenabled = false;
|
||||
m_textureinitialized = false;
|
||||
}
|
||||
|
||||
GL_ShapeDrawer::~GL_ShapeDrawer()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < m_shapecaches.size(); i++)
|
||||
{
|
||||
m_shapecaches[i]->~ShapeCache();
|
||||
btAlignedFree(m_shapecaches[i]);
|
||||
}
|
||||
m_shapecaches.clear();
|
||||
if (m_textureinitialized)
|
||||
{
|
||||
glDeleteTextures(1, (const GLuint*)&m_texturehandle);
|
||||
}
|
||||
}
|
||||
|
||||
void GL_ShapeDrawer::drawSceneInternal(const btDiscreteDynamicsWorld* dynamicsWorld, int pass, int cameraUpAxis)
|
||||
{
|
||||
btAssert(dynamicsWorld);
|
||||
|
||||
btScalar m[16];
|
||||
btMatrix3x3 rot;
|
||||
rot.setIdentity();
|
||||
const int numObjects = dynamicsWorld->getNumCollisionObjects();
|
||||
btVector3 wireColor(1, 0, 0);
|
||||
//glDisable(GL_CULL_FACE);
|
||||
|
||||
for (int i = 0; i < numObjects; i++)
|
||||
{
|
||||
const btCollisionObject* colObj = dynamicsWorld->getCollisionObjectArray()[i];
|
||||
const btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
|
||||
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);
|
||||
rot = myMotionState->m_graphicsWorldTrans.getBasis();
|
||||
}
|
||||
else
|
||||
{
|
||||
colObj->getWorldTransform().getOpenGLMatrix(m);
|
||||
rot = colObj->getWorldTransform().getBasis();
|
||||
}
|
||||
btVector3 wireColor(1.f, 1.0f, 0.5f); //wants deactivation
|
||||
if (i & 1) wireColor = btVector3(0.f, 0.0f, 1.f);
|
||||
///color differently for active, sleeping, wantsdeactivation states
|
||||
if (colObj->getActivationState() == 1) //active
|
||||
{
|
||||
if (i & 1)
|
||||
{
|
||||
wireColor += btVector3(1.f, 0.f, 0.f);
|
||||
}
|
||||
else
|
||||
{
|
||||
wireColor += btVector3(.5f, 0.f, 0.f);
|
||||
}
|
||||
}
|
||||
if (colObj->getActivationState() == 2) //ISLAND_SLEEPING
|
||||
{
|
||||
if (i & 1)
|
||||
{
|
||||
wireColor += btVector3(0.f, 1.f, 0.f);
|
||||
}
|
||||
else
|
||||
{
|
||||
wireColor += btVector3(0.f, 0.5f, 0.f);
|
||||
}
|
||||
}
|
||||
|
||||
btVector3 aabbMin(0, 0, 0), aabbMax(0, 0, 0);
|
||||
//m_dynamicsWorld->getBroadphase()->getBroadphaseAabb(aabbMin,aabbMax);
|
||||
|
||||
aabbMin -= btVector3(BT_LARGE_FLOAT, BT_LARGE_FLOAT, BT_LARGE_FLOAT);
|
||||
aabbMax += btVector3(BT_LARGE_FLOAT, BT_LARGE_FLOAT, BT_LARGE_FLOAT);
|
||||
// printf("aabbMin=(%f,%f,%f)\n",aabbMin.getX(),aabbMin.getY(),aabbMin.getZ());
|
||||
// printf("aabbMax=(%f,%f,%f)\n",aabbMax.getX(),aabbMax.getY(),aabbMax.getZ());
|
||||
// m_dynamicsWorld->getDebugDrawer()->drawAabb(aabbMin,aabbMax,btVector3(1,1,1));
|
||||
|
||||
//switch(pass)
|
||||
|
||||
//if (!(getDebugMode()& btIDebugDraw::DBG_DrawWireframe))
|
||||
int debugMode = 0; //getDebugMode()
|
||||
//btVector3 m_sundirection(-1,-1,-1);
|
||||
|
||||
btVector3 m_sundirection(btVector3(1, -2, 1) * 1000);
|
||||
if (cameraUpAxis == 2)
|
||||
{
|
||||
m_sundirection = btVector3(1, 1, -2) * 1000;
|
||||
}
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 0:
|
||||
drawOpenGL(m, colObj->getCollisionShape(), wireColor, debugMode, aabbMin, aabbMax);
|
||||
break;
|
||||
case 1:
|
||||
drawShadow(m, m_sundirection * rot, colObj->getCollisionShape(), aabbMin, aabbMax);
|
||||
break;
|
||||
case 2:
|
||||
drawOpenGL(m, colObj->getCollisionShape(), wireColor * btScalar(0.3), 0, aabbMin, aabbMax);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//this GL_ShapeDrawer will be removed, in the meanwhile directly access this global 'useShadoMaps'
|
||||
extern bool useShadowMap;
|
||||
void GL_ShapeDrawer::drawScene(const btDiscreteDynamicsWorld* dynamicsWorld, bool useShadows1, int cameraUpAxis)
|
||||
{
|
||||
bool useShadows = useShadowMap;
|
||||
GLfloat light_ambient[] = {btScalar(0.2), btScalar(0.2), btScalar(0.2), btScalar(1.0)};
|
||||
GLfloat light_diffuse[] = {btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0)};
|
||||
GLfloat light_specular[] = {btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0)};
|
||||
/* light_position is NOT default value */
|
||||
GLfloat light_position0[] = {btScalar(1.0), btScalar(10.0), btScalar(1.0), btScalar(0.0)};
|
||||
GLfloat light_position1[] = {btScalar(-1.0), btScalar(-10.0), btScalar(-1.0), btScalar(0.0)};
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHT1);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
glClearColor(btScalar(0.7), btScalar(0.7), btScalar(0.7), btScalar(0));
|
||||
|
||||
if (useShadows)
|
||||
{
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
glEnable(GL_CULL_FACE);
|
||||
drawSceneInternal(dynamicsWorld, 0, cameraUpAxis);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFFL);
|
||||
glFrontFace(GL_CCW);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
||||
drawSceneInternal(dynamicsWorld, 1, cameraUpAxis);
|
||||
glFrontFace(GL_CW);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
|
||||
drawSceneInternal(dynamicsWorld, 1, cameraUpAxis);
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
glPolygonMode(GL_FRONT, GL_FILL);
|
||||
glPolygonMode(GL_BACK, GL_FILL);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glEnable(GL_LIGHTING);
|
||||
glDepthMask(GL_TRUE);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CCW);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glStencilFunc(GL_NOTEQUAL, 0, 0xFFFFFFFFL);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
glDisable(GL_LIGHTING);
|
||||
drawSceneInternal(dynamicsWorld, 2, cameraUpAxis);
|
||||
glEnable(GL_LIGHTING);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
drawSceneInternal(dynamicsWorld, 0, cameraUpAxis);
|
||||
}
|
||||
}
|
||||
81
Engine/lib/bullet/examples/ExampleBrowser/GL_ShapeDrawer.h
Normal file
81
Engine/lib/bullet/examples/ExampleBrowser/GL_ShapeDrawer.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef GL_SHAPE_DRAWER_H
|
||||
#define GL_SHAPE_DRAWER_H
|
||||
|
||||
class btCollisionShape;
|
||||
class btShapeHull;
|
||||
class btDiscreteDynamicsWorld;
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btShapeHull.h"
|
||||
|
||||
/// OpenGL shape drawing
|
||||
class GL_ShapeDrawer
|
||||
{
|
||||
protected:
|
||||
struct ShapeCache
|
||||
{
|
||||
struct Edge
|
||||
{
|
||||
btVector3 n[2];
|
||||
int v[2];
|
||||
};
|
||||
ShapeCache(btConvexShape* s) : m_shapehull(s) {}
|
||||
btShapeHull m_shapehull;
|
||||
btAlignedObjectArray<Edge> m_edges;
|
||||
};
|
||||
//clean-up memory of dynamically created shape hulls
|
||||
btAlignedObjectArray<ShapeCache*> m_shapecaches;
|
||||
unsigned int m_texturehandle;
|
||||
bool m_textureenabled;
|
||||
bool m_textureinitialized;
|
||||
|
||||
ShapeCache* cache(btConvexShape*);
|
||||
|
||||
virtual void drawSceneInternal(const btDiscreteDynamicsWorld* world, int pass, int cameraUpAxis);
|
||||
|
||||
public:
|
||||
GL_ShapeDrawer();
|
||||
|
||||
virtual ~GL_ShapeDrawer();
|
||||
|
||||
virtual void drawScene(const btDiscreteDynamicsWorld* world, bool useShadows, int cameraUpAxis);
|
||||
|
||||
///drawOpenGL might allocate temporary memoty, stores pointer in shape userpointer
|
||||
virtual void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color, int debugMode, const btVector3& worldBoundsMin, const btVector3& worldBoundsMax);
|
||||
virtual void drawShadow(btScalar* m, const btVector3& extrusion, const btCollisionShape* shape, const btVector3& worldBoundsMin, const btVector3& worldBoundsMax);
|
||||
|
||||
bool enableTexture(bool enable)
|
||||
{
|
||||
bool p = m_textureenabled;
|
||||
m_textureenabled = enable;
|
||||
return (p);
|
||||
}
|
||||
bool hasTextureEnabled() const
|
||||
{
|
||||
return m_textureenabled;
|
||||
}
|
||||
|
||||
void drawSphere(btScalar r, int lats, int longs);
|
||||
static void drawCoordSystem();
|
||||
};
|
||||
|
||||
void OGL_displaylist_register_shape(btCollisionShape* shape);
|
||||
void OGL_displaylist_clean();
|
||||
|
||||
#endif //GL_SHAPE_DRAWER_H
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
#include "GraphingTexture.h"
|
||||
#include "../OpenGLWindow/OpenGLInclude.h"
|
||||
#include <assert.h>
|
||||
|
||||
GraphingTexture::GraphingTexture()
|
||||
: m_textureId(0),
|
||||
m_width(0),
|
||||
m_height(0)
|
||||
{
|
||||
}
|
||||
|
||||
GraphingTexture::~GraphingTexture()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void GraphingTexture::destroy()
|
||||
{
|
||||
//TODO(erwincoumans) release memory etc...
|
||||
m_width = 0;
|
||||
m_height = 0;
|
||||
glDeleteTextures(1, (GLuint*)&m_textureId);
|
||||
m_textureId = 0;
|
||||
}
|
||||
|
||||
bool GraphingTexture::create(int texWidth, int texHeight)
|
||||
{
|
||||
m_width = texWidth;
|
||||
m_height = texHeight;
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
m_imageData.resize(texWidth * texHeight * 4);
|
||||
for (int y = 0; y < texHeight; ++y)
|
||||
{
|
||||
// const int t=y>>5;
|
||||
GLubyte* pi = &m_imageData[y * texWidth * 4];
|
||||
for (int x = 0; x < texWidth; ++x)
|
||||
{
|
||||
if (x >= y) //x<2||y<2||x>253||y>253)
|
||||
{
|
||||
pi[0] = 0;
|
||||
pi[1] = 0;
|
||||
pi[2] = 255;
|
||||
pi[3] = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
pi[0] = 255;
|
||||
pi[1] = 0;
|
||||
pi[2] = 0;
|
||||
pi[3] = 255;
|
||||
}
|
||||
|
||||
pi += 4;
|
||||
}
|
||||
}
|
||||
|
||||
glGenTextures(1, (GLuint*)&m_textureId);
|
||||
|
||||
uploadImageData();
|
||||
return true;
|
||||
}
|
||||
|
||||
void GraphingTexture::uploadImageData()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||
assert(glGetError() == GL_NO_ERROR);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &m_imageData[0]);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
assert(glGetError() == GL_NO_ERROR);
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef GRAPHING_TEXTURE_H
|
||||
#define GRAPHING_TEXTURE_H
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
struct GraphingTexture
|
||||
{
|
||||
int m_textureId;
|
||||
//assume rgba (8 bit per component, total of 32bit per pixel, for m_width*m_height pixels)
|
||||
btAlignedObjectArray<unsigned char> m_imageData;
|
||||
int m_width;
|
||||
int m_height;
|
||||
|
||||
GraphingTexture();
|
||||
virtual ~GraphingTexture();
|
||||
|
||||
bool create(int texWidth, int texHeight);
|
||||
void destroy();
|
||||
|
||||
void setPixel(int x, int y, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
|
||||
{
|
||||
if (y >= 0 && y < m_height && x >= 0 && x < m_width)
|
||||
{
|
||||
m_imageData[x * 4 + y * 4 * m_width + 0] = red;
|
||||
m_imageData[x * 4 + y * 4 * m_width + 1] = green;
|
||||
m_imageData[x * 4 + y * 4 * m_width + 2] = blue;
|
||||
m_imageData[x * 4 + y * 4 * m_width + 3] = alpha;
|
||||
}
|
||||
}
|
||||
|
||||
void getPixel(int x, int y, unsigned char& red, unsigned char& green, unsigned char& blue, unsigned char& alpha)
|
||||
{
|
||||
red = m_imageData[x * 4 + y * 4 * m_width + 0];
|
||||
green = m_imageData[x * 4 + y * 4 * m_width + 1];
|
||||
blue = m_imageData[x * 4 + y * 4 * m_width + 2];
|
||||
alpha = m_imageData[x * 4 + y * 4 * m_width + 3];
|
||||
}
|
||||
void uploadImageData();
|
||||
|
||||
int getTextureId()
|
||||
{
|
||||
return m_textureId;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //GRAPHING_TEXTURE_H
|
||||
|
|
@ -0,0 +1,304 @@
|
|||
#include "GwenParameterInterface.h"
|
||||
#include "gwenInternalData.h"
|
||||
#include <cstring>
|
||||
#ifdef _WIN32
|
||||
#define safe_printf _snprintf
|
||||
#else
|
||||
#define safe_printf snprintf
|
||||
#endif
|
||||
struct MyButtonEventHandler : public Gwen::Event::Handler
|
||||
{
|
||||
Gwen::Controls::Button* m_buttonControl;
|
||||
ButtonParamChangedCallback m_callback;
|
||||
void* m_userPointer;
|
||||
int m_buttonId;
|
||||
|
||||
MyButtonEventHandler(Gwen::Controls::Button* buttonControl, ButtonParamChangedCallback callback, int buttonId, void* userPointer)
|
||||
: m_buttonControl(buttonControl),
|
||||
m_callback(callback),
|
||||
m_userPointer(userPointer),
|
||||
m_buttonId(buttonId)
|
||||
{
|
||||
}
|
||||
|
||||
void onButtonPress(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
if (m_callback)
|
||||
{
|
||||
bool buttonState = true;
|
||||
if (m_buttonControl->IsToggle())
|
||||
{
|
||||
buttonState = m_buttonControl->GetToggleState();
|
||||
}
|
||||
(*m_callback)(m_buttonId, buttonState, m_userPointer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct MySliderEventHandler : public Gwen::Event::Handler
|
||||
{
|
||||
SliderParamChangedCallback m_callback;
|
||||
void* m_userPointer;
|
||||
Gwen::Controls::TextBox* m_label;
|
||||
Gwen::Controls::Slider* m_pSlider;
|
||||
char m_variableName[1024];
|
||||
T* m_targetValue;
|
||||
bool m_showValue;
|
||||
|
||||
MySliderEventHandler(const char* varName, Gwen::Controls::TextBox* label, Gwen::Controls::Slider* pSlider, T* target, SliderParamChangedCallback callback, void* userPtr)
|
||||
: m_callback(callback),
|
||||
m_userPointer(userPtr),
|
||||
m_label(label),
|
||||
m_pSlider(pSlider),
|
||||
m_targetValue(target),
|
||||
m_showValue(true)
|
||||
|
||||
{
|
||||
strncpy(m_variableName, varName, sizeof(m_variableName));
|
||||
}
|
||||
|
||||
void SliderMoved(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
|
||||
//printf("value = %f\n", pSlider->GetValue());//UnitPrint( Utility::Format( L"Slider Value: %.2f", pSlider->GetValue() ) );
|
||||
float bla = pSlider->GetValue();
|
||||
T v = T(bla);
|
||||
SetValue(v);
|
||||
|
||||
if (m_callback)
|
||||
{
|
||||
(*m_callback)(v, m_userPointer);
|
||||
}
|
||||
}
|
||||
|
||||
void SetValue(T v)
|
||||
{
|
||||
if (v < m_pSlider->GetRangeMin())
|
||||
{
|
||||
printf("?\n");
|
||||
}
|
||||
|
||||
if (v > m_pSlider->GetRangeMax())
|
||||
{
|
||||
printf("?\n");
|
||||
}
|
||||
m_pSlider->SetValue(v, true);
|
||||
(*m_targetValue) = v;
|
||||
float val = float(v); //todo: specialize on template type
|
||||
if (m_showValue)
|
||||
{
|
||||
char txt[1024];
|
||||
safe_printf(txt, sizeof(txt), "%s : %.3f", m_variableName, val);
|
||||
m_label->SetText(txt);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct GwenParameters
|
||||
{
|
||||
b3AlignedObjectArray<MySliderEventHandler<btScalar>*> m_sliderEventHandlers;
|
||||
b3AlignedObjectArray<Gwen::Controls::HorizontalSlider*> m_sliders;
|
||||
b3AlignedObjectArray<Gwen::Controls::ComboBox*> m_comboBoxes;
|
||||
b3AlignedObjectArray<Gwen::Controls::Button*> m_buttons;
|
||||
b3AlignedObjectArray<MyButtonEventHandler*> m_buttonEventHandlers;
|
||||
b3AlignedObjectArray<Gwen::Controls::TextBox*> m_textLabels;
|
||||
int m_savedYposition;
|
||||
};
|
||||
|
||||
GwenParameterInterface::GwenParameterInterface(GwenInternalData* gwenInternalData)
|
||||
: m_gwenInternalData(gwenInternalData)
|
||||
{
|
||||
m_paramInternalData = new GwenParameters;
|
||||
m_paramInternalData->m_savedYposition = m_gwenInternalData->m_curYposition;
|
||||
}
|
||||
|
||||
GwenParameterInterface::~GwenParameterInterface()
|
||||
{
|
||||
removeAllParameters();
|
||||
delete m_paramInternalData;
|
||||
}
|
||||
|
||||
void GwenParameterInterface::setSliderValue(int sliderIndex, double sliderValue)
|
||||
{
|
||||
int sliderCapped = sliderValue + 4;
|
||||
sliderCapped /= 8;
|
||||
sliderCapped *= 8;
|
||||
|
||||
if (sliderIndex >= 0 && sliderIndex < m_paramInternalData->m_sliders.size())
|
||||
{
|
||||
m_paramInternalData->m_sliders[sliderIndex]->GetRangeMin();
|
||||
|
||||
m_paramInternalData->m_sliders[sliderIndex]->GetRangeMax();
|
||||
float mappedValue = m_paramInternalData->m_sliders[sliderIndex]->GetRangeMin() +
|
||||
(m_paramInternalData->m_sliders[sliderIndex]->GetRangeMax() -
|
||||
m_paramInternalData->m_sliders[sliderIndex]->GetRangeMin()) *
|
||||
sliderCapped / 128.f;
|
||||
printf("mappedValue = %f\n", mappedValue);
|
||||
m_paramInternalData->m_sliders[sliderIndex]->SetValue(mappedValue);
|
||||
}
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void GwenParameterInterface::registerButtonParameter(ButtonParams& params)
|
||||
{
|
||||
Gwen::Controls::Button* button = new Gwen::Controls::Button(m_gwenInternalData->m_demoPage->GetPage());
|
||||
MyButtonEventHandler* handler = new MyButtonEventHandler(button, params.m_callback, params.m_buttonId, params.m_userPointer);
|
||||
button->SetText(params.m_name);
|
||||
button->onPress.Add(handler, &MyButtonEventHandler::onButtonPress);
|
||||
button->SetIsToggle(params.m_isTrigger);
|
||||
button->SetToggleState(params.m_initialState);
|
||||
|
||||
m_paramInternalData->m_buttons.push_back(button);
|
||||
m_paramInternalData->m_buttonEventHandlers.push_back(handler);
|
||||
|
||||
button->SetPos(5, m_gwenInternalData->m_curYposition);
|
||||
button->SetWidth(220);
|
||||
|
||||
m_gwenInternalData->m_curYposition += 22;
|
||||
}
|
||||
|
||||
struct MyComboBoxHander2 : public Gwen::Event::Handler
|
||||
{
|
||||
GwenInternalData* m_data;
|
||||
int m_buttonId;
|
||||
ComboBoxCallback m_callback;
|
||||
void* m_userPointer;
|
||||
|
||||
MyComboBoxHander2(GwenInternalData* data, int buttonId, ComboBoxCallback callback, void* userPointer)
|
||||
: m_data(data),
|
||||
m_buttonId(buttonId),
|
||||
m_callback(callback),
|
||||
m_userPointer(userPointer)
|
||||
{
|
||||
}
|
||||
|
||||
void onSelect(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
Gwen::Controls::ComboBox* but = (Gwen::Controls::ComboBox*)pControl;
|
||||
|
||||
Gwen::String str = Gwen::Utility::UnicodeToString(but->GetSelectedItem()->GetText());
|
||||
|
||||
if (m_callback)
|
||||
(*m_callback)(m_buttonId, str.c_str(), m_userPointer);
|
||||
}
|
||||
};
|
||||
|
||||
void GwenParameterInterface::registerComboBox(ComboBoxParams& params)
|
||||
{
|
||||
Gwen::Controls::ComboBox* combobox = new Gwen::Controls::ComboBox(m_gwenInternalData->m_demoPage->GetPage());
|
||||
m_paramInternalData->m_comboBoxes.push_back(combobox);
|
||||
MyComboBoxHander2* handler = new MyComboBoxHander2(m_gwenInternalData, params.m_comboboxId, params.m_callback, params.m_userPointer);
|
||||
m_gwenInternalData->m_handlers.push_back(handler);
|
||||
|
||||
combobox->onSelection.Add(handler, &MyComboBoxHander2::onSelect);
|
||||
int ypos = m_gwenInternalData->m_curYposition;
|
||||
m_gwenInternalData->m_curYposition += 22;
|
||||
combobox->SetPos(5, ypos);
|
||||
combobox->SetWidth(220);
|
||||
//box->SetPos(120,130);
|
||||
for (int i = 0; i < params.m_numItems; i++)
|
||||
{
|
||||
Gwen::Controls::MenuItem* item = combobox->AddItem(Gwen::Utility::StringToUnicode(params.m_items[i]));
|
||||
if (i == params.m_startItem)
|
||||
combobox->OnItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
void GwenParameterInterface::registerSliderFloatParameter(SliderParams& params)
|
||||
{
|
||||
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox(m_gwenInternalData->m_demoPage->GetPage());
|
||||
m_paramInternalData->m_textLabels.push_back(label);
|
||||
//m_data->m_myControls.push_back(label);
|
||||
label->SetText(params.m_name);
|
||||
label->SetPos(10, 10 + 25);
|
||||
label->SetWidth(210);
|
||||
label->SetPos(10, m_gwenInternalData->m_curYposition);
|
||||
m_gwenInternalData->m_curYposition += 22;
|
||||
|
||||
Gwen::Controls::HorizontalSlider* pSlider = new Gwen::Controls::HorizontalSlider(m_gwenInternalData->m_demoPage->GetPage());
|
||||
m_paramInternalData->m_sliders.push_back(pSlider);
|
||||
//m_data->m_myControls.push_back(pSlider);
|
||||
pSlider->SetPos(10, m_gwenInternalData->m_curYposition);
|
||||
pSlider->SetSize(200, 20);
|
||||
pSlider->SetRange(params.m_minVal, params.m_maxVal);
|
||||
if (params.m_clampToIntegers)
|
||||
{
|
||||
pSlider->SetNotchCount(int(params.m_maxVal - params.m_minVal));
|
||||
pSlider->SetClampToNotches(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
pSlider->SetNotchCount(16); //float(params.m_maxVal-params.m_minVal)/100.f);
|
||||
pSlider->SetClampToNotches(params.m_clampToNotches);
|
||||
}
|
||||
pSlider->SetValue(*params.m_paramValuePointer); //dimensions[i] );
|
||||
char labelName[1024];
|
||||
safe_printf(labelName, sizeof(labelName), "%s", params.m_name); //axisNames[0]);
|
||||
MySliderEventHandler<btScalar>* handler = new MySliderEventHandler<btScalar>(labelName, label, pSlider, params.m_paramValuePointer, params.m_callback, params.m_userPointer);
|
||||
handler->m_showValue = params.m_showValues;
|
||||
m_paramInternalData->m_sliderEventHandlers.push_back(handler);
|
||||
|
||||
pSlider->onValueChanged.Add(handler, &MySliderEventHandler<btScalar>::SliderMoved);
|
||||
handler->SliderMoved(pSlider);
|
||||
// float v = pSlider->GetValue();
|
||||
m_gwenInternalData->m_curYposition += 22;
|
||||
}
|
||||
|
||||
void GwenParameterInterface::syncParameters()
|
||||
{
|
||||
for (int i = 0; i < m_paramInternalData->m_sliderEventHandlers.size(); i++)
|
||||
{
|
||||
MySliderEventHandler<btScalar>* handler = m_paramInternalData->m_sliderEventHandlers[i];
|
||||
handler->m_pSlider->SetValue(*handler->m_targetValue, true);
|
||||
}
|
||||
}
|
||||
|
||||
void GwenParameterInterface::removeAllParameters()
|
||||
{
|
||||
for (int i = 0; i < m_paramInternalData->m_buttons.size(); i++)
|
||||
{
|
||||
delete m_paramInternalData->m_buttons[i];
|
||||
}
|
||||
m_paramInternalData->m_buttons.clear();
|
||||
|
||||
for (int i = 0; i < m_paramInternalData->m_buttonEventHandlers.size(); i++)
|
||||
{
|
||||
delete m_paramInternalData->m_buttonEventHandlers[i];
|
||||
}
|
||||
m_paramInternalData->m_buttonEventHandlers.clear();
|
||||
|
||||
m_gwenInternalData->m_curYposition += 22;
|
||||
|
||||
for (int i = 0; i < m_paramInternalData->m_sliders.size(); i++)
|
||||
{
|
||||
delete m_paramInternalData->m_sliders[i];
|
||||
}
|
||||
m_paramInternalData->m_sliders.clear();
|
||||
|
||||
for (int i = 0; i < m_paramInternalData->m_sliderEventHandlers.size(); i++)
|
||||
{
|
||||
delete m_paramInternalData->m_sliderEventHandlers[i];
|
||||
}
|
||||
m_paramInternalData->m_sliderEventHandlers.clear();
|
||||
|
||||
for (int i = 0; i < m_paramInternalData->m_textLabels.size(); i++)
|
||||
{
|
||||
delete m_paramInternalData->m_textLabels[i];
|
||||
}
|
||||
m_paramInternalData->m_textLabels.clear();
|
||||
|
||||
for (int i = 0; i < m_paramInternalData->m_comboBoxes.size(); i++)
|
||||
{
|
||||
delete m_paramInternalData->m_comboBoxes[i];
|
||||
}
|
||||
m_paramInternalData->m_comboBoxes.clear();
|
||||
|
||||
m_gwenInternalData->m_curYposition = this->m_paramInternalData->m_savedYposition;
|
||||
for (int i = 0; i < m_gwenInternalData->m_handlers.size(); i++)
|
||||
{
|
||||
delete m_gwenInternalData->m_handlers[i];
|
||||
}
|
||||
m_gwenInternalData->m_handlers.clear();
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef GWEN_PARAMETER_INTERFACE_H
|
||||
#define GWEN_PARAMETER_INTERFACE_H
|
||||
|
||||
#include "../CommonInterfaces/CommonParameterInterface.h"
|
||||
|
||||
struct GwenParameterInterface : public CommonParameterInterface
|
||||
{
|
||||
struct GwenInternalData* m_gwenInternalData;
|
||||
|
||||
struct GwenParameters* m_paramInternalData;
|
||||
|
||||
GwenParameterInterface(struct GwenInternalData* gwenInternalData);
|
||||
virtual ~GwenParameterInterface();
|
||||
virtual void registerSliderFloatParameter(SliderParams& params);
|
||||
virtual void registerButtonParameter(ButtonParams& params);
|
||||
virtual void registerComboBox(ComboBoxParams& params);
|
||||
|
||||
virtual void setSliderValue(int sliderIndex, double sliderValue);
|
||||
virtual void syncParameters();
|
||||
virtual void removeAllParameters();
|
||||
};
|
||||
|
||||
#endif //GWEN_PARAMETER_INTERFACE_H
|
||||
|
|
@ -0,0 +1,285 @@
|
|||
#include "GwenProfileWindow.h"
|
||||
#include "gwenUserInterface.h"
|
||||
#include "gwenInternalData.h"
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
|
||||
#ifndef BT_NO_PROFILE
|
||||
|
||||
class MyProfileWindow : public Gwen::Controls::WindowControl
|
||||
{
|
||||
// Gwen::Controls::TabControl* m_TabControl;
|
||||
//Gwen::Controls::ListBox* m_TextOutput;
|
||||
unsigned int m_iFrames;
|
||||
float m_fLastSecond;
|
||||
|
||||
Gwen::Controls::TreeNode* m_node;
|
||||
Gwen::Controls::TreeControl* m_ctrl;
|
||||
|
||||
protected:
|
||||
void onButtonA(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
// OpenTissue::glut::toggleIdle();
|
||||
}
|
||||
|
||||
void SliderMoved(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
// Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
|
||||
//this->m_app->scaleYoungModulus(pSlider->GetValue());
|
||||
// printf("Slider Value: %.2f", pSlider->GetValue() );
|
||||
}
|
||||
|
||||
void OnCheckChangedStiffnessWarping(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
// Gwen::Controls::CheckBox* labeled = (Gwen::Controls::CheckBox* )pControl;
|
||||
// bool checked = labeled->IsChecked();
|
||||
//m_app->m_stiffness_warp_on = checked;
|
||||
}
|
||||
|
||||
public:
|
||||
CProfileIterator* profIter;
|
||||
|
||||
class MyMenuItems3* m_menuItems;
|
||||
MyProfileWindow(Gwen::Controls::Base* pParent)
|
||||
: Gwen::Controls::WindowControl(pParent),
|
||||
profIter(0)
|
||||
{
|
||||
SetTitle(L"Time Profiler");
|
||||
|
||||
SetSize(450, 450);
|
||||
this->SetPos(10, 400);
|
||||
|
||||
// this->Dock( Gwen::Pos::Bottom);
|
||||
|
||||
{
|
||||
m_ctrl = new Gwen::Controls::TreeControl(this);
|
||||
m_node = m_ctrl->AddNode(L"Total Parent Time");
|
||||
|
||||
//Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
//pNode->AddNode( L"Node Two Inside" );
|
||||
//pNode->AddNode( L"Eyes" );
|
||||
//pNode->AddNode( L"Brown" )->AddNode( L"Node Two Inside" )->AddNode( L"Eyes" )->AddNode( L"Brown" );
|
||||
//Gwen::Controls::TreeNode* node = ctrl->AddNode( L"Node Three" );
|
||||
|
||||
//m_ctrl->Dock(Gwen::Pos::Bottom);
|
||||
|
||||
m_ctrl->ExpandAll();
|
||||
m_ctrl->SetKeyboardInputEnabled(true);
|
||||
m_ctrl->SetBounds(this->GetInnerBounds().x, this->GetInnerBounds().y, this->GetInnerBounds().w, this->GetInnerBounds().h);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~MyProfileWindow()
|
||||
{
|
||||
delete m_node;
|
||||
delete m_ctrl;
|
||||
}
|
||||
|
||||
float dumpRecursive(CProfileIterator* profileIterator, Gwen::Controls::TreeNode* parentNode)
|
||||
{
|
||||
profileIterator->First();
|
||||
if (profileIterator->Is_Done())
|
||||
return 0.f;
|
||||
|
||||
float accumulated_time = 0, parent_time = profileIterator->Is_Root() ? CProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time();
|
||||
int i;
|
||||
int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset();
|
||||
if (0 == frames_since_reset)
|
||||
return 0.f;
|
||||
|
||||
//printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time );
|
||||
float totalTime = 0.f;
|
||||
|
||||
int numChildren = 0;
|
||||
Gwen::UnicodeString txt;
|
||||
std::vector<Gwen::Controls::TreeNode*> nodes;
|
||||
|
||||
for (i = 0; !profileIterator->Is_Done(); i++, profileIterator->Next())
|
||||
{
|
||||
numChildren++;
|
||||
float current_total_time = profileIterator->Get_Current_Total_Time();
|
||||
accumulated_time += current_total_time;
|
||||
double fraction = parent_time > SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
|
||||
|
||||
Gwen::String name(profileIterator->Get_Current_Name());
|
||||
#ifdef _WIN32
|
||||
Gwen::UnicodeString uname = Gwen::Utility::StringToUnicode(name);
|
||||
|
||||
txt = Gwen::Utility::Format(L"%s (%.2f %%) :: %.3f ms / frame (%d calls)", uname.c_str(), fraction, (current_total_time / (double)frames_since_reset), profileIterator->Get_Current_Total_Calls());
|
||||
|
||||
#else
|
||||
txt = Gwen::Utility::Format(L"%s (%.2f %%) :: %.3f ms / frame (%d calls)", name.c_str(), fraction, (current_total_time / (double)frames_since_reset), profileIterator->Get_Current_Total_Calls());
|
||||
|
||||
#endif
|
||||
|
||||
Gwen::Controls::TreeNode* childNode = (Gwen::Controls::TreeNode*)profileIterator->Get_Current_UserPointer();
|
||||
if (!childNode)
|
||||
{
|
||||
childNode = parentNode->AddNode(L"");
|
||||
profileIterator->Set_Current_UserPointer(childNode);
|
||||
}
|
||||
childNode->SetText(txt);
|
||||
nodes.push_back(childNode);
|
||||
|
||||
totalTime += current_total_time;
|
||||
//recurse into children
|
||||
}
|
||||
|
||||
for (i = 0; i < numChildren; i++)
|
||||
{
|
||||
profileIterator->Enter_Child(i);
|
||||
Gwen::Controls::TreeNode* curNode = nodes[i];
|
||||
|
||||
dumpRecursive(profileIterator, curNode);
|
||||
|
||||
profileIterator->Enter_Parent();
|
||||
}
|
||||
return accumulated_time;
|
||||
}
|
||||
|
||||
void UpdateText(CProfileIterator* profileIterator, bool idle)
|
||||
{
|
||||
// static bool update=true;
|
||||
|
||||
m_ctrl->SetBounds(0, 0, this->GetInnerBounds().w, this->GetInnerBounds().h);
|
||||
|
||||
// if (!update)
|
||||
// return;
|
||||
// update=false;
|
||||
|
||||
static int test = 1;
|
||||
test++;
|
||||
|
||||
static double time_since_reset = 0.f;
|
||||
if (!idle)
|
||||
{
|
||||
time_since_reset = CProfileManager::Get_Time_Since_Reset();
|
||||
}
|
||||
|
||||
//Gwen::UnicodeString txt = Gwen::Utility::Format( L"FEM Settings %i fps", test );
|
||||
{
|
||||
//recompute profiling data, and store profile strings
|
||||
|
||||
// char blockTime[128];
|
||||
|
||||
// double totalTime = 0;
|
||||
|
||||
// int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset();
|
||||
|
||||
profileIterator->First();
|
||||
|
||||
double parent_time = profileIterator->Is_Root() ? time_since_reset : profileIterator->Get_Current_Parent_Total_Time();
|
||||
|
||||
// Gwen::Controls::TreeNode* curParent = m_node;
|
||||
|
||||
double accumulated_time = dumpRecursive(profileIterator, m_node);
|
||||
|
||||
const char* name = profileIterator->Get_Current_Parent_Name();
|
||||
#ifdef _WIN32
|
||||
Gwen::UnicodeString uname = Gwen::Utility::StringToUnicode(name);
|
||||
Gwen::UnicodeString txt = Gwen::Utility::Format(L"Profiling: %s total time: %.3f ms, unaccounted %.3f %% :: %.3f ms", uname.c_str(), parent_time,
|
||||
parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
|
||||
#else
|
||||
Gwen::UnicodeString txt = Gwen::Utility::Format(L"Profiling: %s total time: %.3f ms, unaccounted %.3f %% :: %.3f ms", name, parent_time,
|
||||
parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
|
||||
#endif
|
||||
//sprintf(blockTime,"--- Profiling: %s (total running time: %.3f ms) ---", profileIterator->Get_Current_Parent_Name(), parent_time );
|
||||
//displayProfileString(xOffset,yStart,blockTime);
|
||||
m_node->SetText(txt);
|
||||
|
||||
//printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",);
|
||||
}
|
||||
|
||||
static int counter = 10;
|
||||
if (counter)
|
||||
{
|
||||
counter--;
|
||||
m_ctrl->ExpandAll();
|
||||
}
|
||||
}
|
||||
void PrintText(const Gwen::UnicodeString& str)
|
||||
{
|
||||
}
|
||||
|
||||
void Render(Gwen::Skin::Base* skin)
|
||||
{
|
||||
m_iFrames++;
|
||||
|
||||
if (m_fLastSecond < Gwen::Platform::GetTimeInSeconds())
|
||||
{
|
||||
SetTitle(Gwen::Utility::Format(L"Profiler %i fps", m_iFrames));
|
||||
|
||||
m_fLastSecond = Gwen::Platform::GetTimeInSeconds() + 1.0f;
|
||||
m_iFrames = 0;
|
||||
}
|
||||
|
||||
Gwen::Controls::WindowControl::Render(skin);
|
||||
}
|
||||
};
|
||||
|
||||
class MyMenuItems3 : public Gwen::Controls::Base
|
||||
{
|
||||
public:
|
||||
class MyProfileWindow* m_profWindow;
|
||||
MyMenuItems3() : Gwen::Controls::Base(0)
|
||||
{
|
||||
}
|
||||
virtual ~MyMenuItems3() {}
|
||||
|
||||
void MenuItemSelect(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
if (m_profWindow->Hidden())
|
||||
{
|
||||
m_profWindow->SetHidden(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_profWindow->SetHidden(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MyProfileWindow* setupProfileWindow(GwenInternalData* data)
|
||||
{
|
||||
MyMenuItems3* menuItems = new MyMenuItems3;
|
||||
|
||||
MyProfileWindow* profWindow = new MyProfileWindow(data->pCanvas);
|
||||
//profWindow->SetHidden(true);
|
||||
|
||||
profWindow->m_menuItems = menuItems;
|
||||
profWindow->profIter = CProfileManager::Get_Iterator();
|
||||
data->m_viewMenu->GetMenu()->AddItem(L"Profiler", menuItems, (Gwen::Event::Handler::Function)&MyMenuItems3::MenuItemSelect);
|
||||
|
||||
menuItems->m_profWindow = profWindow;
|
||||
|
||||
return profWindow;
|
||||
}
|
||||
|
||||
void processProfileData(MyProfileWindow* profWindow, bool idle)
|
||||
{
|
||||
if (profWindow)
|
||||
{
|
||||
if (profWindow->profIter)
|
||||
{
|
||||
profWindow->UpdateText(profWindow->profIter, idle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isProfileWindowVisible(MyProfileWindow* window)
|
||||
{
|
||||
return !window->Hidden();
|
||||
}
|
||||
|
||||
void profileWindowSetVisible(MyProfileWindow* window, bool visible)
|
||||
{
|
||||
window->SetHidden(!visible);
|
||||
}
|
||||
void destroyProfileWindow(MyProfileWindow* window)
|
||||
{
|
||||
CProfileManager::Release_Iterator(window->profIter);
|
||||
delete window->m_menuItems;
|
||||
delete window;
|
||||
CProfileManager::CleanupMemory();
|
||||
}
|
||||
|
||||
#endif //BT_NO_PROFILE
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef GWEN_PROFILE_WINDOW_H
|
||||
#define GWEN_PROFILE_WINDOW_H
|
||||
|
||||
class MyProfileWindow* setupProfileWindow(struct GwenInternalData* data);
|
||||
void processProfileData(MyProfileWindow* window, bool idle);
|
||||
void profileWindowSetVisible(MyProfileWindow* window, bool visible);
|
||||
bool isProfileWindowVisible(MyProfileWindow* window);
|
||||
|
||||
void destroyProfileWindow(MyProfileWindow* window);
|
||||
|
||||
#endif //GWEN_PROFILE_WINDOW_H
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
#include "GwenTextureWindow.h"
|
||||
#include "gwenUserInterface.h"
|
||||
#include "gwenInternalData.h"
|
||||
#include "Gwen/Controls/ImagePanel.h"
|
||||
|
||||
class MyGraphWindow : public Gwen::Controls::WindowControl
|
||||
{
|
||||
Gwen::Controls::ImagePanel* m_imgPanel;
|
||||
|
||||
public:
|
||||
class MyMenuItems2* m_menuItems;
|
||||
|
||||
MyGraphWindow(const MyGraphInput& input)
|
||||
: Gwen::Controls::WindowControl(input.m_data->pCanvas),
|
||||
m_menuItems(0)
|
||||
{
|
||||
Gwen::UnicodeString str = Gwen::Utility::StringToUnicode(input.m_name);
|
||||
SetTitle(str);
|
||||
|
||||
SetPos(input.m_xPos, input.m_yPos);
|
||||
SetSize(12 + input.m_width + 2 * input.m_borderWidth, 30 + input.m_height + 2 * input.m_borderWidth);
|
||||
|
||||
m_imgPanel = new Gwen::Controls::ImagePanel(this);
|
||||
if (input.m_texName)
|
||||
{
|
||||
Gwen::UnicodeString texName = Gwen::Utility::StringToUnicode(input.m_texName);
|
||||
m_imgPanel->SetImage(texName);
|
||||
}
|
||||
m_imgPanel->SetBounds(input.m_borderWidth, input.m_borderWidth,
|
||||
input.m_width,
|
||||
input.m_height);
|
||||
// this->Dock( Gwen::Pos::Bottom);
|
||||
}
|
||||
virtual ~MyGraphWindow()
|
||||
{
|
||||
delete m_imgPanel;
|
||||
}
|
||||
};
|
||||
|
||||
class MyMenuItems2 : public Gwen::Controls::Base
|
||||
{
|
||||
MyGraphWindow* m_graphWindow;
|
||||
|
||||
public:
|
||||
Gwen::Controls::MenuItem* m_item;
|
||||
|
||||
MyMenuItems2(MyGraphWindow* graphWindow)
|
||||
: Gwen::Controls::Base(0),
|
||||
m_graphWindow(graphWindow),
|
||||
m_item(0)
|
||||
{
|
||||
}
|
||||
|
||||
void MenuItemSelect(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
if (m_graphWindow->Hidden())
|
||||
{
|
||||
m_graphWindow->SetHidden(false);
|
||||
//@TODO(erwincoumans) setCheck/SetCheckable drawing is broken, need to see what's wrong
|
||||
// if (m_item)
|
||||
// m_item->SetCheck(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_graphWindow->SetHidden(true);
|
||||
// if (m_item)
|
||||
// m_item->SetCheck(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MyGraphWindow* setupTextureWindow(const MyGraphInput& input)
|
||||
{
|
||||
MyGraphWindow* graphWindow = new MyGraphWindow(input);
|
||||
MyMenuItems2* menuItems = new MyMenuItems2(graphWindow);
|
||||
graphWindow->m_menuItems = menuItems;
|
||||
|
||||
Gwen::UnicodeString str = Gwen::Utility::StringToUnicode(input.m_name);
|
||||
menuItems->m_item = input.m_data->m_viewMenu->GetMenu()->AddItem(str, menuItems, (Gwen::Event::Handler::Function)&MyMenuItems2::MenuItemSelect);
|
||||
// menuItems->m_item->SetCheckable(true);
|
||||
|
||||
return graphWindow;
|
||||
}
|
||||
|
||||
void destroyTextureWindow(MyGraphWindow* window)
|
||||
{
|
||||
delete window->m_menuItems->m_item;
|
||||
delete window->m_menuItems;
|
||||
delete window;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
|
||||
#ifndef GWEN_TEXTURE_WINDOW_H
|
||||
#define GWEN_TEXTURE_WINDOW_H
|
||||
|
||||
struct MyGraphInput
|
||||
{
|
||||
struct GwenInternalData* m_data;
|
||||
int m_xPos;
|
||||
int m_yPos;
|
||||
int m_width;
|
||||
int m_height;
|
||||
int m_borderWidth;
|
||||
const char* m_name;
|
||||
const char* m_texName;
|
||||
MyGraphInput(struct GwenInternalData* data)
|
||||
: m_data(data),
|
||||
m_xPos(0),
|
||||
m_yPos(0),
|
||||
m_width(400),
|
||||
m_height(400),
|
||||
m_borderWidth(0),
|
||||
m_name("GraphWindow"),
|
||||
m_texName(0)
|
||||
{
|
||||
}
|
||||
};
|
||||
class MyGraphWindow* setupTextureWindow(const MyGraphInput& input);
|
||||
void destroyTextureWindow(MyGraphWindow* window);
|
||||
|
||||
#endif //GWEN_TEXTURE_WINDOW_H
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
#ifndef GWEN_INTERNAL_DATA_H
|
||||
#define GWEN_INTERNAL_DATA_H
|
||||
|
||||
#include "../OpenGLWindow/GwenOpenGL3CoreRenderer.h"
|
||||
#include "../OpenGLWindow/GLPrimitiveRenderer.h"
|
||||
#include "Gwen/Platform.h"
|
||||
#include "Gwen/Controls/TreeControl.h"
|
||||
#include "Gwen/Controls/RadioButtonController.h"
|
||||
#include "Gwen/Controls/VerticalSlider.h"
|
||||
#include "Gwen/Controls/HorizontalSlider.h"
|
||||
#include "Gwen/Controls/GroupBox.h"
|
||||
#include "Gwen/Controls/CheckBox.h"
|
||||
#include "Gwen/Controls/StatusBar.h"
|
||||
#include "Gwen/Controls/Button.h"
|
||||
#include "Gwen/Controls/ComboBox.h"
|
||||
#include "Gwen/Controls/MenuStrip.h"
|
||||
#include "Gwen/Controls/Slider.h"
|
||||
#include "Gwen/Controls/Property/Text.h"
|
||||
#include "Gwen/Controls/SplitterBar.h"
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "Gwen/Gwen.h"
|
||||
#include "Gwen/Align.h"
|
||||
#include "Gwen/Utility.h"
|
||||
#include "Gwen/Controls/WindowControl.h"
|
||||
#include "Gwen/Controls/TabControl.h"
|
||||
#include "Gwen/Controls/ListBox.h"
|
||||
#include "Gwen/Skins/Simple.h"
|
||||
//#include "Gwen/Skins/TexturedBase.h"
|
||||
#include "gwenUserInterface.h"
|
||||
|
||||
struct GwenInternalData
|
||||
{
|
||||
//struct sth_stash;
|
||||
//class GwenOpenGL3CoreRenderer* pRenderer;
|
||||
Gwen::Renderer::Base* pRenderer;
|
||||
Gwen::Skin::Simple skin;
|
||||
Gwen::Controls::Canvas* pCanvas;
|
||||
//GLPrimitiveRenderer* m_primRenderer;
|
||||
Gwen::Controls::TabButton* m_demoPage;
|
||||
Gwen::Controls::TabButton* m_explorerPage;
|
||||
Gwen::Controls::TreeControl* m_explorerTreeCtrl;
|
||||
Gwen::Controls::MenuItem* m_viewMenu;
|
||||
class MyMenuItems* m_menuItems;
|
||||
Gwen::Controls::ListBox* m_TextOutput;
|
||||
Gwen::Controls::Label* m_exampleInfoGroupBox;
|
||||
Gwen::Controls::ListBox* m_exampleInfoTextOutput;
|
||||
struct MyTestMenuBar* m_menubar;
|
||||
Gwen::Controls::StatusBar* m_bar;
|
||||
Gwen::Controls::ScrollControl* m_windowRight;
|
||||
Gwen::Controls::TabControl* m_tab;
|
||||
|
||||
int m_curYposition;
|
||||
|
||||
Gwen::Controls::Label* m_rightStatusBar;
|
||||
Gwen::Controls::Label* m_leftStatusBar;
|
||||
b3AlignedObjectArray<class Gwen::Event::Handler*> m_handlers;
|
||||
b3ToggleButtonCallback m_toggleButtonCallback;
|
||||
b3ComboBoxCallback m_comboBoxCallback;
|
||||
};
|
||||
|
||||
#endif //GWEN_INTERNAL_DATA_H
|
||||
|
|
@ -0,0 +1,597 @@
|
|||
|
||||
#include "gwenUserInterface.h"
|
||||
#include "gwenInternalData.h"
|
||||
#include "Gwen/Controls/ImagePanel.h"
|
||||
#include "Gwen/Controls/ColorPicker.h"
|
||||
//#include "Gwen/Controls/HSVColorPicker.h"
|
||||
|
||||
class MyGraphWindow* graphWindow = 0;
|
||||
|
||||
GwenUserInterface::GwenUserInterface()
|
||||
{
|
||||
m_data = new GwenInternalData();
|
||||
m_data->m_toggleButtonCallback = 0;
|
||||
m_data->m_comboBoxCallback = 0;
|
||||
}
|
||||
|
||||
class MyMenuItems : public Gwen::Controls::Base
|
||||
{
|
||||
public:
|
||||
b3FileOpenCallback m_fileOpenCallback;
|
||||
b3QuitCallback m_quitCallback;
|
||||
|
||||
MyMenuItems() : Gwen::Controls::Base(0), m_fileOpenCallback(0)
|
||||
{
|
||||
}
|
||||
void myQuitApp(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
if (m_quitCallback)
|
||||
{
|
||||
(*m_quitCallback)();
|
||||
}
|
||||
}
|
||||
void fileOpen(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
if (m_fileOpenCallback)
|
||||
{
|
||||
(*m_fileOpenCallback)();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct MyTestMenuBar : public Gwen::Controls::MenuStrip
|
||||
{
|
||||
Gwen::Controls::MenuItem* m_fileMenu;
|
||||
Gwen::Controls::MenuItem* m_viewMenu;
|
||||
MyMenuItems* m_menuItems;
|
||||
|
||||
MyTestMenuBar(Gwen::Controls::Base* pParent)
|
||||
: Gwen::Controls::MenuStrip(pParent)
|
||||
{
|
||||
// Gwen::Controls::MenuStrip* menu = new Gwen::Controls::MenuStrip( pParent );
|
||||
{
|
||||
m_menuItems = new MyMenuItems();
|
||||
m_menuItems->m_fileOpenCallback = 0;
|
||||
m_menuItems->m_quitCallback = 0;
|
||||
|
||||
m_fileMenu = AddItem(L"File");
|
||||
|
||||
m_fileMenu->GetMenu()->AddItem(L"Open", m_menuItems, (Gwen::Event::Handler::Function)&MyMenuItems::fileOpen);
|
||||
m_fileMenu->GetMenu()->AddItem(L"Quit", m_menuItems, (Gwen::Event::Handler::Function)&MyMenuItems::myQuitApp);
|
||||
m_viewMenu = AddItem(L"View");
|
||||
}
|
||||
}
|
||||
virtual ~MyTestMenuBar()
|
||||
{
|
||||
delete m_menuItems;
|
||||
}
|
||||
};
|
||||
|
||||
void GwenUserInterface::exit()
|
||||
{
|
||||
//m_data->m_menubar->RemoveAllChildren();
|
||||
delete m_data->m_tab;
|
||||
delete m_data->m_windowRight;
|
||||
delete m_data->m_leftStatusBar;
|
||||
delete m_data->m_TextOutput;
|
||||
delete m_data->m_rightStatusBar;
|
||||
delete m_data->m_bar;
|
||||
delete m_data->m_menubar;
|
||||
|
||||
m_data->m_menubar = 0;
|
||||
delete m_data->pCanvas;
|
||||
m_data->pCanvas = 0;
|
||||
}
|
||||
|
||||
GwenUserInterface::~GwenUserInterface()
|
||||
{
|
||||
for (int i = 0; i < m_data->m_handlers.size(); i++)
|
||||
{
|
||||
delete m_data->m_handlers[i];
|
||||
}
|
||||
|
||||
m_data->m_handlers.clear();
|
||||
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
void GwenUserInterface::resize(int width, int height)
|
||||
{
|
||||
m_data->pCanvas->SetSize(width, height);
|
||||
}
|
||||
|
||||
struct MyComboBoxHander : public Gwen::Event::Handler
|
||||
{
|
||||
GwenInternalData* m_data;
|
||||
int m_buttonId;
|
||||
|
||||
MyComboBoxHander(GwenInternalData* data, int buttonId)
|
||||
: m_data(data),
|
||||
m_buttonId(buttonId)
|
||||
{
|
||||
}
|
||||
|
||||
void onSelect(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
Gwen::Controls::ComboBox* but = (Gwen::Controls::ComboBox*)pControl;
|
||||
|
||||
Gwen::String str = Gwen::Utility::UnicodeToString(but->GetSelectedItem()->GetText());
|
||||
|
||||
if (m_data->m_comboBoxCallback)
|
||||
(*m_data->m_comboBoxCallback)(m_buttonId, str.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
struct MyButtonHander : public Gwen::Event::Handler
|
||||
{
|
||||
GwenInternalData* m_data;
|
||||
int m_buttonId;
|
||||
|
||||
MyButtonHander(GwenInternalData* data, int buttonId)
|
||||
: m_data(data),
|
||||
m_buttonId(buttonId)
|
||||
{
|
||||
}
|
||||
|
||||
void onButtonA(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
Gwen::Controls::Button* but = (Gwen::Controls::Button*)pControl;
|
||||
// int dep = but->IsDepressed();
|
||||
int tog = but->GetToggleState();
|
||||
if (m_data->m_toggleButtonCallback)
|
||||
(*m_data->m_toggleButtonCallback)(m_buttonId, tog);
|
||||
}
|
||||
};
|
||||
|
||||
void GwenUserInterface::textOutput(const char* message)
|
||||
{
|
||||
Gwen::UnicodeString msg = Gwen::Utility::StringToUnicode(message);
|
||||
m_data->m_TextOutput->AddItem(msg);
|
||||
m_data->m_TextOutput->Scroller()->ScrollToBottom();
|
||||
}
|
||||
|
||||
void GwenUserInterface::setExampleDescription(const char* message)
|
||||
{
|
||||
//Gwen apparently doesn't have text/word wrap, so do rudimentary brute-force implementation here.
|
||||
|
||||
std::string wrapmessage = message;
|
||||
int startPos = 0;
|
||||
|
||||
std::string lastFit = "";
|
||||
bool hasSpace = false;
|
||||
std::string lastFitSpace = "";
|
||||
int spacePos = 0;
|
||||
|
||||
m_data->m_exampleInfoTextOutput->Clear();
|
||||
int fixedWidth = m_data->m_exampleInfoTextOutput->GetBounds().w - 25;
|
||||
int wrapLen = int(wrapmessage.length());
|
||||
for (int endPos = 0; endPos <= wrapLen; endPos++)
|
||||
{
|
||||
std::string sub = wrapmessage.substr(startPos, (endPos - startPos));
|
||||
Gwen::Point pt = m_data->pRenderer->MeasureText(m_data->pCanvas->GetSkin()->GetDefaultFont(), sub);
|
||||
|
||||
if (pt.x <= fixedWidth)
|
||||
{
|
||||
lastFit = sub;
|
||||
|
||||
if (message[endPos] == ' ' || message[endPos] == '.' || message[endPos] == ',')
|
||||
{
|
||||
hasSpace = true;
|
||||
lastFitSpace = sub;
|
||||
spacePos = endPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//submit and
|
||||
if (hasSpace)
|
||||
{
|
||||
endPos = spacePos + 1;
|
||||
hasSpace = false;
|
||||
lastFit = lastFitSpace;
|
||||
startPos = endPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
startPos = endPos - 1;
|
||||
}
|
||||
Gwen::UnicodeString msg = Gwen::Utility::StringToUnicode(lastFit);
|
||||
|
||||
m_data->m_exampleInfoTextOutput->AddItem(msg);
|
||||
m_data->m_exampleInfoTextOutput->Scroller()->ScrollToBottom();
|
||||
}
|
||||
}
|
||||
|
||||
if (lastFit.length())
|
||||
{
|
||||
Gwen::UnicodeString msg = Gwen::Utility::StringToUnicode(lastFit);
|
||||
m_data->m_exampleInfoTextOutput->AddItem(msg);
|
||||
m_data->m_exampleInfoTextOutput->Scroller()->ScrollToBottom();
|
||||
}
|
||||
}
|
||||
|
||||
void GwenUserInterface::setStatusBarMessage(const char* message, bool isLeft)
|
||||
{
|
||||
Gwen::UnicodeString msg = Gwen::Utility::StringToUnicode(message);
|
||||
if (isLeft)
|
||||
{
|
||||
m_data->m_leftStatusBar->SetText(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data->m_rightStatusBar->SetText(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void GwenUserInterface::registerFileOpenCallback(b3FileOpenCallback callback)
|
||||
{
|
||||
m_data->m_menuItems->m_fileOpenCallback = callback;
|
||||
}
|
||||
|
||||
void GwenUserInterface::registerQuitCallback(b3QuitCallback callback)
|
||||
{
|
||||
m_data->m_menuItems->m_quitCallback = callback;
|
||||
}
|
||||
|
||||
void GwenUserInterface::init(int width, int height, Gwen::Renderer::Base* renderer, float retinaScale)
|
||||
{
|
||||
m_data->m_curYposition = 20;
|
||||
//m_data->m_primRenderer = new GLPrimitiveRenderer(width,height);
|
||||
m_data->pRenderer = renderer; //new GwenOpenGL3CoreRenderer(m_data->m_primRenderer,stash,width,height,retinaScale);
|
||||
|
||||
m_data->skin.SetRender(m_data->pRenderer);
|
||||
|
||||
m_data->pCanvas = new Gwen::Controls::Canvas(&m_data->skin);
|
||||
m_data->pCanvas->SetSize(width, height);
|
||||
m_data->pCanvas->SetDrawBackground(false);
|
||||
m_data->pCanvas->SetBackgroundColor(Gwen::Color(150, 170, 170, 255));
|
||||
|
||||
MyTestMenuBar* menubar = new MyTestMenuBar(m_data->pCanvas);
|
||||
m_data->m_viewMenu = menubar->m_viewMenu;
|
||||
m_data->m_menuItems = menubar->m_menuItems;
|
||||
m_data->m_menubar = menubar;
|
||||
|
||||
Gwen::Controls::StatusBar* bar = new Gwen::Controls::StatusBar(m_data->pCanvas);
|
||||
m_data->m_bar = bar;
|
||||
|
||||
m_data->m_rightStatusBar = new Gwen::Controls::Label(bar);
|
||||
|
||||
m_data->m_rightStatusBar->SetWidth(width / 2);
|
||||
//m_data->m_rightStatusBar->SetText( L"Label Added to Right" );
|
||||
bar->AddControl(m_data->m_rightStatusBar, true);
|
||||
|
||||
m_data->m_TextOutput = new Gwen::Controls::ListBox(m_data->pCanvas);
|
||||
|
||||
m_data->m_TextOutput->Dock(Gwen::Pos::Bottom);
|
||||
m_data->m_TextOutput->SetHeight(100);
|
||||
|
||||
m_data->m_leftStatusBar = new Gwen::Controls::Label(bar);
|
||||
|
||||
//m_data->m_leftStatusBar->SetText( L"Label Added to Left" );
|
||||
m_data->m_leftStatusBar->SetWidth(width / 2);
|
||||
bar->AddControl(m_data->m_leftStatusBar, false);
|
||||
|
||||
//Gwen::KeyboardFocus
|
||||
/*Gwen::Controls::GroupBox* box = new Gwen::Controls::GroupBox(m_data->pCanvas);
|
||||
box->SetText("text");
|
||||
box->SetName("name");
|
||||
box->SetHeight(500);
|
||||
*/
|
||||
Gwen::Controls::ScrollControl* windowRight = new Gwen::Controls::ScrollControl(m_data->pCanvas);
|
||||
windowRight->Dock(Gwen::Pos::Right);
|
||||
windowRight->SetWidth(250);
|
||||
windowRight->SetHeight(250);
|
||||
windowRight->SetScroll(false, true);
|
||||
m_data->m_windowRight = windowRight;
|
||||
|
||||
//windowLeft->SetSkin(
|
||||
Gwen::Controls::TabControl* tab = new Gwen::Controls::TabControl(windowRight);
|
||||
m_data->m_tab = tab;
|
||||
|
||||
//tab->SetHeight(300);
|
||||
tab->SetWidth(240);
|
||||
tab->SetHeight(13250);
|
||||
//tab->Dock(Gwen::Pos::Left);
|
||||
tab->Dock(Gwen::Pos::Fill);
|
||||
//tab->SetMargin( Gwen::Margin( 2, 2, 2, 2 ) );
|
||||
|
||||
Gwen::UnicodeString str1(L"Params");
|
||||
m_data->m_demoPage = tab->AddPage(str1);
|
||||
|
||||
// Gwen::UnicodeString str2(L"OpenCL");
|
||||
// tab->AddPage(str2);
|
||||
//Gwen::UnicodeString str3(L"page3");
|
||||
// tab->AddPage(str3);
|
||||
|
||||
//but->onPress.Add(handler, &MyHander::onButtonA);
|
||||
|
||||
//box->Dock(Gwen::Pos::Left);
|
||||
|
||||
/*Gwen::Controls::WindowControl* windowBottom = new Gwen::Controls::WindowControl(m_data->pCanvas);
|
||||
windowBottom->SetHeight(100);
|
||||
windowBottom->Dock(Gwen::Pos::Bottom);
|
||||
windowBottom->SetTitle("bottom");
|
||||
*/
|
||||
// Gwen::Controls::Property::Text* prop = new Gwen::Controls::Property::Text(m_data->pCanvas);
|
||||
//prop->Dock(Gwen::Pos::Bottom);
|
||||
/*Gwen::Controls::SplitterBar* split = new Gwen::Controls::SplitterBar(m_data->pCanvas);
|
||||
split->Dock(Gwen::Pos::Center);
|
||||
split->SetHeight(300);
|
||||
split->SetWidth(300);
|
||||
*/
|
||||
/*
|
||||
|
||||
|
||||
*/
|
||||
|
||||
Gwen::Controls::ScrollControl* windowLeft = new Gwen::Controls::ScrollControl(m_data->pCanvas);
|
||||
windowLeft->Dock(Gwen::Pos::Left);
|
||||
// windowLeft->SetTitle("title");
|
||||
windowLeft->SetScroll(false, false);
|
||||
windowLeft->SetWidth(250);
|
||||
windowLeft->SetPos(50, 50);
|
||||
windowLeft->SetHeight(500);
|
||||
//windowLeft->SetClosable(false);
|
||||
// windowLeft->SetShouldDrawBackground(true);
|
||||
windowLeft->SetTabable(true);
|
||||
|
||||
Gwen::Controls::TabControl* explorerTab = new Gwen::Controls::TabControl(windowLeft);
|
||||
|
||||
//tab->SetHeight(300);
|
||||
// explorerTab->SetWidth(230);
|
||||
explorerTab->SetHeight(250);
|
||||
//tab->Dock(Gwen::Pos::Left);
|
||||
explorerTab->Dock(Gwen::Pos::Fill);
|
||||
|
||||
//m_data->m_exampleInfoTextOutput->SetBounds(2, 10, 236, 400);
|
||||
|
||||
//windowRight
|
||||
|
||||
Gwen::UnicodeString explorerStr1(L"Explorer");
|
||||
m_data->m_explorerPage = explorerTab->AddPage(explorerStr1);
|
||||
Gwen::UnicodeString shapesStr1(L"Test");
|
||||
Gwen::Controls::TabButton* shapes = explorerTab->AddPage(shapesStr1);
|
||||
|
||||
///todo(erwincoumans) figure out why the HSV color picker is extremely slow
|
||||
//Gwen::Controls::HSVColorPicker* color = new Gwen::Controls::HSVColorPicker(shapes->GetPage());
|
||||
Gwen::Controls::ColorPicker* color = new Gwen::Controls::ColorPicker(shapes->GetPage());
|
||||
color->SetKeyboardInputEnabled(true);
|
||||
|
||||
Gwen::Controls::TreeControl* ctrl = new Gwen::Controls::TreeControl(m_data->m_explorerPage->GetPage());
|
||||
m_data->m_explorerTreeCtrl = ctrl;
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
ctrl->Focus();
|
||||
ctrl->SetBounds(2, 10, 236, 300);
|
||||
|
||||
m_data->m_exampleInfoGroupBox = new Gwen::Controls::Label(m_data->m_explorerPage->GetPage());
|
||||
m_data->m_exampleInfoGroupBox->SetPos(2, 314);
|
||||
m_data->m_exampleInfoGroupBox->SetHeight(15);
|
||||
m_data->m_exampleInfoGroupBox->SetWidth(234);
|
||||
m_data->m_exampleInfoGroupBox->SetText("Example Description");
|
||||
|
||||
m_data->m_exampleInfoTextOutput = new Gwen::Controls::ListBox(m_data->m_explorerPage->GetPage());
|
||||
|
||||
//m_data->m_exampleInfoTextOutput->Dock( Gwen::Pos::Bottom );
|
||||
m_data->m_exampleInfoTextOutput->SetPos(2, 332);
|
||||
m_data->m_exampleInfoTextOutput->SetHeight(150);
|
||||
m_data->m_exampleInfoTextOutput->SetWidth(233);
|
||||
}
|
||||
|
||||
void GwenUserInterface::forceUpdateScrollBars()
|
||||
{
|
||||
b3Assert(m_data);
|
||||
b3Assert(m_data->m_explorerTreeCtrl);
|
||||
if (m_data && m_data->m_explorerTreeCtrl)
|
||||
{
|
||||
m_data->m_explorerTreeCtrl->ForceUpdateScrollBars();
|
||||
}
|
||||
}
|
||||
|
||||
void GwenUserInterface::setFocus()
|
||||
{
|
||||
b3Assert(m_data);
|
||||
b3Assert(m_data->m_explorerTreeCtrl);
|
||||
if (m_data && m_data->m_explorerTreeCtrl)
|
||||
{
|
||||
m_data->m_explorerTreeCtrl->Focus();
|
||||
}
|
||||
}
|
||||
|
||||
b3ToggleButtonCallback GwenUserInterface::getToggleButtonCallback()
|
||||
{
|
||||
return m_data->m_toggleButtonCallback;
|
||||
}
|
||||
|
||||
void GwenUserInterface::setToggleButtonCallback(b3ToggleButtonCallback callback)
|
||||
{
|
||||
m_data->m_toggleButtonCallback = callback;
|
||||
}
|
||||
void GwenUserInterface::registerToggleButton2(int buttonId, const char* name)
|
||||
{
|
||||
assert(m_data);
|
||||
assert(m_data->m_demoPage);
|
||||
|
||||
Gwen::Controls::Button* but = new Gwen::Controls::Button(m_data->m_demoPage->GetPage());
|
||||
|
||||
///some heuristic to find the button location
|
||||
int ypos = m_data->m_curYposition;
|
||||
but->SetPos(10, ypos);
|
||||
but->SetWidth(200);
|
||||
//but->SetBounds( 200, 30, 300, 200 );
|
||||
|
||||
MyButtonHander* handler = new MyButtonHander(m_data, buttonId);
|
||||
m_data->m_handlers.push_back(handler);
|
||||
m_data->m_curYposition += 22;
|
||||
but->onToggle.Add(handler, &MyButtonHander::onButtonA);
|
||||
but->SetIsToggle(true);
|
||||
but->SetToggleState(false);
|
||||
but->SetText(name);
|
||||
}
|
||||
|
||||
void GwenUserInterface::setComboBoxCallback(b3ComboBoxCallback callback)
|
||||
{
|
||||
m_data->m_comboBoxCallback = callback;
|
||||
}
|
||||
|
||||
b3ComboBoxCallback GwenUserInterface::getComboBoxCallback()
|
||||
{
|
||||
return m_data->m_comboBoxCallback;
|
||||
}
|
||||
void GwenUserInterface::registerComboBox2(int comboboxId, int numItems, const char** items, int startItem)
|
||||
{
|
||||
Gwen::Controls::ComboBox* combobox = new Gwen::Controls::ComboBox(m_data->m_demoPage->GetPage());
|
||||
MyComboBoxHander* handler = new MyComboBoxHander(m_data, comboboxId);
|
||||
m_data->m_handlers.push_back(handler);
|
||||
|
||||
combobox->onSelection.Add(handler, &MyComboBoxHander::onSelect);
|
||||
int ypos = m_data->m_curYposition;
|
||||
combobox->SetPos(10, ypos);
|
||||
combobox->SetWidth(100);
|
||||
//box->SetPos(120,130);
|
||||
for (int i = 0; i < numItems; i++)
|
||||
{
|
||||
Gwen::Controls::MenuItem* item = combobox->AddItem(Gwen::Utility::StringToUnicode(items[i]));
|
||||
if (i == startItem)
|
||||
combobox->OnItemSelected(item);
|
||||
}
|
||||
|
||||
m_data->m_curYposition += 22;
|
||||
}
|
||||
|
||||
void GwenUserInterface::draw(int width, int height)
|
||||
{
|
||||
// printf("width = %d, height=%d\n", width,height);
|
||||
if (m_data->pCanvas)
|
||||
{
|
||||
m_data->pCanvas->SetSize(width, height);
|
||||
//m_data->m_primRenderer->setScreenSize(width,height);
|
||||
m_data->pRenderer->Resize(width, height);
|
||||
m_data->pCanvas->RenderCanvas();
|
||||
//restoreOpenGLState();
|
||||
}
|
||||
}
|
||||
|
||||
bool GwenUserInterface::mouseMoveCallback(float x, float y)
|
||||
{
|
||||
bool handled = false;
|
||||
|
||||
static int m_lastmousepos[2] = {0, 0};
|
||||
static bool isInitialized = false;
|
||||
if (m_data->pCanvas)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
isInitialized = true;
|
||||
m_lastmousepos[0] = x + 1;
|
||||
m_lastmousepos[1] = y + 1;
|
||||
}
|
||||
handled = m_data->pCanvas->InputMouseMoved(x, y, m_lastmousepos[0], m_lastmousepos[1]);
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
#include "../CommonInterfaces/CommonWindowInterface.h"
|
||||
|
||||
bool GwenUserInterface::keyboardCallback(int bulletKey, int state)
|
||||
{
|
||||
int gwenKey = -1;
|
||||
if (m_data->pCanvas)
|
||||
{
|
||||
//convert 'Bullet' keys into 'Gwen' keys
|
||||
switch (bulletKey)
|
||||
{
|
||||
case B3G_RETURN:
|
||||
{
|
||||
gwenKey = Gwen::Key::Return;
|
||||
break;
|
||||
}
|
||||
case B3G_LEFT_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Left;
|
||||
break;
|
||||
}
|
||||
case B3G_RIGHT_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Right;
|
||||
break;
|
||||
}
|
||||
case B3G_UP_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Up;
|
||||
break;
|
||||
}
|
||||
case B3G_DOWN_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Down;
|
||||
break;
|
||||
}
|
||||
case B3G_BACKSPACE:
|
||||
{
|
||||
gwenKey = Gwen::Key::Backspace;
|
||||
break;
|
||||
}
|
||||
case B3G_DELETE:
|
||||
{
|
||||
gwenKey = Gwen::Key::Delete;
|
||||
break;
|
||||
}
|
||||
case B3G_HOME:
|
||||
{
|
||||
gwenKey = Gwen::Key::Home;
|
||||
break;
|
||||
}
|
||||
case B3G_END:
|
||||
{
|
||||
gwenKey = Gwen::Key::End;
|
||||
break;
|
||||
}
|
||||
case B3G_SHIFT:
|
||||
{
|
||||
gwenKey = Gwen::Key::Shift;
|
||||
break;
|
||||
}
|
||||
case B3G_CONTROL:
|
||||
{
|
||||
gwenKey = Gwen::Key::Control;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
if (gwenKey >= 0)
|
||||
{
|
||||
return m_data->pCanvas->InputKey(gwenKey, state == 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bulletKey < 256 && state)
|
||||
{
|
||||
Gwen::UnicodeChar c = (Gwen::UnicodeChar)bulletKey;
|
||||
return m_data->pCanvas->InputCharacter(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GwenUserInterface::mouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
bool handled = false;
|
||||
if (m_data->pCanvas)
|
||||
{
|
||||
handled = m_data->pCanvas->InputMouseMoved(x, y, x, y);
|
||||
|
||||
if (button >= 0)
|
||||
{
|
||||
handled = m_data->pCanvas->InputMouseButton(button, (bool)state);
|
||||
if (handled)
|
||||
{
|
||||
//if (!state)
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef _GWEN_USER_INTERFACE_H
|
||||
#define _GWEN_USER_INTERFACE_H
|
||||
|
||||
struct GwenInternalData;
|
||||
|
||||
typedef void (*b3ComboBoxCallback)(int combobox, const char* item);
|
||||
typedef void (*b3ToggleButtonCallback)(int button, int state);
|
||||
typedef void (*b3FileOpenCallback)();
|
||||
typedef void (*b3QuitCallback)();
|
||||
|
||||
namespace Gwen
|
||||
{
|
||||
namespace Renderer
|
||||
{
|
||||
class Base;
|
||||
};
|
||||
}; // namespace Gwen
|
||||
class GwenUserInterface
|
||||
{
|
||||
GwenInternalData* m_data;
|
||||
|
||||
public:
|
||||
GwenUserInterface();
|
||||
|
||||
virtual ~GwenUserInterface();
|
||||
|
||||
void init(int width, int height, Gwen::Renderer::Base* gwenRenderer, float retinaScale);
|
||||
void exit();
|
||||
void setFocus();
|
||||
void forceUpdateScrollBars();
|
||||
|
||||
void draw(int width, int height);
|
||||
|
||||
void resize(int width, int height);
|
||||
|
||||
bool mouseMoveCallback(float x, float y);
|
||||
bool mouseButtonCallback(int button, int state, float x, float y);
|
||||
bool keyboardCallback(int key, int state);
|
||||
|
||||
void setToggleButtonCallback(b3ToggleButtonCallback callback);
|
||||
b3ToggleButtonCallback getToggleButtonCallback();
|
||||
|
||||
void registerToggleButton2(int buttonId, const char* name);
|
||||
|
||||
void setComboBoxCallback(b3ComboBoxCallback callback);
|
||||
b3ComboBoxCallback getComboBoxCallback();
|
||||
void registerComboBox2(int buttonId, int numItems, const char** items, int startItem = 0);
|
||||
|
||||
void setStatusBarMessage(const char* message, bool isLeft = true);
|
||||
|
||||
void textOutput(const char* msg);
|
||||
void setExampleDescription(const char* msg);
|
||||
|
||||
void registerFileOpenCallback(b3FileOpenCallback callback);
|
||||
void registerQuitCallback(b3QuitCallback callback);
|
||||
|
||||
GwenInternalData* getInternalData()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //_GWEN_USER_INTERFACE_H
|
||||
|
|
@ -0,0 +1,432 @@
|
|||
#include "InProcessExampleBrowser.h"
|
||||
|
||||
//#define EXAMPLE_CONSOLE_ONLY
|
||||
#ifdef EXAMPLE_CONSOLE_ONLY
|
||||
#include "EmptyBrowser.h"
|
||||
typedef EmptyBrowser DefaultBrowser;
|
||||
#else
|
||||
#include "OpenGLExampleBrowser.h"
|
||||
typedef OpenGLExampleBrowser DefaultBrowser;
|
||||
#endif //EXAMPLE_CONSOLE_ONLY
|
||||
|
||||
#include "Bullet3Common/b3CommandLineArgs.h"
|
||||
#include "../Utils/b3Clock.h"
|
||||
|
||||
#include "ExampleEntries.h"
|
||||
#include "Bullet3Common/b3Scalar.h"
|
||||
#include "../SharedMemory/InProcessMemory.h"
|
||||
|
||||
void ExampleBrowserThreadFunc(void* userPtr, void* lsMemory);
|
||||
void* ExampleBrowserMemoryFunc();
|
||||
void ExampleBrowserMemoryReleaseFunc(void* ptr);
|
||||
|
||||
#include <stdio.h>
|
||||
//#include "BulletMultiThreaded/PlatformDefinitions.h"
|
||||
|
||||
#include "Bullet3Common/b3Logging.h"
|
||||
#include "ExampleEntries.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "EmptyExample.h"
|
||||
|
||||
#include "../SharedMemory/PhysicsServerExample.h"
|
||||
#include "../SharedMemory/PhysicsServerExampleBullet2.h"
|
||||
#include "../SharedMemory/GraphicsServerExample.h"
|
||||
|
||||
|
||||
#include "../SharedMemory/PhysicsClientExample.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include "../MultiThreading/b3PosixThreadSupport.h"
|
||||
|
||||
static b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads)
|
||||
{
|
||||
b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
|
||||
ExampleBrowserThreadFunc,
|
||||
ExampleBrowserMemoryFunc,
|
||||
ExampleBrowserMemoryReleaseFunc,
|
||||
numThreads);
|
||||
b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);
|
||||
|
||||
return threadSupport;
|
||||
}
|
||||
|
||||
#elif defined(_WIN32)
|
||||
#include "../MultiThreading/b3Win32ThreadSupport.h"
|
||||
|
||||
b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads)
|
||||
{
|
||||
b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads", ExampleBrowserThreadFunc, ExampleBrowserMemoryFunc, ExampleBrowserMemoryReleaseFunc, numThreads);
|
||||
b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo);
|
||||
return threadSupport;
|
||||
}
|
||||
#endif
|
||||
|
||||
class ExampleEntriesPhysicsServer : public ExampleEntries
|
||||
{
|
||||
struct ExampleEntriesInternalData2* m_data;
|
||||
|
||||
public:
|
||||
ExampleEntriesPhysicsServer();
|
||||
virtual ~ExampleEntriesPhysicsServer();
|
||||
|
||||
static void registerExampleEntry(int menuLevel, const char* name, const char* description, CommonExampleInterface::CreateFunc* createFunc, int option = 0);
|
||||
|
||||
virtual void initExampleEntries();
|
||||
|
||||
virtual void initOpenCLExampleEntries();
|
||||
|
||||
virtual int getNumRegisteredExamples();
|
||||
|
||||
virtual CommonExampleInterface::CreateFunc* getExampleCreateFunc(int index);
|
||||
|
||||
virtual const char* getExampleName(int index);
|
||||
|
||||
virtual const char* getExampleDescription(int index);
|
||||
|
||||
virtual int getExampleOption(int index);
|
||||
};
|
||||
|
||||
struct ExampleEntryPhysicsServer
|
||||
{
|
||||
int m_menuLevel;
|
||||
const char* m_name;
|
||||
const char* m_description;
|
||||
CommonExampleInterface::CreateFunc* m_createFunc;
|
||||
int m_option;
|
||||
|
||||
ExampleEntryPhysicsServer(int menuLevel, const char* name)
|
||||
: m_menuLevel(menuLevel), m_name(name), m_description(0), m_createFunc(0), m_option(0)
|
||||
{
|
||||
}
|
||||
|
||||
ExampleEntryPhysicsServer(int menuLevel, const char* name, const char* description, CommonExampleInterface::CreateFunc* createFunc, int option = 0)
|
||||
: m_menuLevel(menuLevel), m_name(name), m_description(description), m_createFunc(createFunc), m_option(option)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct ExampleEntriesInternalData2
|
||||
{
|
||||
btAlignedObjectArray<ExampleEntryPhysicsServer> m_allExamples;
|
||||
};
|
||||
|
||||
static ExampleEntryPhysicsServer gDefaultExamplesPhysicsServer[] =
|
||||
{
|
||||
|
||||
ExampleEntryPhysicsServer(0, "Robotics Control"),
|
||||
|
||||
ExampleEntryPhysicsServer(1, "Physics Server", "Create a physics server that communicates with a physics client over shared memory",
|
||||
PhysicsServerCreateFuncBullet2),
|
||||
ExampleEntryPhysicsServer(1, "Physics Server (RTC)", "Create a physics server that communicates with a physics client over shared memory. At each update, the Physics Server will continue calling 'stepSimulation' based on the real-time clock (RTC).",
|
||||
PhysicsServerCreateFuncBullet2, PHYSICS_SERVER_USE_RTC_CLOCK),
|
||||
|
||||
ExampleEntryPhysicsServer(1, "Physics Server (Logging)", "Create a physics server that communicates with a physics client over shared memory. It will log all commands to a file.",
|
||||
PhysicsServerCreateFuncBullet2, PHYSICS_SERVER_ENABLE_COMMAND_LOGGING),
|
||||
ExampleEntryPhysicsServer(1, "Physics Server (Replay Log)", "Create a physics server that replay a command log from disk.",
|
||||
PhysicsServerCreateFuncBullet2, PHYSICS_SERVER_REPLAY_FROM_COMMAND_LOG),
|
||||
ExampleEntryPhysicsServer(1, "Graphics Server", "Create a graphics server", GraphicsServerCreateFuncBullet),
|
||||
|
||||
};
|
||||
|
||||
ExampleEntriesPhysicsServer::ExampleEntriesPhysicsServer()
|
||||
{
|
||||
m_data = new ExampleEntriesInternalData2;
|
||||
}
|
||||
|
||||
ExampleEntriesPhysicsServer::~ExampleEntriesPhysicsServer()
|
||||
{
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
void ExampleEntriesPhysicsServer::initOpenCLExampleEntries()
|
||||
{
|
||||
}
|
||||
|
||||
void ExampleEntriesPhysicsServer::initExampleEntries()
|
||||
{
|
||||
m_data->m_allExamples.clear();
|
||||
|
||||
int numDefaultEntries = sizeof(gDefaultExamplesPhysicsServer) / sizeof(ExampleEntryPhysicsServer);
|
||||
for (int i = 0; i < numDefaultEntries; i++)
|
||||
{
|
||||
m_data->m_allExamples.push_back(gDefaultExamplesPhysicsServer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ExampleEntriesPhysicsServer::registerExampleEntry(int menuLevel, const char* name, const char* description, CommonExampleInterface::CreateFunc* createFunc, int option)
|
||||
{
|
||||
}
|
||||
|
||||
int ExampleEntriesPhysicsServer::getNumRegisteredExamples()
|
||||
{
|
||||
return m_data->m_allExamples.size();
|
||||
}
|
||||
|
||||
CommonExampleInterface::CreateFunc* ExampleEntriesPhysicsServer::getExampleCreateFunc(int index)
|
||||
{
|
||||
return m_data->m_allExamples[index].m_createFunc;
|
||||
}
|
||||
|
||||
int ExampleEntriesPhysicsServer::getExampleOption(int index)
|
||||
{
|
||||
return m_data->m_allExamples[index].m_option;
|
||||
}
|
||||
|
||||
const char* ExampleEntriesPhysicsServer::getExampleName(int index)
|
||||
{
|
||||
return m_data->m_allExamples[index].m_name;
|
||||
}
|
||||
|
||||
const char* ExampleEntriesPhysicsServer::getExampleDescription(int index)
|
||||
{
|
||||
return m_data->m_allExamples[index].m_description;
|
||||
}
|
||||
|
||||
struct ExampleBrowserArgs
|
||||
{
|
||||
ExampleBrowserArgs()
|
||||
: m_fakeWork(1), m_argc(0)
|
||||
{
|
||||
}
|
||||
b3CriticalSection* m_cs;
|
||||
float m_fakeWork;
|
||||
int m_argc;
|
||||
char** m_argv;
|
||||
};
|
||||
|
||||
struct ExampleBrowserThreadLocalStorage
|
||||
{
|
||||
SharedMemoryInterface* m_sharedMem;
|
||||
int threadId;
|
||||
};
|
||||
|
||||
enum TestExampleBrowserCommunicationEnums
|
||||
{
|
||||
eRequestTerminateExampleBrowser = 13,
|
||||
eExampleBrowserIsUnInitialized,
|
||||
eExampleBrowserIsInitialized,
|
||||
eExampleBrowserInitializationFailed,
|
||||
eExampleBrowserHasTerminated
|
||||
};
|
||||
|
||||
static double gMinUpdateTimeMicroSecs = 4000.;
|
||||
|
||||
void ExampleBrowserThreadFunc(void* userPtr, void* lsMemory)
|
||||
{
|
||||
printf("ExampleBrowserThreadFunc started\n");
|
||||
|
||||
ExampleBrowserThreadLocalStorage* localStorage = (ExampleBrowserThreadLocalStorage*)lsMemory;
|
||||
|
||||
ExampleBrowserArgs* args = (ExampleBrowserArgs*)userPtr;
|
||||
//int workLeft = true;
|
||||
b3CommandLineArgs args2(args->m_argc, args->m_argv);
|
||||
int minUpdateMs = 4000;
|
||||
if (args2.GetCmdLineArgument("minGraphicsUpdateTimeMs", minUpdateMs))
|
||||
{
|
||||
gMinUpdateTimeMicroSecs = minUpdateMs;
|
||||
}
|
||||
b3Clock clock;
|
||||
|
||||
ExampleEntriesPhysicsServer examples;
|
||||
examples.initExampleEntries();
|
||||
|
||||
DefaultBrowser* exampleBrowser = new DefaultBrowser(&examples);
|
||||
exampleBrowser->setSharedMemoryInterface(localStorage->m_sharedMem);
|
||||
|
||||
bool init = exampleBrowser->init(args->m_argc, args->m_argv);
|
||||
clock.reset();
|
||||
if (init)
|
||||
{
|
||||
args->m_cs->lock();
|
||||
args->m_cs->setSharedParam(0, eExampleBrowserIsInitialized);
|
||||
args->m_cs->unlock();
|
||||
|
||||
do
|
||||
{
|
||||
clock.usleep(0);
|
||||
|
||||
//B3_PROFILE("ExampleBrowserThreadFunc");
|
||||
float deltaTimeInSeconds = clock.getTimeMicroseconds() / 1000000.f;
|
||||
{
|
||||
if (deltaTimeInSeconds > 0.1)
|
||||
{
|
||||
deltaTimeInSeconds = 0.1;
|
||||
}
|
||||
if (deltaTimeInSeconds < (gMinUpdateTimeMicroSecs / 1e6))
|
||||
{
|
||||
//B3_PROFILE("clock.usleep");
|
||||
exampleBrowser->updateGraphics();
|
||||
}
|
||||
else
|
||||
{
|
||||
//B3_PROFILE("exampleBrowser->update");
|
||||
clock.reset();
|
||||
exampleBrowser->updateGraphics();
|
||||
exampleBrowser->update(deltaTimeInSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
} while (!exampleBrowser->requestedExit() && (args->m_cs->getSharedParam(0) != eRequestTerminateExampleBrowser));
|
||||
}
|
||||
else
|
||||
{
|
||||
args->m_cs->lock();
|
||||
args->m_cs->setSharedParam(0, eExampleBrowserInitializationFailed);
|
||||
args->m_cs->unlock();
|
||||
}
|
||||
|
||||
delete exampleBrowser;
|
||||
args->m_cs->lock();
|
||||
args->m_cs->setSharedParam(0, eExampleBrowserHasTerminated);
|
||||
args->m_cs->unlock();
|
||||
printf("finished\n");
|
||||
//do nothing
|
||||
}
|
||||
|
||||
void* ExampleBrowserMemoryFunc()
|
||||
{
|
||||
//don't create local store memory, just return 0
|
||||
return new ExampleBrowserThreadLocalStorage;
|
||||
}
|
||||
|
||||
void ExampleBrowserMemoryReleaseFunc(void* ptr)
|
||||
{
|
||||
ExampleBrowserThreadLocalStorage* p = (ExampleBrowserThreadLocalStorage*)ptr;
|
||||
delete p;
|
||||
}
|
||||
|
||||
struct btInProcessExampleBrowserInternalData
|
||||
{
|
||||
ExampleBrowserArgs m_args;
|
||||
b3ThreadSupportInterface* m_threadSupport;
|
||||
SharedMemoryInterface* m_sharedMem;
|
||||
};
|
||||
|
||||
btInProcessExampleBrowserInternalData* btCreateInProcessExampleBrowser(int argc, char** argv2, bool useInProcessMemory)
|
||||
{
|
||||
btInProcessExampleBrowserInternalData* data = new btInProcessExampleBrowserInternalData;
|
||||
|
||||
data->m_sharedMem = useInProcessMemory ? new InProcessMemory : 0;
|
||||
|
||||
int numThreads = 1;
|
||||
int i;
|
||||
|
||||
data->m_threadSupport = createExampleBrowserThreadSupport(numThreads);
|
||||
|
||||
printf("argc=%d\n", argc);
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
printf("argv[%d] = %s\n", i, argv2[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < data->m_threadSupport->getNumTasks(); i++)
|
||||
{
|
||||
ExampleBrowserThreadLocalStorage* storage = (ExampleBrowserThreadLocalStorage*)data->m_threadSupport->getThreadLocalMemory(i);
|
||||
b3Assert(storage);
|
||||
storage->threadId = i;
|
||||
storage->m_sharedMem = data->m_sharedMem;
|
||||
}
|
||||
|
||||
data->m_args.m_cs = data->m_threadSupport->createCriticalSection();
|
||||
data->m_args.m_cs->setSharedParam(0, eExampleBrowserIsUnInitialized);
|
||||
data->m_args.m_argc = argc;
|
||||
data->m_args.m_argv = argv2;
|
||||
|
||||
for (i = 0; i < numThreads; i++)
|
||||
{
|
||||
data->m_threadSupport->runTask(B3_THREAD_SCHEDULE_TASK, (void*)&data->m_args, i);
|
||||
}
|
||||
|
||||
while (data->m_args.m_cs->getSharedParam(0) == eExampleBrowserIsUnInitialized)
|
||||
{
|
||||
b3Clock::usleep(1000);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
bool btIsExampleBrowserTerminated(btInProcessExampleBrowserInternalData* data)
|
||||
{
|
||||
return (data->m_args.m_cs->getSharedParam(0) == eExampleBrowserHasTerminated);
|
||||
}
|
||||
|
||||
SharedMemoryInterface* btGetSharedMemoryInterface(btInProcessExampleBrowserInternalData* data)
|
||||
{
|
||||
return data->m_sharedMem;
|
||||
}
|
||||
|
||||
void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data)
|
||||
{
|
||||
int numActiveThreads = 1;
|
||||
|
||||
data->m_args.m_cs->lock();
|
||||
data->m_args.m_cs->setSharedParam(0, eRequestTerminateExampleBrowser);
|
||||
data->m_args.m_cs->unlock();
|
||||
|
||||
while (numActiveThreads)
|
||||
{
|
||||
int arg0, arg1;
|
||||
if (data->m_threadSupport->isTaskCompleted(&arg0, &arg1, 0))
|
||||
{
|
||||
numActiveThreads--;
|
||||
printf("numActiveThreads = %d\n", numActiveThreads);
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("polling..");
|
||||
b3Clock::usleep(0);
|
||||
}
|
||||
};
|
||||
|
||||
printf("btShutDownExampleBrowser stopping threads\n");
|
||||
data->m_threadSupport->deleteCriticalSection(data->m_args.m_cs);
|
||||
|
||||
delete data->m_threadSupport;
|
||||
delete data->m_sharedMem;
|
||||
delete data;
|
||||
}
|
||||
|
||||
struct btInProcessExampleBrowserMainThreadInternalData
|
||||
{
|
||||
ExampleEntriesPhysicsServer m_examples;
|
||||
DefaultBrowser* m_exampleBrowser;
|
||||
SharedMemoryInterface* m_sharedMem;
|
||||
b3Clock m_clock;
|
||||
};
|
||||
|
||||
btInProcessExampleBrowserMainThreadInternalData* btCreateInProcessExampleBrowserMainThread(int argc, char** argv, bool useInProcessMemory)
|
||||
{
|
||||
btInProcessExampleBrowserMainThreadInternalData* data = new btInProcessExampleBrowserMainThreadInternalData;
|
||||
data->m_examples.initExampleEntries();
|
||||
data->m_exampleBrowser = new DefaultBrowser(&data->m_examples);
|
||||
data->m_sharedMem = useInProcessMemory ? new InProcessMemory : 0;
|
||||
data->m_exampleBrowser->setSharedMemoryInterface(data->m_sharedMem);
|
||||
bool init;
|
||||
init = data->m_exampleBrowser->init(argc, argv);
|
||||
data->m_clock.reset();
|
||||
return data;
|
||||
}
|
||||
|
||||
bool btIsExampleBrowserMainThreadTerminated(btInProcessExampleBrowserMainThreadInternalData* data)
|
||||
{
|
||||
return data->m_exampleBrowser->requestedExit();
|
||||
}
|
||||
|
||||
void btUpdateInProcessExampleBrowserMainThread(btInProcessExampleBrowserMainThreadInternalData* data)
|
||||
{
|
||||
float deltaTimeInSeconds = data->m_clock.getTimeMicroseconds() / 1000000.f;
|
||||
data->m_clock.reset();
|
||||
data->m_exampleBrowser->updateGraphics();
|
||||
data->m_exampleBrowser->update(deltaTimeInSeconds);
|
||||
}
|
||||
void btShutDownExampleBrowserMainThread(btInProcessExampleBrowserMainThreadInternalData* data)
|
||||
{
|
||||
data->m_exampleBrowser->setSharedMemoryInterface(0);
|
||||
delete data->m_exampleBrowser;
|
||||
delete data;
|
||||
}
|
||||
|
||||
class SharedMemoryInterface* btGetSharedMemoryInterfaceMainThread(btInProcessExampleBrowserMainThreadInternalData* data)
|
||||
{
|
||||
return data->m_sharedMem;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef IN_PROCESS_EXAMPLE_BROWSER_H
|
||||
#define IN_PROCESS_EXAMPLE_BROWSER_H
|
||||
|
||||
struct btInProcessExampleBrowserInternalData;
|
||||
|
||||
btInProcessExampleBrowserInternalData* btCreateInProcessExampleBrowser(int argc, char** argv2, bool useInProcessMemory);
|
||||
|
||||
bool btIsExampleBrowserTerminated(btInProcessExampleBrowserInternalData* data);
|
||||
|
||||
void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data);
|
||||
|
||||
class SharedMemoryInterface* btGetSharedMemoryInterface(btInProcessExampleBrowserInternalData* data);
|
||||
|
||||
///////////////////////
|
||||
|
||||
struct btInProcessExampleBrowserMainThreadInternalData;
|
||||
|
||||
btInProcessExampleBrowserMainThreadInternalData* btCreateInProcessExampleBrowserMainThread(int argc, char** argv, bool useInProcessMemory);
|
||||
|
||||
bool btIsExampleBrowserMainThreadTerminated(btInProcessExampleBrowserMainThreadInternalData* data);
|
||||
|
||||
void btUpdateInProcessExampleBrowserMainThread(btInProcessExampleBrowserMainThreadInternalData* data);
|
||||
|
||||
void btShutDownExampleBrowserMainThread(btInProcessExampleBrowserMainThreadInternalData* data);
|
||||
|
||||
class SharedMemoryInterface* btGetSharedMemoryInterfaceMainThread(btInProcessExampleBrowserMainThreadInternalData* data);
|
||||
|
||||
//////////////////////
|
||||
|
||||
#endif //IN_PROCESS_EXAMPLE_BROWSER_H
|
||||
1347
Engine/lib/bullet/examples/ExampleBrowser/OpenGLExampleBrowser.cpp
Normal file
1347
Engine/lib/bullet/examples/ExampleBrowser/OpenGLExampleBrowser.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef OPENGL_BROWSER_GUI_H
|
||||
#define OPENGL_BROWSER_GUI_H
|
||||
|
||||
#include "ExampleBrowserInterface.h"
|
||||
|
||||
class OpenGLExampleBrowser : public ExampleBrowserInterface
|
||||
{
|
||||
struct OpenGLExampleBrowserInternalData* m_internalData;
|
||||
|
||||
public:
|
||||
OpenGLExampleBrowser(class ExampleEntries* examples);
|
||||
virtual ~OpenGLExampleBrowser();
|
||||
|
||||
virtual CommonExampleInterface* getCurrentExample();
|
||||
|
||||
virtual bool init(int argc, char* argv[]);
|
||||
|
||||
virtual void update(float deltaTime);
|
||||
|
||||
virtual void updateGraphics();
|
||||
|
||||
virtual bool requestedExit();
|
||||
|
||||
virtual void setSharedMemoryInterface(class SharedMemoryInterface* sharedMem);
|
||||
|
||||
static void registerFileImporter(const char* extension, CommonExampleInterface::CreateFunc* createFunc);
|
||||
};
|
||||
|
||||
#endif //OPENGL_BROWSER_GUI_H
|
||||
1555
Engine/lib/bullet/examples/ExampleBrowser/OpenGLGuiHelper.cpp
Normal file
1555
Engine/lib/bullet/examples/ExampleBrowser/OpenGLGuiHelper.cpp
Normal file
File diff suppressed because it is too large
Load diff
113
Engine/lib/bullet/examples/ExampleBrowser/OpenGLGuiHelper.h
Normal file
113
Engine/lib/bullet/examples/ExampleBrowser/OpenGLGuiHelper.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
#ifndef OPENGL_GUI_HELPER_H
|
||||
#define OPENGL_GUI_HELPER_H
|
||||
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
||||
|
||||
class btCollisionShape;
|
||||
class btTransform;
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "../OpenGLWindow/GLInstanceGraphicsShape.h"
|
||||
|
||||
struct OpenGLGuiHelper : public GUIHelperInterface
|
||||
{
|
||||
struct OpenGLGuiHelperInternalData* m_data;
|
||||
|
||||
OpenGLGuiHelper(struct CommonGraphicsApp* glApp, bool useOpenGL2);
|
||||
|
||||
virtual ~OpenGLGuiHelper();
|
||||
|
||||
virtual struct CommonRenderInterface* getRenderInterface();
|
||||
virtual const struct CommonRenderInterface* getRenderInterface() const;
|
||||
|
||||
virtual void createRigidBodyGraphicsObject(btRigidBody* body, const btVector3& color);
|
||||
|
||||
virtual void createCollisionObjectGraphicsObject(btCollisionObject* body, const btVector3& color);
|
||||
|
||||
virtual int registerTexture(const unsigned char* texels, int width, int height);
|
||||
virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType, int textureId);
|
||||
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
|
||||
virtual void removeAllGraphicsInstances();
|
||||
virtual void removeGraphicsInstance(int graphicsUid);
|
||||
virtual void changeInstanceFlags(int instanceUid, int flags);
|
||||
virtual void changeRGBAColor(int instanceUid, const double rgbaColor[4]);
|
||||
virtual void changeScaling(int instanceUid, const double scaling[3]);
|
||||
virtual void changeSpecularColor(int instanceUid, const double specularColor[3]);
|
||||
virtual void changeTexture(int textureUniqueId, const unsigned char* rgbTexels, int width, int height);
|
||||
virtual void removeTexture(int textureUid);
|
||||
virtual int getShapeIndexFromInstance(int instanceUid);
|
||||
virtual void replaceTexture(int shapeIndex, int textureUid);
|
||||
virtual void updateShape(int shapeIndex, float* vertices, int numVertices);
|
||||
virtual void setBackgroundColor(const double rgbBackground[3]);
|
||||
virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape);
|
||||
|
||||
virtual void syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld);
|
||||
|
||||
virtual void render(const btDiscreteDynamicsWorld* rbWorld);
|
||||
|
||||
virtual void createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld);
|
||||
|
||||
virtual struct Common2dCanvasInterface* get2dCanvasInterface();
|
||||
|
||||
virtual CommonParameterInterface* getParameterInterface();
|
||||
|
||||
virtual struct CommonGraphicsApp* getAppInterface();
|
||||
|
||||
virtual void setUpAxis(int axis);
|
||||
|
||||
virtual void resetCamera(float camDist, float yaw, float pitch, float camPosX, float camPosY, float camPosZ);
|
||||
virtual bool getCameraInfo(int* width, int* height, float viewMatrix[16], float projectionMatrix[16], float camUp[3], float camForward[3], float hor[3], float vert[3], float* yaw, float* pitch, float* camDist, float cameraTarget[3]) const;
|
||||
|
||||
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
|
||||
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
|
||||
float* depthBuffer, int depthBufferSizeInPixels,
|
||||
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
|
||||
int startPixelIndex, int destinationWidth,
|
||||
int destinationHeight, int* numPixelsCopied);
|
||||
|
||||
virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]);
|
||||
virtual void setProjectiveTexture(bool useProjectiveTexture);
|
||||
|
||||
virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld);
|
||||
|
||||
virtual void drawText3D(const char* txt, float position[3], float orientation[4], float color[4], float size, int optionFlag);
|
||||
|
||||
virtual void drawText3D(const char* txt, float posX, float posY, float posZ, float size);
|
||||
|
||||
virtual int addUserDebugText3D(const char* txt, const double positionXYZ[3], const double textColorRGB[3], double size, double lifeTime)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual int addUserDebugLine(const double debugLineFromXYZ[3], const double debugLineToXYZ[3], const double debugLineColorRGB[3], double lineWidth, double lifeTime, int trackingVisualShapeIndex, int replaceItemUid)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
virtual int addUserDebugParameter(const char* txt, double rangeMin, double rangeMax, double startValue)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual void removeUserDebugItem(int debugItemUniqueId)
|
||||
{
|
||||
}
|
||||
virtual void removeAllUserDebugItems()
|
||||
{
|
||||
}
|
||||
|
||||
void renderInternalGl2(int pass, const btDiscreteDynamicsWorld* dynamicsWorld);
|
||||
|
||||
void setVRMode(bool vrMode);
|
||||
|
||||
void setVisualizerFlag(int flag, int enable);
|
||||
|
||||
virtual void setVisualizerFlagCallback(VisualizerFlagCallback callback);
|
||||
|
||||
virtual void dumpFramesToVideo(const char* mp4FileName);
|
||||
|
||||
int createCheckeredTexture(int r, int g, int b);
|
||||
|
||||
void computeSoftBodyVertices(btCollisionShape* collisionShape,
|
||||
btAlignedObjectArray<GLInstanceVertex>& gfxVertices,
|
||||
btAlignedObjectArray<int>& indices);
|
||||
};
|
||||
|
||||
#endif //OPENGL_GUI_HELPER_H
|
||||
112
Engine/lib/bullet/examples/ExampleBrowser/main.cpp
Normal file
112
Engine/lib/bullet/examples/ExampleBrowser/main.cpp
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#include "OpenGLExampleBrowser.h"
|
||||
|
||||
#include "Bullet3Common/b3CommandLineArgs.h"
|
||||
#include "../Utils/b3Clock.h"
|
||||
|
||||
#include "ExampleEntries.h"
|
||||
#include "Bullet3Common/b3Logging.h"
|
||||
|
||||
#include "../Importers/ImportObjDemo/ImportObjExample.h"
|
||||
#include "../Importers/ImportBsp/ImportBspExample.h"
|
||||
#include "../Importers/ImportColladaDemo/ImportColladaSetup.h"
|
||||
#include "../Importers/ImportSTLDemo/ImportSTLSetup.h"
|
||||
#include "../Importers/ImportURDFDemo/ImportURDFSetup.h"
|
||||
#include "../Importers/ImportSDFDemo/ImportSDFSetup.h"
|
||||
#include "../Importers/ImportSTLDemo/ImportSTLSetup.h"
|
||||
#include "../Importers/ImportBullet/SerializeSetup.h"
|
||||
|
||||
#include "LinearMath/btAlignedAllocator.h"
|
||||
|
||||
static double gMinUpdateTimeMicroSecs = 1000.;
|
||||
|
||||
static bool interrupted = false;
|
||||
static OpenGLExampleBrowser* sExampleBrowser = 0;
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <signal.h>
|
||||
#include <err.h>
|
||||
#include <unistd.h>
|
||||
static void cleanup(int signo)
|
||||
{
|
||||
if (!interrupted)
|
||||
{ // this is the second time, we're hanging somewhere
|
||||
b3Printf("Aborting and deleting SharedMemoryCommon object");
|
||||
delete sExampleBrowser;
|
||||
sleep(1);
|
||||
sExampleBrowser = 0;
|
||||
errx(EXIT_FAILURE, "aborted example on signal %d", signo);
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Printf("no action");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
interrupted = true;
|
||||
warnx("caught signal %d", signo);
|
||||
}
|
||||
#endif //_WIN32
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#ifndef _WIN32
|
||||
struct sigaction action;
|
||||
memset(&action, 0x0, sizeof(action));
|
||||
action.sa_handler = cleanup;
|
||||
static const int signos[] = {SIGHUP, SIGINT, SIGQUIT, SIGABRT, SIGSEGV, SIGPIPE, SIGTERM};
|
||||
for (int ii(0); ii < sizeof(signos) / sizeof(*signos); ++ii)
|
||||
{
|
||||
if (0 != sigaction(signos[ii], &action, NULL))
|
||||
{
|
||||
err(EXIT_FAILURE, "signal %d", signos[ii]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
b3CommandLineArgs args(argc, argv);
|
||||
b3Clock clock;
|
||||
args.GetCmdLineArgument("minUpdateTimeMicroSecs", gMinUpdateTimeMicroSecs);
|
||||
|
||||
ExampleEntriesAll examples;
|
||||
examples.initExampleEntries();
|
||||
|
||||
OpenGLExampleBrowser* exampleBrowser = new OpenGLExampleBrowser(&examples);
|
||||
sExampleBrowser = exampleBrowser; //for <CTRL-C> etc, cleanup shared memory
|
||||
bool init = exampleBrowser->init(argc, argv);
|
||||
exampleBrowser->registerFileImporter(".urdf", ImportURDFCreateFunc);
|
||||
exampleBrowser->registerFileImporter(".sdf", ImportSDFCreateFunc);
|
||||
exampleBrowser->registerFileImporter(".obj", ImportObjCreateFunc);
|
||||
exampleBrowser->registerFileImporter(".stl", ImportSTLCreateFunc);
|
||||
exampleBrowser->registerFileImporter(".bullet", SerializeBulletCreateFunc);
|
||||
|
||||
clock.reset();
|
||||
if (init)
|
||||
{
|
||||
do
|
||||
{
|
||||
float deltaTimeInSeconds = clock.getTimeMicroseconds() / 1000000.f;
|
||||
if (deltaTimeInSeconds > 0.1)
|
||||
{
|
||||
deltaTimeInSeconds = 0.1;
|
||||
}
|
||||
if (deltaTimeInSeconds < (gMinUpdateTimeMicroSecs / 1e6))
|
||||
{
|
||||
b3Clock::usleep(gMinUpdateTimeMicroSecs / 10.);
|
||||
}
|
||||
else
|
||||
{
|
||||
clock.reset();
|
||||
exampleBrowser->update(deltaTimeInSeconds);
|
||||
}
|
||||
} while (!exampleBrowser->requestedExit() && !interrupted);
|
||||
}
|
||||
delete exampleBrowser;
|
||||
}
|
||||
|
||||
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
int numBytesLeaked = btDumpMemoryLeaks();
|
||||
btAssert(numBytesLeaked == 0);
|
||||
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
|
||||
return 0;
|
||||
}
|
||||
320
Engine/lib/bullet/examples/ExampleBrowser/premake4.lua
Normal file
320
Engine/lib/bullet/examples/ExampleBrowser/premake4.lua
Normal file
|
|
@ -0,0 +1,320 @@
|
|||
project "App_BulletExampleBrowser"
|
||||
|
||||
language "C++"
|
||||
|
||||
kind "ConsoleApp"
|
||||
|
||||
if os.is("Linux") then
|
||||
buildoptions{"-fPIC"}
|
||||
end
|
||||
|
||||
if _OPTIONS["enable_grpc"] then
|
||||
initGRPC()
|
||||
defines{"ENABLE_STATIC_GRPC_PLUGIN"}
|
||||
files {
|
||||
"../../examples/SharedMemory/PhysicsClientGRPC.cpp",
|
||||
"../../examples/SharedMemory/PhysicsClientGRPC.h",
|
||||
"../../examples/SharedMemory/PhysicsClientGRPC_C_API.cpp",
|
||||
"../../examples/SharedMemory/PhysicsClientGRPC_C_API.h",
|
||||
"../../examples/SharedMemory/plugins/grpcPlugin/grpcPlugin.cpp",
|
||||
|
||||
}
|
||||
end
|
||||
|
||||
hasCL = findOpenCL("clew")
|
||||
|
||||
if (hasCL) then
|
||||
initOpenCL("clew")
|
||||
end
|
||||
|
||||
links{"BulletExampleBrowserLib","gwen", "OpenGL_Window","BulletSoftBody", "BulletInverseDynamicsUtils", "BulletInverseDynamics", "BulletDynamics","BulletCollision","LinearMath","BussIK", "Bullet3Common"}
|
||||
initOpenGL()
|
||||
initGlew()
|
||||
|
||||
includedirs {
|
||||
".",
|
||||
"../../src",
|
||||
"../../examples/SharedMemory",
|
||||
"../ThirdPartyLibs",
|
||||
}
|
||||
|
||||
|
||||
if os.is("MacOSX") then
|
||||
links{"Cocoa.framework"}
|
||||
end
|
||||
|
||||
if (hasCL) then
|
||||
links {
|
||||
"Bullet3OpenCL_clew",
|
||||
"Bullet3Dynamics",
|
||||
"Bullet3Collision",
|
||||
"Bullet3Geometry",
|
||||
"Bullet3Common",
|
||||
}
|
||||
end
|
||||
|
||||
if _OPTIONS["audio"] then
|
||||
files {"../TinyAudio/*.cpp"}
|
||||
defines {"B3_ENABLE_TINY_AUDIO"}
|
||||
|
||||
if os.is("Windows") then
|
||||
links {"winmm","Wsock32","dsound"}
|
||||
defines {"WIN32","__WINDOWS_MM__","__WINDOWS_DS__"}
|
||||
end
|
||||
|
||||
if os.is("Linux") then initX11()
|
||||
defines {"__OS_LINUX__","__LINUX_ALSA__"}
|
||||
links {"asound","pthread"}
|
||||
end
|
||||
|
||||
|
||||
if os.is("MacOSX") then
|
||||
links{"Cocoa.framework"}
|
||||
links{"CoreAudio.framework", "coreMIDI.framework", "Cocoa.framework"}
|
||||
defines {"__OS_MACOSX__","__MACOSX_CORE__"}
|
||||
end
|
||||
end
|
||||
|
||||
if _OPTIONS["lua"] then
|
||||
includedirs{"../ThirdPartyLibs/lua-5.2.3/src"}
|
||||
links {"lua-5.2.3"}
|
||||
defines {"ENABLE_LUA"}
|
||||
files {"../LuaDemo/LuaPhysicsSetup.cpp"}
|
||||
end
|
||||
|
||||
defines {"INCLUDE_CLOTH_DEMOS"}
|
||||
|
||||
files {
|
||||
|
||||
"main.cpp",
|
||||
"ExampleEntries.cpp",
|
||||
"../InverseKinematics/*",
|
||||
"../BulletRobotics/FixJointBoxes.cpp",
|
||||
"../BulletRobotics/BoxStack.cpp",
|
||||
"../BulletRobotics/JointLimit.cpp",
|
||||
"../TinyRenderer/geometry.cpp",
|
||||
"../TinyRenderer/model.cpp",
|
||||
"../TinyRenderer/tgaimage.cpp",
|
||||
"../TinyRenderer/our_gl.cpp",
|
||||
"../TinyRenderer/TinyRenderer.cpp",
|
||||
"../SharedMemory/IKTrajectoryHelper.cpp",
|
||||
"../SharedMemory/IKTrajectoryHelper.h",
|
||||
"../SharedMemory/PhysicsClientC_API.cpp",
|
||||
"../SharedMemory/PhysicsClientC_API.h",
|
||||
"../SharedMemory/PhysicsServerExample.cpp",
|
||||
"../SharedMemory/PhysicsServerExampleBullet2.cpp",
|
||||
"../SharedMemory/PhysicsClientExample.cpp",
|
||||
"../SharedMemory/PhysicsServer.cpp",
|
||||
"../SharedMemory/PhysicsServerSharedMemory.cpp",
|
||||
"../SharedMemory/PhysicsClientSharedMemory.cpp",
|
||||
"../SharedMemory/PhysicsClientSharedMemory_C_API.cpp",
|
||||
"../SharedMemory/PhysicsClientSharedMemory_C_API.h",
|
||||
"../SharedMemory/PhysicsClientSharedMemory2.cpp",
|
||||
"../SharedMemory/PhysicsClientSharedMemory2.h",
|
||||
"../SharedMemory/PhysicsClientSharedMemory2_C_API.cpp",
|
||||
"../SharedMemory/PhysicsClientSharedMemory2_C_API.h",
|
||||
"../SharedMemory/SharedMemoryCommandProcessor.cpp",
|
||||
"../SharedMemory/SharedMemoryCommandProcessor.h",
|
||||
"../SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp",
|
||||
"../SharedMemory/GraphicsClientExample.cpp",
|
||||
"../SharedMemory/GraphicsClientExample.h",
|
||||
"../SharedMemory/GraphicsServerExample.cpp",
|
||||
"../SharedMemory/GraphicsServerExample.h",
|
||||
"../SharedMemory/GraphicsSharedMemoryBlock.h",
|
||||
"../SharedMemory/GraphicsSharedMemoryCommands.h",
|
||||
"../SharedMemory/GraphicsSharedMemoryPublic.h",
|
||||
"../SharedMemory/RemoteGUIHelper.cpp",
|
||||
"../SharedMemory/RemoteGUIHelper.h",
|
||||
"../SharedMemory/PhysicsClient.cpp",
|
||||
"../SharedMemory/PosixSharedMemory.cpp",
|
||||
"../SharedMemory/Win32SharedMemory.cpp",
|
||||
"../SharedMemory/InProcessMemory.cpp",
|
||||
"../SharedMemory/PhysicsDirect.cpp",
|
||||
"../SharedMemory/PhysicsDirect.h",
|
||||
"../SharedMemory/PhysicsDirectC_API.cpp",
|
||||
"../SharedMemory/PhysicsDirectC_API.h",
|
||||
"../SharedMemory/PhysicsLoopBack.cpp",
|
||||
"../SharedMemory/PhysicsLoopBack.h",
|
||||
"../SharedMemory/PhysicsLoopBackC_API.cpp",
|
||||
"../SharedMemory/PhysicsLoopBackC_API.h",
|
||||
"../SharedMemory/PhysicsServerCommandProcessor.cpp",
|
||||
"../SharedMemory/PhysicsServerCommandProcessor.h",
|
||||
"../SharedMemory/b3PluginManager.cpp",
|
||||
"../SharedMemory/plugins/collisionFilterPlugin/collisionFilterPlugin.cpp",
|
||||
"../SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp",
|
||||
"../SharedMemory/plugins/tinyRendererPlugin/tinyRendererPlugin.cpp",
|
||||
"../SharedMemory/plugins/pdControlPlugin/pdControlPlugin.cpp",
|
||||
"../SharedMemory/plugins/pdControlPlugin/pdControlPlugin.h",
|
||||
"../SharedMemory/SharedMemoryCommands.h",
|
||||
"../SharedMemory/SharedMemoryPublic.h",
|
||||
"../SharedMemory/b3RobotSimulatorClientAPI_NoGUI.cpp",
|
||||
"../SharedMemory/b3RobotSimulatorClientAPI_NoGUI.h",
|
||||
"../SharedMemory/b3RobotSimulatorClientAPI_NoDirect.cpp",
|
||||
"../SharedMemory/b3RobotSimulatorClientAPI_NoDirect.h",
|
||||
"../MultiThreading/MultiThreadingExample.cpp",
|
||||
"../MultiThreading/b3PosixThreadSupport.cpp",
|
||||
"../MultiThreading/b3Win32ThreadSupport.cpp",
|
||||
"../MultiThreading/b3ThreadSupportInterface.cpp",
|
||||
"../InverseDynamics/InverseDynamicsExample.cpp",
|
||||
"../InverseDynamics/InverseDynamicsExample.h",
|
||||
"../RobotSimulator/b3RobotSimulatorClientAPI.cpp",
|
||||
"../RobotSimulator/b3RobotSimulatorClientAPI.h",
|
||||
"../BasicDemo/BasicExample.*",
|
||||
"../Tutorial/*",
|
||||
"../ExtendedTutorials/*",
|
||||
"../Utils/RobotLoggingUtil.cpp",
|
||||
"../Utils/RobotLoggingUtil.h",
|
||||
"../Evolution/NN3DWalkers.cpp",
|
||||
"../Evolution/NN3DWalkers.h",
|
||||
"../Collision/*",
|
||||
"../RoboticsLearning/*",
|
||||
"../Collision/Internal/*",
|
||||
"../Benchmarks/*",
|
||||
"../MultiThreadedDemo/*",
|
||||
"../Heightfield/HeightfieldExample.*",
|
||||
"../CommonInterfaces/*.h",
|
||||
"../ForkLift/ForkLiftDemo.*",
|
||||
"../Importers/**",
|
||||
"../../Extras/Serialize/BulletWorldImporter/*",
|
||||
"../../Extras/Serialize/BulletFileLoader/*",
|
||||
"../Planar2D/Planar2D.*",
|
||||
"../RenderingExamples/*",
|
||||
"../VoronoiFracture/*",
|
||||
"../SoftDemo/*",
|
||||
"../DeformableDemo/*",
|
||||
"../ReducedDeformableDemo/*",
|
||||
"../RollingFrictionDemo/*",
|
||||
"../rbdl/*",
|
||||
"../FractureDemo/*",
|
||||
"../DynamicControlDemo/*",
|
||||
"../Constraints/*",
|
||||
"../Vehicles/*",
|
||||
"../Raycast/*",
|
||||
"../MultiBody/MultiDofDemo.cpp",
|
||||
"../MultiBody/SerialChains.cpp",
|
||||
"../MultiBody/TestJointTorqueSetup.cpp",
|
||||
"../MultiBody/Pendulum.cpp",
|
||||
"../MultiBody/MultiBodySoftContact.cpp",
|
||||
"../MultiBody/MultiBodyConstraintFeedback.cpp",
|
||||
"../MultiBody/InvertedPendulumPDControl.cpp",
|
||||
"../MultiBody/KinematicMultiBodyExample.cpp",
|
||||
"../RigidBody/RigidBodySoftContact.cpp",
|
||||
"../RigidBody/KinematicRigidBodyExample.cpp",
|
||||
"../ThirdPartyLibs/stb_image/stb_image.cpp",
|
||||
"../ThirdPartyLibs/Wavefront/tiny_obj_loader.*",
|
||||
"../GyroscopicDemo/GyroscopicSetup.cpp",
|
||||
"../GyroscopicDemo/GyroscopicSetup.h",
|
||||
"../ThirdPartyLibs/tinyxml2/tinyxml2.cpp",
|
||||
"../ThirdPartyLibs/tinyxml2/tinyxml2.h",
|
||||
}
|
||||
|
||||
if _OPTIONS["enable_stable_pd"] then
|
||||
defines {"STATIC_LINK_SPD_PLUGIN"}
|
||||
files {
|
||||
"../SharedMemory/plugins/stablePDPlugin/SpAlg.cpp",
|
||||
"../SharedMemory/plugins/stablePDPlugin/SpAlg.h",
|
||||
"../SharedMemory/plugins/stablePDPlugin/Shape.cpp",
|
||||
"../SharedMemory/plugins/stablePDPlugin/Shape.h",
|
||||
"../SharedMemory/plugins/stablePDPlugin/RBDUtil.cpp",
|
||||
"../SharedMemory/plugins/stablePDPlugin/RBDUtil.h",
|
||||
"../SharedMemory/plugins/stablePDPlugin/RBDModel.cpp",
|
||||
"../SharedMemory/plugins/stablePDPlugin/RBDModel.h",
|
||||
"../SharedMemory/plugins/stablePDPlugin/MathUtil.cpp",
|
||||
"../SharedMemory/plugins/stablePDPlugin/MathUtil.h",
|
||||
"../SharedMemory/plugins/stablePDPlugin/KinTree.cpp",
|
||||
"../SharedMemory/plugins/stablePDPlugin/KinTree.h",
|
||||
"../SharedMemory/plugins/stablePDPlugin/BulletConversion.cpp",
|
||||
"../SharedMemory/plugins/stablePDPlugin/BulletConversion.h",
|
||||
}
|
||||
end
|
||||
if (hasCL and findOpenGL3()) then
|
||||
files {
|
||||
"../OpenCL/broadphase/*",
|
||||
"../OpenCL/CommonOpenCL/*",
|
||||
"../OpenCL/rigidbody/GpuConvexScene.cpp",
|
||||
"../OpenCL/rigidbody/GpuRigidBodyDemo.cpp",
|
||||
}
|
||||
end
|
||||
|
||||
if (_OPTIONS["enable_static_vr_plugin"]) then
|
||||
files {"../../examples/SharedMemory/plugins/vrSyncPlugin/vrSyncPlugin.cpp"}
|
||||
end
|
||||
|
||||
if os.is("Linux") then
|
||||
initX11()
|
||||
end
|
||||
|
||||
|
||||
|
||||
project "BulletExampleBrowserLib"
|
||||
|
||||
hasCL = findOpenCL("clew")
|
||||
|
||||
if (hasCL) then
|
||||
|
||||
-- project ("App_Bullet3_OpenCL_Demos_" .. vendor)
|
||||
|
||||
initOpenCL("clew")
|
||||
|
||||
end
|
||||
|
||||
language "C++"
|
||||
|
||||
kind "StaticLib"
|
||||
|
||||
includedirs {
|
||||
".",
|
||||
"../../src",
|
||||
"../ThirdPartyLibs",
|
||||
}
|
||||
|
||||
if os.is("Linux") then
|
||||
buildoptions{"-fPIC"}
|
||||
end
|
||||
|
||||
if _OPTIONS["lua"] then
|
||||
includedirs{"../ThirdPartyLibs/lua-5.2.3/src"}
|
||||
links {"lua-5.2.3"}
|
||||
defines {"ENABLE_LUA"}
|
||||
files {"../LuaDemo/LuaPhysicsSetup.cpp"}
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
initOpenGL()
|
||||
initGlew()
|
||||
|
||||
defines {"INCLUDE_CLOTH_DEMOS"}
|
||||
|
||||
|
||||
|
||||
files {
|
||||
"OpenGLExampleBrowser.cpp",
|
||||
"OpenGLGuiHelper.cpp",
|
||||
"OpenGLExampleBrowser.cpp",
|
||||
"../Utils/b3Clock.cpp",
|
||||
"../Utils/b3Clock.h",
|
||||
"../Utils/ChromeTraceUtil.cpp",
|
||||
"../Utils/ChromeTraceUtil.h",
|
||||
"*.h",
|
||||
"GwenGUISupport/*.cpp",
|
||||
"GwenGUISupport/*.h",
|
||||
"CollisionShape2TriangleMesh.cpp",
|
||||
"CollisionShape2TriangleMesh.h",
|
||||
"../Utils/b3ResourcePath.*",
|
||||
"GL_ShapeDrawer.cpp",
|
||||
"InProcessExampleBrowser.cpp",
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if os.is("Linux") then
|
||||
initX11()
|
||||
end
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue