More physics stuff
This commit is contained in:
parent
c1dfe5c80e
commit
50fdd455e3
3 changed files with 71 additions and 2 deletions
|
@ -11,6 +11,9 @@ include_directories(${SFML_INCLUDE_DIR})
|
||||||
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
|
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
|
||||||
include_directories(${EIGEN3_INCLUDE_DIR})
|
include_directories(${EIGEN3_INCLUDE_DIR})
|
||||||
|
|
||||||
|
# Find and include ReactPhysics3D
|
||||||
|
find_package(ReactPhysics3D REQUIRED)
|
||||||
|
|
||||||
|
|
||||||
# Set up your project's source files
|
# Set up your project's source files
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
|
@ -21,8 +24,8 @@ set(SOURCES
|
||||||
src/game/game.h
|
src/game/game.h
|
||||||
src/util/easylogging++.cc
|
src/util/easylogging++.cc
|
||||||
src/util/easylogging++.h
|
src/util/easylogging++.h
|
||||||
src/coordinates/isometric_coordinate_transformer.cpp
|
src/coordinates/coordinate_transformer.cpp
|
||||||
src/coordinates/isometric_coordinate_transformer.h
|
src/coordinates/coordinate_transformer.h
|
||||||
src/coordinates/translated_coordinates.cpp
|
src/coordinates/translated_coordinates.cpp
|
||||||
src/coordinates/translated_coordinates.h
|
src/coordinates/translated_coordinates.h
|
||||||
src/coordinates/coordinates.h
|
src/coordinates/coordinates.h
|
||||||
|
@ -33,9 +36,17 @@ set(SOURCES
|
||||||
src/game/game_factory.cpp
|
src/game/game_factory.cpp
|
||||||
src/game/game_factory.hpp)
|
src/game/game_factory.hpp)
|
||||||
|
|
||||||
|
set(PHYSICS_00_SOURCES
|
||||||
|
src/prototypes/physics_00.cpp
|
||||||
|
)
|
||||||
|
|
||||||
# Add an executable target
|
# Add an executable target
|
||||||
add_executable(Holesome ${SOURCES})
|
add_executable(Holesome ${SOURCES})
|
||||||
|
add_executable(Physics_00 ${PHYSICS_00_SOURCES})
|
||||||
|
|
||||||
# Link SFML and other libraries to your executable target
|
# Link SFML and other libraries to your executable target
|
||||||
target_link_libraries(Holesome sfml-graphics sfml-audio)
|
target_link_libraries(Holesome sfml-graphics sfml-audio)
|
||||||
target_link_libraries(Holesome Eigen3::Eigen)
|
target_link_libraries(Holesome Eigen3::Eigen)
|
||||||
|
target_link_libraries(Holesome ReactPhysics3D::ReactPhysics3D)
|
||||||
|
|
||||||
|
target_link_libraries(Physics_00 ReactPhysics3D::ReactPhysics3D)
|
||||||
|
|
16
README.md
16
README.md
|
@ -49,3 +49,19 @@ Potential expansions:
|
||||||
## Project Setup
|
## Project Setup
|
||||||
|
|
||||||
Install SFML and Eigen: `sudo apt install libsfml-dev libsfml-doc libeigen3-dev`
|
Install SFML and Eigen: `sudo apt install libsfml-dev libsfml-doc libeigen3-dev`
|
||||||
|
|
||||||
|
### Compiling ReactPhysics3D from source
|
||||||
|
|
||||||
|
Website: [ReactPhysics3D](https://www.reactphysics3d.com)
|
||||||
|
|
||||||
|
1. Make sure cmake, g++ and make are installed
|
||||||
|
2. Clone the repository `git clone https://github.com/DanielChappuis/reactphysics3d.git`
|
||||||
|
3. Build and install the library
|
||||||
|
```
|
||||||
|
cd reactphysics3d
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
```
|
||||||
|
|
42
src/prototypes/physics_00.cpp
Normal file
42
src/prototypes/physics_00.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#include <reactphysics3d/reactphysics3d.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// ReactPhysics3D namespace
|
||||||
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
|
// Main function
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
// First you need to create the PhysicsCommon object.
|
||||||
|
// This is a factory module that you can use to create physics
|
||||||
|
// world and other objects. It is also responsible for
|
||||||
|
// logging and memory management
|
||||||
|
PhysicsCommon physicsCommon;
|
||||||
|
|
||||||
|
// Create a physics world
|
||||||
|
PhysicsWorld* world = physicsCommon.createPhysicsWorld();
|
||||||
|
|
||||||
|
// Create a rigid body in the world
|
||||||
|
Vector3 position(0, 20, 0);
|
||||||
|
Quaternion orientation = Quaternion::identity();
|
||||||
|
Transform transform(position, orientation);
|
||||||
|
RigidBody* body = world->createRigidBody(transform);
|
||||||
|
|
||||||
|
const decimal timeStep = 1.0f / 60.0f;
|
||||||
|
|
||||||
|
// Step the simulation a few steps
|
||||||
|
for (int i=0; i < 20; i++) {
|
||||||
|
|
||||||
|
world->update(timeStep);
|
||||||
|
|
||||||
|
// Get the updated position of the body
|
||||||
|
const Transform& transform = body->getTransform();
|
||||||
|
const Vector3& position = transform.getPosition();
|
||||||
|
|
||||||
|
// Display the position of the body
|
||||||
|
std::cout << "Body Position: (" << position.x << ", " <<
|
||||||
|
position.y << ", " << position.z << ")" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue